Skip to main content

Function Loader

Type

Function

GLTF Loader

Default Usage

import { Scene, GLTFLoader } 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)

// Load model to scene.
const model = await GLTFLoader('/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, FBXLoader } 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)

// Load model to scene.
const model = await FBXLoader('/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, OBJLoader } 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)

// Load model to scene.
const model = await OBJLoader('/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.