時々、頂点や色を変更するBufferGeometryがあります。私は、頂点にもっと多くのスペースを割り当てる必要がある場合、新しいバッファーメトリーを作成することでこれを行います。そうでない場合、私はすでに持っているものを再利用しますが、drawRangeを変更します。Geometry.center()が適用されていません
私の問題は、私のジオメトリにはない以下のコードの私は最初の「this.mesh!=未定義& & this.prev(あれば...」のように新しい頂点とBufferGeometryを更新一環ということです私は明示的にそれを適用していますが、幾何学がちょうど後で中心合わせされる必要がある場合、これを解決するにはどうすればいいですか?(以下のコードを使用すると、オブジェクトはcenter()位置)。そのmesh.positionに注意してください。これでは何の関係もありません、それはすべての時間と同じです。
if(this.mesh != undefined && this.prev_len > vertices.length) {
for (var i = 0; i < vertices.length; i++) {
this.v.setXYZ(i, vertices[i][0], vertices[i][1], vertices[i][2]);
this.c.setXYZW(i, colors[i][0], colors[i][1], colors[i][2], 1);
}
this.geometry.setDrawRange(0, vertices.length);
this.geometry.attributes.position.needsUpdate = true;
this.geometry.attributes.color.needsUpdate = true;
this.geometry.computeVertexNormals();
// Here seems to be the problem. center() is not actually applied?
// I've debuged three.js and it seems to perform the translate() in center() function. But it seems to be changed afterwards?
this.mesh.geometry.center();
} else {
this.v = new THREE.BufferAttribute(new Float32Array(vertices.length * 3), 3);
this.c = new THREE.BufferAttribute(new Float32Array(colors.length * 3), 3);
for (var i = 0; i < vertices.length; i++) {
this.v.setXYZ(i, vertices[i][0], vertices[i][1], vertices[i][2]);
this.c.setXYZW(i, colors[i][0], colors[i][1], colors[i][2], 1);
}
this.geometry = new THREE.BufferGeometry();
this.geometry.dynamic = true;
this.geometry.addAttribute('position', this.v);
this.geometry.addAttribute('color', this.c);
this.geometry.attributes.position.dynamic = true;
this.geometry.attributes.color.dynamic = true;
this.geometry.computeVertexNormals();
this.prev_len = vertices.length;
if(this.mesh == undefined) {
this.mesh = new THREE.Mesh(this.geometry, this.material);
this.mesh.position.set(
this.from_x,
this.from_y,
this.from_z
);
scene.add(this.mesh);
this.geometry.center();
} else {
// This works fine, the geometry becomes centered.
this.mesh.geometry = this.geometry;
this.geometry.center();
}
}
いいえ、それは同じです。しかし、確かに、私はthis.geometryにcenter()を試みました。しかし問題は残っている。 – nergal