How to clone an object3d in Three.js?

前端 未结 3 719
我在风中等你
我在风中等你 2020-12-10 03:23

I want to clone a model loaded with loader, I found this issue on github,but the solution doesn\'t work. It seems there has been an structural change in Object3D.

Ho

3条回答
  •  轮回少年
    2020-12-10 04:06

    I found one fast solution (not the most efficient)

    The GLTFLoader uses the THREE.FileLoader() method internally, which allows you to cache files.
    To do so, you need to add this line before you create an instance of the GLTFLoader

    THREE.Cache.enabled = true;
    

    Then you can load multiple times the same model, but only the first time will take longer, for example:

    THREE.Cache.enabled = true;
    
    var loader = new GLTFLoader();
    
    var deeplyClonedModels = [];
    
    for( var i = 0; i < 10; i++ ){
    
       loader.load('foo.gltf', function ( gltf ) {
    
         deeplyClonedModels.push(gltf.scene);
    
      });
    
    }
    

提交回复
热议问题