|
@@ -19,7 +19,7 @@ export function useInstanceCreator(prefix: string) {
|
|
|
|
|
|
Object.entries(props).forEach(([key, value]) => {
|
|
|
const camelKey = key.replace(/(-\w)/g, m => m[1].toUpperCase())
|
|
|
- instance.setAttribute(camelKey, new BufferAttribute(...value))
|
|
|
+ instance.setAttribute(camelKey, new BufferAttribute(...(value as ConstructorParameters<typeof BufferAttribute>)))
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -134,76 +134,79 @@ export function useInstanceCreator(prefix: string) {
|
|
|
}
|
|
|
|
|
|
function createComponentInstances(catalogue: Ref<TresCatalogue>) {
|
|
|
- return Object.entries(catalogue.value)
|
|
|
- .filter(([_key, value]) => (value as { prototype: any })?.prototype?.constructor?.toString().includes('class'))
|
|
|
- .map(([key, threeObj]) => {
|
|
|
- const name = `${prefix}${key}`
|
|
|
- const cmp = defineComponent({
|
|
|
- name,
|
|
|
- setup(props, { slots, attrs, ...ctx }) {
|
|
|
- const { scene: fallback } = useScene()
|
|
|
- const scene = inject<Ref<Scene>>('local-scene') || fallback
|
|
|
- const catalogue = inject<Ref<TresCatalogue>>('catalogue')
|
|
|
- const { pushCamera } = useCamera()
|
|
|
-
|
|
|
- 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) {
|
|
|
- pushCamera(instance)
|
|
|
- }
|
|
|
-
|
|
|
- // If the instance is a valid Object3D, add it to the scene
|
|
|
- if (instance.isObject3D) {
|
|
|
- scene?.value.add(instance)
|
|
|
- }
|
|
|
-
|
|
|
- if (scene?.value && instance.isFog) {
|
|
|
- scene.value.fog = instance as unknown as FogBase
|
|
|
- }
|
|
|
-
|
|
|
- if (import.meta.hot) {
|
|
|
- import.meta.hot.on('vite:beforeUpdate', () => {
|
|
|
- scene.value.remove(instance)
|
|
|
- })
|
|
|
+ return (
|
|
|
+ Object.entries(catalogue.value)
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
+ .filter(([_key, value]) => (value as { prototype: any })?.prototype?.constructor?.toString().includes('class'))
|
|
|
+ .map(([key, threeObj]) => {
|
|
|
+ const name = `${prefix}${key}`
|
|
|
+ const cmp = defineComponent({
|
|
|
+ name,
|
|
|
+ setup(props, { slots, attrs, ...ctx }) {
|
|
|
+ const { scene: fallback } = useScene()
|
|
|
+ const scene = inject<Ref<Scene>>('local-scene') || fallback
|
|
|
+ const catalogue = inject<Ref<TresCatalogue>>('catalogue')
|
|
|
+ const { pushCamera } = useCamera()
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ pushCamera(instance)
|
|
|
+ }
|
|
|
+
|
|
|
+ // If the instance is a valid Object3D, add it to the scene
|
|
|
+ if (instance.isObject3D) {
|
|
|
+ scene?.value.add(instance)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (scene?.value && instance.isFog) {
|
|
|
+ scene.value.fog = instance as unknown as FogBase
|
|
|
+ }
|
|
|
+
|
|
|
+ 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,
|
|
|
+ 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.default ? slots.default() : undefined,
|
|
|
+ attrs,
|
|
|
+ ctx,
|
|
|
+ scene,
|
|
|
})
|
|
|
- }
|
|
|
-
|
|
|
- ctx.expose(instance)
|
|
|
- logMessage(name, {
|
|
|
- sceneuuid: scene?.value.uuid,
|
|
|
- catalogue: catalogue?.value.uuid,
|
|
|
- props,
|
|
|
- slots: slots.default ? slots.default() : undefined,
|
|
|
- attrs,
|
|
|
- ctx,
|
|
|
- scene,
|
|
|
- })
|
|
|
- return () => {}
|
|
|
- },
|
|
|
- })
|
|
|
+ return () => {}
|
|
|
+ },
|
|
|
+ })
|
|
|
|
|
|
- return [name, cmp]
|
|
|
- })
|
|
|
+ return [name, cmp]
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
return {
|