UNPKG

@polygonjs/polygonjs

Version:

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

40 lines (39 loc) 1.38 kB
"use strict"; import { BaseSopOperation } from "./_Base"; import { InputCloneMode } from "../../../engine/poly/InputCloneMode"; import { BufferAttribute, BufferGeometry, Box3 } from "three"; import { ObjectType } from "../../../core/geometry/Constant"; const tmpBox = new Box3(); export class BboxScatterSopOperation extends BaseSopOperation { static type() { return "bboxScatter"; } cook(inputCoreGroups, params) { const inputCoreGroup = inputCoreGroups[0]; const stepSize = params.stepSize; inputCoreGroup.boundingBox(tmpBox); const min = tmpBox.min; const max = tmpBox.max; const positions = []; for (let x = min.x; x <= max.x; x += stepSize) { for (let y = min.y; y <= max.y; y += stepSize) { for (let z = min.z; z <= max.z; z += stepSize) { positions.push(x); positions.push(y); positions.push(z); } } } const geometry = new BufferGeometry(); geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3)); const object = BaseSopOperation.createObject(geometry, ObjectType.POINTS); if (this._node) { object.name = this._node.name(); } return this.createCoreGroupFromObjects([object]); } } BboxScatterSopOperation.DEFAULT_PARAMS = { stepSize: 1 }; BboxScatterSopOperation.INPUT_CLONED_STATE = InputCloneMode.NEVER;