D3D File format information

Hi :)

I was using a few time ago Sivmodeler in order to convert my .obj files to .d3d files.
However, this program isn't working anymore on my computer, so i wanted to do my own one and EDIT my D3D files.
So i have opened in a textedit a .d3d file, and i see what it contains.
But how a d3d file is make ? What means eache line and how is order each number ? How simply rotate an object to 90° for exemple ?
Is there any documentation about this file format plz ?
Thanx for any information :D
 
are you talking about model files?

Here's what I've been able to deduce so far. I'm not sure what the first line is for.

Code:
line 1 ??
line 2 ... remaining number of lines

line starting with 0 ... primitive begin
    second number 1 ... pr_pointlist
    second number 2 ... pr_linelist
    second number 3 ... pr_linestrip
    second number 4 ... pr_trianglelist
    second number 5 ... pr_trianglestrip
    second number 6 ... pr_trianglefan

line starting with 1 ... primitive end

line starting with 2 ... d3d_model_vertex             (pos_x, pos_y, pos_z)
line starting with 3 ... d3d_model_vertex_colour        (pos_x, pos_y, pos_z, colour, alpha)
line starting with 4 ... d3d_model_vertex_texture         (pos_x, pos_y, pos_z, tex_x, tex_y)
line starting with 5 ... d3d_model_vertex_texture_colour   (pos_x, pos_y, pos_z, tex_x, tex_y, colour, alpha)
line starting with 6 ... d3d_model_vertex_normal          (pos_x, pos_y, pos_z, normal_x, normal_y, normal_z)
line starting with 7 ... d3d_model_vertex_normal_colour  (pos_x, pos_y, pos_z, normal_x, normal_y, normal_z, colour, alpha)
line starting with 8 ... d3d_model_vertex_normal_texture  (pos_x, pos_y, pos_z, normal_x, normal_y, normal_z, tex_x, tex_y)
line starting with 9 ... d3d_model_vertex_normal_texture_colour  (pos_x, pos_y, pos_z, normal_x, normal_y, normal_z, tex_x, tex_y, colour, alpha)
Rotating a vertex:
You'll need to repeat this process for every vertex.

first choose a point to rotate around.
can skip if rotating around origin (0,0,0).

var _r; //point around which to rotate vertex
_r[X] = 4;
_r[Y] = -14;
_r[Z] = 15;

subtract _p from vertex position
I'm assuming you have extracted a vertex position out of the file by this point.
var _v; //vertex pos - rotate point
_v[X] = vertex_x - _r[X];
_v[Y] = vertex_y - _r[Y];
_v[Z] = vertex_z - _r[Z];

in the following 3 examples "_c" is cosine and "_s" sine of angle by which we rotate around each axis

//example of rotating around x axis
var _n; //rotated point
_n[X] = _v[X];
_n[Y] = _v[Y] * _c + _v[Z] * _s;
_n[Z] = _v[Z] * _c - _v[Y] * _s;

//example of rotating around y axis
var _n; //rotated point
_n[X] = _v[X] * _c - _v[Z] * _s;
_n[Y] = _v[Y];
_n[Z] = _v[Z] * _c + _v[X] * _s;

//example of rotating around z axis
var _n; //rotated point
_n[X] = _v[X] * _c + _v[Y] * _s;
_n[Y] = _v[Y] * _c - _v[X] * _s;
_n[Z] = _v[Z];

//final step is to "un-subtract" the position of the point around which we are rotating.
//again, this step may be skipped if rotating around origin
//this would be the new vertex position.
_n[X] += _r[X];
_n[Y] += _r[Y];
_n[Z] += _r[Z];

Don't forget to rotate the normal direction as well. In that case you won't need a point to rotate around.
 
Last edited:

Bart

WiseBart
The following piece of code generates a model file that contains all information you'll need:
Code:
var mdl = d3d_model_create();

d3d_model_primitive_begin(mdl,pr_trianglelist);
d3d_model_vertex(mdl,1,2,3);
d3d_model_vertex_colour(mdl,4,5,6,c_white,1.0);
d3d_model_vertex_normal(mdl,7,8,9,10,11,12);
d3d_model_vertex_normal_colour(mdl,13,14,15,16,17,18,c_white,1.0);
d3d_model_vertex_normal_texture(mdl,19,20,21,22,23,24,1,1);
d3d_model_vertex_normal_texture_colour(mdl,25,26,27,28,29,30,31,32,c_white,1.0);
d3d_model_vertex_texture(mdl,33,34,35,1,1);
d3d_model_vertex_texture_colour(mdl,36,37,38,39,40,c_white,1.0);
d3d_model_primitive_end(mdl);
d3d_model_primitive_begin(mdl,pr_trianglestrip);
d3d_model_primitive_end(mdl);
d3d_model_primitive_begin(mdl,pr_trianglefan);
d3d_model_primitive_end(mdl);

