UNPKG

@polygonjs/polygonjs

Version:

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

64 lines (54 loc) 2.12 kB
/** * get a ray property * * */ import {ParamlessTypedJsNode} from './_Base'; import {JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF} from '../utils/io/connections/Js'; import {Vector3} from 'three'; import {JsLinesCollectionController} from './code/utils/JsLinesCollectionController'; import {Poly} from '../../Poly'; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; enum GetRayPropertyJsNodeInputName { origin = 'origin', direction = 'direction', } export class GetRayPropertyJsNode extends ParamlessTypedJsNode { static override type() { return 'getRayProperty'; } override initializeNode() { this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.RAY, JsConnectionPointType.RAY, CONNECTION_OPTIONS), ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(GetRayPropertyJsNodeInputName.origin, JsConnectionPointType.VECTOR3), new JsConnectionPoint(GetRayPropertyJsNodeInputName.direction, JsConnectionPointType.VECTOR3), ]); } override setLines(shadersCollectionController: JsLinesCollectionController) { const usedOutputNames = this.io.outputs.used_output_names(); const ray = this.variableForInput(shadersCollectionController, JsConnectionPointType.RAY); const _v3 = ( propertyName: GetRayPropertyJsNodeInputName, functionName: 'getRayOrigin' | 'getRayDirection', type: JsConnectionPointType ) => { if (!usedOutputNames.includes(propertyName)) { return; } const varName = this.jsVarName(propertyName); const tmpVarName = shadersCollectionController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName, value: func.asString(ray, tmpVarName), }, ]); }; _v3(GetRayPropertyJsNodeInputName.origin, 'getRayOrigin', JsConnectionPointType.VECTOR3); _v3(GetRayPropertyJsNodeInputName.direction, 'getRayDirection', JsConnectionPointType.VECTOR3); } }