Skip to main content Skills Marketplace Descubra e explore skills de IA criadas pela comunidade.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Copiar promptMostrar detalhes do prompt Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
npx skills add https://github.com/BEKO2210/Firstbrain --skill threejs-loadersO comando permanece em uma só linha. Role horizontalmente para revisá-lo antes de copiar.
Prefere uma cópia local? Baixe os arquivos disponíveis atualmente no SkillsMP.
Baixar Zip Baixando... Ocupações relacionadas SOC
Baseado na classificação ocupacional SOC
name threejs-loaders description Three.js asset loading - GLTF, textures, images, models, async patterns. Use when loading 3D models, textures, HDR environments, or managing loading progress. type skill created 2026-02-27T00:00:00.000Z domain design-creative category 3d-animation risk unknown source community tags ["skill","design-creative","3d-animation","threejs","loaders"]
Three.js Loaders
When to Use
You need to load models, textures, HDR assets, or other external resources in Three.js.
The task involves GLTFLoader, TextureLoader, loading progress, or async asset orchestration.
You are managing scene assets rather than authoring geometry or shaders directly.
Quick Start
import * as THREE from "three" ;
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js" ;
const loader = new GLTFLoader ();
loader.load ("model.glb" , (gltf ) => {
scene.add (gltf.scene );
});
const textureLoader = new THREE .TextureLoader ();
const texture = textureLoader.load ("texture.jpg" );
LoadingManager
Coordinate multiple loaders and track progress.
const manager = new THREE .LoadingManager ();
manager.onStart = (url, loaded, total ) => {
console .log (`Started loading: ${url} ` );
};
manager.onLoad = {
. ( );
();
};
manager. = {
progress = (loaded / total) * ;
. ( );
(progress);
};
manager. = {
. ( );
};
textureLoader = . (manager);
gltfLoader = (manager);
textureLoader. ( );
textureLoader. ( );
gltfLoader. ( );
() =>
console
log
"All assets loaded!"
startGame
onProgress
(url, loaded, total ) =>
const
100
console
log
`Loading: ${progress.toFixed(1 )} %`
updateProgressBar
onError
(url ) =>
console
error
`Error loading: ${url} `
const
new
THREE
TextureLoader
const
new
GLTFLoader
load
"texture1.jpg"
load
"texture2.jpg"
load
"model.glb"
Texture Loading
TextureLoader const loader = new THREE .TextureLoader ();
loader.load (
"texture.jpg" ,
(texture ) => {
material.map = texture;
material.needsUpdate = true ;
},
undefined ,
(error ) => {
console .error ("Error loading texture" , error);
},
);
const texture = loader.load ("texture.jpg" );
material.map = texture;
Texture Configuration const texture = loader.load ("texture.jpg" , (tex ) => {
tex.colorSpace = THREE .SRGBColorSpace ;
tex.wrapS = THREE .RepeatWrapping ;
tex.wrapT = THREE .RepeatWrapping ;
tex.repeat .set (2 , 2 );
tex.offset .set (0.5 , 0.5 );
tex.rotation = Math .PI / 4 ;
tex.center .set (0.5 , 0.5 );
tex.minFilter = THREE .LinearMipmapLinearFilter ;
tex.magFilter = THREE .LinearFilter ;
tex.anisotropy = renderer.capabilities .getMaxAnisotropy ();
tex.flipY = true ;
tex.needsUpdate = true ;
});
CubeTextureLoader For environment maps and skyboxes.
const loader = new THREE .CubeTextureLoader ();
const cubeTexture = loader.load ([
"px.jpg" ,
"nx.jpg" ,
"py.jpg" ,
"ny.jpg" ,
"pz.jpg" ,
"nz.jpg" ,
]);
scene.background = cubeTexture;
scene.environment = cubeTexture;
material.envMap = cubeTexture;
HDR/EXR Loading import { RGBELoader } from "three/addons/loaders/RGBELoader.js" ;
import { EXRLoader } from "three/addons/loaders/EXRLoader.js" ;
const rgbeLoader = new RGBELoader ();
rgbeLoader.load ("environment.hdr" , (texture ) => {
texture.mapping = THREE .EquirectangularReflectionMapping ;
scene.environment = texture;
scene.background = texture;
});
const exrLoader = new EXRLoader ();
exrLoader.load ("environment.exr" , (texture ) => {
texture.mapping = THREE .EquirectangularReflectionMapping ;
scene.environment = texture;
});
PMREMGenerator Generate prefiltered environment maps for PBR.
import { RGBELoader } from "three/addons/loaders/RGBELoader.js" ;
const pmremGenerator = new THREE .PMREMGenerator (renderer);
pmremGenerator.compileEquirectangularShader ();
new RGBELoader ().load ("environment.hdr" , (texture ) => {
const envMap = pmremGenerator.fromEquirectangular (texture).texture ;
scene.environment = envMap;
scene.background = envMap;
texture.dispose ();
pmremGenerator.dispose ();
});
GLTF/GLB Loading The most common 3D format for web.
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js" ;
const loader = new GLTFLoader ();
loader.load ("model.glb" , (gltf ) => {
const model = gltf.scene ;
scene.add (model);
const animations = gltf.animations ;
if (animations.length > 0 ) {
const mixer = new THREE .AnimationMixer (model);
animations.forEach ((clip ) => {
mixer.clipAction (clip).play ();
});
}
const cameras = gltf.cameras ;
console .log (gltf.asset );
console .log (gltf.userData );
});
GLTF with Draco Compression import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js" ;
import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js" ;
const dracoLoader = new DRACOLoader ();
dracoLoader.setDecoderPath (
"https://www.gstatic.com/draco/versioned/decoders/1.5.6/" ,
);
dracoLoader.preload ();
const gltfLoader = new GLTFLoader ();
gltfLoader.setDRACOLoader (dracoLoader);
gltfLoader.load ("compressed-model.glb" , (gltf ) => {
scene.add (gltf.scene );
});
GLTF with KTX2 Textures import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js" ;
import { KTX2Loader } from "three/addons/loaders/KTX2Loader.js" ;
const ktx2Loader = new KTX2Loader ();
ktx2Loader.setTranscoderPath (
"https://cdn.jsdelivr.net/npm/three@0.183.0/examples/jsm/libs/basis/" ,
);
ktx2Loader.detectSupport (renderer);
const gltfLoader = new GLTFLoader ();
gltfLoader.setKTX2Loader (ktx2Loader);
gltfLoader.load ("model-with-ktx2.glb" , (gltf ) => {
scene.add (gltf.scene );
});
GLTF with Meshopt Compression (r183) import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js" ;
import { MeshoptDecoder } from "three/addons/libs/meshopt_decoder.module.js" ;
const gltfLoader = new GLTFLoader ();
gltfLoader.setMeshoptDecoder (MeshoptDecoder );
gltfLoader.load ("compressed-model.glb" , (gltf ) => {
scene.add (gltf.scene );
});
KHR_meshopt_compression is an alternative to Draco that often provides better compression for animated meshes and preserves mesh topology.
Process GLTF Content loader.load ("model.glb" , (gltf ) => {
const model = gltf.scene ;
model.traverse ((child ) => {
if (child.isMesh ) {
child.castShadow = true ;
child.receiveShadow = true ;
}
});
const head = model.getObjectByName ("Head" );
model.traverse ((child ) => {
if (child.isMesh && child.material ) {
child.material .envMapIntensity = 0.5 ;
}
});
const box = new THREE .Box3 ().setFromObject (model);
const center = box.getCenter (new THREE .Vector3 ());
const size = box.getSize (new THREE .Vector3 ());
model.position .sub (center);
const maxDim = Math .max (size.x , size.y , size.z );
model.scale .setScalar (1 / maxDim);
scene.add (model);
});
Other Model Formats
OBJ + MTL import { OBJLoader } from "three/addons/loaders/OBJLoader.js" ;
import { MTLLoader } from "three/addons/loaders/MTLLoader.js" ;
const mtlLoader = new MTLLoader ();
mtlLoader.load ("model.mtl" , (materials ) => {
materials.preload ();
const objLoader = new OBJLoader ();
objLoader.setMaterials (materials);
objLoader.load ("model.obj" , (object ) => {
scene.add (object);
});
});
FBX import { FBXLoader } from "three/addons/loaders/FBXLoader.js" ;
const loader = new FBXLoader ();
loader.load ("model.fbx" , (object ) => {
object.scale .setScalar (0.01 );
const mixer = new THREE .AnimationMixer (object);
object.animations .forEach ((clip ) => {
mixer.clipAction (clip).play ();
});
scene.add (object);
});
STL import { STLLoader } from "three/addons/loaders/STLLoader.js" ;
const loader = new STLLoader ();
loader.load ("model.stl" , (geometry ) => {
const material = new THREE .MeshStandardMaterial ({ color : 0x888888 });
const mesh = new THREE .Mesh (geometry, material);
scene.add (mesh);
});
PLY import { PLYLoader } from "three/addons/loaders/PLYLoader.js" ;
const loader = new PLYLoader ();
loader.load ("model.ply" , (geometry ) => {
geometry.computeVertexNormals ();
const material = new THREE .MeshStandardMaterial ({ vertexColors : true });
const mesh = new THREE .Mesh (geometry, material);
scene.add (mesh);
});
Async/Promise Loading
Promisified Loader function loadModel (url ) {
return new Promise ((resolve, reject ) => {
loader.load (url, resolve, undefined , reject);
});
}
async function init ( ) {
try {
const gltf = await loadModel ("model.glb" );
scene.add (gltf.scene );
} catch (error) {
console .error ("Failed to load model:" , error);
}
}
Load Multiple Assets async function loadAssets ( ) {
const [modelGltf, envTexture, colorTexture] = await Promise .all ([
loadGLTF ("model.glb" ),
loadRGBE ("environment.hdr" ),
loadTexture ("color.jpg" ),
]);
scene.add (modelGltf.scene );
scene.environment = envTexture;
material.map = colorTexture;
}
function loadGLTF (url ) {
return new Promise ((resolve, reject ) => {
new GLTFLoader ().load (url, resolve, undefined , reject);
});
}
function loadRGBE (url ) {
return new Promise ((resolve, reject ) => {
new RGBELoader ().load (
url,
(texture ) => {
texture.mapping = THREE .EquirectangularReflectionMapping ;
resolve (texture);
},
undefined ,
reject,
);
});
}
function loadTexture (url ) {
return new Promise ((resolve, reject ) => {
new THREE .TextureLoader ().load (url, resolve, undefined , reject);
});
}
Caching
Built-in Cache
THREE .Cache .enabled = true ;
THREE .Cache .clear ();
THREE .Cache .add ("key" , data);
THREE .Cache .get ("key" );
THREE .Cache .remove ("key" );
Custom Asset Manager class AssetManager {
constructor ( ) {
this .textures = new Map ();
this .models = new Map ();
this .gltfLoader = new GLTFLoader ();
this .textureLoader = new THREE .TextureLoader ();
}
async loadTexture (key, url ) {
if (this .textures .has (key)) {
return this .textures .get (key);
}
const texture = await new Promise ((resolve, reject ) => {
this .textureLoader .load (url, resolve, undefined , reject);
});
this .textures .set (key, texture);
return texture;
}
async loadModel (key, url ) {
if (this .models .has (key)) {
return this .models .get (key).clone ();
}
const gltf = await new Promise ((resolve, reject ) => {
this .gltfLoader .load (url, resolve, undefined , reject);
});
this .models .set (key, gltf.scene );
return gltf.scene .clone ();
}
dispose ( ) {
this .textures .forEach ((t ) => t.dispose ());
this .textures .clear ();
this .models .clear ();
}
}
const assets = new AssetManager ();
const texture = await assets.loadTexture ("brick" , "brick.jpg" );
const model = await assets.loadModel ("tree" , "tree.glb" );
Loading from Different Sources
Data URL / Base64 const loader = new THREE .TextureLoader ();
const texture = loader.load ("data:image/png;base64,iVBORw0KGgo..." );
Blob URL async function loadFromBlob (blob ) {
const url = URL .createObjectURL (blob);
const texture = await loadTexture (url);
URL .revokeObjectURL (url);
return texture;
}
ArrayBuffer
const response = await fetch ("model.glb" );
const buffer = await response.arrayBuffer ();
const loader = new GLTFLoader ();
loader.parse (buffer, "" , (gltf ) => {
scene.add (gltf.scene );
});
Custom Path/URL
loader.setPath ("assets/models/" );
loader.load ("model.glb" );
loader.setResourcePath ("assets/textures/" );
manager.setURLModifier ((url ) => {
return `https://cdn.example.com/${url} ` ;
});
Error Handling
async function loadWithFallback (primaryUrl, fallbackUrl ) {
try {
return await loadModel (primaryUrl);
} catch (error) {
console .warn (`Primary failed, trying fallback: ${error} ` );
return await loadModel (fallbackUrl);
}
}
async function loadWithRetry (url, maxRetries = 3 ) {
for (let i = 0 ; i < maxRetries; i++) {
try {
return await loadModel (url);
} catch (error) {
if (i === maxRetries - 1 ) throw error;
await new Promise ((r ) => setTimeout (r, 1000 * (i + 1 )));
}
}
}
async function loadWithTimeout (url, timeout = 30000 ) {
const controller = new AbortController ();
const timeoutId = setTimeout (() => controller.abort (), timeout);
try {
const response = await fetch (url, { signal : controller.signal });
clearTimeout (timeoutId);
return response;
} catch (error) {
if (error.name === "AbortError" ) {
throw new Error ("Loading timed out" );
}
throw error;
}
}
Performance Tips
Use compressed formats : DRACO for geometry, KTX2/Basis for textures
Load progressively : Show placeholders while loading
Lazy load : Only load what's needed
Use CDN : Faster asset delivery
Enable cache : THREE.Cache.enabled = true
const placeholder = new THREE .Mesh (
new THREE .BoxGeometry (1 , 1 , 1 ),
new THREE .MeshBasicMaterial ({ wireframe : true }),
);
scene.add (placeholder);
loadModel ("model.glb" ).then ((gltf ) => {
scene.remove (placeholder);
scene.add (gltf.scene );
});
VRMLLoader Camera Support (r183) As of r183, VRMLLoader supports loading cameras defined in VRML files.
See Also
threejs-textures - Texture configuration
threejs-animation - Playing loaded animations
threejs-materials - Material from loaded models
Connections
Domain: [[Design & Kreativitaet]]
Kategorie: [[3D & Animation]]
Navigation: [[Skills Uebersicht]], [[Home]]