1
0
Эх сурвалжийг харах

fix: added scene fallback as parent for controls

alvarosabu 1 жил өмнө
parent
commit
e986f9ca2e

+ 3 - 0
playground/vite.config.ts

@@ -11,6 +11,9 @@ export default defineConfig({
   plugins: [
   plugins: [
     glsl(),
     glsl(),
     vue({
     vue({
+      script: {
+        propsDestructure: true,
+      },
       template: {
       template: {
         compilerOptions: {
         compilerOptions: {
           isCustomElement: tag => (tag.startsWith('Tres') && tag !== 'TresCanvas') || tag === 'primitive',
           isCustomElement: tag => (tag.startsWith('Tres') && tag !== 'TresCanvas') || tag === 'primitive',

+ 4 - 3
src/core/nodeOps.ts

@@ -14,7 +14,7 @@ function noop(fn: string): any {
 }
 }
 
 
 let fallback: TresObject | null = null
 let fallback: TresObject | null = null
-
+let scene: Scene | null = null
 const OBJECT_3D_USER_DATA_KEYS = {
 const OBJECT_3D_USER_DATA_KEYS = {
   GEOMETRY_VIA_PROP: 'tres__geometryViaProp',
   GEOMETRY_VIA_PROP: 'tres__geometryViaProp',
   MATERIAL_VIA_PROP: 'tres__materialViaProp',
   MATERIAL_VIA_PROP: 'tres__materialViaProp',
@@ -79,6 +79,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     return instance
     return instance
   },
   },
   insert(child, parent) {
   insert(child, parent) {
+    if (parent && parent.isScene) scene = parent
     if (
     if (
       (child?.__vnode?.type === 'TresGroup' || child?.__vnode?.type === 'TresObject3D') &&
       (child?.__vnode?.type === 'TresGroup' || child?.__vnode?.type === 'TresObject3D') &&
       parent === null &&
       parent === null &&
@@ -86,12 +87,12 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     ) {
     ) {
       fallback = child
       fallback = child
       return
       return
+    } else if (child?.__vnode?.type.includes('Controls') && parent === null) {
+      fallback = scene
     }
     }
 
 
     if (!parent) parent = fallback as TresObject
     if (!parent) parent = fallback as TresObject
 
 
-    //vue core
-    /*  parent.insertBefore(child, anchor || null) */
     if (child?.isObject3D && parent?.isObject3D) {
     if (child?.isObject3D && parent?.isObject3D) {
       parent.add(child)
       parent.add(child)
       child.dispatchEvent({ type: 'added' })
       child.dispatchEvent({ type: 'added' })