87 lines
1.7 KiB
C++
87 lines
1.7 KiB
C++
#include "load3ds.h"
|
|
#include "../punkt3d.h"
|
|
|
|
Load3ds::Load3ds(std::string _fname, bool _parse) {
|
|
filename = _fname;
|
|
parsed = false;
|
|
error = false;
|
|
|
|
if(_parse)
|
|
parse();
|
|
}
|
|
|
|
|
|
bool Load3ds::parse() {
|
|
if(parsed)
|
|
unload();
|
|
std::ifstream mfile(filename.c_str(), std::ios::binary);
|
|
|
|
if(!mfile) {
|
|
return false;
|
|
}
|
|
|
|
unsigned short ident;
|
|
unsigned int len;
|
|
std::cout << "size: " << sizeof(int) << std::endl;
|
|
while(!mfile.eof()) {
|
|
ident = len = 0;
|
|
mfile.read((char *)&ident, 2);
|
|
mfile.read((char *)&len, 4);
|
|
// mfile.read((char *)&m, 1);
|
|
// mfile.read((char *)&n, 1);
|
|
std::cout << "Chunk: 0x" << std::hex << ident << " (" << std::dec << len << ")" << std::endl;
|
|
switch(ident) {
|
|
case 0x4d4d:
|
|
// Main Chunk
|
|
std::cout << "yeah!" << std::endl;
|
|
break;
|
|
case 0x3d3d:
|
|
// 3D Editor Chunk
|
|
std::cout << "editorchunk" << std::endl;
|
|
break;
|
|
case 0x4000:
|
|
{
|
|
std::cout << "namechunk" << std::endl;
|
|
std::string name;
|
|
char c;
|
|
do {
|
|
mfile.read(&c, 1);
|
|
name += c;
|
|
} while(c!=0);
|
|
std::cout << "Name: " << name << std::endl;
|
|
}
|
|
break;
|
|
case 0x4100:
|
|
break;
|
|
case 0x4110:{
|
|
unsigned short panz;
|
|
Punkt3D p;
|
|
mfile.read((char*)&panz, 2);
|
|
glBegin(GL_LINE_LOOP);
|
|
for(unsigned int i=0; i<panz; i++) {
|
|
mfile.read((char*)&p.x, sizeof(float));
|
|
mfile.read((char*)&p.y, sizeof(float));
|
|
mfile.read((char*)&p.z, sizeof(float));
|
|
// p.print("Punkt");
|
|
glVertex3f(p);
|
|
}
|
|
glEnd();
|
|
}
|
|
break;
|
|
default:
|
|
//Switch Chunk
|
|
std::cout << "einfach ignorieren..." << std::endl;
|
|
mfile.ignore(len-6);
|
|
break;
|
|
}
|
|
}
|
|
mfile.close();
|
|
|
|
return true;
|
|
}
|
|
|
|
void Load3ds::unload() {
|
|
parsed = false;
|
|
error = false;
|
|
}
|