Initial pieces for full OBJ support.

Needs testing by aircraft developers, this is just the first piece.
This commit is contained in:
James Turner
2016-09-27 20:41:31 -05:00
parent 809ddb21c9
commit 6854598b79
2 changed files with 44 additions and 13 deletions
+29 -7
View File
@@ -1,6 +1,6 @@
// ModelRegistry.hxx -- interface to the OSG model registry // 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 <timoore@redhat.com> // Copyright (C) 2007 Tim Moore <timoore@redhat.com>
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
@@ -44,6 +44,8 @@
#include <osgDB/SharedStateManager> #include <osgDB/SharedStateManager>
#include <osgUtil/Optimizer> #include <osgUtil/Optimizer>
#include <simgear/sg_inlines.h>
#include <simgear/scene/util/SGSceneFeatures.hxx> #include <simgear/scene/util/SGSceneFeatures.hxx>
#include <simgear/scene/util/SGStateAttributeVisitor.hxx> #include <simgear/scene/util/SGStateAttributeVisitor.hxx>
#include <simgear/scene/util/SGTextureStateAttributeVisitor.hxx> #include <simgear/scene/util/SGTextureStateAttributeVisitor.hxx>
@@ -155,7 +157,7 @@ public:
Image* image = texture->getImage(0); Image* image = texture->getImage(0);
if (!image) if (!image)
return; return;
texture->setDataVariance(Object::STATIC); texture->setDataVariance(Object::STATIC);
} }
@@ -201,7 +203,7 @@ ModelRegistry::readImage(const string& fileName,
SG_LOG(SG_IO, SG_WARN, "Image loading failed:" << res.message()); SG_LOG(SG_IO, SG_WARN, "Image loading failed:" << res.message());
return res; return res;
} }
if (res.loadedFromCache()) if (res.loadedFromCache())
SG_LOG(SG_IO, SG_BULK, "Returning cached image \"" SG_LOG(SG_IO, SG_BULK, "Returning cached image \""
<< res.getImage()->getFileName() << "\""); << res.getImage()->getFileName() << "\"");
@@ -224,7 +226,7 @@ ModelRegistry::readImage(const string& fileName,
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
// GL_EXT_texture_sRGB // GL_EXT_texture_sRGB
// patented, no way to decompress these // patented, no way to decompress these
#ifndef GL_EXT_texture_sRGB #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_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
// GL_TDFX_texture_compression_FXT1 // GL_TDFX_texture_compression_FXT1
// can decompress these in software but // can decompress these in software but
// no code present in simgear. // no code present in simgear.
@@ -247,7 +249,7 @@ ModelRegistry::readImage(const string& fileName,
#endif #endif
case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGB_FXT1_3DFX:
case GL_COMPRESSED_RGBA_FXT1_3DFX: case GL_COMPRESSED_RGBA_FXT1_3DFX:
// GL_EXT_texture_compression_rgtc // GL_EXT_texture_compression_rgtc
// can decompress these in software but // can decompress these in software but
// no code present in simgear. // no code present in simgear.
@@ -475,7 +477,7 @@ struct ACProcessPolicy {
osg::Group* root = new Group; osg::Group* root = new Group;
MatrixTransform* transform = new MatrixTransform; MatrixTransform* transform = new MatrixTransform;
root->addChild(transform); root->addChild(transform);
transform->setDataVariance(Object::STATIC); transform->setDataVariance(Object::STATIC);
transform->setMatrix(m); transform->setMatrix(m);
transform->addChild(node); transform->addChild(node);
@@ -489,7 +491,27 @@ typedef ModelRegistryCallback<ACProcessPolicy, DefaultCachePolicy,
OSGSubstitutePolicy, BuildLeafBVHPolicy> OSGSubstitutePolicy, BuildLeafBVHPolicy>
ACCallback; 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<OBJProcessPolicy,
DefaultCachePolicy,
ACOptimizePolicy,
OSGSubstitutePolicy, BuildLeafBVHPolicy>
OBJCallback;
namespace namespace
{ {
ModelRegistryCallbackProxy<ACCallback> g_acRegister("ac"); ModelRegistryCallbackProxy<ACCallback> g_acRegister("ac");
ModelRegistryCallbackProxy<OBJCallback> g_objRegister("obj");
} }
+15 -6
View File
@@ -68,7 +68,7 @@ void SGModelLib::setPanelFunc(panel_func pf)
static_panelFunc = pf; static_panelFunc = pf;
} }
std::string SGModelLib::findDataFile(const std::string& file, std::string SGModelLib::findDataFile(const std::string& file,
const osgDB::Options* opts, const osgDB::Options* opts,
SGPath currentPath) SGPath currentPath)
{ {
@@ -97,8 +97,10 @@ osg::Node* loadFile(const string& path, SGReaderWriterOptions* options)
{ {
using namespace osg; using namespace osg;
using namespace osgDB; using namespace osgDB;
if (boost::iends_with(path, ".ac")) if (boost::iends_with(path, ".ac") || boost::iends_with(path, ".obj")) {
options->setInstantiateEffects(true); options->setInstantiateEffects(true);
}
ref_ptr<Node> model = readRefNodeFile(path, options); ref_ptr<Node> model = readRefNodeFile(path, options);
if (!model) if (!model)
return 0; return 0;
@@ -118,11 +120,11 @@ SGModelLib::loadModel(const string &path,
opt->getDatabasePathList().push_front( osgDB::getFilePath(path) ); opt->getDatabasePathList().push_front( osgDB::getFilePath(path) );
opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get());
opt->setModelData(data); opt->setModelData(data);
if (load2DPanels) { if (load2DPanels) {
opt->setLoadPanel(static_panelFunc); opt->setLoadPanel(static_panelFunc);
} }
osg::Node *n = loadFile(path, opt.get()); osg::Node *n = loadFile(path, opt.get());
if (n && n->getName().empty()) if (n && n->getName().empty())
n->setName("Direct loaded model \"" + path + "\""); 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->setPropertyNode(prop_root ? prop_root: static_propRoot.get());
opt->setModelData(data); opt->setModelData(data);
opt->setLoadPanel(static_panelFunc); 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); opt->setInstantiateEffects(true);
}
if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true)) if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true))
opt->setObjectCacheHint(osgDB::Options::CACHE_ALL); opt->setObjectCacheHint(osgDB::Options::CACHE_ALL);
else else
@@ -171,8 +176,12 @@ SGModelLib::loadPagedModel(const string &path, SGPropertyNode *prop_root,
opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get());
opt->setModelData(data); opt->setModelData(data);
opt->setLoadPanel(static_panelFunc); 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); opt->setInstantiateEffects(true);
}
if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true)) if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true))
opt->setObjectCacheHint(osgDB::Options::CACHE_ALL); opt->setObjectCacheHint(osgDB::Options::CACHE_ALL);
else else