Capítulo 848 de 859
Loading and using textures in three.js — from a single image on material.map, to per-face material arrays, to the memory realities of GPU texture storage — where uncompressed size (not file size) is what actually matters for memory, and where filtering/mipmaps control how a texture looks at small or oblique sizes.
TextureLoader.load(url) returns a Texture immediately (transparent until the image finishes loading asynchronously); waiting for completion needs either the loader's callback or a shared LoadingManager with onLoad/onProgress.BoxGeometry up to 6 (one per face), ConeGeometry 2, CylinderGeometry 3 — but this is less common/performant than a texture atlas (multiple images packed into one texture, selected per-triangle via texture coordinates).width * height * 4 * 1.33 bytes of GPU memory regardless of how well the source file compresses — a 157KB but 3024×3761 JPEG can consume around 60MB once uploaded, since the GPU generally needs uncompressed data.texture.magFilter/minFilter control how pixels are chosen when a texture is drawn larger or smaller than its native size; NearestFilter gives a blocky/pixelated look (e.g. Minecraft-style), LinearFilter interpolates; mipmaps (progressively half-sized, pre-blended copies down to 1×1) let the GPU cheaply pick an appropriately-sized version instead of averaging many source pixels per draw.function loadColorTexture(path) {
const texture = loader.load(path);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const cube = new THREE.Mesh(geometry, [
new THREE.MeshBasicMaterial({ map: loadColorTexture("resources/images/flower-1.jpg") }),
new THREE.MeshBasicMaterial({ map: loadColorTexture("resources/images/flower-2.jpg") }),
// ...4 more, one per BoxGeometry face
]);
BoxGeometry's 6 faces via a material array.TextureLoader.load() returns immediately; use its callback or a LoadingManager if you need to know when the image has actually arrived.width * height * 4 * 1.33 bytes — driven by pixel dimensions, not file compression or format.NearestFilter/LinearFilter) and mipmaps control appearance at minified/magnified sizes — mipmaps in particular avoid expensive per-pixel averaging when a texture is drawn much smaller than its native resolution.