Skip to content

useFBX

A composable that allows you to easily load FBX models into your TresJS scene.

Usage

vue
<script setup lang="ts">
import { useFBX } from '@tresjs/cientos'

const path = 'https://raw.githubusercontent.com/'
  + 'Tresjs/assets/main/models/fbx/low-poly-truck/Jeep_done.fbx'
const { state, nodes, materials } = useFBX(path)
</script>

<template>
  <primitive v-if="state" :object="state" :scale="0.025" />
</template>
vue
<script setup lang="ts">
import { OrbitControls } from '@tresjs/cientos'
import { TresCanvas } from '@tresjs/core'
import TheModel from './TheModel.vue'
</script>

<template>
  <TresCanvas clear-color="#1F90FF">
    <TresPerspectiveCamera :position="[11, 11, 11]" />
    <OrbitControls />
    <TheModel />
    <TresDirectionalLight
      :intensity="2"
      :position="[3, 3, 3]"
    />
    <TresAmbientLight :intensity="1" />
  </TresCanvas>
</template>

Return Values

NameTypeDescription
stateGroupThe loaded FBX model state
nodesobjectComputed object containing all nodes in the scene
materialsobjectComputed object containing all materials in the scene
isLoadingbooleanWhether the model is currently loading
execute() => Promise<void>Function to reload the model

Options

NameTypeDescription
traverseFunctionA traverse function applied to the scene upon loading the model.

Accessing Nodes and Materials

The composable provides computed properties to easily access nodes and materials in your scene:

ts
const { nodes, materials } = useFBX('/model.fbx')

// Access a specific node
const mesh = nodes.value.MeshName

// Access a specific material
const material = materials.value.MaterialName

This makes it easier to manipulate specific parts of your model or apply materials programmatically.