我希望优化three.js中sphereGeometry的渲染,因为它成为了我的程序瓶颈。以下是javascript程序:
var sphereThree = [];
for(var idSphere = 0; idSphere < numSphere; idSphere++){
var sphereGeometry = new THREE.SphereGeometry(1.0);
var sphereMaterial = new THREE.MeshLambertMaterial({color: 'rgb(255, 0, 0)'});
sphereThree[idSphere] = new THREE.Mesh(sphereGeometry, sphereMaterial);
sphereThree[idSphere].position.x = x[idSphere];
sphereThree[idSphere].position.y = y[idSphere];
sphereThree[idSphere].position.z = z[idSphere];
scene.add(sphereThree[idSphere]);
}
如下链接所述:
- 使用Three.js动画一个百万字母
- 优化Three.js性能:模拟成千上万个独立移动的物体
它们指出我们不应该单独添加对象,最好同时添加相同类型的对象以进行优化。然而,由于我在这个领域还是新手,不知道如何使用SphereGeometry编写此优化代码。
如果有人知道如何使用SphereGeometry编写这些内容,或者知道一种有效的渲染许多(10,000或更多)球体的方法,能否教一下我们?
谢谢!
sphereGeometry
,但使用多个sphereMaterials
来改变颜色。至于大小,请使用sphereThree[idSphere].scale.x = sphereThree[idSphere].scale.y = sphereThree[idSphere].scale.z = scale
来设置缩放。 - gmansphereMaterials
增加了渲染时间。无论如何,谢谢! - eng27