Merge pull request #12051 from dback2/polyobjimportfixes

Poly obj import fixes
This commit is contained in:
Brad Hefta-Gaub 2018-01-05 13:33:29 -08:00 committed by GitHub
commit 6a3609093d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -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<QByteArray> 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
for (int i = 0; i < parts.count(); ++i) {
int part = parts[i].toInt();
if (part < 0) {
switch (i) {
case 0:
parts[i].setNum(vertices.size() + part + 1);
break;
case 1:
parts[i].setNum(textureUVs.size() + part + 1);
break;
case 2:
parts[i].setNum(normals.size() + part + 1);
break;
}
}
}
const QByteArray noData {};
face.add(parts[0], (parts.count() > 1) ? parts[1] : noData, (parts.count() > 2) ? parts[2] : noData,
vertices, vertexColors);

View file

@ -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.0000001f;
void Model::setScaleInternal(const glm::vec3& scale) {
if (glm::distance(_scale, scale) > SCALE_CHANGE_EPSILON) {

View file

@ -49,7 +49,7 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat
// extract scale of the matrix as the length of each axis
Mat3 scaleMat = glm::inverse(rotationMat) * rotationScaleMatrix;
scale = glm::max(Vec3(ACCURACY_THREASHOLD), Vec3(scaleMat[0][0], scaleMat[1][1], scaleMat[2][2]));
scale = Vec3(scaleMat[0][0], scaleMat[1][1], scaleMat[2][2]);
// Let's work on a local matrix containing rotation only
Mat3 matRot(