iohannes
Published on 2025-03-18 / 0 Visits

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

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;
      }
    });
  }
});