From 6854598b79b33968bf3d1e3aa91ab64475a8d8ea Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 26 Sep 2016 17:18:22 +0100 Subject: [PATCH] Initial pieces for full OBJ support. Needs testing by aircraft developers, this is just the first piece. --- simgear/scene/model/ModelRegistry.cxx | 36 +++++++++++++++++++++------ simgear/scene/model/modellib.cxx | 21 +++++++++++----- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/simgear/scene/model/ModelRegistry.cxx b/simgear/scene/model/ModelRegistry.cxx index 65b72d68..9741432c 100644 --- a/simgear/scene/model/ModelRegistry.cxx +++ b/simgear/scene/model/ModelRegistry.cxx @@ -1,6 +1,6 @@ // ModelRegistry.hxx -- interface to the OSG model registry // -// Copyright (C) 2005-2007 Mathias Froehlich +// Copyright (C) 2005-2007 Mathias Froehlich // Copyright (C) 2007 Tim Moore // // This program is free software; you can redistribute it and/or @@ -44,6 +44,8 @@ #include #include +#include + #include #include #include @@ -155,7 +157,7 @@ public: Image* image = texture->getImage(0); if (!image) return; - + texture->setDataVariance(Object::STATIC); } @@ -201,7 +203,7 @@ ModelRegistry::readImage(const string& fileName, SG_LOG(SG_IO, SG_WARN, "Image loading failed:" << res.message()); return res; } - + if (res.loadedFromCache()) SG_LOG(SG_IO, SG_BULK, "Returning cached image \"" << res.getImage()->getFileName() << "\""); @@ -224,7 +226,7 @@ ModelRegistry::readImage(const string& fileName, case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - + // GL_EXT_texture_sRGB // patented, no way to decompress these #ifndef GL_EXT_texture_sRGB @@ -237,7 +239,7 @@ ModelRegistry::readImage(const string& fileName, case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - + // GL_TDFX_texture_compression_FXT1 // can decompress these in software but // no code present in simgear. @@ -247,7 +249,7 @@ ModelRegistry::readImage(const string& fileName, #endif case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGBA_FXT1_3DFX: - + // GL_EXT_texture_compression_rgtc // can decompress these in software but // no code present in simgear. @@ -475,7 +477,7 @@ struct ACProcessPolicy { osg::Group* root = new Group; MatrixTransform* transform = new MatrixTransform; root->addChild(transform); - + transform->setDataVariance(Object::STATIC); transform->setMatrix(m); transform->addChild(node); @@ -489,7 +491,27 @@ typedef ModelRegistryCallback ACCallback; +struct OBJProcessPolicy { + OBJProcessPolicy(const string& extension) {} + Node* process(Node* node, const string& filename, + const Options* opt) + { + SG_UNUSED(filename); + SG_UNUSED(opt); + return node; + } +}; + + +typedef ModelRegistryCallback +OBJCallback; + namespace { ModelRegistryCallbackProxy g_acRegister("ac"); +ModelRegistryCallbackProxy g_objRegister("obj"); + } diff --git a/simgear/scene/model/modellib.cxx b/simgear/scene/model/modellib.cxx index 73aa55f6..3d931f2b 100644 --- a/simgear/scene/model/modellib.cxx +++ b/simgear/scene/model/modellib.cxx @@ -68,7 +68,7 @@ void SGModelLib::setPanelFunc(panel_func pf) static_panelFunc = pf; } -std::string SGModelLib::findDataFile(const std::string& file, +std::string SGModelLib::findDataFile(const std::string& file, const osgDB::Options* opts, SGPath currentPath) { @@ -97,8 +97,10 @@ osg::Node* loadFile(const string& path, SGReaderWriterOptions* options) { using namespace osg; using namespace osgDB; - if (boost::iends_with(path, ".ac")) + if (boost::iends_with(path, ".ac") || boost::iends_with(path, ".obj")) { options->setInstantiateEffects(true); + } + ref_ptr model = readRefNodeFile(path, options); if (!model) return 0; @@ -118,11 +120,11 @@ SGModelLib::loadModel(const string &path, opt->getDatabasePathList().push_front( osgDB::getFilePath(path) ); opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setModelData(data); - + if (load2DPanels) { opt->setLoadPanel(static_panelFunc); } - + osg::Node *n = loadFile(path, opt.get()); if (n && n->getName().empty()) n->setName("Direct loaded model \"" + path + "\""); @@ -145,8 +147,11 @@ SGModelLib::loadDeferredModel(const string &path, SGPropertyNode *prop_root, opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setModelData(data); opt->setLoadPanel(static_panelFunc); - if (SGPath(path).lower_extension() == "ac") + std::string lext = SGPath(path).lower_extension(); + if ((lext == "ac") || (lext == "obj")) { opt->setInstantiateEffects(true); + } + if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true)) opt->setObjectCacheHint(osgDB::Options::CACHE_ALL); else @@ -171,8 +176,12 @@ SGModelLib::loadPagedModel(const string &path, SGPropertyNode *prop_root, opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setModelData(data); opt->setLoadPanel(static_panelFunc); - if (SGPath(path).lower_extension() == "ac") + std::string lext = SGPath(path).lower_extension(); + + if ((lext == "ac") || (lext == "obj")) { opt->setInstantiateEffects(true); + } + if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true)) opt->setObjectCacheHint(osgDB::Options::CACHE_ALL); else