Initially, I created a new THREE.Object3D() and named it groupChair. I then loaded 3 obj files and added them to groupChair within the callback function. After that, I added the groupChair to the scene and it worked perfectly. However, I encountered an issue when trying to clone the groupChair object.
Below is the code snippet:
var groupChair = new THREE.Object3D();
var cloneChair;
var cushion;
var backrest;
var frame;
var loader = new THREE.OBJLoader( manager );
// Loading the first obj file
loader.load('model-stuff/chair/obj/cushion.obj', function( object ) {
object.traverse( function ( child ){
if ( child instanceof THREE.Mesh ) {
child.material = new THREE.MeshStandardMaterial({
map: textureColorForCushion,
roughness: 3,
metalness:0.6,
blending: THREE.NormalBlending,
shading: THREE.SmoothShading,
envMap: textureCube,
});
child.receiveShadow = true;
child.castShadow = true;
}
});
cushion = object;
groupChair.add( cushion );
}, onProgress, onError);
// Loading the second obj file
loader.load('model-stuff/chair/obj/backrest.obj', function( object ) {
object.traverse( function ( child ){
if ( child instanceof THREE.Mesh ) {
child.material = new THREE.MeshStandardMaterial({
map: textureColorForCushion,
roughness: 3,
metalness:0.6,
blending: THREE.NormalBlending,
shading: THREE.SmoothShading,
envMap: textureCube,
});
child.receiveShadow = true;
child.castShadow = true;
}
});
backrest = object;
groupChair.add( backrest );
}, onProgress, onError);
// Loading the third obj file
loader.load('model-stuff/chair/obj/frame.obj', function( object ) {
object.traverse( function ( child ){
if ( child instanceof THREE.Mesh ) {
child.material = new THREE.MeshStandardMaterial({
map: textureColorForFrame,
roughness: 0.9,
metalness:0.4,
blending: THREE.NormalBlending,
shading: THREE.SmoothShading,
envMap: textureCube,
});
child.receiveShadow = true;
child.castShadow = true;
}
});
frame = object;
groupChair.add( frame );
}, onProgress, onError);
scene.add( groupChair );
// Attempting to clone the groupChair object, but faced an issue
cloneChair = groupChair.clone();
cloneChair.position.set(30,0,0);
scene.add( cloneChair );