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 all commits
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@


## [3.3.0-next.0](https://github.com/Tresjs/tres/compare/3.2.3...3.3.0-next.0) (2023-09-29)


### Features

* context (TresContext) is now exposed from TresCanvas ([#404](https://github.com/Tresjs/tres/issues/404)) ([838d779](https://github.com/Tresjs/tres/commit/838d779e59494cacf61274fe497373983dbe8278))


### Bug Fixes

* made v-if work again ([277e901](https://github.com/Tresjs/tres/commit/277e901f8e41dc72bf755db17c584b3e28086347))

## [3.2.3](https://github.com/Tresjs/tres/compare/3.2.2...3.2.3) (2023-09-22)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tresjs/core",
"type": "module",
"version": "3.2.3",
"version": "3.3.0-next.0",
"packageManager": "[email protected]",
"description": "Declarative ThreeJS using Vue Components",
"author": "Alvaro Saburido <[email protected]> (https://github.com/alvarosabu/)",
Expand Down
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