mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 13:43:49 +02:00
convert negative relative indices to absolute indices
This commit is contained in:
parent
15fcf66d0e
commit
fd297f1c03
2 changed files with 22 additions and 2 deletions
|
@ -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
|
||||
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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue