|
@@ -4,7 +4,7 @@ import { OrthographicCamera, PerspectiveCamera, Scene } from 'three'
|
|
|
import { defineComponent, inject, Ref } from 'vue'
|
|
|
import { isArray, isDefined, isFunction } from '@alvarosabu/utils'
|
|
|
import { normalizeVectorFlexibleParam } from '/@/utils/normalize'
|
|
|
-import { useCamera, useScene } from '/@/core/'
|
|
|
+import { useCamera, useCatalogue, useScene } from '/@/core/'
|
|
|
import { useLogger } from '/@/composables'
|
|
|
import { TresAttributes, TresCatalogue, TresInstance, TresVNode, TresVNodeType } from '/@/types'
|
|
|
|
|
@@ -69,7 +69,8 @@ export function useInstanceCreator(prefix: string) {
|
|
|
return
|
|
|
} else {
|
|
|
const vNodeType = ((vnode.type as TresVNodeType).name as string).replace(prefix, '')
|
|
|
- const catalogue = inject<Ref<TresCatalogue>>('catalogue')
|
|
|
+ const { catalogue: fallback } = useCatalogue()
|
|
|
+ const catalogue = inject<Ref<TresCatalogue>>('catalogue') || fallback
|
|
|
// check if args prop is defined on the vnode
|
|
|
let internalInstance
|
|
|
if (catalogue) {
|
|
@@ -130,7 +131,7 @@ export function useInstanceCreator(prefix: string) {
|
|
|
const catalogue = inject<Ref<TresCatalogue>>('catalogue')
|
|
|
const { pushCamera } = useCamera()
|
|
|
|
|
|
- const instance = createInstance(threeObj, attrs, slots)
|
|
|
+ let instance = createInstance(threeObj, attrs, slots)
|
|
|
processProps(attrs, instance)
|
|
|
// If the instance is a camera, push it to the camera stack
|
|
|
if (instance instanceof PerspectiveCamera || instance instanceof OrthographicCamera) {
|
|
@@ -142,12 +143,38 @@ export function useInstanceCreator(prefix: string) {
|
|
|
scene?.value.add(instance)
|
|
|
}
|
|
|
|
|
|
+ if (import.meta.hot) {
|
|
|
+ import.meta.hot.on('vite:beforeUpdate', () => {
|
|
|
+ scene.value.remove(instance)
|
|
|
+ })
|
|
|
+
|
|
|
+ import.meta.hot.on('vite:afterUpdate', () => {
|
|
|
+ instance = createInstance(threeObj, attrs, slots)
|
|
|
+ processProps(attrs, instance)
|
|
|
+
|
|
|
+ if (instance.isObject3D) {
|
|
|
+ scene?.value.add(instance)
|
|
|
+ }
|
|
|
+
|
|
|
+ logMessage(name, {
|
|
|
+ instance,
|
|
|
+ sceneuuid: scene?.value.uuid,
|
|
|
+ catalogue: catalogue?.value.uuid,
|
|
|
+ props,
|
|
|
+ slots: slots.default ? slots.default() : undefined,
|
|
|
+ attrs,
|
|
|
+ ctx,
|
|
|
+ scene,
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
ctx.expose(instance)
|
|
|
logMessage(name, {
|
|
|
sceneuuid: scene?.value.uuid,
|
|
|
catalogue: catalogue?.value.uuid,
|
|
|
props,
|
|
|
- slots,
|
|
|
+ slots: slots.default ? slots.default() : undefined,
|
|
|
attrs,
|
|
|
ctx,
|
|
|
scene,
|