Giter Site home page Giter Site logo

Comments (2)

andretchen0 avatar andretchen0 commented on June 20, 2024

Per #140 , on-demand works through Vue renderer prop patching.

In your example, you're bypassing the Vue renderer and modifying the position directly:

sphereRef.value.position.x += Math.sin(elapsed) * 0.01

If instead you do this, things work as expected:

<script setup lang="ts">
import { TresCanvas, useRenderLoop } from '@tresjs/core'
import BlenderCube from '../../components/BlenderCube.vue'
import GraphPane from '../../components/GraphPane.vue'
import RenderingLogger from '../../components/RenderingLogger.vue'

const { onLoop } = useRenderLoop()
const x = shallowRef(0)
onLoop(({ elapsed }) => {
  x.value = Math.sin(elapsed)
})
</script>

<template>
  <GraphPane />
  <TresCanvas
    render-mode="on-demand"
    clear-color="#82DBC5"
    @render="onRender"
  >
    <TresPerspectiveCamera
      :position="[5, 5, 5]"
      :look-at="[0, 0, 0]"
    />
    <Suspense>
      <BlenderCube :position-x="x" />
    </Suspense>
    <TresGridHelper />
    <RenderingLogger />
    <TresAmbientLight :intensity="1" />
    <TresDirectionalLight
      :position="[0, 8, 4]"
      :intensity="0.7"
    />
  </TresCanvas>
</template>

from tres.

alvarosabu avatar alvarosabu commented on June 20, 2024

Hey @andretchen0 , yes, it will work with patch props because of the invalidate function we have inside. However, for performance reasons, we recommend always editing the template ref.

If so, user would need to manually invalidate like this:

const { invalidate } = useTres()

useLoop(({ elapsed }) => {
  if (!sphereRef.value) { return }
  sphereRef.value.position.y += Math.sin(elapsed) * 0.01
  invalidate()
})

Similar to R3F https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#triggering-manual-frames

I will add this to the documentation.

from tres.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.