Game Development Reference
In-Depth Information
The environment
The environment contains the uniform values specific for a location. For example,
the lights are part of the environment. Simple applications might use only one
environment, while more complex applications might use multiple environments
depending on the location of ModelInstance . A ModelInstance class can only
contain one environment though, as shown here:
public Environment environment;
...
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight,
0.4f, 0.4f, 0.4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f,
-0.8f, -0.2f));
...
modelBatch.render(instance, environment);
In the preceding code, a new environment is set and a directional light source is
added. This environment is then rendered by calling modelBatch.render() .
Loading a model
In a game, we need an actual model exported from Blender or any other
3D animation software.
The assets for our example are provided with the code
bundle of this chapter.
Copy these three files to the assets folder of the android project:
car.g3dj : This is the model file to be used in our example
tiretext.jpg and yellowtaxi.jpg : These are the materials for the model
Replacing the ModelBuilder class in our ModelTest.java file, we add the
following code:
assets = new AssetManager();
assets.load("car.g3dj", Model.class);
assets.finishLoading();
model = assets.get("car.g3dj", Model.class);
instance = new ModelInstance(model);
 
Search WWH ::




Custom Search