three.js获取模型所有子对象

作者:iohannes 发布时间: 2025-03-18 阅读量:17
new OBJLoader().load('dt.obj', function (object) {
  function getChildrenObj(object, resultMap) {
    object.traverse((v) => {
      if (v.isMesh && v.material) {
        v.castShadow = true;
        v.frustumCulled = false;
        const { name, color, map } = v.material;
        v.material = new THREE.MeshStandardMaterial({
          map,
          transparent: true,
          color,
          name
        });
        resultMap[v.name] = v;
      }
    });
  }
});