UNPKG

@polygonjs/polygonjs

Version:

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

32 lines (31 loc) 1.25 kB
"use strict"; import { ObjectType } from "./../../../core/geometry/Constant"; import { BaseSopOperation } from "./_Base"; import { Vector3 } from "three"; import { ConvexGeometry } from "three/examples/jsm/geometries/ConvexGeometry"; import { InputCloneMode } from "../../../engine/poly/InputCloneMode"; export class ConvexHullSopOperation extends BaseSopOperation { static type() { return "convexHull"; } cook(inputCoreGroups, params) { const inputCoreGroup = inputCoreGroups[0]; const objects = inputCoreGroup.threejsObjectsWithGeo(); const newObjects = objects.map((object) => this._createConvexHull(object)); return this.createCoreGroupFromObjects(newObjects); } _createConvexHull(object) { const srcGeo = object.geometry; const positionAttribute = srcGeo.getAttribute("position"); const vertices = []; for (let i = 0; i < positionAttribute.count; i++) { const vertex = new Vector3(); vertex.fromBufferAttribute(positionAttribute, i); vertices.push(vertex); } const newGeo = new ConvexGeometry(vertices); return this.createObject(newGeo, ObjectType.MESH); } } ConvexHullSopOperation.DEFAULT_PARAMS = {}; ConvexHullSopOperation.INPUT_CLONED_STATE = InputCloneMode.NEVER;