gpt4 book ai didi

Three.js:如何更新BufferGeometry顶点

转载 作者:行者123 更新时间:2023-12-04 00:56:26 24 4
gpt4 key购买 nike

我只需要更新一条有 2 个顶点的线,我尝试使用上面在 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;

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

最佳答案

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

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

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

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

三.js r.63

关于Three.js:如何更新BufferGeometry顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20303239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com