@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
74 lines (73 loc) • 3.69 kB
JavaScript
"use strict";
import { TRIGGER_CONNECTION_NAME, TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JS_CONNECTION_POINT_IN_NODE_DEF, JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js";
import { Poly } from "../../Poly";
import { inputObject3D, setObject3DOutputLine } from "./_BaseObject3D";
import { Vector4 } from "three";
import { RefJsDefinition } from "./utils/JsDefinition";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
export var RenderPixelJsNodeOutputName = /* @__PURE__ */ ((RenderPixelJsNodeOutputName2) => {
RenderPixelJsNodeOutputName2["value"] = "value";
return RenderPixelJsNodeOutputName2;
})(RenderPixelJsNodeOutputName || {});
class RenderPixelJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.uv = ParamConfig.VECTOR2([0, 0]);
this.backgroundColor = ParamConfig.COLOR([0, 0, 0]);
}
}
const ParamsConfig = new RenderPixelJsParamsConfig();
export class RenderPixelJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "renderPixel";
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS),
new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS),
new JsConnectionPoint(JsConnectionPointType.MATERIAL, JsConnectionPointType.MATERIAL, CONNECTION_OPTIONS),
new JsConnectionPoint(JsConnectionPointType.CAMERA, JsConnectionPointType.CAMERA, CONNECTION_OPTIONS)
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER),
new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D),
new JsConnectionPoint(JsConnectionPointType.MATERIAL, JsConnectionPointType.MATERIAL, CONNECTION_OPTIONS),
new JsConnectionPoint("value" /* value */, JsConnectionPointType.VECTOR4, CONNECTION_OPTIONS)
]);
}
setLines(linesController) {
const usedOutputNames = this.io.outputs.used_output_names();
if (usedOutputNames.includes("value" /* value */)) {
this._addValueRef(linesController);
if (!usedOutputNames.includes(JsConnectionPointType.TRIGGER)) {
this.setTriggeringLines(linesController, "");
}
}
setObject3DOutputLine(this, linesController);
}
setTriggerableLines(linesController) {
const object3D = inputObject3D(this, linesController);
const material = this.variableForInput(linesController, JsConnectionPointType.MATERIAL);
const camera = this.variableForInput(linesController, JsConnectionPointType.CAMERA);
const backgroundColor = this.variableForInputParam(linesController, this.p.backgroundColor);
const uv = this.variableForInputParam(linesController, this.p.uv);
const refValue = this._addValueRef(linesController);
const func = Poly.namedFunctionsRegister.getFunction("renderPixel", this, linesController);
const bodyLine = func.asString(object3D, material, camera, backgroundColor, uv, `this.${refValue}.value`);
linesController.addTriggerableLines(this, [bodyLine]);
}
_addValueRef(linesController) {
const outValue = this.jsVarName("value" /* value */);
const tmpVarName = linesController.addVariable(this, new Vector4());
linesController.addDefinitions(this, [
new RefJsDefinition(this, linesController, JsConnectionPointType.BOOLEAN, outValue, tmpVarName)
]);
return outValue;
}
}