mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 04:08:13 +02:00
Fixing formatting issues; renamed ::getVec3Vec3 to ::getVertex.
This commit is contained in:
parent
ff3e9263ef
commit
559e2e0ebb
2 changed files with 16 additions and 12 deletions
|
@ -123,7 +123,7 @@ glm::vec3 OBJTokenizer::getVec3() {
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
bool OBJTokenizer::getVec3Vec3(glm::vec3& vertex, glm::vec3& vertexColor) {
|
bool OBJTokenizer::getVertex(glm::vec3& vertex, glm::vec3& vertexColor) {
|
||||||
// Used for vertices which may also have a vertex color (RGB [0,1]) to follow.
|
// Used for vertices which may also have a vertex color (RGB [0,1]) to follow.
|
||||||
// NOTE: Returns true if there is a vertex color.
|
// NOTE: Returns true if there is a vertex color.
|
||||||
auto x = getFloat(); // N.B.: getFloat() has side-effect
|
auto x = getFloat(); // N.B.: getFloat() has side-effect
|
||||||
|
@ -134,10 +134,11 @@ bool OBJTokenizer::getVec3Vec3(glm::vec3& vertex, glm::vec3& vertexColor) {
|
||||||
auto r = 1.0f, g = 1.0f, b = 1.0f;
|
auto r = 1.0f, g = 1.0f, b = 1.0f;
|
||||||
bool hasVertexColor = false;
|
bool hasVertexColor = false;
|
||||||
if (isNextTokenFloat()) {
|
if (isNextTokenFloat()) {
|
||||||
// If there's another float it's one of two things: a W component or an R component. The standard OBJ spec doesn't output a W component,
|
// If there's another float it's one of two things: a W component or an R component. The standard OBJ spec
|
||||||
// so we're making the assumption that if a float follows (unless it's only a single value) that it's a vertex color.
|
// doesn't output a W component, so we're making the assumption that if a float follows (unless it's
|
||||||
|
// only a single value) that it's a vertex color.
|
||||||
r = getFloat();
|
r = getFloat();
|
||||||
if(isNextTokenFloat()) {
|
if (isNextTokenFloat()) {
|
||||||
// Safe to assume the following values are the green/blue components.
|
// Safe to assume the following values are the green/blue components.
|
||||||
g = getFloat();
|
g = getFloat();
|
||||||
b = getFloat();
|
b = getFloat();
|
||||||
|
@ -167,7 +168,8 @@ void setMeshPartDefaults(FBXMeshPart& meshPart, QString materialID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OBJFace
|
// OBJFace
|
||||||
// NOTE (trent, 7/20/17): The vertexColors vector being passed-in isn't necessary here, but I'm just pairing it with the vertices vector for consistency.
|
// NOTE (trent, 7/20/17): The vertexColors vector being passed-in isn't necessary here, but I'm just
|
||||||
|
// pairing it with the vertices vector for consistency.
|
||||||
bool OBJFace::add(const QByteArray& vertexIndex, const QByteArray& textureIndex, const QByteArray& normalIndex, const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& vertexColors) {
|
bool OBJFace::add(const QByteArray& vertexIndex, const QByteArray& textureIndex, const QByteArray& normalIndex, const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& vertexColors) {
|
||||||
bool ok;
|
bool ok;
|
||||||
int index = vertexIndex.toInt(&ok);
|
int index = vertexIndex.toInt(&ok);
|
||||||
|
@ -412,7 +414,7 @@ bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mappi
|
||||||
} else if (token == "v") {
|
} else if (token == "v") {
|
||||||
glm::vec3 vertex, vertexColor;
|
glm::vec3 vertex, vertexColor;
|
||||||
|
|
||||||
bool hasVertexColor = tokenizer.getVec3Vec3(vertex, vertexColor);
|
bool hasVertexColor = tokenizer.getVertex(vertex, vertexColor);
|
||||||
vertices.append(vertex);
|
vertices.append(vertex);
|
||||||
|
|
||||||
if(hasVertexColor) {
|
if(hasVertexColor) {
|
||||||
|
@ -445,7 +447,8 @@ bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mappi
|
||||||
assert(parts.count() >= 1);
|
assert(parts.count() >= 1);
|
||||||
assert(parts.count() <= 3);
|
assert(parts.count() <= 3);
|
||||||
const QByteArray noData {};
|
const QByteArray noData {};
|
||||||
face.add(parts[0], (parts.count() > 1) ? parts[1] : noData, (parts.count() > 2) ? parts[2] : noData, vertices, vertexColors);
|
face.add(parts[0], (parts.count() > 1) ? parts[1] : noData, (parts.count() > 2) ? parts[2] : noData,
|
||||||
|
vertices, vertexColors);
|
||||||
face.groupName = currentGroup;
|
face.groupName = currentGroup;
|
||||||
face.materialName = currentMaterialName;
|
face.materialName = currentMaterialName;
|
||||||
}
|
}
|
||||||
|
@ -576,8 +579,8 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
glm::vec3 v2 = checked_at(vertices, face.vertexIndices[2]);
|
glm::vec3 v2 = checked_at(vertices, face.vertexIndices[2]);
|
||||||
|
|
||||||
glm::vec3 vc0, vc1, vc2;
|
glm::vec3 vc0, vc1, vc2;
|
||||||
bool hasVertexColors = ( vertexColors.size( ) > 0 );
|
bool hasVertexColors = (vertexColors.size() > 0);
|
||||||
if(hasVertexColors) {
|
if (hasVertexColors) {
|
||||||
// If there are any vertex colors, it's safe to assume all meshes had them exported.
|
// If there are any vertex colors, it's safe to assume all meshes had them exported.
|
||||||
vc0 = checked_at(vertexColors, face.vertexIndices[0]);
|
vc0 = checked_at(vertexColors, face.vertexIndices[0]);
|
||||||
vc1 = checked_at(vertexColors, face.vertexIndices[1]);
|
vc1 = checked_at(vertexColors, face.vertexIndices[1]);
|
||||||
|
@ -599,7 +602,7 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
meshPart.triangleIndices.append(mesh.vertices.count());
|
meshPart.triangleIndices.append(mesh.vertices.count());
|
||||||
mesh.vertices << v2;
|
mesh.vertices << v2;
|
||||||
|
|
||||||
if( hasVertexColors ) {
|
if (hasVertexColors) {
|
||||||
// Add vertex colors.
|
// Add vertex colors.
|
||||||
mesh.colors << vc0;
|
mesh.colors << vc0;
|
||||||
mesh.colors << vc1;
|
mesh.colors << vc1;
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
void ungetChar(char ch) { _device->ungetChar(ch); }
|
void ungetChar(char ch) { _device->ungetChar(ch); }
|
||||||
const QString getComment() const { return _comment; }
|
const QString getComment() const { return _comment; }
|
||||||
glm::vec3 getVec3();
|
glm::vec3 getVec3();
|
||||||
bool getVec3Vec3(glm::vec3& vertex, glm::vec3& vertexColor);
|
bool getVertex(glm::vec3& vertex, glm::vec3& vertexColor);
|
||||||
glm::vec2 getVec2();
|
glm::vec2 getVec2();
|
||||||
float getFloat() { return std::stof((nextToken() != OBJTokenizer::DATUM_TOKEN) ? nullptr : getDatum().data()); }
|
float getFloat() { return std::stof((nextToken() != OBJTokenizer::DATUM_TOKEN) ? nullptr : getDatum().data()); }
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ public:
|
||||||
QString groupName; // We don't make use of hierarchical structure, but it can be preserved for debugging and future use.
|
QString groupName; // We don't make use of hierarchical structure, but it can be preserved for debugging and future use.
|
||||||
QString materialName;
|
QString materialName;
|
||||||
// Add one more set of vertex data. Answers true if successful
|
// Add one more set of vertex data. Answers true if successful
|
||||||
bool add(const QByteArray& vertexIndex, const QByteArray& textureIndex, const QByteArray& normalIndex, const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& vertexColors);
|
bool add(const QByteArray& vertexIndex, const QByteArray& textureIndex, const QByteArray& normalIndex,
|
||||||
|
const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& vertexColors);
|
||||||
// Return a set of one or more OBJFaces from this one, in which each is just a triangle.
|
// Return a set of one or more OBJFaces from this one, in which each is just a triangle.
|
||||||
// Even though FBXMeshPart can handle quads, it would be messy to try to keep track of mixed-size faces, so we treat everything as triangles.
|
// Even though FBXMeshPart can handle quads, it would be messy to try to keep track of mixed-size faces, so we treat everything as triangles.
|
||||||
QVector<OBJFace> triangulate();
|
QVector<OBJFace> triangulate();
|
||||||
|
|
Loading…
Reference in a new issue