Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Three.JS中合并克隆对象的几何图形?_Javascript_Three.js - Fatal编程技术网

Javascript 如何在Three.JS中合并克隆对象的几何图形?

Javascript 如何在Three.JS中合并克隆对象的几何图形?,javascript,three.js,Javascript,Three.js,所以我正在测试一次显示大量对象的最佳非体素方法,因此我发现了如何合并几何体 现在,我可以轻松地合并大多数几何体,但我似乎无法合并克隆对象的几何体 我注意到,通过简单地使用克隆对象,我几乎可以获得与合并几何体时相同的性能 有没有办法将这两件事结合起来以获得更好的性能 下面是我的代码示例,注释掉了坏方法 var testGeo = new THREE.BoxGeometry( 1, 1, 1 ); var testMat = new THREE.MeshLambertMaterial( {color

所以我正在测试一次显示大量对象的最佳非体素方法,因此我发现了如何合并几何体

现在,我可以轻松地合并大多数几何体,但我似乎无法合并克隆对象的几何体

我注意到,通过简单地使用克隆对象,我几乎可以获得与合并几何体时相同的性能

有没有办法将这两件事结合起来以获得更好的性能

下面是我的代码示例,注释掉了坏方法

var testGeo = new THREE.BoxGeometry( 1, 1, 1 );
var testMat = new THREE.MeshLambertMaterial( {color: 0xffff00  });
var testMesh = new THREE.Mesh( testGeo, testMat );
testMesh.position.set(1, 5, 1);
testMesh.castShadow = true;
testMesh.receiveShadow = true;
scene.add( testMesh );

//Testing with 900 objects.
var iterLength = 30;
for(var i = 0; i< iterLength; i++) {
    for(var j = 0; j< iterLength; j++) {


        var testGeo2 = new THREE.BoxGeometry( 1, 1, 1 );
        var testMat2 = new THREE.MeshLambertMaterial( {color: 0xffff00  });
        var testMesh2 = new THREE.Mesh( testGeo2, testMat2 );
        testMesh2.position.set(i, 2, j);
        testMesh2.castShadow = true;
        testMesh2.receiveShadow = true;


        //Clone Test (This won't work)
        /*
        var testMesh2 = testMesh.clone();
        testMesh2.position.set(i, 2, j);
        */


        //Reference Material/Geo test. (This also doesn't work)
        /*
        var testMesh2 = new THREE.Mesh( testGeo, testMat );
        testMesh2.position.set(i, 2, j);
        testMesh2.castShadow = true;
        testMesh2.receiveShadow = true;
        */


        //Merge.
        testMesh2.updateMatrix();
        testGeo.merge(testMesh2.geometry, testMesh2.matrix);
    }
}