UNPKG

@polygonjs/polygonjs

Version:

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

41 lines (36 loc) 1.53 kB
/** * gets the position where a ray intersects with a box3 * * @remarks * * */ import {BaseRayBox3JsNode} from './_BaseRayBox3'; import {JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF} from '../utils/io/connections/Js'; import {JsLinesCollectionController} from './code/utils/JsLinesCollectionController'; import {Vector3} from 'three'; import {Poly} from '../../Poly'; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; const OUTPUT_NAME = 'position'; export class RayIntersectBoxJsNode extends BaseRayBox3JsNode { static override type() { return 'rayIntersectBox'; } override initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR3, CONNECTION_OPTIONS), ]); } override setLines(shadersCollectionController: JsLinesCollectionController) { const ray = this.variableForInput(shadersCollectionController, JsConnectionPointType.RAY); const box3 = this.variableForInput(shadersCollectionController, JsConnectionPointType.BOX3); const out = this.jsVarName(OUTPUT_NAME); const tmpVarName = shadersCollectionController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction('rayIntersectBox3', this, shadersCollectionController); const bodyLine = func.asString(ray, box3, tmpVarName); shadersCollectionController.addBodyOrComputed(this, [ {dataType: JsConnectionPointType.VECTOR3, varName: out, value: bodyLine}, ]); } }