Skip to content

Commit

Permalink
fix: made v-if work again
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinoooo committed Sep 29, 2023
1 parent 193b4ed commit 277e901
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
28 changes: 19 additions & 9 deletions playground/src/pages/TheBasic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ function onPointerEnter(ev) {
ev.object.material.color.set('#DFFF45')
}
}
const sphereExists = ref(true)
</script>

<template>
<input
v-model="sphereExists"
type="checkbox"
>
<TresCanvas v-bind="state">
<TresPerspectiveCamera
:position="[5, 5, 5]"
Expand All @@ -42,15 +48,19 @@ function onPointerEnter(ev) {
<OrbitControls />
<TresAmbientLight :intensity="0.5" />

<TresMesh
ref="sphereRef"
:position="[0, 4, 0]"
cast-shadow
@pointer-enter="onPointerEnter"
>
<TresSphereGeometry :args="[2, 32, 32]" />
<TresMeshToonMaterial color="teal" />
</TresMesh>
<TresGroup>
<TresMesh
ref="sphereRef"
:visible="sphereExists"
:user-data="{ debug: true }"
:position="[0, 4, 0]"
cast-shadow
@pointer-enter="onPointerEnter"
>
<TresSphereGeometry :args="[2, 32, 32]" />
<TresMeshToonMaterial color="teal" />
</TresMesh>
</TresGroup>

<TresDirectionalLight
:position="[0, 8, 4]"
Expand Down
29 changes: 8 additions & 21 deletions src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function noop(fn: string): any {
fn
}

let fallback: TresObject | null = null
let scene: TresScene | null = null

const { logError } = useLogger()
Expand Down Expand Up @@ -76,20 +75,8 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
},
insert(child, parent) {
if (parent && parent.isScene) scene = parent as unknown as TresScene
if (
(child?.__vnode?.type === 'TresGroup' || child?.__vnode?.type === 'TresObject3D')
&& parent === null
&& !child?.__vnode?.ctx?.asyncResolved
) {
fallback = child
return
}
else if (parent === null
&& (child?.__vnode?.type.includes('Controls') || child?.__vnode?.type.includes('Helper'))) {
fallback = scene as unknown as TresObject
}

if (!parent) parent = fallback as TresObject

const parentObject = parent || scene

if (child?.isObject3D) {
if (child?.isCamera) {
Expand All @@ -112,17 +99,17 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
}
}

if (child?.isObject3D && parent?.isObject3D) {
parent.add(child)
if (child?.isObject3D && parentObject?.isObject3D) {
parentObject.add(child)
child.dispatchEvent({ type: 'added' })
}
else if (child?.isFog) {
parent.fog = child
parentObject.fog = child
}
else if (typeof child?.attach === 'string') {
child.__previousAttach = child[parent?.attach as string]
if (parent) {
parent[child.attach] = child
child.__previousAttach = child[parentObject?.attach as string]
if (parentObject) {
parentObject[child.attach] = child
}
}
},
Expand Down

0 comments on commit 277e901

Please sign in to comment.