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 <LogHandler.h>
#include <hfm/HFMSimpleFormat.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...
@ -1833,21 +1834,14 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr
return hfmModelPtr;
}
void FBXFormat::registerFormat(hfm::FormatRegistry& registry) {
MIMEType getFBXMIMEType() {
MIMEType mimeType("fbx");
mimeType.extensions.push_back("fbx");
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) {
registry.unregisterMIMEType(mimeTypeID);
mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
}
std::shared_ptr<HFMSerializer> FBXSerializer::Factory::get() {
return std::make_shared<FBXSerializer>();
}
std::shared_ptr<hfm::Format> FBXSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<FBXSerializer>>(getFBXMIMEType());
HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
QBuffer buffer(const_cast<QByteArray*>(&data));

View file

@ -95,19 +95,9 @@ public:
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 {
public:
class Factory : public HFMSerializer::Factory {
std::shared_ptr<HFMSerializer> get() override;
};
static std::shared_ptr<hfm::Format> FORMAT;
HFMModel* _hfmModel;
/// Reads HFMModel from the supplied model and mapping data.

View file

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

View file

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

View file

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