UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

65 lines (64 loc) 3.12 kB
"use strict"; import { ParamlessTypedJsNode } from "./_Base"; import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js"; import { RBDProperty } from "../../../core/physics/PhysicsRBD"; import { Vector3 } from "three"; import { inputObject3D } from "./_BaseObject3D"; import { Poly } from "../../Poly"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; export class GetPhysicsRBDPropertyJsNode extends ParamlessTypedJsNode { static type() { return "getPhysicsRBDproperty"; } initializeNode() { this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS) ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(RBDProperty.ANGULAR_VELOCITY, JsConnectionPointType.VECTOR3), new JsConnectionPoint(RBDProperty.LINEAR_VELOCITY, JsConnectionPointType.VECTOR3), new JsConnectionPoint(RBDProperty.ANGULAR_DAMPING, JsConnectionPointType.FLOAT), new JsConnectionPoint(RBDProperty.LINEAR_DAMPING, JsConnectionPointType.FLOAT), new JsConnectionPoint(RBDProperty.IS_MOVING, JsConnectionPointType.BOOLEAN), new JsConnectionPoint(RBDProperty.IS_SLEEPING, JsConnectionPointType.BOOLEAN) ]); } setLines(shadersCollectionController) { const usedOutputNames = this.io.outputs.used_output_names(); const object3D = inputObject3D(this, shadersCollectionController); const _v3 = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const out = this.jsVarName(propertyName); const tmpVarName = shadersCollectionController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName: out, value: func.asString(object3D, tmpVarName) } ]); }; const _p = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName: this.jsVarName(propertyName), value: func.asString(object3D) } ]); }; _v3(RBDProperty.ANGULAR_VELOCITY, "getPhysicsRBDAngularVelocity", JsConnectionPointType.VECTOR3); _v3(RBDProperty.LINEAR_VELOCITY, "getPhysicsRBDLinearVelocity", JsConnectionPointType.VECTOR3); _p(RBDProperty.ANGULAR_DAMPING, "getPhysicsRBDAngularDamping", JsConnectionPointType.FLOAT); _p(RBDProperty.LINEAR_DAMPING, "getPhysicsRBDLinearDamping", JsConnectionPointType.FLOAT); _p(RBDProperty.IS_MOVING, "getPhysicsRBDIsMoving", JsConnectionPointType.BOOLEAN); _p(RBDProperty.IS_SLEEPING, "getPhysicsRBDIsSleeping", JsConnectionPointType.BOOLEAN); } }