Browse Source

fix: added scene fallback as parent for controls

alvarosabu 1 year ago
parent
commit
e986f9ca2e
2 changed files with 7 additions and 3 deletions
  1. 3 0
      playground/vite.config.ts
  2. 4 3
      src/core/nodeOps.ts

+ 3 - 0
playground/vite.config.ts

@@ -11,6 +11,9 @@ export default defineConfig({
   plugins: [
     glsl(),
     vue({
+      script: {
+        propsDestructure: true,
+      },
       template: {
         compilerOptions: {
           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 scene: Scene | null = null
 const OBJECT_3D_USER_DATA_KEYS = {
   GEOMETRY_VIA_PROP: 'tres__geometryViaProp',
   MATERIAL_VIA_PROP: 'tres__materialViaProp',
@@ -79,6 +79,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     return instance
   },
   insert(child, parent) {
+    if (parent && parent.isScene) scene = parent
     if (
       (child?.__vnode?.type === 'TresGroup' || child?.__vnode?.type === 'TresObject3D') &&
       parent === null &&
@@ -86,12 +87,12 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     ) {
       fallback = child
       return
+    } else if (child?.__vnode?.type.includes('Controls') && parent === null) {
+      fallback = scene
     }
 
     if (!parent) parent = fallback as TresObject
 
-    //vue core
-    /*  parent.insertBefore(child, anchor || null) */
     if (child?.isObject3D && parent?.isObject3D) {
       parent.add(child)
       child.dispatchEvent({ type: 'added' })