所以我正在测试最好的非体素方法,一次显示很多对象,所以我找到了如何合并几何。
现在,我可以轻松地合并大多数几何体,但我似乎无法合并克隆对象的几何体。
我注意到,通过简单地使用克隆对象,我几乎可以获得与合并几何时相同的性能。
有没有办法将这两件事情结合起来以获得更好的表现?
以下是我的代码示例,其中删除了已破坏的方法。
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);
}
}