-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 503 conditional rendering of primitives (#514)
* feat(nodeOps): switch instance logic for reactive `object` prop * chore: playground primitives with models * chore: fix linter * chore: fix tests and linters, primitive object is now reactive * chore: refactor instance swaping logic to overwrite set and copy properties * chore: tests * chore: remove console.log * chore: remove unused import watch * feat: add primitive conditional to patch object prop
- Loading branch information
1 parent
898a8b1
commit 79d8a76
Showing
7 changed files
with
225 additions
and
36 deletions.
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,21 @@ | ||
<script setup lang="ts"> | ||
import { useControls } from '@tresjs/leches' | ||
import { useGLTF } from '@tresjs/cientos' | ||
const { nodes } | ||
= await useGLTF('https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/blender-cube.glb', | ||
{ draco: true }) | ||
const { scene: AkuAku, nodes: akukuNodes } = await useGLTF( | ||
'https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/aku-aku/AkuAku.gltf', | ||
{ draco: true }, | ||
) | ||
const { isCube } = useControls({ | ||
isCube: false, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<primitive :object="isCube ? nodes.Cube : AkuAku" /> | ||
</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,135 @@ | ||
<script setup lang="ts"> | ||
import { ref, watchEffect } from 'vue' | ||
import { | ||
BasicShadowMap, | ||
SRGBColorSpace, | ||
NoToneMapping, | ||
Mesh, | ||
TorusGeometry, | ||
MeshToonMaterial, | ||
TorusKnotGeometry, | ||
PlaneGeometry, | ||
Group, | ||
SphereGeometry, | ||
} from 'three' | ||
import { TresCanvas, useRenderLoop } 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 canvas = ref() | ||
const meshRef = ref() | ||
const { knot } = useControls({ | ||
knot: true, | ||
}) | ||
const { isVisible } = useControls({ | ||
isVisible: true, | ||
}) | ||
watchEffect(() => { | ||
if (meshRef.value) { | ||
console.log(meshRef.value) | ||
} | ||
}) | ||
const torus = 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', | ||
}), | ||
) | ||
sphere.position.set(2, -2, 0) | ||
const firstGroup = new Group() | ||
firstGroup.add(torus) | ||
firstGroup.add(torusKnot) | ||
const secondGroup = new Group() | ||
secondGroup.add(sphere) | ||
const primitiveRef = ref() | ||
useRenderLoop().onLoop(() => { | ||
if (primitiveRef.value) { | ||
primitiveRef.value.rotation.x += 0.01 | ||
primitiveRef.value.rotation.y += 0.01 | ||
} | ||
}) | ||
watchEffect(() => { | ||
console.log('primitiveRef.value', primitiveRef.value) | ||
}) | ||
const reactivePrimitiveRef = ref(new Mesh( | ||
new TorusKnotGeometry(1, 0.5, 100, 16), | ||
new MeshToonMaterial({ | ||
color: 'orange', | ||
}), | ||
)) | ||
const modelArray = ref([torus, torusKnot, sphere]) | ||
</script> | ||
|
||
<template> | ||
<TresLeches /> | ||
<TresCanvas | ||
v-bind="gl" | ||
ref="canvas" | ||
window-size | ||
class="awiwi" | ||
:style="{ background: '#008080' }" | ||
> | ||
<TresPerspectiveCamera | ||
:position="[7, 7, 7]" | ||
/> | ||
<OrbitControls /> | ||
<!-- <primitive | ||
:object="reactivePrimitiveRef" | ||
/> --> | ||
<!-- <primitive | ||
v-for="(model, index) of modelArray" | ||
:key="index" | ||
:object="model" | ||
:position="[index * 2, index * 2, 0]" | ||
/> --> | ||
<primitive | ||
v-if="isVisible" | ||
ref="primitiveRef" | ||
:object="knot ? torusKnot : torus" | ||
/> | ||
<!-- <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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.