Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): made v-if work again #409

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: made v-if work again
  • Loading branch information
Tinoooo committed Sep 29, 2023
commit 277e901f8e41dc72bf755db17c584b3e28086347
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
Loading