d3d_model_block(mdl,41,42,43,44,45,46,1,1);
d3d_model_cone(mdl,47,48,49,50,51,52,1,1,1,12);
d3d_model_cylinder(mdl,53,54,55,56,57,58,1,1,1,12);
d3d_model_ellipsoid(mdl,59,60,61,62,63,64,1,1,12);
d3d_model_floor(mdl,65,66,67,68,69,70,1,1);
d3d_model_wall(mdl,71,72,73,74,75,76,1,1);

d3d_model_save(mdl,"model.d3d");
The first line contains the version number, which I believe has always been 100.
The second line contains the remaining number of lines.
And from then on, each line in the output is generated by a single call to one of the d3d model functions.

For an overview:
Code:
100     // Version number
20      // Number of lines remaining/to come
0     4.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_primitive_begin(mdl,pr_trianglelist);
2     1.0000     2.0000     3.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_vertex(mdl,1,2,3);
3     4.0000     5.0000     6.0000 16777215.0000     1.0000     0.0000     0.0000     0.0000     0.0000     0.0000  //d3d_model_vertex_colour(mdl,4,5,6,c_white,1.0);
6     7.0000     8.0000     9.0000    10.0000    11.0000    12.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_vertex_normal(mdl,7,8,9,10,11,12);
7    13.0000    14.0000    15.0000    16.0000    17.0000    18.0000 16777215.0000     1.0000     0.0000     0.0000  //d3d_model_vertex_normal_colour(mdl,13,14,15,16,17,18,c_white,1.0);
8    19.0000    20.0000    21.0000    22.0000    23.0000    24.0000     1.0000     1.0000     0.0000     0.0000     //d3d_model_vertex_normal_texture(mdl,19,20,21,22,23,24,1,1);
9    25.0000    26.0000    27.0000    28.0000    29.0000    30.0000    31.0000    32.0000 16777215.0000     1.0000  //d3d_model_vertex_normal_texture_colour(mdl,25,26,27,28,29,30,31,32,c_white,1.0);
4    33.0000    34.0000    35.0000     1.0000     1.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_vertex_texture(mdl,33,34,35,1,1);
5    36.0000    37.0000    38.0000    39.0000    40.0000 16777215.0000     1.0000     0.0000     0.0000     0.0000  //d3d_model_vertex_texture_colour(mdl,36,37,38,39,40,c_white,1.0);
1     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_primitive_end(mdl);
0     5.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_primitive_begin(mdl,pr_trianglestrip);
1     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_primitive_end(mdl);
0     6.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_primitive_begin(mdl,pr_trianglefan);
1     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     //d3d_model_primitive_end(mdl);
10    41.0000    42.0000    43.0000    44.0000    45.0000    46.0000     1.0000     1.0000     0.0000     0.0000    //d3d_model_block(mdl,41,42,43,44,45,46,1,1);    
12    47.0000    48.0000    49.0000    50.0000    51.0000    52.0000     1.0000     1.0000     0.0000     0.0000    //d3d_model_cone(mdl,47,48,49,50,51,52,1,1,1,12);
11    53.0000    54.0000    55.0000    56.0000    57.0000    58.0000     1.0000     1.0000     0.0000     0.0000    //d3d_model_cylinder(mdl,53,54,55,56,57,58,1,1,1,12);
13    59.0000    60.0000    61.0000    62.0000    63.0000    64.0000     1.0000     1.0000     0.0000     0.0000    //d3d_model_ellipsoid(mdl,59,60,61,62,63,64,1,1,12);
15    65.0000    66.0000    67.0000    68.0000    69.0000    70.0000     1.0000     1.0000     0.0000     0.0000    //d3d_model_floor(mdl,65,66,67,68,69,70,1,1);
14    71.0000    72.0000    73.0000    74.0000    75.0000    76.0000     1.0000     1.0000     0.0000     0.0000    //d3d_model_wall(mdl,71,72,73,74,75,76,1,1);
 

FredFredrickson

Member
GMC Elder
I actually made an Addon for Blender that will help with this sort of thing - you might find it useful: http://martincrownover.com/blender-addon-gm3d/

Basically, you can load up/edit your model in Blender, then export directly from Blender to a GML script of the model, or a GameMaker format model.

