Clone mesh doesn’t clone its material and geometry objects

Description of the problem

When I try to clone a mesh object I expect it will be full cloned, with “new” material and geometry objects. Is this behavior on purpose?

Three.js version
  • Dev
  • r93
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
  • chromium (nw js actually)
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
    captura de tela de 2018-06-04 21-59-15

Author: Fantashit

1 thought on “Clone mesh doesn’t clone its material and geometry objects

  1. Hi @marcobraghim, this is as intended. There is a high performance cost to deeply cloning materials, textures, and geometry — not just while duplicating them, but higher cost to render after that. Because you generally want to have as few materials and geometries as possible, it’s better to clone only what you need:

    mesh2 = mesh1.clone();
    mesh2.traverse((node) => {
      if (node.isMesh) {
        node.material = node.material.clone();
      }
    });

Comments are closed.