1 | const CSG = require('./CSG')
|
2 | const {cube} = require('./primitives3d')
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | const toPointCloud = function (csg, cuberadius) {
|
8 | csg = csg.reTesselated()
|
9 |
|
10 | let result = new CSG()
|
11 |
|
12 |
|
13 |
|
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 |
|
33 | module.exports = {toPointCloud}
|