Problems encountered in threejs loading model

Today, when dealing with the Obj model loaded by threejs, I want to load it into the page at one time according to the different types of the model.

Determine the type of the model according to the name in the children in the model

//consle.log(this.modelObject.children.length) //86
this.modelObject.traverse(child => {
      console.log("in")
      scene.add(child);
  })

If the above code does not add scene.add(child), the number of "in" printed on the console is correct. Once scene.add(child) is added, the number of "in" printed on the console will not correct

After understanding, it is found that the scene.add() method will not copy a child to the scene. The original child belongs to this.modelObject. If the child is directly added to the scene, the hierarchical relationship (parent-child relationship) will be confused.

Therefore, it is necessary to create a separate piece of data and add it to the scene so that the data in the model can be loaded into the scene in turn.

this.modelObject.traverse(child => {
      console.log("in")
      scene.add(child.clone());
  })

或者 
scene.add(...this.modelObject.children)

\

おすすめ

転載: blog.csdn.net/workhard0905/article/details/121403526
おすすめ