UNPKG

@polygonjs/polygonjs

Version:

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

54 lines (53 loc) 2.21 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { RaySopOperation, RAY_SOP_MODES } from "../../operations/sop/Ray"; import { SopType } from "../../poly/registers/nodes/types/Sop"; const DEFAULT = RaySopOperation.DEFAULT_PARAMS; class RaySopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param method used to ray points onto the collision geometry */ this.mode = ParamConfig.INTEGER(DEFAULT.mode, { menu: { entries: RAY_SOP_MODES.map((name, value) => ({ name, value })) } }); /** @param toggle on to use the normals as the ray direction */ this.useNormals = ParamConfig.BOOLEAN(DEFAULT.useNormals); /** @param if the normals are not used as the ray direction, this define the direction used */ this.direction = ParamConfig.VECTOR3(DEFAULT.direction.toArray(), { visibleIf: { useNormals: 0 } }); /** @param moves the points or leaves them in place */ this.transformPoints = ParamConfig.BOOLEAN(DEFAULT.transformPoints); /** @param copies the normals from the right geometry to the left one */ this.transferFaceNormals = ParamConfig.BOOLEAN(DEFAULT.transferFaceNormals); /** @param copies the UVs */ this.transferUVs = ParamConfig.BOOLEAN(DEFAULT.transferUVs); /** @param adds an attribute with the distance to the hit position on the target geometry */ this.addDistAttribute = ParamConfig.BOOLEAN(DEFAULT.addDistAttribute); } } const ParamsConfig = new RaySopParamsConfig(); export class RaySopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.RAY; } initializeNode() { this.io.inputs.setCount(2); this.io.inputs.initInputsClonedState(RaySopOperation.INPUT_CLONED_STATE); } cook(inputCoreGroups) { this._operation = this._operation || new RaySopOperation(this._scene, this.states, this); const coreGroup = this._operation.cook(inputCoreGroups, this.pv); this.setCoreGroup(coreGroup); } setMode(mode) { this.p.mode.set(RAY_SOP_MODES.indexOf(mode)); } }