![](https://cdn.statically.io/img/cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon@2.png)
I'm trying to replace an object3D
with a character
model, with another one, while keeping all it's properties, such as the position
var object = new THREE.Object3D( ); object = models.character[0].clone( ); object.position.set( 100, 230, 15 ); scene.add( object.scene ); const clip = THREE.AnimationClip.findByName( object.animations, 'idle' ); var action = mixer.clipAction( clip ); action.play(); //...later on, replace the model, while keeping it's position object = models.character[1].clone( );
How do I replace the model of an THREE.Object3D( )
?
1 Answer
An Object3D
doesn't have a model because it doesn't have geometry or materials. This line of code doesn't do anything because you're immediately replacing the Object3D with something else:
var object = new THREE.Object3D( ); object = models.character[0].clone( );
I think you should be using a Mesh
, which is a subclass of Object3D. Now, if you want to change the "model" of a Mesh
, you can access its .geometry
property, and assign it a new one:
// This is the original geometry const mesh = new THREE.Mesh(geometry, material); mesh.position.set(100, 230, 15); // Here we assign a new geometry to the Mesh mesh.geometry = someOtherGeometry;
1ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobXJwZ2WCeYGOrZ%2BrnZVit7R5x6iuZqyfYr%2BmvMuamp5lpJ2ybrnOnZylZZ%2BbeqK6jKiZo52TqYCl