git-svn-id: svn://db.shs.com.ru/libs@684 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -143,33 +143,36 @@ Light * assimpLight(const aiLight * l) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ObjectBase * assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, aiMesh ** ai_meshes,
|
ObjectBaseList assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, aiMesh ** ai_meshes,
|
||||||
const QVector<Material*> & materials,
|
const QVector<Material*> & materials,
|
||||||
const QMap<QString, Light * > & light_by_name, QVector<Light*> & out_lights) {
|
const QMap<QString, Light * > & light_by_name, QVector<Light*> & out_lights) {
|
||||||
if (!n) return 0;
|
if (!n) return ObjectBaseList();
|
||||||
ObjectBase * ret = 0;
|
ObjectBaseList ret;
|
||||||
|
ObjectBase * obj = 0;
|
||||||
QString name = n->mName.C_Str();
|
QString name = n->mName.C_Str();
|
||||||
Light * light = light_by_name.value(name, 0);
|
Light * light = light_by_name.value(name, 0);
|
||||||
if (light) {
|
if (light) {
|
||||||
ret = light->clone();
|
obj = light->clone();
|
||||||
out_lights << (Light*)ret;
|
out_lights << (Light*)obj;
|
||||||
} else
|
} else
|
||||||
ret = new ObjectBase();
|
obj = new ObjectBase();
|
||||||
ret->setName(name);
|
obj->setName(name);
|
||||||
ret->setMatrix(fromAiMatrix4D(n->mTransformation));
|
obj->setMatrix(fromAiMatrix4D(n->mTransformation));
|
||||||
|
ret << obj;
|
||||||
//qDebug() << "add object" << ret << ret->name();
|
//qDebug() << "add object" << ret << ret->name();
|
||||||
if (!light) {
|
if (!light) {
|
||||||
//qDebug() << name << "has" << n->mNumMeshes << "meshes";
|
//qDebug() << name << "has" << n->mNumMeshes << "meshes";
|
||||||
for (uint i = 0; i < n->mNumMeshes; ++i) {
|
for (uint i = 0; i < n->mNumMeshes; ++i) {
|
||||||
int mi = n->mMeshes[i];
|
int mi = n->mMeshes[i];
|
||||||
if (meshes[mi]) {
|
if (meshes[mi]) {
|
||||||
if (!ret->mesh()) {
|
if (obj->mesh()) {
|
||||||
ret->setMesh(new Mesh());
|
obj = obj->clone(false);
|
||||||
|
ret << obj;
|
||||||
|
}
|
||||||
|
obj->setMesh(meshes[mi]);
|
||||||
int mati = ai_meshes[mi]->mMaterialIndex;
|
int mati = ai_meshes[mi]->mMaterialIndex;
|
||||||
if (mati >= 0 || mati < materials.size())
|
if (mati >= 0 || mati < materials.size())
|
||||||
ret->setMaterial(materials[mati]);
|
obj->setMaterial(materials[mati]);
|
||||||
}
|
|
||||||
ret->mesh()->append(meshes[mi]);
|
|
||||||
//ret->setMesh(meshes[mi]);
|
//ret->setMesh(meshes[mi]);
|
||||||
//qDebug() << "set mesh" << mi << ret->mesh();
|
//qDebug() << "set mesh" << mi << ret->mesh();
|
||||||
//break;
|
//break;
|
||||||
@@ -177,8 +180,9 @@ ObjectBase * assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, aiM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (uint i = 0; i < n->mNumChildren; ++i) {
|
for (uint i = 0; i < n->mNumChildren; ++i) {
|
||||||
ObjectBase * co = assimpObject(n->mChildren[i], meshes, ai_meshes, materials, light_by_name, out_lights);
|
ObjectBaseList cl = assimpObject(n->mChildren[i], meshes, ai_meshes, materials, light_by_name, out_lights);
|
||||||
if (co) ret->addChild(co);
|
foreach (ObjectBase * c, cl)
|
||||||
|
obj->addChild(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -212,8 +216,9 @@ Scene * loadScene(const QString & filepath) {
|
|||||||
light_by_name[l->name()] = l;
|
light_by_name[l->name()] = l;
|
||||||
|
|
||||||
QVector<Light*> out_lights;
|
QVector<Light*> out_lights;
|
||||||
ObjectBase * root = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights);
|
ObjectBaseList rootl = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights);
|
||||||
if (!root) return 0;
|
if (rootl.isEmpty()) return 0;
|
||||||
|
ObjectBase * root = rootl[0];
|
||||||
|
|
||||||
ObjectBaseList rcl = root->children(true);
|
ObjectBaseList rcl = root->children(true);
|
||||||
foreach (ObjectBase * c, rcl) {
|
foreach (ObjectBase * c, rcl) {
|
||||||
|
|||||||
Reference in New Issue
Block a user