@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
77 lines (70 loc) • 3.52 kB
text/typescript
/**
* get an object property
*
*
*/
import {ParamlessTypedJsNode} from './_Base';
import {JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF} from '../utils/io/connections/Js';
import {JsLinesCollectionController} from './code/utils/JsLinesCollectionController';
import {
GetObjectPropertyJsNodeInputName,
OBJECT_VECTOR3_PROPERTIES,
OBJECT_BOOLEAN_PROPERTIES,
} from '../../../core/reactivity/ObjectPropertyReactivity';
import {Poly} from '../../Poly';
import {inputObject3D} from './_BaseObject3D';
import {JsType} from '../../poly/registers/nodes/types/Js';
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
export class GetObjectPropertyJsNode extends ParamlessTypedJsNode {
static override type() {
return JsType.GET_OBJECT_PROPERTY;
}
override initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS),
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.position, JsConnectionPointType.VECTOR3),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.rotation, JsConnectionPointType.EULER),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.quaternion, JsConnectionPointType.QUATERNION),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.scale, JsConnectionPointType.VECTOR3),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.matrix, JsConnectionPointType.MATRIX4),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.up, JsConnectionPointType.VECTOR3),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.visible, JsConnectionPointType.BOOLEAN),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.matrixAutoUpdate, JsConnectionPointType.BOOLEAN),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.castShadow, JsConnectionPointType.BOOLEAN),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.receiveShadow, JsConnectionPointType.BOOLEAN),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.frustumCulled, JsConnectionPointType.BOOLEAN),
// new ActorConnectionPoint(GetObjectPropertyActorNodeInputName.id, ActorConnectionPointType.INTEGER),
// new ActorConnectionPoint(GetObjectPropertyActorNodeInputName.uuid, ActorConnectionPointType.BOOLEAN),
new JsConnectionPoint(GetObjectPropertyJsNodeInputName.material, JsConnectionPointType.MATERIAL),
]);
}
override setLines(linesController: JsLinesCollectionController) {
const usedOutputNames = this.io.outputs.used_output_names();
const object3D = inputObject3D(this, linesController);
const _f = (propertyName: string, type: JsConnectionPointType) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const func = Poly.namedFunctionsRegister.getFunction('getObjectProperty', this, linesController);
linesController.addBodyOrComputed(this, [
{
dataType: type,
varName: this.jsVarName(propertyName),
value: func.asString(object3D, `'${propertyName}'`),
},
]);
};
OBJECT_VECTOR3_PROPERTIES.forEach((propertyName) => {
_f(propertyName, JsConnectionPointType.VECTOR3);
});
OBJECT_BOOLEAN_PROPERTIES.forEach((propertyName) => {
_f(propertyName, JsConnectionPointType.BOOLEAN);
});
_f('rotation', JsConnectionPointType.EULER);
_f('quaternion', JsConnectionPointType.QUATERNION);
_f('matrix', JsConnectionPointType.MATRIX4);
_f('material', JsConnectionPointType.MATERIAL);
}
}