Skip to content

useTres

The useTres composable provides access to a simplified version of the TresJS context. It is a wrapper around the useTresContext composable that provides a more convenient API for common use cases.

Usage

ts
import { useTres } from '@tresjs/core'

const { scene, renderer, camera, invalidate } = useTres()

WARNING

useTres can be only be used inside a child component of a TresCanvas since this component acts as the provider for the context data.

vue
<script setup>
import { TresCanvas } from '@tresjs/core'
import SubComponent from './SubComponent.vue'
</script>

<template>
  <TresCanvas>
    <SubComponent />
  </TresCanvas>
</template>
vue
<script lang="ts" setup>
import { useTres } from '@tresjs/core'

const { camera } = useTres()

watchEffect(() => {
  console.log(camera.value)
})
</script>

Properties

PropertyDescription
camerathe currently active camera
scenethe scene
rendererContains the WebGLRenderer
sizescontains width, height and aspect ratio of your canvas
loopthe renderer loop
controlsthe controls of your scene
raycasterthe global raycaster used for pointer events
perfthe performance monitor
extendExtends the component catalogue. See extending.

Methods

MethodDescription
invalidateMarks the scene as needing an update in the next frame. This is used in on-demand rendering mode to schedule a render.
advanceManually advances the render loop by one frame. This is particularly useful in manual rendering mode where you want explicit control over when frames are rendered.