Getting position of Mesh to replace it with another inside a Group

Here is a demo. The ground and the racers are one group object – you can see it moving and spinning continuously. Racers are from a GLB file. When you press the [Change model] button, all racers are replaced by tractors (also a GLB file). Each tractor takes the position, orientation and scale from its racer; and then replaces it.

The actual copying of properties and replacing is done this way (lines 135-140):

newModel.position.copy( oldModel.position );
newModel.rotation.copy( oldModel.rotation );
newModel.scale.copy( oldModel.scale );
					
ground.remove( oldModel );
ground.add( newModel );

Online demo:
https://codepen.io/boytchev/full/mdGPpmW

image

4 Likes