Make Serializers use SimpleFormat

This commit is contained in:
sabrina-shanman 2018-11-30 17:20:16 -08:00
parent 2178baf1a8
commit 30c4830bd8
7 changed files with 21 additions and 66 deletions

View file

@ -33,6 +33,7 @@
#include <gpu/Format.h> #include <gpu/Format.h>
#include <LogHandler.h> #include <LogHandler.h>
#include <hfm/HFMSimpleFormat.h>
#include <hfm/ModelFormatLogging.h> #include <hfm/ModelFormatLogging.h>
// TOOL: Uncomment the following line to enable the filtering of all the unkwnon fields of a node so we can break point easily while loading a model with problems... // TOOL: Uncomment the following line to enable the filtering of all the unkwnon fields of a node so we can break point easily while loading a model with problems...
@ -1833,21 +1834,14 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr
return hfmModelPtr; return hfmModelPtr;
} }
void FBXFormat::registerFormat(hfm::FormatRegistry& registry) { MIMEType getFBXMIMEType() {
MIMEType mimeType("fbx"); MIMEType mimeType("fbx");
mimeType.extensions.push_back("fbx"); mimeType.extensions.push_back("fbx");
mimeType.fileSignatures.emplace_back("Kaydara FBX Binary \x00", 0); mimeType.fileSignatures.emplace_back("Kaydara FBX Binary \x00", 0);
mimeTypeID = registry.registerMIMEType(mimeType, std::make_shared<FBXSerializer::Factory>()); return mimeType;
} }
void FBXFormat::unregisterFormat(hfm::FormatRegistry& registry) { std::shared_ptr<hfm::Format> FBXSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<FBXSerializer>>(getFBXMIMEType());
registry.unregisterMIMEType(mimeTypeID);
mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
}
std::shared_ptr<HFMSerializer> FBXSerializer::Factory::get() {
return std::make_shared<FBXSerializer>();
}
HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
QBuffer buffer(const_cast<QByteArray*>(&data)); QBuffer buffer(const_cast<QByteArray*>(&data));

View file

