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 QMap<QString, Light * > & light_by_name, QVector<Light*> & out_lights) {
|
||||
if (!n) return 0;
|
||||
ObjectBase * ret = 0;
|
||||
if (!n) return ObjectBaseList();
|
||||
ObjectBaseList ret;
|
||||
ObjectBase * obj = 0;
|
||||
QString name = n->mName.C_Str();
|
||||
Light * light = light_by_name.value(name, 0);
|
||||
if (light) {
|
||||
ret = light->clone();
|
||||
out_lights << (Light*)ret;
|
||||
obj = light->clone();
|
||||
out_lights << (Light*)obj;
|
||||
} else
|
||||
ret = new ObjectBase();
|
||||
ret->setName(name);
|
||||
ret->setMatrix(fromAiMatrix4D(n->mTransformation));
|
||||
obj = new ObjectBase();
|
||||
obj->setName(name);
|
||||
obj->setMatrix(fromAiMatrix4D(n->mTransformation));
|
||||
ret << obj;
|
||||
//qDebug() << "add object" << ret << ret->name();
|
||||
if (!light) {
|
||||
//qDebug() << name << "has" << n->mNumMeshes << "meshes";
|
||||
for (uint i = 0; i < n->mNumMeshes; ++i) {
|
||||
int mi = n->mMeshes[i];
|
||||
if (meshes[mi]) {
|
||||
if (!ret->mesh()) {
|
||||
ret->setMesh(new Mesh());
|
||||
int mati = ai_meshes[mi]->mMaterialIndex;
|
||||
if (mati >= 0 || mati < materials.size())
|
||||
ret->setMaterial(materials[mati]);
|
||||
if (obj->mesh()) {
|
||||
obj = obj->clone(false);
|
||||
ret << obj;
|
||||
}
|
||||
ret->mesh()->append(meshes[mi]);
|
||||
obj->setMesh(meshes[mi]);
|
||||
int mati = ai_meshes[mi]->mMaterialIndex;
|
||||
if (mati >= 0 || mati < materials.size())
|
||||
obj->setMaterial(materials[mati]);
|
||||
//ret->setMesh(meshes[mi]);
|
||||
//qDebug() << "set mesh" << mi << ret->mesh();
|
||||
//break;
|
||||
@@ -177,8 +180,9 @@ ObjectBase * assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, aiM
|
||||
}
|
||||
}
|
||||
for (uint i = 0; i < n->mNumChildren; ++i) {
|
||||
ObjectBase * co = assimpObject(n->mChildren[i], meshes, ai_meshes, materials, light_by_name, out_lights);
|
||||
if (co) ret->addChild(co);
|
||||
ObjectBaseList cl = assimpObject(n->mChildren[i], meshes, ai_meshes, materials, light_by_name, out_lights);
|
||||
foreach (ObjectBase * c, cl)
|
||||
obj->addChild(c);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -212,8 +216,9 @@ Scene * loadScene(const QString & filepath) {
|
||||
light_by_name[l->name()] = l;
|
||||
|
||||
QVector<Light*> out_lights;
|
||||
ObjectBase * root = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights);
|
||||
if (!root) return 0;
|
||||
ObjectBaseList rootl = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights);
|
||||
if (rootl.isEmpty()) return 0;
|
||||
ObjectBase * root = rootl[0];
|
||||
|
||||
ObjectBaseList rcl = root->children(true);
|
||||
foreach (ObjectBase * c, rcl) {
|
||||
|
||||
Reference in New Issue
Block a user