1
$\begingroup$

I recently downloaded the newest version of Blender(v 2.71). I immediately encountered a problem when exporting my models to DirectX format(.x). The new export script tries to minimize the file size( I assume this is the reason ) and in so doing has created the need to rewrite the X file importer for my application.

The file now has a single reference for each position, and a single reference for each normal. For a cube the file looks like this:

Mesh Cube { // 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; 0.999999; 1.000000;,
       0.999999;-1.000001; 1.000000;,
      -1.000000;-1.000000; 1.000000;,
      -1.000000; 1.000000; 1.000000;;
      12;
      3;1,2,3;,
      3;7,6,5;,
      3;0,4,5;,
      3;1,5,6;,
      3;6,7,3;,
      3;0,3,7;,
      3;0,1,3;,
      3;4,7,5;,
      3;1,0,5;,
      3;2,1,6;,
      3;2,6,3;,
      3;4,0,7;;
      MeshNormals { // Cube normals
        12;
         0.000000;-0.000000;-1.000000;,
         0.000000;-0.000000; 1.000000;,
         1.000000;-0.000001;-0.000000;,
        -0.000000;-1.000000;-0.000000;,
        -1.000000; 0.000000;-0.000000;,
         0.000000; 1.000000; 0.000000;,
         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;;
        12;
        3;0,0,0;,
        3;1,1,1;,
        3;2,2,2;,
        3;3,3,3;,
        3;4,4,4;,
        3;5,5,5;,
        3;6,6,6;,
        3;7,7,7;,
        3;8,8,8;,
        3;9,9,9;,
        3;10,10,10;,
        3;11,11,11;;
      } // End of Cube normals

Notice that the positions and normals are no longer in a 1-to-1 correspondence. This means that in my application I must map the normals to the appropriate positions...not difficult. The problem is that I must execute a vertex splitting algorithm for each mesh I import. There are only 8 vertices referenced for 12 faces and each face has a different normal...Vertices cannot be shared if their normals are different. My application expects 36 vertices; 3 per face(12 faces for a cube).

For a cube, the algorithm isn't too bad but for an entire scene a splitting algorithm can take quite some time. Furthermore, on occasion the entire scene may need to be reloaded upon events such as 'lost' device. This is undesirable behavior.

My question is this: Should an X file be formatted in this manner? It makes the file smaller but increases the load time of each mesh. The X files in the DirectX SDK all have 1:1 correspondence between positions and normals...

I can customize the script of course...I just want to know about the X file format...

$\endgroup$
3
  • 4
    $\begingroup$ This question appears to be off-topic because it is about DirectX, not Blender. $\endgroup$ Commented Oct 22, 2014 at 21:01
  • $\begingroup$ how is the question off topic when Blender is the author of the export script in question? $\endgroup$
    – P. Avery
    Commented Oct 23, 2014 at 3:27
  • $\begingroup$ Because the problem is while importing. $\endgroup$ Commented Oct 23, 2014 at 12:33

1 Answer 1

0
$\begingroup$

The x file makes sense, it has a 1 to 1 correspondence of vertex to normals. If you use smooth shading, you should fix your rendering code.

The rendering code: 1. Upload vertices array , normals array and UV's array.

  1. Draw triangles using the vertex indexes provided

It's rather simple, look here: http://www.songho.ca/opengl/gl_vertexarray.html

$\endgroup$
4
  • $\begingroup$ The file most definitely does not have a 1:1 correspondence of positions to normals. There are 8 positions and 12 normals. The file has a 1:1 correspondence of face to normals(the export script writes one normal per face). It isn't a problem to load a mesh formatted as is the one above...The question was whether or not the file SHOULD be formatted this way. The new export script is only 'unrolling' vertex data if uv coordinates exist and the option to export uvs is selected. If unrolled then the mesh would have 1:1 correspondance of positions to normals... $\endgroup$
    – P. Avery
    Commented Oct 20, 2014 at 16:22
  • $\begingroup$ One normal per face is for flat shading, one normal per vertex is for smooth shading. Check if your cube is flat shaded or smooth shaded in blender. $\endgroup$ Commented Oct 21, 2014 at 8:38
  • $\begingroup$ I'm not concerned with the mapping of data within the file...It does indeed map correctly. My question is whether or not a file should be formatted this way. Files in the Microsoft DirectX SDK are not formatted this way. Their files are unrolled... $\endgroup$
    – P. Avery
    Commented Oct 21, 2014 at 16:31
  • $\begingroup$ When files are unrolled, the opposite problem exists (a lot more vertices). In games most models need smooth shading, so thats how things are. $\endgroup$ Commented Oct 24, 2014 at 11:26

Not the answer you're looking for? Browse other questions tagged .