@ -95,19 +95,9 @@ public:
class ExtractedMesh; class ExtractedMesh;
class FBXFormat : public hfm::Format {
public:
virtual void registerFormat(hfm::FormatRegistry& registry) override;
virtual void unregisterFormat(hfm::FormatRegistry& registry) override;
protected:
hfm::FormatRegistry::MIMETypeID mimeTypeID { hfm::FormatRegistry::INVALID_MIME_TYPE_ID };
};
class FBXSerializer : public HFMSerializer { class FBXSerializer : public HFMSerializer {
public: public:
class Factory : public HFMSerializer::Factory { static std::shared_ptr<hfm::Format> FORMAT;
std::shared_ptr<HFMSerializer> get() override;
};
HFMModel* _hfmModel; HFMModel* _hfmModel;
/// Reads HFMModel from the supplied model and mapping data. /// Reads HFMModel from the supplied model and mapping data.

View file

@ -34,6 +34,7 @@
#include <PathUtils.h> #include <PathUtils.h>
#include "FBXSerializer.h" #include "FBXSerializer.h"
#include <hfm/HFMSimpleFormat.h>
GLTFSerializer::GLTFSerializer() { GLTFSerializer::GLTFSerializer() {
@ -910,21 +911,14 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
return true; return true;
} }
void GLTFFormat::registerFormat(hfm::FormatRegistry& registry) { MIMEType getGLTFMIMEType() {
MIMEType mimeType("gltf"); MIMEType mimeType("gltf");
mimeType.extensions.push_back("gltf"); mimeType.extensions.push_back("gltf");
mimeType.webMediaTypes.push_back("model/gltf+json"); mimeType.webMediaTypes.push_back("model/gltf+json");
mimeTypeID = registry.registerMIMEType(mimeType, std::make_shared<GLTFSerializer::Factory>()); return mimeType;
} }
void GLTFFormat::unregisterFormat(hfm::FormatRegistry& registry) { std::shared_ptr<hfm::Format> GLTFSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<GLTFSerializer>>(getGLTFMIMEType());
registry.unregisterMIMEType(mimeTypeID);
mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
}
std::shared_ptr<HFMSerializer> GLTFSerializer::Factory::get() {
return std::make_shared<GLTFSerializer>();
}
HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {

View file

@ -701,21 +701,13 @@ struct GLTFFile {
} }
}; };
class GLTFFormat : public hfm::Format {
public:
virtual void registerFormat(hfm::FormatRegistry& registry) override;
virtual void unregisterFormat(hfm::FormatRegistry& registry) override;
protected:
hfm::FormatRegistry::MIMETypeID mimeTypeID;
};
class GLTFSerializer : public QObject, public HFMSerializer { class GLTFSerializer : public QObject, public HFMSerializer {
Q_OBJECT Q_OBJECT
public: public:
class Factory : public HFMSerializer::Factory {
std::shared_ptr<HFMSerializer> get() override;
};
GLTFSerializer(); GLTFSerializer();
static std::shared_ptr<hfm::Format> FORMAT;
HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
private: private:
GLTFFile _file; GLTFFile _file;

View file

@ -28,6 +28,7 @@
#include <ResourceManager.h> #include <ResourceManager.h>
#include "FBXSerializer.h" #include "FBXSerializer.h"
#include <hfm/HFMSimpleFormat.h>
#include <hfm/ModelFormatLogging.h> #include <hfm/ModelFormatLogging.h>
#include <shared/PlatformHacks.h> #include <shared/PlatformHacks.h>
@ -651,20 +652,13 @@ done:
return result; return result;
} }
void OBJFormat::registerFormat(hfm::FormatRegistry& registry) { MIMEType getOBJMIMEType() {
MIMEType mimeType("obj"); MIMEType mimeType("obj");
mimeType.extensions.push_back("obj"); mimeType.extensions.push_back("obj");
mimeTypeID = registry.registerMIMEType(mimeType, std::make_shared<OBJSerializer::Factory>()); return mimeType;
} }
void OBJFormat::unregisterFormat(hfm::FormatRegistry& registry) { std::shared_ptr<hfm::Format> OBJSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<OBJSerializer>>(getOBJMIMEType());
registry.unregisterMIMEType(mimeTypeID);
mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
}
std::shared_ptr<HFMSerializer> OBJSerializer::Factory::get() {
return std::make_shared<OBJSerializer>();
}
HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { HFMModel::Pointer 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);

View file

@ -90,20 +90,11 @@ public:
OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f), illuminationModel(-1) {} OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f), illuminationModel(-1) {}
}; };
class OBJFormat : public hfm::Format {
public:
virtual void registerFormat(hfm::FormatRegistry& registry) override;
virtual void unregisterFormat(hfm::FormatRegistry& registry) override;
protected:
hfm::FormatRegistry::MIMETypeID mimeTypeID;
};
class OBJSerializer: public QObject, public HFMSerializer { // QObject so we can make network requests. class OBJSerializer: public QObject, public HFMSerializer { // QObject so we can make network requests.
Q_OBJECT Q_OBJECT
public: public:
class Factory : public HFMSerializer::Factory { static std::shared_ptr<hfm::Format> FORMAT;
std::shared_ptr<HFMSerializer> get() override;
};
typedef QVector<OBJFace> FaceGroup; typedef QVector<OBJFace> FaceGroup;
QVector<glm::vec3> vertices; QVector<glm::vec3> vertices;
QVector<glm::vec3> vertexColors; QVector<glm::vec3> vertexColors;

View file

@ -20,9 +20,9 @@ ModelFormatRegistry::ModelFormatRegistry() : hfm::FormatRegistry() {
} }
void ModelFormatRegistry::addDefaultFormats() { void ModelFormatRegistry::addDefaultFormats() {
addFormat(std::make_shared<FBXFormat>()); addFormat(FBXSerializer::FORMAT);
addFormat(std::make_shared<OBJFormat>()); addFormat(OBJSerializer::FORMAT);
addFormat(std::make_shared<GLTFFormat>()); addFormat(GLTFSerializer::FORMAT);
} }
void ModelFormatRegistry::addFormat(const std::shared_ptr<hfm::Format>& format) { void ModelFormatRegistry::addFormat(const std::shared_ptr<hfm::Format>& format) {