UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

76 lines (75 loc) 2.41 kB
"use strict"; import { ParamEvent } from "./../../poly/ParamEvent"; import { ClampToEdgeWrapping, LinearFilter, TextureLoader } from "three"; import { TypedCopNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { LUT3dlLoader, LUTCubeLoader } from "postprocessing"; import { LOADING_MANAGER } from "../../../core/loader/_Base"; import { CopType } from "../../poly/registers/nodes/types/Cop"; import { EXTENSIONS_BY_NODE_TYPE_BY_CONTEXT } from "../../../core/loader/FileExtensionRegister"; import { NodeContext } from "../../poly/NodeContext"; class LutCopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param url to fetch the lut from */ this.url = ParamConfig.STRING("", { fileBrowse: { extensions: EXTENSIONS_BY_NODE_TYPE_BY_CONTEXT[NodeContext.COP][CopType.LUT] } }); /** @param reload the image */ this.reload = ParamConfig.BUTTON(null, { callback: (node, param) => { LutCopNode.PARAM_CALLBACK_reload(node); } }); } } const ParamsConfig = new LutCopParamsConfig(); export class LutCopNode extends TypedCopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return CopType.LUT; } initializeNode() { this.io.inputs.setCount(0); } async cook(input_contents) { const textureLoader = new TextureLoader(LOADING_MANAGER); let loader = textureLoader; let onLoad = (texture) => { texture.generateMipmaps = false; texture.minFilter = LinearFilter; texture.magFilter = LinearFilter; texture.wrapS = ClampToEdgeWrapping; texture.wrapT = ClampToEdgeWrapping; texture.flipY = false; }; const { url } = this.pv; if (/.3dl$/im.test(url)) { loader = new LUT3dlLoader(LOADING_MANAGER); onLoad = null; } if (/.cube$/im.test(url)) { loader = new LUTCubeLoader(LOADING_MANAGER); onLoad = null; } loader.load(this.pv.url, (texture) => { console.log(texture); if (loader instanceof TextureLoader) { if (onLoad) { onLoad(texture); } } this.setTexture(texture); }); } static PARAM_CALLBACK_reload(node) { node.paramCallbackReload(); } paramCallbackReload() { this.p.url.setDirty(); this.p.url.emit(ParamEvent.ASSET_RELOAD_REQUEST); } }