我只需要更新一条有两个顶点的线,我试图使用上面这些在r58中更改的东西,但线条不能移动,我只是初始化:
var geometry = new THREE.BufferGeometry();
geometry.addAttribute('position', Float32Array, 2, 3);
geometry.dynamic = true;
var position = geometry.attributes.position;
position.needsUpdate = true;
var p = position.array;
var i = 0;
p[i++] = vertex1.position.x;
p[i++] = vertex1.position.y;
p[i++] = vertex1.position.z;
p[i++] = vertex2.position.x;
p[i++] = vertex2.position.y;
p[i] = vertex2.position.z;
var color = new THREE.Color();
color.g = color.b = 1 - this.value;
var material = new THREE.LineBasicMaterial({
color: color.getHex(),
linewidth: 5 // THIS DON'T WORKS IN WINDOWS?
});
this.model = new THREE.Line(geometry, material);
并且在更新渲染中我只是这样做:
var p = this.model.geometry.attributes.position.array;
var i = 0;
p[i++] = vertex1.position.x;
p[i++] = vertex1.position.y;
p[i++] = vertex1.position.z;
p[i++] = vertex2.position.x;
p[i++] = vertex2.position.y;
p[i] = vertex2.position.z;
但这些线条没有移动或渲染自己。
答案 0 :(得分:13)
在您的情况下,您需要在更新顶点时在渲染循环中添加以下内容:
this.model.geometry.attributes.position.needsUpdate = true;
您可以在创建几何图形时删除行position.needsUpdate = true
。
我还建议您更新到当前版本。
three.js r.63