mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
pull comments that get used as scaling hints into a hash table
This commit is contained in:
parent
af6ce8fb07
commit
bacd6445f2
1 changed files with 23 additions and 7 deletions
|
@ -21,9 +21,12 @@
|
||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
|
|
||||||
|
|
||||||
|
QHash<QString, float> COMMENT_SCALE_HINTS;
|
||||||
|
|
||||||
|
|
||||||
class OBJTokenizer {
|
class OBJTokenizer {
|
||||||
public:
|
public:
|
||||||
OBJTokenizer(QIODevice* device) : _device(device), _pushedBackToken(-1) { }
|
OBJTokenizer(QIODevice* device);
|
||||||
enum SpecialToken {
|
enum SpecialToken {
|
||||||
NO_TOKEN = -1,
|
NO_TOKEN = -1,
|
||||||
NO_PUSHBACKED_TOKEN = -1,
|
NO_PUSHBACKED_TOKEN = -1,
|
||||||
|
@ -46,6 +49,15 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
OBJTokenizer::OBJTokenizer(QIODevice* device) : _device(device), _pushedBackToken(-1) {
|
||||||
|
// This is a list of comments that exports use to hint at scaling
|
||||||
|
if (COMMENT_SCALE_HINTS.isEmpty()) {
|
||||||
|
COMMENT_SCALE_HINTS["This file uses centimeters as units"] = 1.0f / 100.0f;
|
||||||
|
COMMENT_SCALE_HINTS["This file uses millimeters as units"] = 1.0f / 1000.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int OBJTokenizer::nextToken() {
|
int OBJTokenizer::nextToken() {
|
||||||
if (_pushedBackToken != NO_PUSHBACKED_TOKEN) {
|
if (_pushedBackToken != NO_PUSHBACKED_TOKEN) {
|
||||||
int token = _pushedBackToken;
|
int token = _pushedBackToken;
|
||||||
|
@ -60,7 +72,7 @@ int OBJTokenizer::nextToken() {
|
||||||
}
|
}
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '#': {
|
case '#': {
|
||||||
_comment = _device->readLine(); // skip the comment
|
_comment = _device->readLine(); // stash comment for a future call to getComment
|
||||||
qDebug() << "COMMENT:" << _comment;
|
qDebug() << "COMMENT:" << _comment;
|
||||||
return COMMENT_TOKEN;
|
return COMMENT_TOKEN;
|
||||||
}
|
}
|
||||||
|
@ -136,11 +148,15 @@ bool parseOBJGroup(OBJTokenizer &tokenizer, const QVariantHash& mapping,
|
||||||
while (true) {
|
while (true) {
|
||||||
int tokenType = tokenizer.nextToken();
|
int tokenType = tokenizer.nextToken();
|
||||||
if (tokenType == OBJTokenizer::COMMENT_TOKEN) {
|
if (tokenType == OBJTokenizer::COMMENT_TOKEN) {
|
||||||
if (tokenizer.getComment().contains("This file uses centimeters as units")) {
|
// loop through the list of known comments which suggest a scaling factor.
|
||||||
scaleGuess = 1.0f / 100.0f;
|
// if we find one, save the scaling hint into scaleGuess
|
||||||
}
|
QString comment = tokenizer.getComment();
|
||||||
if (tokenizer.getComment().contains("This file uses millimeters as units")) {
|
QHashIterator<QString, float> i(COMMENT_SCALE_HINTS);
|
||||||
scaleGuess = 1.0f / 1000.0f;
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
if (comment.contains(i.key())) {
|
||||||
|
scaleGuess = i.value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue