Convert 3D model file to .h format

How can i convert my 3D Model file into “.h” format ?

^ Not sure what this guy is trying to say

Here’s how to convert the 3D model into an H file:

  1. Start a new program that loads a 3D model into memory
  2. Output the memory to code text. For example, if I had a 3D model structure that took a Vector3f (a struct that has three floats) for each vertex, I would output the vertices of the 3D model data as code that looks like this: “AddVertex(Vector3f(10.0f, 12.1f, -1.5f));”
  3. Make the .h file have the code you’ve outputted… you can even have the exporter make the entire .h file if you want by including text for the header includes and functions and such… have the code in a function with the name of the model.
  4. Include the .h file in your project, and run the function… something like “MammothTank();”

Does this make sense? I’ve done this before on a project of mine, it’s not too difficult when you understand the basic idea.

So if you had a file that had a cube model, the vertex list might look like this in data:

{ 0.0f, 0.0f, 0.0f },{1.0f, 0.0f, 0.0f),{1.0f, 1.0f, 0.0f},{0.0f, 1.0f, 0.0f},{ 0.0f, 0.0f, 1.0f },{1.0f, 0.0f, 1.0f),{1.0f, 1.0f, 1.0f},{0.0f, 1.0f, 1.0f}

And you’d take in that data and have it outputted as the following text

#include "ModelManager.h" // Whatever your model management system is... I'm imagining a system that holds and allows retrieval of Model3D class entities, and includes Vector3.h or whatever your vertex data structure is

void MammothTank()
   AddVertex(Vector3(0.0f, 0.0f, 0.0f));
   AddVertex(Vector3(1.0f, 0.0f, 0.0f));
   AddVertex(Vector3(1.0f, 1.0f, 0.0f));
   AddVertex(Vector3(0.0f, 1.0f, 0.0f));
   AddVertex(Vector3(0.0f, 0.0f, 1.0f));
   AddVertex(Vector3(1.0f, 0.0f, 1.0f));
   AddVertex(Vector3(1.0f, 1.0f, 1.0f));
   AddVertex(Vector3(0.0f, 1.0f, 1.0f));

And you would also add the rest of the data in the same way… Let me know if the general idea doesn’t make sense to you. I’m going very general since you didn’t mention what 3D model type you are using or how you want the data to be taken in within the .h file.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.