Ubik

Sign in to follow this  
  • entries
    101
  • comments
    122
  • views
    57906

Model Loading

Sign in to follow this  
Will F

98 views

I've been working on code to load a .3ds model. I used Focus on 3D Models as a starting point, but had some issues with the book, so I wrote one from scratch. I really do like the book, but i'm going to complain about it a bit.

Couldn't get the code from the book to compile with gcc without some changes (and once I did it wouldn't render). For instance:

// gcc chokes on these pragmas
#pragma pack(push, packing)

#pragma pack(1)

// some structs that I want aligned on 1 byte boundaries
// so I can properly read in from a .3ds binary file

#pragma pack(pop, packing)

// but works with
#pragma pack(push, 1)

// ...

#pragma pack(pop)



There were also issues with scoping. Here's some code from the book:
for (int i = 0; i < someVarible; i++)
doSomething();

// Error: i is no longer in scope
for (i = 0; i < someOtherVarible; i++)
doSomethingElse();



The book also used C style file functions, so I decided to write mine with a C++ ifstream. Hadn't really used streams to read from files, and since .3ds is a binary file I thought it'd be educational. If nothing else i've found a use for reinterpret_cast.

Only other complaint is that the book glosses over a bit of info, one section describes a chunk and neglects to mention a 2 byte piece of info in the chunk - which resulted in a little bug in my code. After digging around I found a few really dated 3ds specs at wotsit, which helped me track down the problem.

Oh well, i've got my code far enough along that I can display a model in wireframe. Should be able to do materials and texturing pretty soon. It's been awhile since I've posted a screen shot of anything, so maybe i'll do so when I get it done.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now