0

我成功地加载了一个包含代表城市建筑物的多边形数据的数据集。所以每个多边形代表一个建筑物。在 Threejs 中,我可以成功地表示它们,但是当我尝试将单独的线合并为一个几何图形时,所有线都连接起来(我理解为什么这是有道理的,因为所有顶点都添加到同一个集合中)。

但是,如何将这些单独的建筑多边形合并成一个几何图形,而不会使单独的建筑多边形的线相互连接呢?

我现在拥有的代码:

var geometry = new THREE.Geometry();

            for (var i = 0; i < data.length; i++) {
                var temp = new THREE.Geometry();
                var polygon = data[i];
                for (var j = 0; j < polygon.length; j++) {
                    temp.vertices.push(new THREE.Vector3(polygon[j][0], polygon[j][1], 0));
                }
                temp.vertices.push(new THREE.Vector3(polygon[0][0], polygon[0][1], 0));

                THREE.GeometryUtils.merge(geometry, temp);
            }
            scene.add(new THREE.Line(geometry, buildingMaterial, THREE.LineStrip));

data 是包含建筑物所有多边形数据的变量。

4

1 回答 1

3

解决了:

            var cube = new THREE.Geometry();

            for (var i = 0; i < data.length; i++) {
                var shape = new THREE.Shape(_.uniq(_.map(data[i], function(d) { return new THREE.Vector3(d[0], d[1], 100); })));
                shape.extrude({amount: 100})
                var points = shape.createPointsGeometry();
                THREE.GeometryUtils.merge(cube, shape.extrude({amount: -1 - Math.random() * 1, bevelSegments: 0, steps: 1 , bevelSegments: 0, bevelSize: 0, bevelThickness: 0}));

            }

            var mesh = new THREE.Mesh(cube, new THREE.MeshBasicMaterial({color: 0x333333, wireframe: false}));
            scene.add(mesh);
于 2013-05-27T15:44:54.290 回答