UNPKG

polygonjs-engine

Version:

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

48 lines (47 loc) 1.57 kB
import {BufferGeometry as BufferGeometry2} from "three/src/core/BufferGeometry"; import {BufferAttribute as BufferAttribute2} from "three/src/core/BufferAttribute"; import {TypedSopNode} from "./_Base"; import {ObjectType} from "../../../core/geometry/Constant"; import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig"; class BboxScatterSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.stepSize = ParamConfig.FLOAT(0.1); } } const ParamsConfig2 = new BboxScatterSopParamsConfig(); export class BboxScatterSopNode extends TypedSopNode { constructor() { super(...arguments); this.params_config = ParamsConfig2; } static type() { return "bboxScatter"; } static displayedInputNames() { return ["geometry to create points from"]; } initializeNode() { this.io.inputs.setCount(1); } cook(input_contents) { const container = input_contents[0]; const stepSize = this.pv.stepSize; const bbox = container.boundingBox(); const min = bbox.min; const max = bbox.max; const positions = []; for (let x = min.x; x < max.x; x += stepSize) { for (let y = min.x; y < max.y; y += stepSize) { for (let z = min.x; z < max.z; z += stepSize) { positions.push(x); positions.push(y); positions.push(z); } } } const geometry = new BufferGeometry2(); geometry.setAttribute("position", new BufferAttribute2(new Float32Array(positions), 3)); this.setGeometry(geometry, ObjectType.POINTS); } }