I have existing Mesh objects with CylinderGeometry, and as the animation proceeds I want to update the position and direction of the cylinders. I would like to reuse the old CylinderGeometry objects and just update them by calling geo.applyMatrix(…). But the CylinderGeometry object has no resetMatrix() method. It only has an applyMatrix(…) method. Nor is there a getMatrix() method. So I end up having to dispose the old geometry and create a new one. That is, I have to use:
function updateCylinderBetween(cyl,positionX, positionY ) {
const direction = new THREE.Vector3().subVectors(positionX, positionY);
const geo = new THREE.CylinderGeometry(cyl.geometry.radiusTop,cyl.geometry.radiusBottom, direction.length(), 6, 4, true);
geo.height = direction.length();
geo.applyMatrix4(new THREE.Matrix4().makeTranslation(0, direction.length() / 2, 0));
geo.applyMatrix4(new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(90)));
cyl.geometry.dispose();
cyl.geometry = geo;
cyl.position.copy(positionX);
cyl.lookAt(positionY);
}
I want to use:
// This version would be more efficient:
function updateCylinderBetweenBuggy(cyl,positionX, positionY ) {
const direction = new THREE.Vector3().subVectors(positionX, positionY);
const geo = cyl.geometry; // new THREE.CylinderGeometry(cyl.geometry.radiusTop,cyl.geometry.radiusBottom, direction.length(), 6, 4, true);
geo.height = direction.length();
//geo.resetMatrix(); ??? to identity matrix
geo.applyMatrix4(new THREE.Matrix4().makeTranslation(0, direction.length() / 2, 0));
geo.applyMatrix4(new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(90)));
cyl.position.copy(positionX);
cyl.lookAt(positionY);
}
Am I missing something? Or does BufferGeometry need a new method clearMatrix()?
I have a bunch of spheres in the scene. Some of them are connected by cylinders. When the spheres move, I want to move the cylinders to march the spheres. However, I [thought I] found a simpler way to do it, and I don’t need to reset the matrix:
I’m wrong! My previous version doesn’t work if I rotate with OrbitControls. In order for the cylinders to appear correctly, I need to recreate the geometry via new THREE.CylinderGeometry as in my original Nov 2 post. So, I still think it would help if BufferGeometry had a resetMatrix() method.
I want to move each sphere separately (in different directions), so moving them in a Group wouldn’t help. Maybe there’s some other way to do what I want to do without recreating the CylinderGeometry and without adding that resetMatrix method.