-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
feat: 503 conditional rendering of primitives #514
Merged
alvarosabu
merged 10 commits into
v4
from
feature/503-conditional-rendering-of-primitives
Feb 21, 2024
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cf979fa
feat(nodeOps): switch instance logic for reactive `object` prop
alvarosabu 5a24eea
chore: playground primitives with models
alvarosabu 5ed02b6
chore: fix linter
alvarosabu 8d52f32
chore: fix tests and linters, primitive object is now reactive
alvarosabu 2df1e65
chore: refactor instance swaping logic to overwrite set and copy prop…
alvarosabu 3490c4a
Merge branch 'v4' into feature/503-conditional-rendering-of-primitives
alvarosabu 37ab904
chore: tests
alvarosabu b0ba190
chore: remove console.log
alvarosabu de730ef
chore: remove unused import watch
alvarosabu 8408351
feat: add primitive conditional to patch object prop
alvarosabu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script setup lang="ts"> | ||
import { useControls } from '@tresjs/leches' | ||
import { useGLTF } from '@tresjs/cientos' | ||
|
||
const { scene } = await useGLTF('https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/blender-cube.glb', | ||
{ draco: true }) | ||
|
||
const { nodes } = await useGLTF( | ||
'https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/aku-aku/AkuAku.gltf', | ||
{ draco: true }, | ||
) | ||
const model = nodes.AkuAku | ||
const { isCube } = useControls({ | ||
isCube: true, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<primitive :object="isCube ? scene : model" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<script setup lang="ts"> | ||
import { ref, watchEffect } from 'vue' | ||
import { BasicShadowMap, SRGBColorSpace, NoToneMapping, Mesh, TorusGeometry, MeshToonMaterial, TorusKnotGeometry, PlaneGeometry, Group, SphereGeometry } from 'three' | ||
import { TresCanvas } from '@tresjs/core' | ||
import { OrbitControls } from '@tresjs/cientos' | ||
import { TresLeches, useControls } from '@tresjs/leches' | ||
import '@tresjs/leches/styles' | ||
|
||
const gl = { | ||
clearColor: '#82DBC5', | ||
shadows: true, | ||
alpha: false, | ||
shadowMapType: BasicShadowMap, | ||
outputColorSpace: SRGBColorSpace, | ||
toneMapping: NoToneMapping, | ||
} | ||
|
||
const wireframe = ref(true) | ||
|
||
const canvas = ref() | ||
const meshRef = ref() | ||
|
||
const { knot } = useControls({ | ||
knot: true, | ||
}) | ||
|
||
watchEffect(() => { | ||
if (meshRef.value) { | ||
console.log(meshRef.value) | ||
} | ||
}) | ||
|
||
const torusMesh = new Mesh( | ||
new TorusGeometry(1, 0.5, 16, 100), | ||
new MeshToonMaterial({ | ||
color: '#82DBC5', | ||
}), | ||
) | ||
|
||
const torusKnot = new Mesh( | ||
new TorusKnotGeometry(1, 0.5, 100, 16), | ||
new MeshToonMaterial({ | ||
color: '#ff00ff', | ||
}), | ||
) | ||
|
||
const sphere = new Mesh( | ||
new SphereGeometry(1, 32, 32), | ||
new MeshToonMaterial({ | ||
color: '#82DBC5', | ||
}), | ||
) | ||
|
||
const firstGroup = new Group() | ||
firstGroup.add(torusMesh) | ||
firstGroup.add(torusKnot) | ||
|
||
const secondGroup = new Group() | ||
secondGroup.add(sphere) | ||
</script> | ||
|
||
<template> | ||
<TresLeches /> | ||
<TresCanvas | ||
v-bind="gl" | ||
ref="canvas" | ||
window-size | ||
class="awiwi" | ||
:style="{ background: '#008080' }" | ||
> | ||
<TresPerspectiveCamera | ||
:position="[7, 7, 7]" | ||
:look-at="[0, 4, 0]" | ||
/> | ||
<OrbitControls /> | ||
<primitive | ||
:position="[4, 2, 0]" | ||
:object="knot ? firstGroup : secondGroup" | ||
/> | ||
<Suspense> | ||
<DynamicModel /> | ||
</Suspense> | ||
<TresAxesHelper :args="[1]" /> | ||
<TresDirectionalLight | ||
:position="[0, 2, 4]" | ||
:intensity="2" | ||
cast-shadow | ||
/> | ||
</TresCanvas> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
nodeOps.ts
, I mentioned that cloning means that setup references are lost. Below is some demonstration code that can be pasted here.Both
torus
andtorusKnot
continue to exist after theclone
, but they no longer point to the on-screen objects, so the on-screen objects don't update.If the objects aren't
clone()
d innodeOps
, the on-screen shapes will rotate – but other errors pop up.I don't know if there's a workaround here. Just pointing it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andretchen0 This argument makes me think we should abandon the idea of trying to make
:object
prop reactive, swiping instances without losing the ref is getting too complicated.Users could still use primitives with conditional rendering, I wanted
primitive
to work similar tocomponent
but honestly at this point I don't know how to achieve it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alvarosabu
I don't understand the internals of Tres well enough to have an opinion on the feasibility here.
I'll start reading the source after I finish
<AnimatedSprite />
for Cientos.I agree that this is a worthwhile goal. It'd be great if it "just works".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andretchen0 let me know if you are up to a pair-programming call to discuss the internals when you get free let me know, we definitely can use your knowledge and your quality feedback inside of the custom renderer code. 💚
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alvarosabu
Sure thing. That could be fun!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @andretchen0 I created a thread on the core team discord channel discussing this but to give a summary:
I found a way of making it work (animations), the only constraint is that the object passed through
:object
needs to be of the same type (mesh -> mesh) (group -> group). If we do (mesh -> group), it doesn't work anymore.Screen_Recording_2024-02-02_at_12.43.44.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll go read the Discord.