Remove combineParts from the Serializer interface

This commit is contained in:
sabrina-shanman 2018-11-08 16:20:38 -08:00
parent 0cbe0bd266
commit baa8cdb054
10 changed files with 26 additions and 25 deletions

View file

@ -145,7 +145,7 @@ void OBJBaker::bakeOBJ() {
bool combineParts = true; // set true so that OBJSerializer reads material info from material library
OBJSerializer serializer;
auto geometry = serializer.read(objData, QVariantHash(), _modelURL, combineParts);
auto geometry = serializer.read(objData, QVariantHash(), _modelURL);
// Write OBJ Data as FBX tree nodes
createFBXNodeTree(_rootNode, *geometry);

View file

@ -1796,13 +1796,13 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr
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));
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);
qCDebug(modelformat) << "Reading FBX: " << url;

View file

@ -103,8 +103,8 @@ public:
HFMModel* _hfmModel;
/// Reads HFMModel from the supplied model and mapping data.
/// \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(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false);
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl());
FBXNode _rootNode;
static FBXNode parseFBX(QIODevice* device);

View file

@ -910,13 +910,12 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
return true;
}
HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping,
const QUrl& url, bool combineParts) {
HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
_url = url;
// 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")) {
QString localFileName = PathUtils::expandToLocalDataAbsolutePath(normalizeUrl).toLocalFile();
_url = QUrl(QFileInfo(localFileName).absoluteFilePath());
@ -927,7 +926,7 @@ HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mappi
HFMModel* hfmModelPtr = new HFMModel();
HFMModel& hfmModel = *hfmModelPtr;
buildGeometry(hfmModel, url);
buildGeometry(hfmModel, _url);
//hfmDebugDump(data);
return hfmModelPtr;

View file

@ -707,8 +707,7 @@ class GLTFSerializer : public QObject, public HFMSerializer {
Q_OBJECT
public:
GLTFSerializer();
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:
GLTFFile _file;
QUrl _url;

View file

@ -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);
QBuffer buffer { const_cast<QByteArray*>(&data) };
buffer.open(QIODevice::ReadOnly);
@ -665,6 +665,7 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin
bool needsMaterialLibrary = false;
_url = url;
bool combineParts = mapping.value("combineParts").toBool();
hfmModel.meshExtents.reset();
hfmModel.meshes.append(HFMMesh());
@ -822,7 +823,7 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin
}
// Build the single mesh.
FBXSerializer::buildModelMesh(mesh, url.toString());
FBXSerializer::buildModelMesh(mesh, _url.toString());
// hfmDebugDump(hfmModel);
} 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
// a texture with the same basename as the .obj file.
if (preDefinedMaterial.userSpecifiesUV && !url.isEmpty()) {
QString filename = url.fileName();
if (preDefinedMaterial.userSpecifiesUV && !_url.isEmpty()) {
QString filename = _url.fileName();
int extIndex = filename.lastIndexOf('.'); // by construction, this does not fail
QString basename = filename.remove(extIndex + 1, sizeof("obj"));
preDefinedMaterial.diffuseColor = glm::vec3(1.0f);
QVector<QByteArray> extensions = { "jpg", "jpeg", "png", "tga" };
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++) {
QByteArray candidateString = base + extensions[i];
if (isValidTexture(candidateString)) {

View file

@ -101,7 +101,7 @@ public:
QString currentMaterialName;
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:
QUrl _url;

View file

@ -21,7 +21,7 @@
namespace hfm {
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;
};
};

View file

@ -195,23 +195,26 @@ void GeometryReader::run() {
HFMModel::Pointer hfmModel;
QVariantHash serializerMapping = _mapping;
serializerMapping["combineParts"] = _combineParts;
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) {
throw QString("empty geometry, possibly due to an unsupported FBX version");
}
} 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")) {
QByteArray uncompressedData;
if (gunzip(_data, uncompressedData)){
hfmModel.reset(OBJSerializer().read(uncompressedData, _mapping, _url, _combineParts));
hfmModel.reset(OBJSerializer().read(uncompressedData, serializerMapping, _url));
} else {
throw QString("failed to decompress .obj.gz");
}
} 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) {
throw QString("empty geometry, possibly due to an unsupported GLTF version");
}

View file

@ -43,8 +43,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) {
QByteArray fbxContents = fbx.readAll();
HFMModel::Pointer hfmModel;
if (filename.toLower().endsWith(".obj")) {
bool combineParts = false;
hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename, combineParts));
hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename));
} else if (filename.toLower().endsWith(".fbx")) {
hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), filename));
} else {