gpt4 book ai didi

javascript - 数组中的值被覆盖

转载 作者:行者123 更新时间:2023-12-03 01:21:05 25 4
gpt4 key购买 nike

meshEdge 中的值将被 gemoetry 的最后一个值覆盖。我已经尝试过了,但问题仍然存在。

var geometry = new THREE.BufferGeometry();
var meshEdges = new Array();
var firstPoint = [];
for (i = 0; i < json.edges.length; i++) {
firstPoint[i] = json.edges[i].edeVertices;
positions = new Float32Array([firstPoint[i][0] , firstPoint[i][1], firstPoint[i][2], firstPoint[i][3], firstPoint[i][4], firstPoint[i][5]]);
geometry.addAttribute('position', new THREE.BufferAttribute(positions,3));
meshEdges.push(geometry);

}

知道我做错了什么吗?提前致谢。

最佳答案

您一次又一次地插入相同的几何图形。数组有对此的引用,当几何图形更新时,数组值也会更新。因此,每次创建一个新的几何体并推送它。

 var meshEdges = new Array();
var firstPoint = [];
for (i = 0; i < json.edges.length; i++) {
var geometry = new THREE.BufferGeometry();
firstPoint[i] = json.edges[i].edeVertices;
positions = new Float32Array([firstPoint[i][0] , firstPoint[i][1], firstPoint[i][2], firstPoint[i][3], firstPoint[i][4], firstPoint[i][5]]);
geometry.addAttribute('position', new THREE.BufferAttribute(positions,3));
meshEdges.push(geometry);
}

关于javascript - 数组中的值被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51758809/

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