meshEdge中的值被几何图形的最后一个值覆盖。我已经尝试了一些东西,但问题仍然存在。
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);
}
任何想法我在做什么错。
提前致谢。
最佳答案
您一次又一次地推动相同的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);
}