Jump to content

  • Log In with Google      Sign In   
  • Create Account


Load .3ds missing something?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 bdrewes   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 February 2002 - 12:09 PM

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

Sponsor:

#2 Jason Zelos   Members   -  Reputation: 211

Like
Likes
Like

Posted 16 February 2002 - 02:22 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

#3 bdrewes   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 February 2002 - 03:24 PM

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?


#4 shali   Members   -  Reputation: 123

Like
Likes
Like

Posted 16 February 2002 - 05:38 PM

where can I find the full reference about .3ds format or tutorials about load .3ds file?

goddess just one...

#5 Jason Zelos   Members   -  Reputation: 211

Like
Likes
Like

Posted 17 February 2002 - 06:25 AM

Unsigned Short.......

Your using a short which by default is signed.

an unsigned short can hold 0-65K.

,Jay

#6 Jason Zelos   Members   -  Reputation: 211

Like
Likes
Like

Posted 17 February 2002 - 06:28 AM

www.wotsit.org.


,Jay




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS