Archived

This topic is now archived and is closed to further replies.

ante

Loading .3DSMAX

Recommended Posts

Hi! I''m sorry, but i''m french and my english can be very bad. So, i''m looking for exemples, src,...about the 3dsmax files (not 3ds). How can I load it? use it in opengl projects,... thanks a lot! bye!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

#define EDIT_OBJECT 0x4000
#define OBJ_TRIMESH 0x4100



int main()
{
unsigned int numvert, numpoly;
unsigned int chunkid;
int chunksize;
long position;
FILE * input;
FILE * output;
int i, version;
float x, y, z, unit;
unsigned int a, b, c, d;
char bout;

input = fopen("test.3ds", "rb";
if(input != NULL)
{
output = fopen("test.txt", "w";
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
version = 0;
fread(&version, 4, 1, input);
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
unit = 0.0;
fread(&unit, 4, 1, input);
chunksize=6;
while(chunkid != EDIT_OBJECT)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}


fseek(input, 1, 1);///////////////////////////////////////////////////////////


chunksize = 6;
while(chunkid != OBJ_TRIMESH)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}
position = ftell(input);
chunksize = 6;
while(chunkid != 0x4110)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}


numvert = 0;
fread(&numvert, 2, 1, input);
fprintf(output, "%d\n", numvert);


x = y = z = 0.0;
for(i=0; i<numvert; i++)
{
x = y = z = 0.0;
fread(&x, 4, 1, input);
fread(&y, 4, 1, input);
fread(&z, 4, 1, input);
fprintf(output, "%f ", x);
fprintf(output, "%f ", y);
fprintf(output, "%f\n", z);
}


fseek(input, position, 0);//that causes a problem 0 must be the lenght of a null terminated string: the object name!
chunksize=6;
while(chunkid != 0x4120)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}

numpoly = 0;
fread(&numpoly, 2, 1, input);
fprintf(output, "%d\n", numpoly);

for(i=0; i<numpoly;i++)
{
a = b = c = d = 0;
fread(&a, 2, 1, input);
fread(&b, 2, 1, input);
fread(&c, 2, 1, input);
fread(&d, 2, 1, input);
fprintf(output, "%d ", a);
fprintf(output, "%d ", b);
fprintf(output, "%d\n", c);
}


return 0;

}
}


i use this to load the vertexes, and polygon references out of the file! ill send you info on the file format on your email!

Share this post


Link to post
Share on other sites

#define EDIT_OBJECT 0x4000
#define OBJ_TRIMESH 0x4100



int main()
{
unsigned int numvert, numpoly;
unsigned int chunkid;
int chunksize;
long position;
FILE * input;
FILE * output;
int i, version;
float x, y, z, unit;
unsigned int a, b, c, d;
char bout;

input = fopen("test.3ds", "rb");
if(input != NULL)
{
output = fopen("test.txt", "w");
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
version = 0;
fread(&version, 4, 1, input);
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
chunkid = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
unit = 0.0;
fread(&unit, 4, 1, input);
chunksize=6;
while(chunkid != EDIT_OBJECT)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}


fseek(input, 1, 1);///////////////////////////////////////////////////////////thats not! this causes a problem, if you read the docs ive send, you will see that this is a null terminated string, here: 1 byte


chunksize = 6;
while(chunkid != OBJ_TRIMESH)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}
position = ftell(input);
chunksize = 6;
while(chunkid != 0x4110)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}


numvert = 0;
fread(&numvert, 2, 1, input);
fprintf(output, "%d\n", numvert);


x = y = z = 0.0;
for(i=0; i {
x = y = z = 0.0;
fread(&x, 4, 1, input);
fread(&y, 4, 1, input);
fread(&z, 4, 1, input);
fprintf(output, "%f ", x);
fprintf(output, "%f ", y);
fprintf(output, "%f\n", z);
}


fseek(input, position, 0);//oups, thats ok
chunksize=6;
while(chunkid != 0x4120)
{
fseek(input, chunksize-6, 1);
chunkid = 0;
chunksize = 0;
fread(&chunkid, 2, 1, input);
fread(&chunksize, 4, 1, input);
}

numpoly = 0;
fread(&numpoly, 2, 1, input);
fprintf(output, "%d\n", numpoly);

for(i=0; i {
a = b = c = d = 0;
fread(&a, 2, 1, input);
fread(&b, 2, 1, input);
fread(&c, 2, 1, input);
fread(&d, 2, 1, input);
fprintf(output, "%d ", a);
fprintf(output, "%d ", b);
fprintf(output, "%d\n", c);
}


return 0;

}
}


