git-svn-id: svn://db.shs.com.ru/libs@540 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -28,11 +28,11 @@ void LoaderOBJ::initOBJMesh(GLObjectBase * o, const QVector<Vector3d> & src_vert
|
||||
Vector3d v[3], t[3], n[3];
|
||||
//for (int i = 0; i < points.size(); ++i)
|
||||
// points[i] -= pos;
|
||||
uint fcnt = faces.size() * 3;
|
||||
int fcnt = faces.size() * 3;
|
||||
vertices.resize(fcnt * 3);
|
||||
normals.resize(vertices.size());
|
||||
if (has_uv) uvs.resize(fcnt * 2);
|
||||
uint ind = 0, induv = 0;
|
||||
int ind = 0, induv = 0;
|
||||
//qDebug() << "initOBJMesh" << faces.size();
|
||||
for (int i = 0; i < faces.size(); ++i) {
|
||||
cf = faces[i];
|
||||
@@ -74,9 +74,9 @@ Vector3d readVector3d(QString s) {
|
||||
Vector3d ret;
|
||||
QStringList sl(s.trimmed().split(" "));
|
||||
sl.removeAll(""); sl.removeAll(" ");
|
||||
if (sl.size() > 0) ret.x = sl[0].toDouble();
|
||||
if (sl.size() > 1) ret.y = sl[1].toDouble();
|
||||
if (sl.size() > 2) ret.z = sl[2].toDouble();
|
||||
if (sl.size() > 0) ret.x = sl[0].toFloat();
|
||||
if (sl.size() > 1) ret.y = sl[1].toFloat();
|
||||
if (sl.size() > 2) ret.z = sl[2].toFloat();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ Vector2d readVector2d(QString s) {
|
||||
Vector2d ret;
|
||||
QStringList sl(s.trimmed().split(" "));
|
||||
sl.removeAll(""); sl.removeAll(" ");
|
||||
if (sl.size() > 0) ret.x = sl[0].toDouble();
|
||||
if (sl.size() > 1) ret.y = sl[1].toDouble();
|
||||
if (sl.size() > 0) ret.x = sl[0].toFloat();
|
||||
if (sl.size() > 1) ret.y = sl[1].toFloat();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -157,18 +157,18 @@ QVector<Material> readMTL(QString obj_path, QString path) {
|
||||
if (line.startsWith("Ks")) {
|
||||
Vector3d v = readVector3d(line.mid(2).trimmed());
|
||||
mat.map_specular.color_amount = v.length();
|
||||
double mc = qMax(v.x, qMax(v.y, v.z));
|
||||
if (mc > 0.) v /= mc;
|
||||
float mc = qMax(v.x, qMax(v.y, v.z));
|
||||
if (mc > 0.f) v /= mc;
|
||||
mat.color_specular = QColor::fromRgbF(v.x, v.y, v.z);
|
||||
//qDebug() << mat.shine_strength << mat.color_specular;
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("Ns")) {
|
||||
mat.map_specularity.color_amount = 2. / exp(line.mid(2).trimmed().toDouble());
|
||||
mat.map_specularity.color_amount = 2.f / expf(line.mid(2).trimmed().toFloat());
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("d")) {
|
||||
mat.transparency = 1. - line.mid(1).trimmed().toDouble();
|
||||
mat.transparency = 1.f - line.mid(1).trimmed().toFloat();
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("map_Kd")) {
|
||||
@@ -181,7 +181,7 @@ QVector<Material> readMTL(QString obj_path, QString path) {
|
||||
line = line.mid(3).trimmed();
|
||||
QString sv = line.left(line.indexOf(" "));
|
||||
line = line.mid(sv.size()).trimmed();
|
||||
mat.map_normal.color_amount = sv.toDouble();
|
||||
mat.map_normal.color_amount = sv.toFloat();
|
||||
}
|
||||
mat.map_normal.bitmap_path = findFile(line, sp);
|
||||
//qDebug() << "BUMP" << mat.name << mat.bump_scale << mat.bump.bitmap_path;
|
||||
@@ -203,17 +203,17 @@ Material LoaderOBJ::materialByName(const QVector<Material> & materials, const QS
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * loadFromOBJFile(const QString & filepath, double scale) {
|
||||
GLObjectBase * loadFromOBJFile(const QString & filepath, float scale) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
qDebug() << "[Loader OBJ] Error: can`t open \"" + filepath + "\"";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QTextStream stream(&f);
|
||||
QVector<Vector3d> vertices, normals, texcoords;
|
||||
QVector<Material> materials;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = 0;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = nullptr;
|
||||
QString name;
|
||||
root->setName(QFileInfo(f).baseName());
|
||||
int cnt = 0;
|
||||
@@ -237,7 +237,7 @@ GLObjectBase * loadFromOBJFile(const QString & filepath, double scale) {
|
||||
}
|
||||
if (line.startsWith("g ")) {
|
||||
name = line.mid(1).trimmed();
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
LoaderOBJ::initOBJMesh(co, vertices, normals, texcoords);
|
||||
root->addChild(co);
|
||||
}
|
||||
@@ -261,7 +261,7 @@ GLObjectBase * loadFromOBJFile(const QString & filepath, double scale) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
LoaderOBJ::initOBJMesh(co, vertices, normals, texcoords);
|
||||
root->addChild(co);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user