Skip to content

Commit

Permalink
fix: added scene fallback as parent for controls
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed May 26, 2023
1 parent 899880a commit e986f9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default defineConfig({
plugins: [
glsl(),
vue({
script: {
propsDestructure: true,
},
template: {
compilerOptions: {
isCustomElement: tag => (tag.startsWith('Tres') && tag !== 'TresCanvas') || tag === 'primitive',
Expand Down
7 changes: 4 additions & 3 deletions src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -79,19 +79,20 @@ 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 &&
!child?.__vnode?.ctx?.asyncResolved
) {
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' })
Expand Down

0 comments on commit e986f9c

Please sign in to comment.