Skip to main content

Function Loader

Type

Function

GLTF Loader

Default Usage

Every example below can be viewed with either the WebGPU (default) or the WebGL renderer — switch tabs to compare.

import { Scene, GLTFLoaderAsync } from 'react-three-lite'
import type * as THREE from 'three'

function App() {
const handleCreated = async (scene: THREE.Scene, { camera }: { camera: THREE.Camera }) => {
camera.position.set(0, 1.5, 3)
camera.lookAt(0, 0, 0)

// Load model to scene.
const model = await GLTFLoaderAsync('/models/perseverance-draco.glb', true)
model.scale.set(0.8, 0.8, 0.8)
scene.add(model)
}

return (
<Scene
style={{ marginTop: '10px', width: '100%', height: '300px' }}
onCreated={handleCreated}
/>
)
}

Parameters

NameTypeDefaultDescription
urlstringrequired The model url.
useDracobooleanfalseoptional Whether to use Draco decoder. Set to true for Draco-compressed GLTF models.
dracoDecoderPathstringhttps://www.gstatic.com/draco/versioned/decoders/1.5.7/optional The Draco decoder path. Only needed when useDraco is true.
cachebooleantrueoptional The model will be cached into the indexDB. Default is true.
onProgressfunctionoptional The callback function when loading the model.

FBX Loader

Default Usage

import { Scene, FBXLoaderAsync } from 'react-three-lite'
import type * as THREE from 'three'

function App() {
const handleCreated = async (scene: THREE.Scene, { camera }: { camera: THREE.Camera }) => {
camera.position.set(0, 1.5, 3)
camera.lookAt(0, 0, 0)

// Load model to scene.
const model = await FBXLoaderAsync('/models/perseverance.fbx')
model.scale.set(0.8, 0.8, 0.8)
scene.add(model)
}

return (
<Scene
style={{ marginTop: '10px', width: '100%', height: '300px' }}
onCreated={handleCreated}
/>
)
}

Parameters

NameTypeDefaultDescription
urlstringrequired The model url.
cachebooleantrueoptional The model will be cached into the indexDB. Default is true.
onProgressfunctionoptional The callback function when loading the model.

OBJ Loader

Default Usage

import { Scene, OBJLoaderAsync } from 'react-three-lite'
import type * as THREE from 'three'

function App() {
const handleCreated = async (scene: THREE.Scene, { camera }: { camera: THREE.Camera }) => {
camera.position.set(0, 1.5, 3)
camera.lookAt(0, 0, 0)

// Load model to scene.
const model = await OBJLoaderAsync('/models/obj/perseverance.obj', '/models/obj/perseverance.mtl')
model.scale.set(0.8, 0.8, 0.8)
scene.add(model)
}

return (
<Scene
style={{ marginTop: '10px', width: '100%', height: '300px' }}
onCreated={handleCreated}
/>
)
}

Parameters

NameTypeDefaultDescription
urlstringrequired The model url.
mtlUrlstringoptional The model material url. Only OBJLoader needs this parameter.
cachebooleantrueoptional The model will be cached into the indexDB. Default is true.
onProgressfunctionoptional The callback function when loading the model.