<TresCanvas /> creates the necessary Three.js environment and bridges the gap between Vue's reactivity system and Three.js's imperative rendering approach. It is responsible for:
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
</script>
<template>
<TresCanvas shadows>
<TresPerspectiveCamera :position="[5, 5, 5]" />
<!-- Your scene content here -->
</TresCanvas>
</template>
The <TresCanvas /> component offers flexible sizing options to fit different layout requirements. Understanding how canvas sizing works is crucial for creating responsive 3D experiences.
By default, <TresCanvas /> automatically adapts to its parent element's dimensions. This is the most common and recommended approach as it integrates seamlessly with your existing CSS layout.
<template>
<div class="w-full aspect-video">
<!-- Canvas automatically fills the container -->
<TresCanvas>
<TresPerspectiveCamera :position="[3, 3, 3]" />
<!-- Your 3D scene here -->
</TresCanvas>
</div>
</template>
For immersive full-screen 3D experiences, use the window-size prop to make the canvas fill the entire browser viewport:
<template>
<!-- Canvas automatically fills the entire window -->
<TresCanvas window-size>
<TresPerspectiveCamera :position="[3, 3, 3]" />
<!-- Your 3D scene here -->
</TresCanvas>
</template>
true, the value is 0. Otherwise it's 1. Enables transparency in the canvas.true - Whether to perform antialiasing. Improves visual quality by smoothing jagged edges.1 - The alpha (transparency) value used when clearing the canvas. Range from 0 (transparent) to 1 (opaque)."#000000" - The color the renderer will use to clear the canvas. Can be any valid CSS color string.true - Whether to enable the provide/inject bridge between Vue and TresJS. When true, Vue's provide/inject will work across the TresJS boundary."always" - Controls when the scene renders:always - Renders every frame continuouslyon-demand - Renders only when changes are detectedmanual - Requires explicit render callsPCFSoftShadowMap - The type of shadow map to use:BasicShadowMap - Basic shadow mapping (fastest, lowest quality)PCFShadowMap - Percentage-Closer Filtering shadows (good quality/performance balance)PCFSoftShadowMap - Soft PCF shadows (best quality, slower)VSMShadowMap - Variance Shadow Maps (advanced technique)ACESFilmicToneMapping - Defines the tone mapping algorithm used by the renderer:NoToneMapping - No tone mapping appliedLinearToneMapping - Linear tone mappingReinhardToneMapping - Reinhard tone mappingCineonToneMapping - Cineon tone mappingACESFilmicToneMapping - ACES Filmic tone mapping (recommended)CustomToneMapping - Custom tone mapping1 - Exposure level of tone mapping. Controls the brightness/exposure of the rendered image.