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

feat: 503 conditional rendering of primitives #514

Merged
merged 10 commits into from
Feb 21, 2024
Prev Previous commit
Next Next commit
chore: tests
  • Loading branch information
alvarosabu committed Feb 2, 2024
commit 37ab90419648a3685d844a2ada0643b60d17a996
42 changes: 37 additions & 5 deletions playground/src/pages/primitives.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Group,
SphereGeometry,
} from 'three'
import { TresCanvas } from '@tresjs/core'
import { TresCanvas, useRenderLoop } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { TresLeches, useControls } from '@tresjs/leches'
import '@tresjs/leches/styles'
Expand All @@ -29,7 +29,7 @@ const canvas = ref()
const meshRef = ref()

const { knot } = useControls({
knot: false,
knot: true,
})

const { isVisible } = useControls({
Expand Down Expand Up @@ -71,6 +71,28 @@ 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>
Expand All @@ -86,13 +108,23 @@ secondGroup.add(sphere)
: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"
:object="knot ? firstGroup : sphere"
ref="primitiveRef"
:object="knot ? torusKnot : torus"
/>
<Suspense>
<!-- <Suspense>
<DynamicModel />
</Suspense>
</Suspense> -->
<TresAxesHelper :args="[1]" />
<TresDirectionalLight
:position="[0, 2, 4]"
Expand Down
Loading