Browse Source

fix(cientos): expose get model on gltf component to get instance

Alvaro 2 years ago
parent
commit
bd23b8d2b3
1 changed files with 8 additions and 2 deletions
  1. 8 2
      packages/cientos/src/core/useGLTF/component.ts

+ 8 - 2
packages/cientos/src/core/useGLTF/component.ts

@@ -10,13 +10,19 @@ export const GLTFModel = defineComponent({
     decoderPath: String,
     decoderPath: String,
   },
   },
 
 
-  async setup(props) {
+  async setup(props, { expose }) {
     const scene = inject<Ref<Scene>>('local-scene')
     const scene = inject<Ref<Scene>>('local-scene')
 
 
+    function getModel() {
+      return model
+    }
+    expose({ getModel })
     const { scene: model } = await useGLTF(props.path as string, { draco: props.draco, decoderPath: props.decoderPath })
     const { scene: model } = await useGLTF(props.path as string, { draco: props.draco, decoderPath: props.decoderPath })
     if (scene?.value) {
     if (scene?.value) {
       scene.value.add(model)
       scene.value.add(model)
     }
     }
-    return () => null
+    return () => {
+      model
+    }
   },
   },
 })
 })