Link

Rendering a 3D Model

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

  1. Create a Game Object
  2. Load the attributes
  3. Add the game object to the scenegraph

Step 1. Create a Game Object

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

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

Step 2. Load Attributes

The U4DEngine::U4DGameObject::loadModel() method loads the attribute data into the character’s data members (line 2). The method requires the name of the 3D model, as specified in Blender 3D. And the file where the attributes are found.

//Line 2. Load attribute (rendering information) into the game entity
// name of character: "astronaut"
// name of attributes file: "charactersAttributes.u4d"
if (myAstronaut->loadModel("astronaut","charactersAttributes.u4d")) {

    //Line 3. 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 3).

Step 3. Add the game object to the scenegraph

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

//Line 4. 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. Create an instance of U4DGameObject type
U4DEngine::U4DGameObject *myAstronaut=new U4DEngine::U4DGameObject();

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

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

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

}

Result

image

Enable Shadows

The Untold Engine is capable of rendering shadows for all characters of type U4DGameObject.

To enable shadows on a character, set the method setEnableShadow() to true. For example:

setEnableShadow(true);

The setEnableShadow() method must be called before sending rendering information to the GPU. That is, before calling the method loadRenderingInformation().

The snippet below shows how to properly enable shadows (line 3):

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

//Line 2. Load attribute (rendering information) into the game entity
if (myAstronaut->loadModel("astronaut","astronautAttributes.u4d")) {
    
    //Line 3. Enable shadows
    myAstronaut->setEnableShadow(true);
    
    //Line 4. Load rendering information into the GPU
    myAstronaut->loadRenderingInformation();
    
    //Line 5. Add astronaut to the scenegraph
    addChild(myAstronaut);
    
}