Skip to main content

Component Loader

Type

Component

GLTF Loader

Default Usage

import { Scene, GLTFLoader } from 'react-three-lite'

function App() {
const handleCreated = (scene, { camera }) => {
camera.position.set(0, 1.5, 3)
}

return (
<Scene
style={{ marginTop: '10px', width: '100%', height: '300px' }}
onCreated={handleCreated}
>
<GLTFLoader modelUrl="/models/perseverance-draco.glb" scale={[0.8, 0.8, 0.8]} useDraco />
</Scene>
)
}

Props

NameTypeDefaultDescription
modelUrlstringrequired The model url.
sceneTHREE.SceneTHREE.Sceneoptional The Scene where the model will be rendered.
scale[number, number, number][1.0, 1.0, 1.0]optional The scale of the model.
cachebooleantrueoptional The model will be cached into the indexDB.
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.

Events

NameParametersDescription
onProgress(event: ProgressEvent) => voidThe callback function when loading the model.
onLoaded(model: THREE.Group) => voidThe callback function when the model is loaded.

FBX Loader

Default Usage

import { Scene, FBXLoader } from 'react-three-lite'

function App() {
const handleCreated = (scene, { camera }) => {
camera.position.set(0, 1.5, 3)
}

return (
<Scene
style={{ marginTop: '10px', width: '100%', height: '300px' }}
onCreated={handleCreated}
>
<FBXLoader modelUrl="/models/perseverance.fbx" scale={[0.8, 0.8, 0.8]} />
</Scene>
)
}

Props

NameTypeDefaultDescription
modelUrlstringrequired The model url.
sceneTHREE.SceneTHREE.Sceneoptional The Scene where the model will be rendered.
scale[number, number, number][1.0, 1.0, 1.0]optional The scale of the model.
cachebooleantrueoptional The model will be cached into the indexDB.

Events

NameParametersDescription
onProgress(event: ProgressEvent) => voidThe callback function when loading the model.
onLoaded(model: THREE.Group) => voidThe callback function when the model is loaded.

OBJ Loader

Default Usage

import { Scene, OBJLoader } from 'react-three-lite'

function App() {
const handleCreated = (scene, { camera }) => {
camera.position.set(0, 1.5, 3)
}

return (
<Scene
style={{ marginTop: '10px', width: '100%', height: '300px' }}
onCreated={handleCreated}
>
<OBJLoader
modelUrl="/models/obj/perseverance.obj"
mtlUrl="/models/obj/perseverance.mtl"
scale={[0.8, 0.8, 0.8]}
/>
</Scene>
)
}

Props

NameTypeDefaultDescription
modelUrlstringrequired The model url.
mtlUrlstringoptional The material url for OBJ models.
sceneTHREE.SceneTHREE.Sceneoptional The Scene where the model will be rendered.
scale[number, number, number][1.0, 1.0, 1.0]optional The scale of the model.
cachebooleantrueoptional The model will be cached into the indexDB.

Events

NameParametersDescription
onProgress(event: ProgressEvent) => voidThe callback function when loading the model.
onLoaded(model: THREE.Group) => voidThe callback function when the model is loaded.