Hopefully this isn't considered blogspam, because it's not meant to be. Blender is a really great piece of software, and I made this to help reduce my reliance on tools that had either a short shelf life or were just unsupported.

The files it outputs are quite large, but it works, and the models load nice and fast.
 
GREAT !!!
Thanx a lot for your answers !
Thanx to your answers, i now understand how .d3d model should work, and how i may modify them.
i'll now make lots of try :)
Thanx a lot to both of you :)
 
Last edited:
P

PlayLight

Guest
I actually made an Addon for Blender that will help with this sort of thing - you might find it useful: http://martincrownover.com/blender-addon-gm3d/

Basically, you can load up/edit your model in Blender, then export directly from Blender to a GML script of the model, or a GameMaker format model.

Hopefully this isn't considered blogspam, because it's not meant to be. Blender is a really great piece of software, and I made this to help reduce my reliance on tools that had either a short shelf life or were just unsupported.

The files it outputs are quite large, but it works, and the models load nice and fast.
Hey FredFredrickson,

While on the topic, a few months ago i included an addition to your python script to allow for exporting animations from Blender (in the form of either multiple GML scripts or multiple 'd3d' files) for a hobby project i was working on. It worked fine but with my minimal python knowledge the modified script seems to hang Blender until the export is completed. As it was only for a hobby project this didn't really bother me, as it did the job, but i was wondering if you had plans on adding this option (or any others) to your official script in the future?
 

FredFredrickson

Member
GMC Elder
Hey FredFredrickson,

While on the topic, a few months ago i included an addition to your python script to allow for exporting animations from Blender (in the form of either multiple GML scripts or multiple 'd3d' files) for a hobby project i was working on. It worked fine but with my minimal python knowledge the modified script seems to hang Blender until the export is completed. As it was only for a hobby project this didn't really bother me, as it did the job, but i was wondering if you had plans on adding this option (or any others) to your official script in the future?
Yeah, I'd love to add new stuff as it comes along! I'm not very proficient with Python either, but when people have suggestions/additions that I think would be a good fit, I'm happy to look at adding it.

If you've shared your version of the script and you'd like me to link to it from the main page on my website, let me know and I'll do that.

I'd have to look at your implementation a bit before I incorporate it into the "mainline" version. Because GameMaker has no built-in support for animated models, I've been hesitant to include something like that, because then I wouldn't be happy with it unless I provide a GML method for playing back the animation - and that's a little beyond the scope of what I wanted to do with it.
 
P

PlayLight

Guest
Yeah, I'd love to add new stuff as it comes along! I'm not very proficient with Python either, but when people have suggestions/additions that I think would be a good fit, I'm happy to look at adding it.

If you've shared your version of the script and you'd like me to link to it from the main page on my website, let me know and I'll do that.

I'd have to look at your implementation a bit before I incorporate it into the "mainline" version. Because GameMaker has no built-in support for animated models, I've been hesitant to include something like that, because then I wouldn't be happy with it unless I provide a GML method for playing back the animation - and that's a little beyond the scope of what I wanted to do with it.
I know what you mean, the animation system i setup to utilize these multiple models works well but it is very specific to my hobby project, not something that could be easily incorporated into other projects currently. It actually uses GM:S buffer binary files to load the models into the game via a buffer asynchronous process to allow for smooth model loading. So the exported animation models are converted to binary files after export. I have been looking for a way to create and export these binary files within the Blender script instead of GML scripts or d3d files, to skip the middle-man, something i'll dive into more when i have some time and i might be able to write a model import script for GM:S to utilize these buffer files. I'll keep you posted anyway when i start working on it again to see if it interests you.

No need to link my modified version of the python script since it temporarily hangs Blender. But i will PM you a download link to it this afternoon so you have a copy to peruse and use if needed.
 

FredFredrickson

Member
GMC Elder
I know what you mean, the animation system i setup to utilize these multiple models works well but it is very specific to my hobby project, not something that could be easily incorporated into other projects currently. It actually uses GM:S buffer binary files to load the models into the game via a buffer asynchronous process to allow for smooth model loading. So the exported animation models are converted to binary files after export. I have been looking for a way to create and export these binary files within the Blender script instead of GML scripts or d3d files, to skip the middle-man, something i'll dive into more when i have some time and i might be able to write a model import script for GM:S to utilize these buffer files. I'll keep you posted anyway when i start working on it again to see if it interests you.

No need to link my modified version of the python script since it temporarily hangs Blender. But i will PM you a download link to it this afternoon so you have a copy to peruse and use if needed.
Cool, sounds interesting. Thanks!

And sorry to CyberTwister for kind of hijacking his thread here! :p
 
Top