我正在使用Three.js r83。THREE.js動態添加點到點幾何不會渲染
我想動態地添加點到幾何,但場景永遠不會更新。
這工作:
var tmaterial = new THREE.PointsMaterial({
color: 0xff0000,
size: 5,
opacity: 1
});
var tgeometry = new THREE.Geometry();
var pointCloud = new THREE.Points(tgeometry, tmaterial);
for(var i = 0; i< 1000; i++) {
x = (Math.random() * 200) - 100;
y = (Math.random() * 200) - 100;
z = (Math.random() * 200) - 100;
tgeometry.vertices.push(new THREE.Vector3(x, y, z));
}
tgeometry.verticesNeedUpdate = true;
tgeometry.computeVertexNormals();
scene.add(pointCloud);
這不起作用:
var tmaterial = new THREE.PointsMaterial({
color: 0xff0000,
size: 5,
opacity: 1
});
var tgeometry = new THREE.Geometry();
var pointCloud = new THREE.Points(tgeometry, tmaterial);
scene.add(pointCloud);
for(var i = 0; i< 1000; i++) {
x = (Math.random() * 200) - 100;
y = (Math.random() * 200) - 100;
z = (Math.random() * 200) - 100;
tgeometry.vertices.push(new THREE.Vector3(x, y, z));
}
tgeometry.verticesNeedUpdate = true;
tgeometry.elementsNeedUpdate = true;
tgeometry.computeVertexNormals();
renderer.render(scene, camera);
正如你看到的,唯一的區別是,我加入頂點前加scene.add(pointCloud);
。
我錯過了什麼?
你可以找到一個fiddle由於@hectate
要明白我的意思,只是更換
init(); setPoints(); animate();
通過
init(); animate(); setPoints();
你是什麼three.js所的版本?檢查文檔[這裏](https://github.com/mrdoob/three。js/wiki /更新)如何更新的東西... – Wilt
請參閱http://stackoverflow.com/questions/36699389/verticesneedupdate-in-three-js/36699654#36699654和http://stackoverflow.com/questions/ 31399856 /繪圖一個行與 - 三JS-動態/ 31411794#31411794。 – WestLangley
@WestLangley我目前正在探索BufferGeometry,看起來像點的數量是固定的。 – Ant