Knowledge Base » How to load multiple models

Many times, you have several models that share almost identical names. For example, in your Blender 3D scene, you may have models with the following names:

  • model0
  • model1
  • model2
  • ..
  • ..
  • model45

There is a nice way to load all of these models at once using the Untold Engine. The snippet below shows how this is done:

//This is a nice way to load all 46 models that make up the scene.
U4DEngine::U4DGameObject *models[46];

for(int i=0;i<sizeof(models)/sizeof(models[0]);i++){

    std::string name="model";
    name+=std::to_string(i);
    
    //create a U4DGame Object
    models[i]=new U4DEngine::U4DGameObject();

    //load all the model information into the object
    if (models[i]->loadModel(name.c_str())) {

        //If you want to disable shadows, then you can remove the shadow shader
        //models[i]->renderEntity->removePassPipelinePair(U4DEngine::shadowPass);

        //send all the information to the GPU
        models[i]->loadRenderingInformation();

        //add the model to the scenegraph
        addChild(models[i]);

    }
}