@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
61 lines (60 loc) • 2.84 kB
JavaScript
"use strict";
import { TypedSopNode } from "./_Base";
import { NodeContext } from "../../poly/NodeContext";
import { MaterialSopOperation } from "../../operations/sop/Material";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
const DEFAULT = MaterialSopOperation.DEFAULT_PARAMS;
class MaterialSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param group to assign the material to */
this.group = ParamConfig.STRING(DEFAULT.group, {
objectMask: true
});
/** @param toggle on to assign the new material */
this.assignMat = ParamConfig.BOOLEAN(DEFAULT.assignMat);
/** @param the material node */
this.material = ParamConfig.NODE_PATH("", {
nodeSelection: {
context: NodeContext.MAT
},
dependentOnFoundNode: false,
visibleIf: { assignMat: 1 }
});
// cloneMat is mostly useful when swapping tex for multiple objects which have different textures
// but can also be used when requiring a unique material per object, when using a copy SOP
/** @param Cloning the material would prevent the material node to have any effect on the processed geometries. But it would allow to have multiple materials, if this was used with a Copy SOP for instance */
this.cloneMat = ParamConfig.BOOLEAN(DEFAULT.cloneMat, {
visibleIf: { assignMat: 1 },
separatorBefore: true
});
/** @param while cloning the material, you may only want to change basic properties (such as depthWrite or transparent), but you would want to still use the same custom uniforms created by GL/param nodes */
this.shareCustomUniforms = ParamConfig.BOOLEAN(DEFAULT.shareCustomUniforms, { visibleIf: { assignMat: 1, cloneMat: 1 } });
/** @param swap one texture with another */
this.swapCurrentTex = ParamConfig.BOOLEAN(DEFAULT.swapCurrentTex);
/** @param texture to swap */
this.texSrc0 = ParamConfig.STRING(DEFAULT.texSrc0, { visibleIf: { swapCurrentTex: 1 } });
/** @param texture to swap */
this.texDest0 = ParamConfig.STRING(DEFAULT.texDest0, { visibleIf: { swapCurrentTex: 1 } });
}
}
const ParamsConfig = new MaterialSopParamsConfig();
export class MaterialSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.MATERIAL;
}
initializeNode() {
this.io.inputs.setCount(1);
this.io.inputs.initInputsClonedState(MaterialSopOperation.INPUT_CLONED_STATE);
}
async cook(inputCoreGroups) {
this._operation = this._operation || new MaterialSopOperation(this._scene, this.states, this);
const coreGroup = await this._operation.cook(inputCoreGroups, this.pv);
this.setCoreGroup(coreGroup);
}
}