Skip to content

Commit

Permalink
feat: on-demand Wobble Material
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Jun 17, 2024
1 parent ee5f40d commit 14b3bc3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const context = ref()
<TresCanvas
v-bind="gl"
ref="context"
render-mode="on-demand"
>
<TresPerspectiveCamera :position="[3, 3, 3]" />
<TresMesh>
Expand Down
2 changes: 1 addition & 1 deletion playground/src/router/routes/materials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const materialsRoutes = [
{
path: '/materials/wobble-material',
name: 'WobbleMaterial',
component: () => import('../../pages/materials/WobbleMaterial.vue'),
component: () => import('../../pages/materials/WobbleMaterialDemo.vue'),
},
{
path: '/materials/glass-material',
Expand Down
4 changes: 4 additions & 0 deletions src/core/materials/meshWobbleMaterial/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { shallowRef } from 'vue'
import { useLoop, useTresContext } from '@tresjs/core'
import { useOnDemandInvalidation } from '../../../composables/useOnDemandInvalidation'
import { WobbleMaterialImpl as MeshWobbleMaterial } from './material'
Expand All @@ -15,6 +16,8 @@ const props = withDefaults(
},
)
const { invalidateOnDemand } = useOnDemandInvalidation(props)
const materialRef = shallowRef()
const { extend } = useTresContext()
Expand All @@ -25,6 +28,7 @@ const { onBeforeRender } = useLoop()
onBeforeRender(({ elapsed }) => {
if (materialRef.value) {
materialRef.value.time = elapsed * props?.speed
invalidateOnDemand()
}
})
Expand Down

0 comments on commit 14b3bc3

Please sign in to comment.