DirectX - Modeling



Source assets which is required for models stored in Autodesk FBX, Wavefront OBJ or other formats. A typical build process is used for conversion which is used in run-time friendly format which is easy to load and render.

For creating a model, Visual Studio includes a built-in system which includes a convert format of a Wavefront OBJ or Autodesk FBX which is considered as a part of the build process which is needed to CMO.

In this chapter, we will make use of the DirectXMesh meshconvert command line tool. The developer can start this activity by saving cup.obj, cup.mtl and cup.jpg into the project directory.

Implementing the Modeling

Following steps are required to implement the modeling −

Step 1

Download the Meshconvert.exe from the official site and save the executable file into the user’s project folder.

Step 2

Open the required command prompt and then change the project’s directory. Run the following command executed in below command prompt −

meshconvert cup._obj -cmo -nodds -flipz -y

With this, you can initiate a model creation. Now let us focus on updating effects settings on the mentioned model.

The model class creates the required effects automatically for the loaded materials which are set to lighting parameters. The updating procedure is possible with the Model::UpdateEffects method.

Updating Effects Settings

Following are the steps required to update effects settings in a specific model −

Step 1

From the drop-down menu, select Project/Properties. Set to "All Configurations"/"All Platforms". On the left-hand tree view, select C/C++ Language. Then set "Enable Run-Time Type Information" to "Yes". Click "OK".

Step 2

In the mentioned file Game.cpp, add the TODO of CreateDevice as shown below −

m_model->UpdateEffects([](IEffect* effect){
   auto lights = dynamic_cast<IEffectLights*>(effect);
   if (lights){
      lights->SetLightingEnabled(true);
      lights->SetPerPixelLighting(true);
      lights->SetLightEnabled(0, true);
      lights->SetLightDiffuseColor(0, Colors::Gold);
      lights->SetLightEnabled(1, false);
      lights->SetLightEnabled(2, false);
   }
   auto fog = dynamic_cast<IEffectFog*>(effect);
   if (fog){
      fog->SetFogEnabled(true);
      fog->SetFogColor(Colors::CornflowerBlue);
      fog->SetFogStart(3.f);
      fog->SetFogEnd(4.f);
   }
});

The above code is designed to build and run our cup with the colored light, per pixel rather than vertex lighting and the fogging was enabled.

Advertisements