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
Next Next commit
feat(nodeOps): switch instance logic for reactive object prop
  • Loading branch information
alvarosabu committed Jan 18, 2024
commit cf979fac0bf390144a8f857b91e27756ea7b14ec
32 changes: 12 additions & 20 deletions playground/src/components/TheExperience.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ref, watchEffect } from 'vue'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { TresLeches, useControls } from '@tresjs/leches'
import '@tresjs/leches/styles'
import TheSphere from './TheSphere.vue'

const gl = {
Expand All @@ -19,25 +17,18 @@ const gl = {
const wireframe = ref(true)

const canvas = ref()
const meshRef = ref()

const { isVisible } = useControls({
isVisible: true,
})

watchEffect(() => {
if (meshRef.value) {
console.log(meshRef.value)
if (canvas.value) {
console.log(canvas.value.context)
}
})
</script>

<template>
<TresLeches />
<TresCanvas
v-bind="gl"
ref="canvas"
window-size
class="awiwi"
:style="{ background: '#008080' }"
>
Expand All @@ -46,10 +37,14 @@ watchEffect(() => {
:look-at="[0, 4, 0]"
/>
<OrbitControls />
<TresFog
:color="gl.clearColor"
:near="5"
:far="15"
/>
<TresMesh
:position="[-2, 6, 0]"
:rotation="[0, Math.PI, 0]"
name="cone"
cast-shadow
>
<TresConeGeometry :args="[1, 1.5, 3]" />
Expand All @@ -66,22 +61,19 @@ watchEffect(() => {
/>
</TresMesh>
<TresMesh
ref="meshRef"
:rotation="[-Math.PI / 2, 0, Math.PI / 2]"
name="floor"
:rotation="[-Math.PI / 2, 0, 0]"
receive-shadow
>
<TresPlaneGeometry :args="[20, 20, 20]" />
<TresMeshToonMaterial
color="#D3FC8A"
/>
<TresPlaneGeometry :args="[10, 10, 10, 10]" />
<TresMeshToonMaterial color="#D3FC8A" />
</TresMesh>
<TheSphere v-if="isVisible" />
<TheSphere />
<TresAxesHelper :args="[1]" />
<TresDirectionalLight
:position="[0, 2, 4]"
:intensity="2"
cast-shadow
/>
<TresOrthographicCamera />
</TresCanvas>
</template>
81 changes: 81 additions & 0 deletions playground/src/pages/primitives.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script setup lang="ts">
import { ref, watchEffect } from 'vue'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping, Mesh, TorusGeometry, MeshToonMaterial, TorusKnotGeometry, PlaneGeometry } 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 plane = new Mesh(
new PlaneGeometry(10, 10, 10, 10),
new MeshToonMaterial({
color: '#82DBC5',
}),
)
</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="[0, 2, 0]"
:object="knot ? torusKnot : torusMesh"
/>
<primitive :object="plane" />
<TresAxesHelper :args="[1]" />
<TresDirectionalLight
:position="[0, 2, 4]"
:intensity="2"
cast-shadow
/>
</TresCanvas>
</template>
5 changes: 5 additions & 0 deletions playground/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const routes = [
name: 'Perf',
component: () => import('./pages/perf/index.vue'),
},
{
path: '/primitives',
name: 'Primitives',
component: () => import('./pages/primitives.vue'),
},
{
path: '/empty',
name: 'empty',
Expand Down
Loading