Loading a texture and applying it to a mesh

The most basic usage of a texture is when it's set as a map on a material. When you use this material to create a mesh, the mesh will be colored based on the supplied texture.

Loading a texture and using it on a mesh can be done in the following manner:

var textureLoader = new THREE.TextureLoader();textureLoader.load("'../../assets/textures/general/metal-rust.jpg")

In this code sample, we use an instance of the THREE.TextureLoader function to load an image file from a specific location. Using this loader, you can use PNG, GIF, or JPEG images as input for a texture (further on in this chapter, we'll show you how to load other texture formats). Note that loading textures is done asynchronously: if ...

Get Learn Three.js - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.