Book Image

Babylon.js Essentials

By : Julien Moreau-Mathis
Book Image

Babylon.js Essentials

By: Julien Moreau-Mathis

Overview of this book

Are you familiar with HTML5? Do you want to build exciting games and Web applications? Then explore the exciting world of game and Web development with one of the best frameworks out there: Babylon.JS. Starting from the beginning, the book introduces the required basics for 3D development and the knowledge you need to use the Babylon.js framework. It focuses on the simplicity provided by Babylon.js and uses a combination of theory and practice. All the chapters are provided with example files ready to run; each example file provides the previously learned features of the framework. Finally, developers will be ready to easily understand new features added to the framework in the future.
Table of Contents (15 chapters)
Babylon.js Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

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; 

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...