Advertisement

Using a custom model format with existing modeling softwares

Started by April 05, 2018 02:49 AM
5 comments, last by Scouting Ninja 6 years, 7 months ago

Let me preface this by saying that I am not familiar with 3d modeling at all. In fact I know almost nothing about it. This is perhaps why I've decided to write my own 3D model format and my own 3D modeling software from scratch (I didn't want to deal with existing formats, which seemed quite complex for what I wanted to do) . 

Now my 3D modeling software is quite adequate for small things, but it's really slow to use and unfit for organic shapes. 

My 3D model format is very simple;


-25,4.48,-25:251,252,250
-24,4.58,-25:250,253,250
-25,4.62,-24:250,252,251
-24,4.58,-25:250,253,250
-24,4.62,-24:250,253,251
-25,4.62,-24:250,252,251
-25,4.62,-24:250,252,251
-24,4.62,-24:250,253,251
...

It's broken in 2 part, the first 3 numbers (separated by ',') are floating point values representing the location of a vertex and the last 3 numbers represents the RGB value of the color of that vertex. Triangles are simply drawn by taking the first 3 vertex, then the next 3, etc till the whole list is drawn. Of course once loaded this data takes the form of a model class, which is a list of instances of a small vertex class.

As you can imagine, this is probably the simplest way to store a model that contains "textures" (which I use loosely), but is good enough for my game. I've looked at several model format but mine seems quite unique at what it does.

Is there anything like it out there? I would like to write a small converter to take models made with more competent 3D software and use them in my engine. Another option would be to write a plugin for an existing 3D modeling software, but I am unsure on how I would go about that since I have almost no experience with them. Could anyone point me in the right direction? At first it seemed like a reasonably simple thing to do but the more I investigate the question the more I think I'll just have to spend a few days fleshing out my own 3D modeling software.

Well, there's already a lot of formats as simple as this one.

Wavefront OBJ would be the one closest in simplicity, and widely supported by modeling sw. It doesn't support per-vertex color officially, but that won't stop some sw (namely MeshLab, MeshMixer) from exporting it.

Still, drawing the models as a list of verts without indexing (to reuse verts) is quite suboptimal. I mean, it's totally ok for a bunch of rectangles, but bad for a bigger models with smooth surfaces.

You'll find that later you'll want to add indexing, normals, texture coordinates. It will require changing your format and your modelling tool, etc. So the obvious choice would be to write the importer for reading few formats that already has required info and is supported by many authoring tools.

You still might want to have your own format, but only if it makes your files loaded significantly faster, preferably without any processing. It should be as close to the real hardware needs as possible. That means binary, with data formats which is supported by target hw - no doubles or half-floats for coordinates, using 16-bit indices, vertex alignment, etc. I.e. it will be a "dump" of actual vertex/index buffers, as required by hardware you're aiming for.

Advertisement
20 hours ago, FFA702 said:

Is there anything like it out there? I would like to write a small converter to take models made with more competent 3D software and use them in my engine.

The way you are doing it here is exactly the same as when 3D models first appeared on computers as far as back in 1970s. Since then 3D models have evolved a lot to do a lot more. The good news is that most 3D formats have what you are showing here as part of how they are constructed.

A text friendly forms do actually exist. OBJ as mentioned by @vstrakh is text friendly, but doesn't hold vertex color. The DirectX format (.X) is not only text friendly but supports most modern graphics needs and even supports animation.

Spoiler

 

Example of DirectX format:

Block.jpg.2576d98968c24da7164056f684b4b238.jpg



xof 0303txt 0032

Frame Root {
  FrameTransformMatrix {
     1.000000, 0.000000, 0.000000, 0.000000,
     0.000000,-0.000000, 1.000000, 0.000000,
     0.000000, 1.000000, 0.000000, 0.000000,
     0.000000, 0.000000, 0.000000, 1.000000;;
  }
  Frame Cube {
    FrameTransformMatrix {
       1.000000, 0.000000, 0.000000, 0.000000,
       0.000000, 1.000000, 0.000000, 0.000000,
       0.000000, 0.000000, 1.000000, 0.000000,
       0.000000, 0.000000, 0.000000, 1.000000;;
    }
    Mesh { // Cube mesh
      8;
       1.000000; 1.000000;-1.000000;,
       1.000000;-1.000000;-1.000000;,
      -1.000000;-1.000000;-1.000000;,
      -1.000000; 1.000000;-1.000000;,
       1.000000; 1.000000; 1.000000;,
       1.000000;-1.000000; 1.000000;,
      -1.000000;-1.000000; 1.000000;,
      -1.000000; 1.000000; 1.000000;;
      6;
      4;3,2,1,0;,
      4;5,6,7,4;,
      4;1,5,4,0;,
      4;2,6,5,1;,
      4;3,7,6,2;,
      4;7,3,0,4;;
      MeshNormals { // Cube normals
        6;
         0.000000; 0.000000;-1.000000;,
         0.000000;-0.000000; 1.000000;,
         1.000000;-0.000000; 0.000000;,
         0.000000;-1.000000; 0.000000;,
        -1.000000;-0.000000; 0.000000;,
        -0.000000; 1.000000; 0.000000;;
        6;
        4;0,0,0,0;,
        4;1,1,1,1;,
        4;2,2,2,2;,
        4;3,3,3,3;,
        4;4,4,4,4;,
        4;5,5,5,5;;
      } // End of Cube normals
    } // End of Cube mesh
  } // End of Cube
} // End of Root

The code above is the mesh. Note that DirectX format stores the vertices relative to the center point. It also uses matrix's but think of them as vectors for location, rotation and scale.

 

I recommend downloading Blender, it has a huge list of export formats that will allow you to test and find the formats you want. Otherwise you would have to look for older or custom made formats, but these won't be supported by modern software.

Well thanks for the answers, I had a look at blender export formats. How hard would it be to write a plugin to export from blender in my own format? Would that be a good compromise? My 3D engine right now is more a learning platform than anything serious and the main focus point is my custom game IDE, I don't mind doing stuff in "hacky" ways for now. Chances are I'll end up redoing all these components later if I want to do something serious with it.

To save file size and load it much faster you can create a lookup color, imagine if you have thousands of vertex and only have four colors you can put mesh #GROUPS, #TRIANGLE and UV and it's almost complete ^_^y

 


#COLOR
0: 251,252,250
1: 250,253,250
2: 250,252,251
3: 250,253,251
#VERTS
-24,4.58,-25: 0
-25,4.62,-24: 2
-24,4.58,-25: 1
-24,4.62,-24: 3
-25,4.62,-24: 2
-25,4.62,-24: 2
-24,4.62,-24: 3
.
.
... thousands

 

The Assimp project might interest you ^_^ y

It's an Open Asset Import Library (short name: Assimp) is a portable Open Source library toimport various well-known 3D model formats in a uniform manner.

 

1 hour ago, FFA702 said:

How hard would it be to write a plugin to export from blender in my own format?

If you know nothing of python it should take a week to learn. If you have made a saving system for a game before it's the same thing, so +/- a hour.

All you do is use python to save the vertices and colors to a text file. Read this text file in your engine of choice and build a mesh with it. That is all importing and exporting really is.

5 minutes ago, DexterZ101 said:

The Assimp project might interest you ^_^ y

Good link.

This topic is closed to new replies.

Advertisement