@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
59 lines (58 loc) • 2.6 kB
JavaScript
;
import { Vector3 } from "three";
import { ParamlessTypedJsNode } from "./_Base";
import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js";
import { GetPointPropertyJsNodeInputName } from "../../../core/reactivity/PointPropertyReactivity";
import { Poly } from "../../Poly";
import { inputObject3D, inputPointIndex } from "./_BaseObject3D";
import { JsType } from "../../poly/registers/nodes/types/Js";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
export class GetPointPropertyJsNode extends ParamlessTypedJsNode {
static type() {
return JsType.GET_POINT_PROPERTY;
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS),
new JsConnectionPoint(GetPointPropertyJsNodeInputName.ptnum, JsConnectionPointType.INT, CONNECTION_OPTIONS)
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(GetPointPropertyJsNodeInputName.ptnum, JsConnectionPointType.INT, CONNECTION_OPTIONS),
new JsConnectionPoint(GetPointPropertyJsNodeInputName.position, JsConnectionPointType.VECTOR3)
]);
}
setLines(linesController) {
const usedOutputNames = this.io.outputs.used_output_names();
const object3D = inputObject3D(this, linesController);
const ptnum = inputPointIndex(this, linesController);
const _v3 = (propertyName, functionName) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const func = Poly.namedFunctionsRegister.getFunction(functionName, this, linesController);
const tmpVarName = linesController.addVariable(this, new Vector3());
linesController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.VECTOR3,
varName: this.jsVarName(propertyName),
value: func.asString(object3D, ptnum, tmpVarName)
}
]);
};
const _int = (propertyName, functionName) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const func = Poly.namedFunctionsRegister.getFunction(functionName, this, linesController);
linesController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.INT,
varName: this.jsVarName(propertyName),
value: func.asString(object3D)
}
]);
};
_int(GetPointPropertyJsNodeInputName.ptnum, "getPointIndex");
_v3(GetPointPropertyJsNodeInputName.position, "getPointPosition");
}
}