Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch the geometry of a mesh in real time three.js

I'm currently creating a mesh in three.js using the following:

sphereGeometry  = new THREE.SphereGeometry( 1, 16,16 );
mesh = new THREE.Mesh( sphereGeometry, material );

I've also created a torus:

torusGeometry   = new THREE.TorusGeometry( 1, 0.42 );

At any point in my animation loop, I want to be able to swap the sphere out for the torus. Is this possible? How do I swap one geometry for another?

like image 658
mheavers Avatar asked Dec 09 '22 14:12

mheavers


1 Answers

in Three.js R59, setGeometry and setMaterial were removed again from Three.Mesh

What you can do to replace geometry is removing your Mesh from Scene and creating a new one with your new geometry and your old material and add it back to your scene. This will work for sure :)

like image 79
GuyGood Avatar answered Dec 28 '22 13:12

GuyGood