Will three.js Object3D.clone() create a deep copy of the geometry?

前端 未结 4 2074
轮回少年
轮回少年 2021-01-03 04:12

I\'m loading models using the collada loader. The loader returns an Object3D, \"dae\", with many child meshes. I\'d like to instantiate the parent \"dae\" object many times

4条回答
  •  时光取名叫无心
    2021-01-03 04:40

    Here is a couple of function I use to clone object's materials deeply. You could modify this to your needs

    Also consider this information : https://github.com/mrdoob/three.js/issues/5754

        /** Gives the aptitude for an object3D to clone recursively with its material cloned (normal clone does not clone material)*/
    
        THREE.Object3D.prototype.GdeepCloneMaterials = function() {
            var object = this.clone( new THREE.Object3D(), false );
    
            for ( var i = 0; i < this.children.length; i++ ) {
    
                var child = this.children[ i ];
                if ( child.GdeepCloneMaterials ) {
                    object.add( child.GdeepCloneMaterials() );
                } else {
                    object.add( child.clone() );
                }
    
            }
            return object;
        };
    
        THREE.Mesh.prototype.GdeepCloneMaterials = function( object, recursive ) {
            if ( object === undefined ) {
                object = new THREE.Mesh( this.geometry, this.material.clone() );
            }
    
            THREE.Object3D.prototype.GdeepCloneMaterials.call( this, object, recursive );
    
            return object;
        };
    

提交回复
热议问题