Three.js:如何更新BufferGeometry顶点 [英] Three.js: How to Update BufferGeometry Vertices

查看:109
本文介绍了Three.js:如何更新BufferGeometry顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要更新一条有 2 个顶点的线,我尝试使用上面在 r58 中更改的这些东西,但是线不能移动,我只是用它来初始化:

I just have to update a line that have 2 vertices, and i trying to use these things above that are changed in r58, but the lines cant move, i just made this to initialize:

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);

在更新渲染中我只是这样做:

and in update rendering i´m just doing this:

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;

但线条没有移动或呈现自身.

but the lines didn´t move or render itself.

推荐答案

在您的情况下,您需要在更新顶点时在渲染循环中添加以下内容:

In your case, you need to add the following in your render loop when you update vertices:

this.model.geometry.attributes.position.needsUpdate = true;

您可以在创建几何图形时删除 position.needsUpdate = true 行.

You can remove the line position.needsUpdate = true when you create the geometry.

我还建议您更新到当前版本.

I would also suggest that you update to the current version.

three.js r.63

three.js r.63

这篇关于Three.js:如何更新BufferGeometry顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