Advertisement

Load .3ds missing something?

Started by February 16, 2002 06:09 PM
4 comments, last by bdrewes 22 years, 10 months ago
Hi, I'm trying to work out some code to load a .3ds file. From the file spec, the following code seems like it should work, it confirms that it found the specific chunks I'm looking for but returns some nonsense value as the number of vertices in the file. Is there something I am missing?
    
#include <iostream.h>
#include <fstream.h>

#define MAIN3DS 0x4D4D
#define TRI_VERTEXL 0x4110

void main() {
   ifstream infile;

   char *buffer;
   int length;
   short chunkid;

   infile.open("Doc1.3ds", ios::binary);
   infile.seekg(0, ios::end);

   length = infile.tellg();
   buffer = new char[length];

   infile.seekg(0, ios::beg);
   infile.read(buffer, length);
   infile.close();

   //************


   int vCounter = 0;

   for (int i = 0; i < length; i++) {
      chunkid = *(short *)(buffer+i);
      
      switch (chunkid) {
      case MAIN3DS:
         cout << "Found chunk MAIN3DS at byte:" << i << endl;
         break;
      case TRI_VERTEXL:
         cout << "Found chunk TRI_VERTEXL at byte:" << i << endl;
         
         vCounter = *(short *)(buffer+i);
         cout << vCounter << endl;
         break;
      }
   }
}
    
Edited by - bdrewes on February 16, 2002 7:15:32 PM
Hav''nt got any .3ds code on me but are you sure that the number of vertices can be read into a Short ?

Short = 2 bytes from -32K to 32K

try Unsigned Short or Unsigned Int (or others)

,Jay
Advertisement
Well, the specifications for a .3ds described here: http://www.dcs.ed.ac.uk/home/mxr/gfx/3d/3DS.spec says that the ''number of vertices'' is stored as an unsigned int. They describe an unsigned int (unless I''m reading it wrong) as 2 bytes. Here is what it says:

* Subchunks of 4100 - Triangular Polygon List

id Description
4110 Vertex List
4111 Vertex Options
4120 Face List
4130 Face Material
4140 Mapping Coordinates
4150 Face smoothing group
4160 Translation Matrix
4165 Object visible/invisble
4170 Standard Mapping

* 4110 - Vertex List

start end size type name
0 1 2 unsigned int Total vertices in object
2 5 4 float X-value
6 9 4 float Y-value
10 13 4 float Z-value

bytes 2..13 are repeated times the total amount of vertices in the object

so...Im guessing that at the time this was written, or for the computer the 3d studio code was written on, an unsigned int was 2 bytes. So I think type casting as short is needed.

Also, I tested it and on my system unsigned int is the same size as int (4), and unsigned short is that same as short (2). What really is the difference?
where can I find the full reference about .3ds format or tutorials about load .3ds file?

goddess just one...
汇编语言不会编
Unsigned Short.......

Your using a short which by default is signed.

an unsigned short can hold 0-65K.

,Jay
www.wotsit.org.


,Jay

This topic is closed to new replies.

Advertisement