i use this to load the vertexes, and polygon references out of the file! ill send you info on the file format on your email! this programm is just for testing purposes!

Edited by - Zeusel on January 15, 2002 1:06:01 PM

Share this post


Link to post
Share on other sites
hey Zeusel, do you think you could find the time to send me a copy of those docs as well. ive been digging around but havent found anything to solid yet.

thanks.

---------------------------
"Bingo-Bango! Sugar in the gas tank!"

Share this post


Link to post
Share on other sites
Hi!

thanks for your help! but are you sure that this code is good for .max files because you load a .3ds file, no? is not the same thing. I''d like .max files because contains the animation (frame,...) (like md3 files).

bye

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Perhaps you should search the forum for exactly this topic, it pops up every week or so.

To summarize: you *cannot* load .max files ! Don''t even try to find something on the net, you won''t. .max is a proprietary fileformat of Discreet, and it does *not* contain mesh, animation, or geometry in any way. It contains *code*. Infact, microcode for the modifiers, it''s a meta-fileformat that explains 3DSmax how to create the scene using it''s internal geometry builders.

A sample max file can contain this:

- Create 2 spheres, with the following parameters: blah, blah...
- Apply a mesh select modifier on the following parts: blah...
- Deform by a NURBS defined by the following control points: ...
- Make a boolean difference operation between following objects: ...

etc. NO geometry. NO animation. Just an instruction list. And to read it you would need the source of 3DSMax or rewrite 3DSmax on your own...

Stay with the 3ds format, or if it doesn''t suit your needs, create your own format including an exporter plugin.

- AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> i''ve not the choice, i''m going to develop a plugin to export .max files...thanks for all!!

Yes, this is what most people end up doing. It''s the best thing to do, it''s perhaps not easy to get it working first, but once you have your exporter, you can include all information you need in your file. I agree, .3ds is old and unusable on ''real'' scenes, and .md3 isn''t so good either, but interpreting .max files is total overkill

Just take the plugin SDK on your Max4 CD, there are good examples of simple exporters you can modify. If you run into problems, you can also have a look at Discreet''s help forums and their Sparks programm.

- AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

Actually, i''ve got a graphics animation demo that uses
.max files to read in and display them



I don''t think so. Perhaps they use some own fileformat they renamed to .max or something.

- AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> yeah i think cracking the max format fully would even be harder than cracking the doc format

And even if someone cracked it, what is he going to do with it ? Present the user a list of microcode on the screen ? Or rewrite all possible modifiers that are in 3dsmax, and hopefully get the same results ? Not not mention, that since 3dsmax is closed source, it would be extremely hard to recode the modifers, so that they behave *exactly* as the ones in max. This someone would need to decompile 3dsmax, and of course, he will need to include the complete code of all modifers in *any* app that will read his cracked .max format...

Or he is just going to write a converter, that converts .max to his own format ? Oh, wait a second, I think we already got that: It''s called ''Discreet 3DStudio Max'' ! It can read .max files and export them to your own format ! Wow

Whole point is: It makes no sense trying to read / crack / RE the .max format. Because it''s a modelling format (it stores your models history, not the models themselves), not a 3D format.

- AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
No, there are no small tools, you need Max to read .max files, because they need max internal code to be processed. A ''small'' tool converting them would actually be max without a GUI... Also keep in mind, that 3rd party plugins will write additional data chunks to the .max file, so you would also need those plugins to decode such a .max file.

You could use Gmax, but it can''t read .max files either (only .gmax). Technically, both are the same, Discreet just added a piece of code to gmax, in order to prevent it reading .max files, because of obvious license reasons (Max can actually read .max files).

If you want to read .max files, you won''t have an alternative: buy 3DSMax.

- AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yo...
Va jeter un oeil a ce program, ca devrait t''interesser:
il traduit une fichier .ase (qui peut etre cree par 3dsmax) en code pour opengl (en C++)

http://www.kuenzle-family.ch/philippe/gl/

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Right, surprisingly nobody mentioned the ase format in this thread, until the last AP come up with it. It''s definitely a good idea to look into it, it''s an easy to understand ASCII format, and it exports tons of usefull (and not so usefull) information. Although I don''t like those 3D -> C++ code converters, just parse the file yourself, it''s not that hard.

- AH

Share this post


Link to post
Share on other sites