From 243a1d6598e69b50a59bdc5f2e571d6a1f498f7a Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 30 Nov 2018 14:34:44 -0800 Subject: [PATCH] Add ModelFormatRegistry for handling model loading on the application side --- interface/src/Application.cpp | 3 ++ .../model-networking/ModelFormatRegistry.cpp | 40 +++++++++++++++++++ .../model-networking/ModelFormatRegistry.h | 29 ++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp create mode 100644 libraries/model-networking/src/model-networking/ModelFormatRegistry.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 21af28ffcb..6ff8618918 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -101,6 +101,7 @@ #include #include #include +#include #include #include #include @@ -883,6 +884,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(NodeType::Agent, listenPort); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -2745,6 +2747,7 @@ Application::~Application() { DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); diff --git a/libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp b/libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp new file mode 100644 index 0000000000..26f5b66b48 --- /dev/null +++ b/libraries/model-networking/src/model-networking/ModelFormatRegistry.cpp @@ -0,0 +1,40 @@ +// +// ModelFormatRegistry.cpp +// libraries/model-networking/src/model-networking +// +// Created by Sabrina Shanman on 2018/11/30. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ModelFormatRegistry.h" + +#include "FBXSerializer.h" +#include "OBJSerializer.h" +#include "GLTFSerializer.h" + +ModelFormatRegistry::ModelFormatRegistry() : hfm::FormatRegistry() { + addDefaultFormats(); +} + +void ModelFormatRegistry::addDefaultFormats() { + addFormat(std::make_shared()); + addFormat(std::make_shared()); + addFormat(std::make_shared()); +} + +void ModelFormatRegistry::addFormat(const std::shared_ptr& format) { + format->registerFormat(*this); + withWriteLock([&](){ + formats.push_back(format); + }); +} + +ModelFormatRegistry::~ModelFormatRegistry() { + for (auto& format : formats) { + format->unregisterFormat(*this); + } + formats.clear(); +} diff --git a/libraries/model-networking/src/model-networking/ModelFormatRegistry.h b/libraries/model-networking/src/model-networking/ModelFormatRegistry.h new file mode 100644 index 0000000000..becc53fc1b --- /dev/null +++ b/libraries/model-networking/src/model-networking/ModelFormatRegistry.h @@ -0,0 +1,29 @@ +// +// ModelFormatRegistry.h +// libraries/model-networking/src/model-networking +// +// Created by Sabrina Shanman on 2018/11/30. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ModelFormatRegistry_h +#define hifi_ModelFormatRegistry_h + +#include +#include + +class ModelFormatRegistry : public hfm::FormatRegistry { +public: + ModelFormatRegistry(); + ~ModelFormatRegistry(); + void addFormat(const std::shared_ptr& format); + +protected: + void addDefaultFormats(); + std::vector> formats; +}; + +#endif // hifi_ModelFormatRegistry_h