git-svn-id: svn://db.shs.com.ru/libs@540 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -45,8 +45,8 @@ QVector4D readXMLVector(QDomElement n) {
|
||||
QStringList sl(n.firstChild().nodeValue().trimmed().split(" "));
|
||||
sl.removeAll("");
|
||||
sl.removeAll(" ");
|
||||
if (sl.size() == 3) return QVector4D(sl[0].toDouble(), sl[1].toDouble(), sl[2].toDouble(), 0.);
|
||||
if (sl.size() == 4) return QVector4D(sl[0].toDouble(), sl[1].toDouble(), sl[2].toDouble(), sl[3].toDouble());
|
||||
if (sl.size() == 3) return QVector4D(sl[0].toFloat(), sl[1].toFloat(), sl[2].toFloat(), 0.);
|
||||
if (sl.size() == 4) return QVector4D(sl[0].toFloat(), sl[1].toFloat(), sl[2].toFloat(), sl[3].toFloat());
|
||||
return QVector4D();
|
||||
}
|
||||
|
||||
@@ -60,13 +60,13 @@ QMatrix4x4 readXMLMatrix(QDomElement n) {
|
||||
int ind = -1;
|
||||
for (int r = 0; r < 4; ++r)
|
||||
for (int c = 0; c < 4; ++c)
|
||||
m(r, c) = sl[++ind].toDouble();
|
||||
m(r, c) = sl[++ind].toFloat();
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
double readXMLFloat(QDomElement n) {
|
||||
return n.firstChildElement("float").firstChild().nodeValue().toDouble();
|
||||
float readXMLFloat(QDomElement n) {
|
||||
return n.firstChildElement("float").firstChild().nodeValue().toFloat();
|
||||
}
|
||||
|
||||
|
||||
@@ -140,9 +140,9 @@ QVector<Material> LoaderDAE::readMaterials(QDomElement le, QDomElement li, bool
|
||||
if (col.isValid()) mat.color_diffuse = col;
|
||||
col = readXMLColor(pn.firstChildElement("specular"));
|
||||
if (col.isValid()) mat.color_specular = col;
|
||||
mat.map_specularity.color_amount = 2. / exp(readXMLFloat(pn.firstChildElement("shininess")));
|
||||
mat.map_specularity.color_amount = 2.f / expf(readXMLFloat(pn.firstChildElement("shininess")));
|
||||
mat.transparency = readXMLFloat(pn.firstChildElement("transparency"));
|
||||
if (!fbx) mat.transparency = 1. - mat.transparency;
|
||||
if (!fbx) mat.transparency = 1.f - mat.transparency;
|
||||
text = readXMLTexture(pn.firstChildElement("diffuse"), prof, li);
|
||||
if (!text.isEmpty()) mat.map_diffuse.bitmap_path = text;
|
||||
text = readXMLTexture(pn.firstChildElement("diffuse"), prof, li);
|
||||
@@ -221,18 +221,18 @@ void readScene(QDomElement n, QMatrix4x4 cm, QVector<QPair<QPair<QString, QStrin
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
GLObjectBase * loadFromDAEFile(const QString & filepath, float scale) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
qDebug() << "[Loader DAE] Error: can`t open \"" + filepath + "\"";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
QTime tm;
|
||||
tm.restart();
|
||||
QDomDocument dom(filepath);
|
||||
if (!dom.setContent(&f)) {
|
||||
qDebug() << "[Loader DAE] Error: can`t parse \"" + filepath + "\"";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
//qDebug() << "parse" << tm.elapsed();
|
||||
tm.restart();
|
||||
@@ -240,7 +240,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
bool fbx = maine.firstChildElement("asset").firstChildElement("contributor").firstChildElement("authoring_tool").firstChild().nodeValue().startsWith("FBX");
|
||||
QVector<Material> materials = LoaderDAE::readMaterials(maine.firstChildElement("library_effects"),
|
||||
maine.firstChildElement("library_images"), fbx);
|
||||
GLObjectBase * root = new GLObjectBase(), * co = 0;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = nullptr;
|
||||
QMap<QString, QVector<GLObjectBase * > > objects;
|
||||
|
||||
QMap<QString, QString> mat_names;
|
||||
@@ -293,9 +293,9 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
sl.removeAll(" ");
|
||||
for (int c = 0; c < sl.size(); c += stride) {
|
||||
Vector3d v;
|
||||
if (stride >= 1) v.x = sl[c].toDouble();
|
||||
if (stride >= 2) v.y = sl[c + 1].toDouble();
|
||||
if (stride >= 3) v.z = sl[c + 2].toDouble();
|
||||
if (stride >= 1) v.x = sl[c].toFloat();
|
||||
if (stride >= 2) v.y = sl[c + 1].toFloat();
|
||||
if (stride >= 3) v.z = sl[c + 2].toFloat();
|
||||
sd << v;
|
||||
}
|
||||
//qDebug() << " found source" << id << "stride =" << stride << ":" << sd;
|
||||
@@ -324,12 +324,12 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
QDomElement di = einp.at(k).toElement();
|
||||
QString src = di.attribute("source"), sem = di.attribute("semantic").toLower();
|
||||
int offset = di.attribute("offset").toInt();
|
||||
QVector<GLfloat> * curv = 0;
|
||||
QVector<GLfloat> * curv = nullptr;
|
||||
int pccnt = 0;
|
||||
if (sem == "vertex") {curv = &vertices; pccnt = 3;}
|
||||
if (sem == "normal") {curv = &normals; pccnt = 3;}
|
||||
if (sem == "texcoord") {curv = &uvs; pccnt = 2;}
|
||||
if (curv == 0) continue;
|
||||
if (curv == nullptr) continue;
|
||||
if (src.startsWith("#")) src.remove(0, 1);
|
||||
QVector<Vector3d> & data(source_data[source_names.value(src, src)]);
|
||||
for (int ii = offset; ii < p.size(); ii += pbv) {
|
||||
@@ -363,17 +363,17 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
}
|
||||
lo->setColor(readXMLColor(dl));
|
||||
QDomNodeList ml = dn.elementsByTagName("multiplier");
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
ml = dn.elementsByTagName("intensity");
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
QString sv;
|
||||
sv = dl.firstChildElement("constant_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_const = sv.toDouble();
|
||||
sv = dl.firstChildElement("linear_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_linear = sv.toDouble();
|
||||
sv = dl.firstChildElement("quadratic_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_quadratic = sv.toDouble();
|
||||
sv = dl.firstChildElement("constant_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_const = sv.toFloat();
|
||||
sv = dl.firstChildElement("linear_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_linear = sv.toFloat();
|
||||
sv = dl.firstChildElement("quadratic_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_quadratic = sv.toFloat();
|
||||
///lo->setTransform(matrices.value(name));
|
||||
if (lo->light_type == Light::Cone) {
|
||||
ml = dn.elementsByTagName("decay_falloff"); if (!ml.isEmpty()) lo->angle_end = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
ml = dn.elementsByTagName("hotspot_beam"); if (!ml.isEmpty()) lo->angle_start = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
ml = dn.elementsByTagName("decay_falloff"); if (!ml.isEmpty()) lo->angle_end = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
ml = dn.elementsByTagName("hotspot_beam"); if (!ml.isEmpty()) lo->angle_start = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
}
|
||||
QVector<GLObjectBase*> ol;
|
||||
ol << lo;
|
||||
@@ -423,7 +423,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
for (int j = 0; j < dol[i].size(); ++j)
|
||||
delete dol[i][j];
|
||||
|
||||
root->setScale(0.001);
|
||||
root->setScale(0.001f);
|
||||
qDebug() << "[Loader DAE] Loaded" << root->childCount() << "objects from" << filepath;
|
||||
return root;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user