Model Loading
Learn how to load models in the Kakara Engine.
The Model Loading system is not finalized and can change in a future version.
Manually typing in the vertex, normal, texture, and index values for a Mesh can be a pain for large meshes. To solve this issue models can be created using 3D modeling software (like Blender). Using these software you can make meshes and export them to a model file (.obj
, .fbx
, etc.). The Kakara Engine allows you to load in these meshes.
Simple Model Loading
The Kakara Engine has a utility class that allows you to do simple mesh loading. That utility class is the StaticModelLoader
. You can use StaticModelLoader.load()
to load in models.
Resource
This is the resource for the model itself.
Texture Directory
This is a string containing the location to the textures for the model. (If you have no textures for your model you can use and empty string.)
Loading a Monkey
Let's delete our old cube code from the loadGraphics
method in the MainScene
class and start fresh. In this tutorial we will be loading a simple monkey mesh (which is a primitive mesh in Blender). You can download the model used in this tutorial here (hosted by DropBox). Put the monkey.fbx
file in the resources
folder (the same one that we put Example_Cube.png
in).
Once again start off by storing the instance of the ResourceManager
. Next you want to call the StaticModelLoad.load()
method.
The StaticModelLoader will automatically create a material for us. Now the only thing we need to do is make a GameItem to hold our mesh array.
If you run the code you can see that the monkey is not facing the right way. We can correct this by rotating the monkey. Add the following below setting the position:
That rotates the monkey by -90 (or 270) degrees on the X axis. Now you can see that the monkey is facing us.
It appears that the monkey could appear all white depending on the GPU and the drivers installed. This does not seem to be an issue with all models.
Complete Code
Valid File Formats
A complete list of supported file formats can be found here.
Last updated