UNPKG

935 BJavaScriptView Raw
1const CSG = require('./CSG')
2const {cube} = require('./primitives3d')
3
4// For debugging
5// Creates a new solid with a tiny cube at every vertex of the source solid
6// this is seperated from the CSG class itself because of the dependency on cube
7const toPointCloud = function (csg, cuberadius) {
8 csg = csg.reTesselated()
9
10 let result = new CSG()
11
12 // make a list of all unique vertices
13 // For each vertex we also collect the list of normals of the planes touching the vertices
14 let vertexmap = {}
15 csg.polygons.map(function (polygon) {
16 polygon.vertices.map(function (vertex) {
17 vertexmap[vertex.getTag()] = vertex.pos
18 })
19 })
20
21 for (let vertextag in vertexmap) {
22 let pos = vertexmap[vertextag]
23 let _cube = cube({
24 center: pos,
25 radius: cuberadius
26 })
27 result = result.unionSub(_cube, false, false)
28 }
29 result = result.reTesselated()
30 return result
31}
32
33module.exports = {toPointCloud}