How to render a 3D Entity

This articles explains how to render a 3D entity using the Untold Engine.

Steps to render a 3D character

The steps to render a 3D object is summarized below:

  1. Load scene data

  2. Create a Game Entity

  3. Load the attributes

  4. Add the game object to the scenegraph

Step 1. Load Scene Data

Before you can render a character, you must load the character's attributes. The loading is done through the use of U4DEngine::U4DResourceLoader class. The class loads the binary files (.u4d) representing the scene attributes (line 1a) and textures (line 1b).

Note: Please make sure to read the Untold Engine Toolchain before continuing on with this tutorial.

//Line 1. The U4DResourceLoader is in charge of loading the binary file containing the scene data
U4DEngine::U4DResourceLoader *resourceLoader=U4DEngine::U4DResourceLoader::sharedInstance();

//Line 1a.Load binary file with scene data
resourceLoader->loadSceneData("spaceScene.u4d");

//Line 1b. Load binary file with texture data
resourceLoader->loadTextureData("spaceTextures.u4d");

Step 2. Create a Game Entity

In line 2, we provide a name for the game model, myAstronaut, and use the C++ keyword new to create an instance of U4DEngine::U4DModel.

//Line 2. Create an instance of U4DModel type
U4DEngine::U4DModel *myAstronaut=new U4DEngine::U4DModel();

Step 3. Load Attributes

The U4DEngine::U4DModel::loadModel() method loads the attribute data into the character's data members (line 3). The method requires the name of the 3D model, as specified in Blender 3D.

//Line 3. Load attribute (rendering information) into the game entity
// name of character in blender: "astronaut"
if (myAstronaut->loadModel("astronaut")) {

    //Line 4. Load rendering information into the GPU
    myAstronaut->loadRenderingInformation();

}

Note that the loadModel() method returns a boolean value. The method will return false if the file was not found, or if the attributes are corrupted.

If the loadModel() method returns true, the next step is to send the attributes to the GPU. This is accomplished with the U4DEngine::U4DRenderManager::loadRenderingInformation() method (line 4).

Step 4. Add the game model to the scenegraph

Finally, the game object is added to the Entity Manager using the U4DEngine::U4DEntity::addChild() method (line 5).

//Line 5. Add astronaut to the scenegraph
addChild(myAstronaut);

Complete Code Snippet

The complete code to render a 3D Game Character should look as follows:

//Line 1. The U4DResourceLoader is in charge of loading the binary file containing the scene data
U4DEngine::U4DResourceLoader *resourceLoader=U4DEngine::U4DResourceLoader::sharedInstance();

//Line 1a.Load binary file with scene data
resourceLoader->loadSceneData("spaceScene.u4d");

//Line 1b. Load binary file with texture data
resourceLoader->loadTextureData("spaceTextures.u4d");

//Line 2. Create an instance of U4DModel type
U4DEngine::U4DModel *myAstronaut=new U4DEngine::U4DModel();

//Line 3. Load attribute (rendering information) into the game entity
if (myAstronaut->loadModel("astronaut")) {

    //Line 4. Load rendering information into the GPU
    myAstronaut->loadRenderingInformation();

    //Line 5. Add astronaut to the scenegraph
    addChild(myAstronaut);

}

Result

Last updated