Three.js - load JSON model once and add it multiple times

前端 未结 2 628
醉酒成梦
醉酒成梦 2021-01-14 16:17

Is it possible to load a JSON model once and add it to the scene multiple times with different scales, positions, etc?

If I add the Object3D() to an array, give a po

相关标签:
2条回答
  • 2021-01-14 17:01

    You can create new meshes from the same geometries and materials:

    loader.load( "models/model.js", function( geometry ) {
            var mat = new THREE.MeshLambertMaterial( { map: modelTex });
            for (var i = 0; i < 5; i++) { 
                var mesh = new THREE.Mesh( geometry, mat );
                mesh.position.set(i, i, i);
                mesh.scale.set(i, i, i);
                scene.add(mesh);
            }
    });
    
    0 讨论(0)
  • 2021-01-14 17:16

    You need to clone a model first and then set position and scale.

     for(var i = 0; i < 5; i++){ 
            var newModel = model.clone();
                newModel.position.set(i,i,i);
                newModel.scale.set(i,i,i);
    
                scene.add(newModel); 
    }  
    

    Updated: Example how you can create json model without load : Fiddle example or just simple add loop inside load function.

    0 讨论(0)
提交回复
热议问题