Add ModelFormatRegistry for handling model loading on the application side

This commit is contained in:
sabrina-shanman 2018-11-30 14:34:44 -08:00
parent 74015a1a5e
commit 243a1d6598
3 changed files with 72 additions and 0 deletions

View file

@ -101,6 +101,7 @@
#include <MainWindow.h>
#include <MappingRequest.h>
#include <MessagesClient.h>
#include <model-networking/ModelFormatRegistry.h>
#include <model-networking/ModelCacheScriptingInterface.h>
#include <model-networking/TextureCacheScriptingInterface.h>
#include <ModelEntityItem.h>
@ -883,6 +884,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
DependencyManager::set<recording::ClipCache>();
DependencyManager::set<GeometryCache>();
DependencyManager::set<ModelFormatRegistry>();
DependencyManager::set<ModelCache>();
DependencyManager::set<ModelCacheScriptingInterface>();
DependencyManager::set<ScriptCache>();
@ -2745,6 +2747,7 @@ Application::~Application() {
DependencyManager::destroy<FramebufferCache>();
DependencyManager::destroy<TextureCacheScriptingInterface>();
DependencyManager::destroy<TextureCache>();
DependencyManager::destroy<ModelFormatRegistry>();
DependencyManager::destroy<ModelCacheScriptingInterface>();
DependencyManager::destroy<ModelCache>();
DependencyManager::destroy<ScriptCache>();

View file

@ -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<FBXFormat>());
addFormat(std::make_shared<OBJFormat>());
addFormat(std::make_shared<GLTFFormat>());
}
void ModelFormatRegistry::addFormat(const std::shared_ptr<hfm::Format>& format) {
format->registerFormat(*this);
withWriteLock([&](){
formats.push_back(format);
});
}
ModelFormatRegistry::~ModelFormatRegistry() {
for (auto& format : formats) {
format->unregisterFormat(*this);
}
formats.clear();
}

View file

@ -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 <hfm/HFMFormat.h>
#include <hfm/HFMFormatRegistry.h>
class ModelFormatRegistry : public hfm::FormatRegistry {
public:
ModelFormatRegistry();
~ModelFormatRegistry();
void addFormat(const std::shared_ptr<hfm::Format>& format);
protected:
void addDefaultFormats();
std::vector<std::shared_ptr<hfm::Format>> formats;
};
#endif // hifi_ModelFormatRegistry_h