loadgltf.js 550 B

12345678910111213141516
  1. import * as THREE from 'three'
  2. export const loadGltf = function (game, modelPath) {
  3. return new Promise((success, fail) => {
  4. game.gltfLoader.load(modelPath, (gltf) => {
  5. gltf.scene.traverse((child) => {
  6. if (child.isMesh && child.material.isMeshStandardMaterial) {
  7. child.castShadow = true
  8. child.receiveShadow = true
  9. }
  10. })
  11. const group = new THREE.Group()
  12. group.add(gltf.scene)
  13. success(group)
  14. })
  15. })
  16. }