UNPKG

@polygonjs/polygonjs

Version:

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

45 lines (44 loc) 1.58 kB
"use strict"; import { cadDowncast, cadGeometryTypeFromShape } from "../CadCommon"; import { CadLoaderSync } from "../CadLoaderSync"; import { CadObject } from "../CadObject"; import { isArray } from "../../../../Type"; import { MergeSopOperation } from "../../../../../engine/operations/sop/Merge"; import { isObject3D } from "../../../ObjectContent"; export function cadCompoundToObject3D(cadObject, tesselationParams, displayNode) { const oc = CadLoaderSync.oc(); const compound = cadObject.cadGeometry(); const iterator = new oc.TopoDS_Iterator_2(compound, true, true); const iteratedObjects = []; while (iterator.More()) { const newShape = cadDowncast(oc, iterator.Value()); const type = cadGeometryTypeFromShape(oc, newShape); if (type) { const newObject = new CadObject(newShape, type); const result = newObject.toObject3D(tesselationParams, displayNode); if (result) { if (isArray(result)) { iteratedObjects.push(...result); } else { iteratedObjects.push(result); } } } iterator.Next(); } iterator.delete(); const newObjects = MergeSopOperation.makeCompact(iteratedObjects, { preserveMaterials: false }).filter(isObject3D); return newObjects; } export function cadCompoundSubObjectsCount(cadObject) { const oc = CadLoaderSync.oc(); const compound = cadObject.cadGeometry(); let count = 0; const iterator = new oc.TopoDS_Iterator_2(compound, true, true); while (iterator.More()) { count++; iterator.Next(); } iterator.delete(); return count; }