@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
58 lines (57 loc) • 2.28 kB
JavaScript
;
import { TypedJsNode } from "./_Base";
import { NodeParamsConfig } from "../utils/params/ParamsConfig";
import { JsType } from "../../poly/registers/nodes/types/Js";
import { JS_CONNECTION_POINT_IN_NODE_DEF, JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js";
import { ObjectVariableLight } from "./code/assemblers/objectBuilder/ObjectVariables";
import { ObjectBuilderAssemblerConstant } from "./code/assemblers/objectBuilder/ObjectBuilderAssemblerCommon";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
class OutputAmbientLightJsParamsConfig extends NodeParamsConfig {
}
const ParamsConfig = new OutputAmbientLightJsParamsConfig();
export class OutputAmbientLightJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.OUTPUT_AMBIENT_LIGHT;
}
initializeNode() {
super.initializeNode();
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(ObjectVariableLight.INTENSITY, JsConnectionPointType.FLOAT, CONNECTION_OPTIONS),
new JsConnectionPoint(ObjectVariableLight.COLOR, JsConnectionPointType.COLOR, CONNECTION_OPTIONS)
]);
}
setLines(linesController) {
const connectionPoints = this.io.inputs.namedInputConnectionPoints();
if (!connectionPoints) {
return;
}
const inputNames = connectionPoints.map((c) => c.name());
const bodyLines = [];
if (inputNames) {
for (const inputName of inputNames) {
const input = this.io.inputs.named_input(inputName);
if (input) {
const varName = this.variableForInput(linesController, inputName);
switch (inputName) {
case ObjectVariableLight.INTENSITY: {
bodyLines.push(`${ObjectBuilderAssemblerConstant.OBJECT_3D}.${inputName} = ${varName}`);
break;
}
case ObjectVariableLight.COLOR: {
bodyLines.push(`
if(${ObjectBuilderAssemblerConstant.OBJECT_3D}.${inputName} != null){
${ObjectBuilderAssemblerConstant.OBJECT_3D}.${inputName}.copy(${varName})
}`);
break;
}
}
}
}
}
linesController._addBodyLines(this, bodyLines);
}
}