git-svn-id: svn://db.shs.com.ru/libs@42 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -121,6 +121,14 @@ void Loader3DS::init3DSMesh(GLObjectBase * o, const QVector<uint> & smooth) {
|
||||
}
|
||||
|
||||
|
||||
Material Loader3DS::materialByName(const QVector<Material> & materials, const QString & name) {
|
||||
foreach (const Material & m, materials)
|
||||
if (m.name == name)
|
||||
return m;
|
||||
return Material();
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
@@ -129,14 +137,19 @@ GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
}
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QDataStream stream(&f);
|
||||
//QVector<Material> materials;
|
||||
QVector<Material> materials;
|
||||
QVector<uint> smooth;
|
||||
QVector<ushort> face_mats;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = 0;
|
||||
Material mat;
|
||||
Loader3DS::Chunk cc;
|
||||
Loader3DS::Face face;
|
||||
Vector3d pos;
|
||||
QString str;
|
||||
ushort cnt;
|
||||
QString name;
|
||||
QByteArray ba;
|
||||
int cur_map = 0;
|
||||
float fl, fl1, matrix[3][3];
|
||||
uint col;
|
||||
root->setName(QFileInfo(f).baseName());
|
||||
@@ -178,6 +191,15 @@ GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
co->faces[i].p2 = face.v2;
|
||||
}
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_FACEMAT:
|
||||
name = readCharsUntilNull(stream);
|
||||
stream.readRawData((char * )&cnt, sizeof(ushort));
|
||||
face_mats.resize(cnt);
|
||||
for (int i = 0; i < cnt; ++i)
|
||||
stream.readRawData((char * )&(face_mats[i]), sizeof(ushort));
|
||||
//qDebug() << " facemat name" << name << cnt;
|
||||
co->material().name = name;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_MAPLIST:
|
||||
stream.readRawData((char * )&cnt, sizeof(ushort));
|
||||
co->puvws.resize(cnt);
|
||||
@@ -264,13 +286,64 @@ GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
globject_cast<Light * >(co)->decay_end = fl;
|
||||
//qDebug() << " range end" << fl;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_MATERIAL:
|
||||
//stream.skipRawData(cc.size - 6);
|
||||
if (!mat.name.isEmpty())
|
||||
materials << mat;
|
||||
mat = Material();
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_MATERIAL_NAME:
|
||||
mat.name = readCharsUntilNull(stream);
|
||||
//qDebug() << "matname" << mat.name;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_AMBIENT_COLOR:
|
||||
stream.skipRawData(cc.size - 9);
|
||||
stream.readRawData((char * )&col, 3);
|
||||
mat.color_self_illumination = QColor::fromRgb(((uchar * )&col)[0], ((uchar * )&col)[1], ((uchar * )&col)[2]);
|
||||
//qDebug() << "mat diffuse" << mat.color_diffuse;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_DIFFUSE_COLOR:
|
||||
stream.skipRawData(cc.size - 9);
|
||||
stream.readRawData((char * )&col, 3);
|
||||
mat.color_diffuse = QColor::fromRgb(((uchar * )&col)[0], ((uchar * )&col)[1], ((uchar * )&col)[2]);
|
||||
//qDebug() << "mat diffuse" << mat.color_diffuse;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_SPECULAR_COLOR:
|
||||
stream.skipRawData(cc.size - 9);
|
||||
stream.readRawData((char * )&col, 3);
|
||||
mat.color_specular = QColor::fromRgb(((uchar * )&col)[0], ((uchar * )&col)[1], ((uchar * )&col)[2]);
|
||||
//qDebug() << "mat diffuse" << mat.color_diffuse;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_TEXTURE_MAP:
|
||||
cur_map = LOADER_3DS_CHUNK_TEXTURE_MAP;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_BUMP_MAP:
|
||||
cur_map = LOADER_3DS_CHUNK_BUMP_MAP;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_REFLECTION_MAP:
|
||||
cur_map = LOADER_3DS_CHUNK_REFLECTION_MAP;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_MAP_FILENAME:
|
||||
name = readCharsUntilNull(stream);
|
||||
//qDebug() << " mat map" << QString::number(cur_map, 16) << name;
|
||||
switch (cur_map) {
|
||||
case LOADER_3DS_CHUNK_TEXTURE_MAP: mat.diffuse.bitmap_path = name; break;
|
||||
case LOADER_3DS_CHUNK_BUMP_MAP: mat.bump.bitmap_path = name; break;
|
||||
}
|
||||
break;
|
||||
default: /*qDebug() << "???" << QString::number(cc.id, 16).rightJustified(4, '0') << cc.size;*/ stream.skipRawData(cc.size - 6);
|
||||
}
|
||||
}
|
||||
if (!mat.name.isEmpty())
|
||||
materials << mat;
|
||||
foreach (const Material & m, materials)
|
||||
qDebug() << m.name;
|
||||
if (co != 0) {
|
||||
Loader3DS::init3DSMesh(co, smooth);
|
||||
root->addChild(co);
|
||||
}
|
||||
for (int i = 0; i < root->childCount(); ++i)
|
||||
root->child(i)->material() = Loader3DS::materialByName(materials, root->child(i)->material().name);
|
||||
qDebug() << "[Loader 3DS] Loaded" << root->childCount() << "objects from" << filepath;
|
||||
return root;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user