About clone Object showing black materials

Hey,everybody,good evening!
I just now try to use MTLLoader and OBJLoader loading my obj.It is working,but clone them to other layers showing black,I thought obj maybe lose texture ,but console mtl that it had worked.
The code:

    initGraphic(){
            this.loadObject('../../static/model/buiding/first/first/first',new THREE.Vector3(0,0,0),0)
            this.loadObject('../../static/model/buiding/first/houti/houti',new THREE.Vector3(0,0,0),0)
            this.loadObject('../../static/model/buiding/first/houseTop/houseTop',new THREE.Vector3(0,0,0),0)
            this.loadObject('../../static/model/buiding/first/second/second',new THREE.Vector3(0,0,0),0)
        },
        loadObject(url,addPoint,layers){
            let objscene=this.scene
            let that=this
            let mtlLoader=new MTLLoader()
            mtlLoader.load(url+'.mtl',function(mtl){
                mtl.preload()
                if(layers==1)
                console.log(mtl)
                let objLoader=new OBJLoader()
                objLoader.setMaterials(mtl)
                objLoader.load(url+'.obj',function(obj){
                    // shadow
                    // for(let i=0;i<obj.children.length;i++){
                    //     obj.children[i].castShadow=true
                    //     obj.children[i].receiveShadow=true
                    // }
                    objscene.add(obj)
                    for(let i=0;i<obj.children.length;i++){
                         obj.children[i].layers.set(layers)
                        that.defaultboxArr.push(obj.children[i])
                    }
                })
            })
        },
        initOperation(){
            this.raycaster=new THREE.Raycaster()
            this.mouse=new THREE.Vector2()
            this.objectAll=new THREE.Object3D()
            window.addEventListener('click',(event)=>{
                if(this.layers==0) {
                    this.mouse.x = ( event.clientX / this.windowWidth ) * 2 - 1;
                    this.mouse.y = - ( event.clientY / this.windowHeight ) * 2 + 1;
                    this.raycaster.setFromCamera( this.mouse, this.camera );
                    this.intersections= this.raycaster.intersectObjects( this.defaultboxArr );
                     if(this.intersections.length > 0){
                        let newGroup=this.intersections[0].object.parent
                        this.objectAll.children=[]
                        this.objectAll.add(newGroup.clone())
                        this.objectAll.traverse(child=>{
                            child.layers.set(1)
                        })
                         this.scene.add(this.objectAll)
                        this.camera.layers.set(1)
                        this.layers=1
                        this.camera.updateProjectionMatrix ()
                     }
                }
                else{
                     this.camera.layers.set(0);
                      this.layers=0
                     this.camera.updateProjectionMatrix()
                }
           })  
        }

When initializing, I call initGraphic.it’s working. and then ,When I click on an object, the group color changes to black!
When loading normally:


otherwise:

(upload://fzQOAClsE4TQzNmOG3WUgvZi7KI.png)

Thanks for your reading and looking forward to your reply,good night!!!

em… , it is seems that lose the materials and textures.how to solve it!
anybody can help me? :pensive: :pensive:

Unfortunately, it’s not really clear from your code example how the clone operation fails. Do you mind demonstrating the issue with a live example? https://jsfiddle.net/f2Lommf5/

thanks for your reply. i have tried again last night,and knowing that different layers need to add light, but I only added the first layer, and the others didn’t.
now, it’s working.:joy: :joy: :joy: