git-svn-id: svn://db.shs.com.ru/libs@637 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -86,7 +86,7 @@ Light * assimpLight(const aiLight * l) {
|
||||
Light * ret = new Light();
|
||||
ret->setName(l->mName.C_Str());
|
||||
ret->setPos(fromAiVector3D(l->mPosition));
|
||||
ret->direction = fromAiVector3D(l->mDirection);
|
||||
ret->setDirection(fromAiVector3D(l->mDirection));
|
||||
ret->decay_const = l->mAttenuationConstant ;
|
||||
ret->decay_linear = l->mAttenuationLinear ;
|
||||
ret->decay_quadratic = l->mAttenuationQuadratic;
|
||||
@@ -102,14 +102,15 @@ Light * assimpLight(const aiLight * l) {
|
||||
}
|
||||
|
||||
|
||||
ObjectBase * assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, const QMap<QString, Light * > & light_by_name) {
|
||||
ObjectBase * assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, const QMap<QString, Light * > & light_by_name, QVector<Light*> & out_lights) {
|
||||
if (!n) return 0;
|
||||
ObjectBase * ret = 0;
|
||||
QString name = n->mName.C_Str();
|
||||
Light * light = light_by_name.value(name, 0);
|
||||
if (light)
|
||||
if (light) {
|
||||
ret = light->clone();
|
||||
else
|
||||
out_lights << (Light*)ret;
|
||||
} else
|
||||
ret = new ObjectBase();
|
||||
ret->setName(name);
|
||||
ret->setTransform(fromAiMatrix4D(n->mTransformation));
|
||||
@@ -125,7 +126,7 @@ ObjectBase * assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, con
|
||||
}
|
||||
}
|
||||
for (uint i = 0; i < n->mNumChildren; ++i) {
|
||||
ObjectBase * co = assimpObject(n->mChildren[i], meshes, light_by_name);
|
||||
ObjectBase * co = assimpObject(n->mChildren[i], meshes, light_by_name, out_lights);
|
||||
if (co) ret->addChild(co);
|
||||
}
|
||||
|
||||
@@ -138,9 +139,9 @@ Scene * loadScene(const QString & filepath) {
|
||||
qDebug() << "[Loader Assimp] Import" << filepath << "...";
|
||||
Assimp::Importer importer;
|
||||
const aiScene * ais = importer.ReadFile(filepath.toUtf8(), aiProcess_Triangulate |
|
||||
aiProcess_SortByPType |
|
||||
aiProcess_GenUVCoords |
|
||||
aiProcess_TransformUVCoords);
|
||||
aiProcess_SortByPType |
|
||||
aiProcess_GenUVCoords |
|
||||
aiProcess_TransformUVCoords);
|
||||
if (!ais) {
|
||||
qDebug() << "[Loader Assimp] Error: \"" + QString(importer.GetErrorString()) + "\"";
|
||||
return 0;
|
||||
@@ -156,15 +157,25 @@ Scene * loadScene(const QString & filepath) {
|
||||
foreach (Light * l, lights)
|
||||
light_by_name[l->name()] = l;
|
||||
|
||||
ObjectBase * root = assimpObject(ais->mRootNode, meshes, light_by_name);
|
||||
QVector<Light*> out_lights;
|
||||
ObjectBase * root = assimpObject(ais->mRootNode, meshes, light_by_name, out_lights);
|
||||
if (!root) return 0;
|
||||
|
||||
QList<ObjectBase*> rcl = root->children(true);
|
||||
foreach (ObjectBase * c, rcl) {
|
||||
foreach (Light * l, out_lights) {
|
||||
if (c->name() == (l->name() + ".Target")) {
|
||||
l->setAim((l->worldTransform().inverted() * QVector4D(c->worldPos(), 1)).toVector3D());
|
||||
delete c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scene * scene = new Scene();
|
||||
scene->setName(root->name());
|
||||
foreach (ObjectBase * o, root->children())
|
||||
scene->addObject(o);
|
||||
//foreach (ObjectBase * o, lights)
|
||||
// scene->addObject(o);
|
||||
qDeleteAll(lights);
|
||||
|
||||
return scene;
|
||||
|
||||
Reference in New Issue
Block a user