Jump to content
  • Advertisement


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


Loading .3ds missing something?

This topic is 6145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);


   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;
      case TRI_VERTEXL:
         cout << "Found chunk TRI_VERTEXL at byte:" << i << endl;
         vCounter = *(short *)(buffer+i);
         cout << vCounter << endl;

Share this post

Link to post
Share on other sites
It looks like you aren''t reading enough data.

To load a 3DS file, you have to skip all the parts of the file you dont want. Therefore, you have to either pretend to read all the data, or skip it.

You should have a default in your loader that reads a segment of data. I dont remember exactly how I did it, but I''m pretty sure theres a length value in every segment, which describes the length of the segment (whoo... imagine that ) You should use that to skip down past that segment to the next one.

I''m not exactly sure what else may be the problem with your code, though it looks a little small (mine was looong)


P.S. - if this post is a little winding and incoherant, chances are its because I havent slept in about 36 hours. (DAMN YOU MID-TERMS!!!)

Share this post

Link to post
Share on other sites
I wondered about that, but I wonder if I haven't already taken care of that...as I increment:

for (int i = 0; i < length /* length of the file in bytes */; i++);

...the counter 'i' should walk through buffer- or the bytes of the file as you will.

As the switch statement comes up, and TRI_VERTEXL is found; say at byte 136 (i = 136)...hasn't all the parts of the file I don't need been skipped already? i = 136, buffer+i

Edited by - bdrewes on February 17, 2002 10:50:02 PM

Share this post

Link to post
Share on other sites
in your code, the for loop is incrementing ''i'' by one unit every tick, until you get to the value of length.

chunkid = *(short *)(buffer+i);

with this statement, you access the buffer at point 0, then 1, then 2, and so on... not at accurate offsets to the data.

Every flag in a 3DS file has a length unit, describing the length of that portion of data.

Its kinda hard to explain... If you want an example, I think there''s a good one in the GD Showcase.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!