PDA

View Full Version : read vertices of 3ds file



Eddy
03-12-2000, 01:16 AM
> I have written this code to extract the vertices of 3ds file
> According to my documentation ,the vertices list begin to id
> TRI_VERTEXL ( 0x4110 ) : number of vertices (4octets),then vertex(array of
> three float(x,y,z,3x4octets)....
> but my code gives me the false values
> Someone can it do rectify my code ?
> thank you for all assistance
>
> #define TRI_VERTEX 0x4110
>
> FILE *binfile;
>
> unsigned char ReadChar (void)
> {
> return (fgetc (binfile));
> }
>
> unsigned int ReadInt (void)
> {
> unsigned int temp = ReadChar();
> return ( temp | (ReadChar () << 8));
> }
>
> int main(int argc, char* argv[])
> {
> int seek=0;
> unsigned int nbr_vertices;
> float vertices [3];
>
> binfile=fopen("tonneau.3ds","rb");
> if (binfile==NULL)return (-1);
>
> fseek(binfile,0L,SEEK_END);
> seek=ftell(binfile);
> printf("taille du fichier : %d \n",seek);
> seek=0;
>
> fseek(binfile,0L,SEEK_SET);
>
> while(ReadInt() != TRI_VERTEX)
>
>
> fseek(binfile,seek,SEEK_SET);
> seek++;
> }
> printf("TRI_VERTEX found at octet : %d ",seek);
>
> nbr_vertices=ReadInt();
> printf("nombres de vertices = %d\n",nbr_vertices);
>
> for (int i=0;i<nbr_vertices;i++)
> {
> fread (&(vertices [0]),sizeof (float),1,binfile);
> fread (&(vertices [1]),sizeof (float),1,binfile);
> fread (&(vertices [2]),sizeof (float),1,binfile);
>
> printf ("Vertex n %d: X= %4.2f Y= %4.2f Z=%4.2f\n", i,
> vertices [0],
> vertices [1],
> vertices [2]);
> }
>
> return 0;
> }
>
> Didier

Bob
03-12-2000, 03:23 AM
Hello

What do you mean by "false values"?

I had some problems with reading .3DS files too when I found something I didn't know about.
3D studio uses a coordinatesystem where X-axis is left/right, Y-axis is into/out of the screen, and Z-axis is up/down. This can cause some problems if you are using a coordinatesystem where Z is into/out of the screen, and Y is up/down.
Are you sure you are reading the vertices in the right order?

Another possible problem I noticed is the function ReadInt(). An integer is four bytes long, but you are only reading two bytes. This can cause major problems when you continue reading, since the filepointer will be pointing two bytes wrong for each call to ReadInt().

Try this instead:

unsigned int temp;
temp = ReadInt() | ReadInt()<<8 | ReadInt()<<16 | ReadInt()<<24;
return(temp)

Bob

Eddy
03-12-2000, 11:11 AM
Thank you Bob for the coordinate system

I have discovered that the 3ds file contains 5 meshs
(one of 667 vertices and 4 other of 64 vertices )
my code read correctly 64 vertices (one mesh)and gives me incorrect values then
(64000000,00 for x)
How then read the vertices of others meshs?

Didier

dmy
03-12-2000, 10:45 PM
you have to position to the correct sub-hierarchy entry point.

build a chunk parser, and follow the chain until you find an object-name chunk with your desired target.

enter into this chunk (you should find a trimesh) and proceed as you already know.

Dolo/\/\ightY

Eddy
03-13-2000, 09:46 AM
ok! dmy ,thank you,but how to construct a chunk parser ?
I do not understand very well !

Eddy

kel
03-13-2000, 12:15 PM
There is a halfway decent book:
3D Graphics File Formats : A Programmer's Reference
by Keith Rule, Keith Ruler

that should help. The other thing that I do (if you are working in Windows) is use the Direct3D utility Conv3ds.exe (it comes with the DirectX sdk). This can convert the 3ds file into a more readable text .x file that you can use for easier debugging...

dmy
03-13-2000, 12:48 PM
eddy:
i can send you some old code i wrote to read objects from 3dstudio meshes.
it's not very well commented... but it substantially works.
so, you can have an insight about the way i implemented the parser.

Dolo/\/\ightY

Eddy
03-14-2000, 09:44 AM
I know the program conv3ds.exe
I have made a few programming direct3drm
And it 's ok!
the program me convert well the file .3ds in file .x text format and therefore gives me all the vertices of the different meshes
My problem is therefore solved,thank you Kel
if you possesses this code dmy ,sends it me,it me concerns
Thank you to all

Didier