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.
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;
To create the myTexture
object, let's take a look at the BABYLON.Texture
class, as shown in the following:
var myTexture = new BABYLON.Texture("path_to_texture.png", scene);
This is done now. The diffuse texture will now be applied to the...