【发布时间】:2017-05-01 20:07:55
【问题描述】:
我正在使用 Three.js r83。
我正在尝试向几何图形动态添加点,但场景从未更新。
这行得通:
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是什么版本?另请查看文档here 以了解如何更新内容...
-
@WestLangley 我目前正在探索 BufferGeometry,但似乎点数是固定的。
-
最大数量是。渲染的数字不是。研究我发布的第二个链接。
-
从试错法中,在渲染这个之前请求动画帧,就像你能做的最糟糕的事情,只是错了,后果自负。如果是真的,为什么没有人注意到?
标签: javascript three.js geometry points