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.
Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 3 files). Show all
Unified · Split
| @@ -1796,9 +1796,7 @@ NetworkGeometry::NetworkGeometry(const QUrl& url, const QSharedPointer<NetworkGe · 1795 unmodified lines | ||
| 1796 | 1796 | |
| 1797 | 1797 | if (url.isEmpty()) { |
| 1798 | 1798 | // 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(), | |
| 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}; | |
| 1799 | + FBXJoint joint = { false, QVector<int>(), -1 }; | |
| 1802 | 1800 | _geometry.joints.append(joint); |
| 1803 | 1801 | _geometry.leftEyeJointIndex = -1; |
| 1804 | 1802 | _geometry.rightEyeJointIndex = -1; |
| @@ -2107,7 +2105,26 @@ void GeometryReader::run() { · 302 unmodified lines | ||
| 2107 | 2105 | } |
| 2108 | 2106 | fbxgeo = readFBX(_reply, _mapping, grabLightmaps, lightmapLevel); |
| 2109 | 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 | 2129 | QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, fbxgeo)); |
| 2113 | 2130 | } else { |