Using textures with materials

This chapter is the right place to introduce the usage of textures. Textures are images (.png,.jpeg, and so on) that graphics libraries are able to apply to meshes. There are several types of texturing methods handled by Babylon.js, such as video textures, cube textures, and so on. Now, let's explain how to use textures with materials.

Load and apply a texture

As you may have already guessed, loading and applying a texture to a mesh can be easy with Babylon.js. The standard material provides a way, as for colors, to apply a diffuse texture (for example, specular, emissive, and ambient textures). Simply set the .diffuseTexture property to the reference of your texture, as follows:

myMaterial.diffuseTexture = myTexture; ...

Get Babylon.js Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.