History

Textures for .obj reader: Refactor so that uv coordinates can be associated with vertices that might otherwise be on different materials. Defer the assignment vertex/normal/uv assignment until later so that it could potentially be moved directly to model geometry instead of fbx geometry. Handle the actual uv coordinates.

This version does not handle explicit .mtl files, but it does handle those .obj files that follow the convention that there is a .jpg with the same name as the .obj file.

Howard Stearns committed 11 years ago

Commit bd5272d1 parent 5a388a03 files · +212 −220Browse files

Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 3 files). Show all

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+21−4
@@ -1796,9 +1796,7 @@ NetworkGeometry::NetworkGeometry(const QUrl& url, const QSharedPointer<NetworkGe · 1795 unmodified lines
1796 1796
1797 if (url.isEmpty()) {1797 if (url.isEmpty()) {
1798 // make the minimal amount of dummy geometry to satisfy Model1798 // make the minimal amount of dummy geometry to satisfy Model
1799 FBXJoint joint = { false, QVector<int>(), -1, 0.0f, 0.0f, glm::vec3(), glm::mat4(), glm::quat(), glm::quat(),1799 FBXJoint joint = { false, QVector<int>(), -1 };
1800 glm::quat(), glm::mat4(), glm::mat4(), glm::vec3(), glm::vec3(), glm::quat(), glm::quat(),
1801 glm::mat4(), QString(""), glm::vec3(), glm::quat(), SHAPE_TYPE_NONE, false};
1802 _geometry.joints.append(joint);1800 _geometry.joints.append(joint);
1803 _geometry.leftEyeJointIndex = -1;1801 _geometry.leftEyeJointIndex = -1;
1804 _geometry.rightEyeJointIndex = -1;1802 _geometry.rightEyeJointIndex = -1;
@@ -2107,7 +2105,26 @@ void GeometryReader::run() { · 302 unmodified lines
2107 }2105 }
2108 fbxgeo = readFBX(_reply, _mapping, grabLightmaps, lightmapLevel);2106 fbxgeo = readFBX(_reply, _mapping, grabLightmaps, lightmapLevel);
2109 } else if (_url.path().toLower().endsWith(".obj")) {2107 } else if (_url.path().toLower().endsWith(".obj")) {
2110 fbxgeo = readOBJ(_reply, _mapping);2108 fbxgeo = OBJReader().readOBJ(_reply, _mapping);
2109 FBXMesh & mesh = fbxgeo.meshes[0]; // only one, by construction
2110 if (mesh.texCoords.count() > 0) { // If we have uv texture coordinates....
2111 // ... then ensure that every meshPart has a texture filename.
2112 // For now, that's defined directly, using the popular .obj convention that
2113 // the texture is the same as the model basename. Later, we'll extend that
2114 // with separate material files, too.
2115 QString filename = _url.fileName();
2116 int extIndex = filename.lastIndexOf('.'); // by construction, this does not fail
2117 QString basename = filename.remove(extIndex + 1, 3);
2118 QByteArray defaultTexture = basename.toUtf8() + "jpg";
2119 //qCDebug(renderutils) << "basename for " << filename << " is " << basename << ", default:" << defaultTexture;
2120 QVector<FBXMeshPart> & meshParts = mesh.parts;
2121 for (int i = 0; i < meshParts.count(); i++) {
2122 FBXMeshPart & meshPart = meshParts[i];
2123 if (meshPart.diffuseTexture.filename.count() == 0) {
2124 meshPart.diffuseTexture.filename = defaultTexture;
2125 }
2126 }
2127 }
2111 }2128 }
2112 QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, fbxgeo));2129 QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, fbxgeo));
2113 } else {2130 } else {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t