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: 633 useFrame
and useRender
#640
Conversation
✅ Deploy Preview for tresjs-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hey @alvarosabu , This approach doesn't work for directives, at least not directly. import type { Object3D } from 'three'
import type { Ref } from 'vue'
import { extractBindingPosition } from '../utils'
import type { TresVector3 } from '../types'
import { useLogger, useLoop } from '../composables'
const { logWarning } = useLogger()
export const vAlwaysLookAt = {
updated: (el: Object3D, binding: Ref<TresVector3>) => {
const observer = extractBindingPosition(binding)
if (!observer) {
logWarning(`v-always-look-at: problem with binding value: ${binding.value}`)
return
}
useLoop(() => {
el.lookAt(observer)
})
},
}
Any thoughts on how to proceed? |
Do you still want a review on this PR? |
Hey @andretchen0 not yet, will update it depending of the result of the dicussion on Discord. I still need to figure out how to not break directives |
Doing a search on GitHub about usage of the affected directives:
Couting @JaimeTorrealba there are like 2 more users currently using those. I will suggest updating the directives to |
For sure. It's not so much "don't break existing directives" as "we need to create a convenient API for getting a contextful |
Closed this in favor of #673 |
Closes #633
Based on the team dicussion. This PR introduces two new APIs.
useFrame
This composable allows you to execute a callback on every rendered frame, similar to
useRenderLoop
but unique to eachTresCanvas
instance and with access to the context.This composable allows you to execute a callback on every rendered frame, similar to
useRenderLoop
but unique to eachTresCanvas
instance and with access to the context.Warning
useFrame
can be only be used inside of aTresCanvas
since this component acts as the provider for the context data.Your callback function will be triggered just before a frame is rendered and it will be unmounted automatically when the component is destroyed.
Render priority
The
useFrame
composable accepts a second argumentindex
which is used to determine the order in which the loop functions are executed. The default value is0
which means the function will be executed after the renderer updates the scene. If you set the value to-1
, the function will be executed before the renderer updates the scene.useRender
(Take control of the render loop)By default, the render-loop is automatically started when the component is mounted. However, you can take control of the render-loop by using this composable.