mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:08:51 +02:00
Remove combineParts from the Serializer interface
This commit is contained in:
parent
0cbe0bd266
commit
baa8cdb054
10 changed files with 26 additions and 25 deletions
|
@ -145,7 +145,7 @@ void OBJBaker::bakeOBJ() {
|
||||||
|
|
||||||
bool combineParts = true; // set true so that OBJSerializer reads material info from material library
|
bool combineParts = true; // set true so that OBJSerializer reads material info from material library
|
||||||
OBJSerializer serializer;
|
OBJSerializer serializer;
|
||||||
auto geometry = serializer.read(objData, QVariantHash(), _modelURL, combineParts);
|
auto geometry = serializer.read(objData, QVariantHash(), _modelURL);
|
||||||
|
|
||||||
// Write OBJ Data as FBX tree nodes
|
// Write OBJ Data as FBX tree nodes
|
||||||
createFBXNodeTree(_rootNode, *geometry);
|
createFBXNodeTree(_rootNode, *geometry);
|
||||||
|
|
|
@ -1796,13 +1796,13 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr
|
||||||
return hfmModelPtr;
|
return hfmModelPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HFMModel* FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url, bool combineParts) {
|
HFMModel* FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||||
QBuffer buffer(const_cast<QByteArray*>(&data));
|
QBuffer buffer(const_cast<QByteArray*>(&data));
|
||||||
buffer.open(QIODevice::ReadOnly);
|
buffer.open(QIODevice::ReadOnly);
|
||||||
return read(&buffer, mapping, url, combineParts);
|
return read(&buffer, mapping, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url, bool combineParts) {
|
HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url) {
|
||||||
_rootNode = parseFBX(device);
|
_rootNode = parseFBX(device);
|
||||||
|
|
||||||
qCDebug(modelformat) << "Reading FBX: " << url;
|
qCDebug(modelformat) << "Reading FBX: " << url;
|
||||||
|
|
|
@ -103,8 +103,8 @@ public:
|
||||||
HFMModel* _hfmModel;
|
HFMModel* _hfmModel;
|
||||||
/// Reads HFMModel from the supplied model and mapping data.
|
/// Reads HFMModel from the supplied model and mapping data.
|
||||||
/// \exception QString if an error occurs in parsing
|
/// \exception QString if an error occurs in parsing
|
||||||
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) override;
|
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||||
HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false);
|
HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl());
|
||||||
|
|
||||||
FBXNode _rootNode;
|
FBXNode _rootNode;
|
||||||
static FBXNode parseFBX(QIODevice* device);
|
static FBXNode parseFBX(QIODevice* device);
|
||||||
|
|
|
@ -910,13 +910,12 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping,
|
HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||||
const QUrl& url, bool combineParts) {
|
|
||||||
|
|
||||||
_url = url;
|
_url = url;
|
||||||
|
|
||||||
// Normalize url for local files
|
// Normalize url for local files
|
||||||
QUrl normalizeUrl = DependencyManager::get<ResourceManager>()->normalizeURL(url);
|
QUrl normalizeUrl = DependencyManager::get<ResourceManager>()->normalizeURL(_url);
|
||||||
if (normalizeUrl.scheme().isEmpty() || (normalizeUrl.scheme() == "file")) {
|
if (normalizeUrl.scheme().isEmpty() || (normalizeUrl.scheme() == "file")) {
|
||||||
QString localFileName = PathUtils::expandToLocalDataAbsolutePath(normalizeUrl).toLocalFile();
|
QString localFileName = PathUtils::expandToLocalDataAbsolutePath(normalizeUrl).toLocalFile();
|
||||||
_url = QUrl(QFileInfo(localFileName).absoluteFilePath());
|
_url = QUrl(QFileInfo(localFileName).absoluteFilePath());
|
||||||
|
@ -927,7 +926,7 @@ HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mappi
|
||||||
HFMModel* hfmModelPtr = new HFMModel();
|
HFMModel* hfmModelPtr = new HFMModel();
|
||||||
HFMModel& hfmModel = *hfmModelPtr;
|
HFMModel& hfmModel = *hfmModelPtr;
|
||||||
|
|
||||||
buildGeometry(hfmModel, url);
|
buildGeometry(hfmModel, _url);
|
||||||
|
|
||||||
//hfmDebugDump(data);
|
//hfmDebugDump(data);
|
||||||
return hfmModelPtr;
|
return hfmModelPtr;
|
||||||
|
|
|
@ -707,8 +707,7 @@ class GLTFSerializer : public QObject, public HFMSerializer {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GLTFSerializer();
|
GLTFSerializer();
|
||||||
HFMModel* read(const QByteArray& data, const QVariantHash& mapping,
|
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||||
const QUrl& url = QUrl(), bool combineParts = false) override;
|
|
||||||
private:
|
private:
|
||||||
GLTFFile _file;
|
GLTFFile _file;
|
||||||
QUrl _url;
|
QUrl _url;
|
||||||
|
|
|
@ -652,7 +652,7 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url, bool combineParts) {
|
HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||||
PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr);
|
PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr);
|
||||||
QBuffer buffer { const_cast<QByteArray*>(&data) };
|
QBuffer buffer { const_cast<QByteArray*>(&data) };
|
||||||
buffer.open(QIODevice::ReadOnly);
|
buffer.open(QIODevice::ReadOnly);
|
||||||
|
@ -665,6 +665,7 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin
|
||||||
bool needsMaterialLibrary = false;
|
bool needsMaterialLibrary = false;
|
||||||
|
|
||||||
_url = url;
|
_url = url;
|
||||||
|
bool combineParts = mapping.value("combineParts").toBool();
|
||||||
hfmModel.meshExtents.reset();
|
hfmModel.meshExtents.reset();
|
||||||
hfmModel.meshes.append(HFMMesh());
|
hfmModel.meshes.append(HFMMesh());
|
||||||
|
|
||||||
|
@ -822,7 +823,7 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the single mesh.
|
// Build the single mesh.
|
||||||
FBXSerializer::buildModelMesh(mesh, url.toString());
|
FBXSerializer::buildModelMesh(mesh, _url.toString());
|
||||||
|
|
||||||
// hfmDebugDump(hfmModel);
|
// hfmDebugDump(hfmModel);
|
||||||
} catch(const std::exception& e) {
|
} catch(const std::exception& e) {
|
||||||
|
@ -838,14 +839,14 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin
|
||||||
}
|
}
|
||||||
// Some .obj files use the convention that a group with uv coordinates that doesn't define a material, should use
|
// Some .obj files use the convention that a group with uv coordinates that doesn't define a material, should use
|
||||||
// a texture with the same basename as the .obj file.
|
// a texture with the same basename as the .obj file.
|
||||||
if (preDefinedMaterial.userSpecifiesUV && !url.isEmpty()) {
|
if (preDefinedMaterial.userSpecifiesUV && !_url.isEmpty()) {
|
||||||
QString filename = url.fileName();
|
QString filename = _url.fileName();
|
||||||
int extIndex = filename.lastIndexOf('.'); // by construction, this does not fail
|
int extIndex = filename.lastIndexOf('.'); // by construction, this does not fail
|
||||||
QString basename = filename.remove(extIndex + 1, sizeof("obj"));
|
QString basename = filename.remove(extIndex + 1, sizeof("obj"));
|
||||||
preDefinedMaterial.diffuseColor = glm::vec3(1.0f);
|
preDefinedMaterial.diffuseColor = glm::vec3(1.0f);
|
||||||
QVector<QByteArray> extensions = { "jpg", "jpeg", "png", "tga" };
|
QVector<QByteArray> extensions = { "jpg", "jpeg", "png", "tga" };
|
||||||
QByteArray base = basename.toUtf8(), textName = "";
|
QByteArray base = basename.toUtf8(), textName = "";
|
||||||
qCDebug(modelformat) << "OBJSerializer looking for default texture of" << url;
|
qCDebug(modelformat) << "OBJSerializer looking for default texture of" << _url;
|
||||||
for (int i = 0; i < extensions.count(); i++) {
|
for (int i = 0; i < extensions.count(); i++) {
|
||||||
QByteArray candidateString = base + extensions[i];
|
QByteArray candidateString = base + extensions[i];
|
||||||
if (isValidTexture(candidateString)) {
|
if (isValidTexture(candidateString)) {
|
||||||
|
|
|
@ -101,7 +101,7 @@ public:
|
||||||
QString currentMaterialName;
|
QString currentMaterialName;
|
||||||
QHash<QString, OBJMaterial> materials;
|
QHash<QString, OBJMaterial> materials;
|
||||||
|
|
||||||
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) override;
|
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl _url;
|
QUrl _url;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
namespace hfm {
|
namespace hfm {
|
||||||
|
|
||||||
class Serializer {
|
class Serializer {
|
||||||
virtual Model* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) = 0;
|
virtual Model* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -195,23 +195,26 @@ void GeometryReader::run() {
|
||||||
|
|
||||||
HFMModel::Pointer hfmModel;
|
HFMModel::Pointer hfmModel;
|
||||||
|
|
||||||
|
QVariantHash serializerMapping = _mapping;
|
||||||
|
serializerMapping["combineParts"] = _combineParts;
|
||||||
|
|
||||||
if (_url.path().toLower().endsWith(".fbx")) {
|
if (_url.path().toLower().endsWith(".fbx")) {
|
||||||
hfmModel.reset(FBXSerializer().read(_data, _mapping, _url.path()));
|
hfmModel.reset(FBXSerializer().read(_data, serializerMapping, _url));
|
||||||
if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) {
|
if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) {
|
||||||
throw QString("empty geometry, possibly due to an unsupported FBX version");
|
throw QString("empty geometry, possibly due to an unsupported FBX version");
|
||||||
}
|
}
|
||||||
} else if (_url.path().toLower().endsWith(".obj")) {
|
} else if (_url.path().toLower().endsWith(".obj")) {
|
||||||
hfmModel.reset(OBJSerializer().read(_data, _mapping, _url, _combineParts));
|
hfmModel.reset(OBJSerializer().read(_data, serializerMapping, _url));
|
||||||
} else if (_url.path().toLower().endsWith(".obj.gz")) {
|
} else if (_url.path().toLower().endsWith(".obj.gz")) {
|
||||||
QByteArray uncompressedData;
|
QByteArray uncompressedData;
|
||||||
if (gunzip(_data, uncompressedData)){
|
if (gunzip(_data, uncompressedData)){
|
||||||
hfmModel.reset(OBJSerializer().read(uncompressedData, _mapping, _url, _combineParts));
|
hfmModel.reset(OBJSerializer().read(uncompressedData, serializerMapping, _url));
|
||||||
} else {
|
} else {
|
||||||
throw QString("failed to decompress .obj.gz");
|
throw QString("failed to decompress .obj.gz");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (_url.path().toLower().endsWith(".gltf")) {
|
} else if (_url.path().toLower().endsWith(".gltf")) {
|
||||||
hfmModel.reset(GLTFSerializer().read(_data, _mapping, _url));
|
hfmModel.reset(GLTFSerializer().read(_data, serializerMapping, _url));
|
||||||
if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) {
|
if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) {
|
||||||
throw QString("empty geometry, possibly due to an unsupported GLTF version");
|
throw QString("empty geometry, possibly due to an unsupported GLTF version");
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) {
|
||||||
QByteArray fbxContents = fbx.readAll();
|
QByteArray fbxContents = fbx.readAll();
|
||||||
HFMModel::Pointer hfmModel;
|
HFMModel::Pointer hfmModel;
|
||||||
if (filename.toLower().endsWith(".obj")) {
|
if (filename.toLower().endsWith(".obj")) {
|
||||||
bool combineParts = false;
|
hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename));
|
||||||
hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename, combineParts));
|
|
||||||
} else if (filename.toLower().endsWith(".fbx")) {
|
} else if (filename.toLower().endsWith(".fbx")) {
|
||||||
hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), filename));
|
hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), filename));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue