如何为3D网格创建面

时间:2016-04-28 12:17:34

标签: json three.js

关于创建自定义3D网格,我遇到了很大的问题。

function handleLoadedGeometry(filename) {

    var material = new THREE.MeshBasicMaterial({color: 0xFF0000});

    for (var i=0; i<filename.length; i++)// loop through the surfaces (roof/wall/ground...)
    {
        var model = filename[i];
        var coordinates = JSON.parse(model.geometry);
        var geometry = new THREE.Geometry();
        var coordinates_updated =  _transformCoordinates(coordinates.coordinates[0]);

        for (var j = 0; j<coordinates_updated.vertices.length; j++){// loop through all points

            geometry.vertices.push(
                //new THREE.Vector3(coordinates.coordinates[0][j][0], coordinates.coordinates[0][j][1], coordinates.coordinates[0][j][2])//x,y,z Koordinatenpunkte für Surface 1
                new THREE.Vector3(coordinates_updated.vertices[j][0],coordinates_updated.vertices[j][1],coordinates_updated.vertices[j][2])
            );
            geometry.faces.push(
                new THREE.Face3(0,1,2),
                new THREE.Face3(0,2,3)
            );

            geometry.computeBoundingSphere();
        }

        var mesh = new THREE.Mesh(geometry, material);

        material.side = THREE.DoubleSide;
        Scene.scene.add(mesh);
    }
};

最后我得到了这个结果:image

当我添加 material.side = THREE.DoubleSide 时,WallSurface看起来非常好,但屋顶和地面不会。 我是否必须进行三角测量?

0 个答案:

没有答案