UNPKG

@polygonjs/polygonjs

Version:

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

54 lines (48 loc) 1.69 kB
/** * Cuts a geometry with a plane. * * @remarks * The input geometry must have used a BVH SOP node before. * */ import {TypedSopNode} from './_Base'; import {CoreGroup} from '../../../core/geometry/Group'; import {ClipSopOperation} from '../../operations/sop/Clip'; import {NodeParamsConfig, ParamConfig} from '../utils/params/ParamsConfig'; const DEFAULT = ClipSopOperation.DEFAULT_PARAMS; class ClipSopParamsConfig extends NodeParamsConfig { /** @param origin */ origin = ParamConfig.VECTOR3(DEFAULT.origin); /** @param distance */ distance = ParamConfig.FLOAT(DEFAULT.distance, { range: [-10, 10], rangeLocked: [false, false], }); /** @param direction */ direction = ParamConfig.VECTOR3(DEFAULT.direction, { separatorAfter: true, }); /** @param intersectionEdges */ intersectionEdges = ParamConfig.BOOLEAN(DEFAULT.intersectionEdges); /** @param keepBelowPlane */ keepBelowPlane = ParamConfig.BOOLEAN(DEFAULT.keepBelowPlane); /** @param keepAbovePlane */ keepAbovePlane = ParamConfig.BOOLEAN(DEFAULT.keepAbovePlane); } const ParamsConfig = new ClipSopParamsConfig(); export class ClipSopNode extends TypedSopNode<ClipSopParamsConfig> { override paramsConfig = ParamsConfig; static override type() { return 'clip'; } override initializeNode() { this.io.inputs.setCount(1); this.io.inputs.initInputsClonedState(ClipSopOperation.INPUT_CLONED_STATE); } private _operation: ClipSopOperation | undefined; override cook(inputCoreGroups: CoreGroup[]) { this._operation = this._operation || new ClipSopOperation(this._scene, this.states, this); const coreGroup = this._operation.cook(inputCoreGroups, this.pv); this.setCoreGroup(coreGroup); } }