From fd297f1c03649220ee2859f3661a35776949eccc Mon Sep 17 00:00:00 2001 From: David Back Date: Thu, 21 Dec 2017 10:36:41 -0800 Subject: [PATCH] convert negative relative indices to absolute indices --- libraries/fbx/src/OBJReader.cpp | 22 +++++++++++++++++++++- libraries/render-utils/src/Model.cpp | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index 315c6a86d2..6659e879a0 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -457,13 +457,33 @@ bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mappi // vertex-index/texture-index // vertex-index/texture-index/surface-normal-index QByteArray token = tokenizer.getDatum(); - if (!isdigit(token[0])) { // Tokenizer treats line endings as whitespace. Non-digit indicates done; + auto firstChar = token[0]; + // Tokenizer treats line endings as whitespace. Non-digit and non-negative sign indicates done; + if (!isdigit(firstChar) && firstChar != '-') { tokenizer.pushBackToken(OBJTokenizer::DATUM_TOKEN); break; } QList parts = token.split('/'); assert(parts.count() >= 1); assert(parts.count() <= 3); + // If indices are negative relative indices then adjust them to absolute indices based on current vector sizes + // Also add 1 to each index as 1 will be subtracted later on from each index in OBJFace::add + int part0 = parts[0].toInt(); + if (part0 < 0) { + parts[0].setNum(vertices.size() - abs(part0) + 1); + } + if (parts.count() > 1) { + int part1 = parts[1].toInt(); + if (part1 < 0) { + parts[1].setNum(textureUVs.size() - abs(part1) + 1); + } + if (parts.count() > 2) { + int part2 = parts[2].toInt(); + if (part2 < 0) { + parts[2].setNum(normals.size() - abs(part2) + 1); + } + } + } const QByteArray noData {}; face.add(parts[0], (parts.count() > 1) ? parts[1] : noData, (parts.count() > 2) ? parts[2] : noData, vertices, vertexColors); diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index c4bc435691..55da589448 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -163,7 +163,7 @@ void Model::setScale(const glm::vec3& scale) { _scaledToFit = false; } -const float SCALE_CHANGE_EPSILON = 0.001f; +const float SCALE_CHANGE_EPSILON = 0.000001f; void Model::setScaleInternal(const glm::vec3& scale) { if (glm::distance(_scale, scale) > SCALE_CHANGE_EPSILON) {