How to create a copy from a model?

Hi,
In my example, I’ve moved a copy of the model outside of gltfloader. I’m not sure if it’s right or wrong, but the size and location are correct.

const model = new THREE.Mesh();
scene.add(model);

const gltfBox = new THREE.Box3().setFromObject(model);
const helper2 = new THREE.Box3Helper(gltfBox, 0xffff00);
scene.add(helper2);
gltfLoader.load('https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Fox/glTF/Fox.gltf',(gltf) => {
  gltf.scene.traverse((child) => {
    gltf.scene.updateMatrixWorld(true);
    if (child.isMesh) {

      child.scale.set(0.03, 0.03, 0.03);
      child.position.set(0, -1, 0);
      child.rotation.y = -Math.PI * 4;

      model.copy(child);
    }
  });
});

The problem is that box3 doesn’t work properly on the model.

You need to wait for the model to load, which doesn’t happen right away, then you can apply the box. Otherwise you apply the box to an empty mesh.

Changes to your code - just declare variables here:

...
const model = new THREE.Mesh();
scene.add(model);
console.log(model);

let gltfBox, helper2;

function updateBoxes() {
  dummies.forEach((d, idx) => {

move the action to the function that runs after the model is loaded:

...
      sceneMeshes.push(child);
      model.copy(child);

      gltfBox = new THREE.Box3().setFromObject(model);
      helper2 = new THREE.Box3Helper(gltfBox, 0xffff00);
      scene.add(helper2);
      updateBoxes();
      renderer.render(scene, camera);

I appreciate you