Wawa Sensei logo
LoginEnroll now

Texturas

Starter pack

Una textura es una imagen que se usa para colorear la superficie de un mesh. Se puede usar para agregar detalles a un objeto 3D.

Una textura se aplica a un mesh usando un material. El material define c贸mo se aplica la textura al mesh y c贸mo interact煤a con la luz.

useTexture

El hook useTexture de Drei se utiliza para cargar una textura desde un archivo. Devuelve un objeto Texture que se puede usar en un material.

Vamos a cargar el archivo de textura desde el pack de inicio ubicado en public/textures/:

import { useTexture } from "@react-three/drei";

export const Experience = () => {
  const texture = useTexture("textures/PavingStones130_1K_Color.jpg");

  return (
    <>
      <mesh>
        <boxGeometry />
        <meshStandardMaterial map={texture} />
      </mesh>
    </>
  );
};

La textura se aplica al mesh usando la propiedad map del material.

Textura en el cubo

Nuestra textura de adoquines se aplica al cubo.

Como hemos visto con useGLTF, useTexture utiliza internamente useLoader con TextureLoader para cargar la textura.

Si queremos escalar la textura, podemos usar la propiedad repeat de la textura:

import { useTexture } from "@react-three/drei";
import * as THREE from "three";
export const Experience = () => {
  const texture = useTexture("textures/PavingStones130_1K_Color.jpg");

  texture.repeat.set(3, 3);
  texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
  // ...
};

Las propiedades wrapS y wrapT definen c贸mo se repite la textura en el mesh. Por defecto, la textura se clampa al borde del mesh. Aqu铆 usamos RepeatWrapping para repetir la textura.

Textura en el cubo

Nuestra textura se repite 3 veces en el cubo.

Si por el contrario queremos estirar la textura, podemos disminuir el valor de repeat:

End of lesson preview

To get access to the entire lesson, you need to purchase the course.