Tengo una línea existente iniciada
// material const material = new THREE.LineBasicMaterial({ color: 0xffffff }); // array of vertices vertices.push(new THREE.Vector3(0, 0, 0)); vertices.push(new THREE.Vector3(0, 0, 5)); // const geometry = new THREE.BufferGeometry().setFromPoints(vertices); const line = new THREE.Line(geometry, material);Y lo que quiero hacer es extender esta línea siguiendo su iniciación. He leído esta página sobre cómo actualizar cosas y no creo que se ajuste a esta situación porque en lugar de agregar vértices a mi forma, quiero moverlos. Por otra parte, es muy probable que haya entendido mal. Intenté eliminar la línea y luego volver a dibujarla por más tiempo, pero no puedo hacer que funcione sin que mi navegador se bloquee.
BufferGeometry expone sus vértices a través de sus positionsBufferAttribute . Para cambiar las posiciones, debe hacer algo como lo siguiente:
// // Assuming we want to move your line segment (0, 0, 0)-(0, 0, 5) by // one unit in the direction of positive x, to (1, 0, 0)-(1, 0, 5). // // Get a reference to the "position" buffer attribute const pos = geometry.getAttribute("position"); // Set the new positions pos.setXYZ(0, vertices[0].x + 1, vertices[0].y, vertices[0].z); pos.setXYZ(1, vertices[1].x + 1, vertices[1].y, vertices[1].z); // Update the vertex buffer in graphics memory pos.needsUpdate = true; // Update the bounds to support, eg, frustum culling geometry.computeBoundingBox(); geometry.computeBoundingSphere();Existen otros métodos, como modificar la matriz de respaldo del atributo directamente y copiar en una nueva matriz, pero el proceso general será el mismo.