diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index dc39143f6b..b57ff183a0 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -33,6 +33,7 @@ #include #include +#include #include // 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()); + return mimeType; } -void FBXFormat::unregisterFormat(hfm::FormatRegistry& registry) { - registry.unregisterMIMEType(mimeTypeID); - mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID; -} - -std::shared_ptr FBXSerializer::Factory::get() { - return std::make_shared(); -} +std::shared_ptr FBXSerializer::FORMAT = std::make_shared>(getFBXMIMEType()); HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { QBuffer buffer(const_cast(&data)); diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index 231fc5316c..e66a6b911a 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -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 get() override; - }; + static std::shared_ptr FORMAT; HFMModel* _hfmModel; /// Reads HFMModel from the supplied model and mapping data. diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 801adf6bc5..2cad08984f 100644 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -34,6 +34,7 @@ #include #include "FBXSerializer.h" +#include 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()); + return mimeType; } -void GLTFFormat::unregisterFormat(hfm::FormatRegistry& registry) { - registry.unregisterMIMEType(mimeTypeID); - mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID; -} - -std::shared_ptr GLTFSerializer::Factory::get() { - return std::make_shared(); -} +std::shared_ptr GLTFSerializer::FORMAT = std::make_shared>(getGLTFMIMEType()); HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { diff --git a/libraries/fbx/src/GLTFSerializer.h b/libraries/fbx/src/GLTFSerializer.h index 154ba08e9d..626e6c0995 100644 --- a/libraries/fbx/src/GLTFSerializer.h +++ b/libraries/fbx/src/GLTFSerializer.h @@ -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 get() override; - }; GLTFSerializer(); + + static std::shared_ptr FORMAT; + HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; private: GLTFFile _file; diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/fbx/src/OBJSerializer.cpp index ae279bf0a7..62b33e3690 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -28,6 +28,7 @@ #include #include "FBXSerializer.h" +#include #include #include @@ -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()); + return mimeType; } -void OBJFormat::unregisterFormat(hfm::FormatRegistry& registry) { - registry.unregisterMIMEType(mimeTypeID); - mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID; -} - -std::shared_ptr OBJSerializer::Factory::get() { - return std::make_shared(); -} +std::shared_ptr OBJSerializer::FORMAT = std::make_shared>(getOBJMIMEType()); HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); diff --git a/libraries/fbx/src/OBJSerializer.h b/libraries/fbx/src/OBJSerializer.h index 0a3f4c93ac..cbf6ee3ce2 100644 --- a/libraries/fbx/src/OBJSerializer.h +++ b/libraries/fbx/src/OBJSerializer.h @@ -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 get() override; - }; + static std::shared_ptr FORMAT; + typedef QVector FaceGroup; QVector vertices; QVector vertexColors; diff --git a/libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp b/libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp index 26f5b66b48..ccc89eb402 100644 --- a/libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp +++ b/libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp @@ -20,9 +20,9 @@ ModelFormatRegistry::ModelFormatRegistry() : hfm::FormatRegistry() { } void ModelFormatRegistry::addDefaultFormats() { - addFormat(std::make_shared()); - addFormat(std::make_shared()); - addFormat(std::make_shared()); + addFormat(FBXSerializer::FORMAT); + addFormat(OBJSerializer::FORMAT); + addFormat(GLTFSerializer::FORMAT); } void ModelFormatRegistry::addFormat(const std::shared_ptr& format) {