From Mattias Linde, "Nice, this almost gets the job done, one way communication into the plugin is possible.
I've done some additional small modification regarding constness in ReaderWriter and added mutable on _pluginData so passing data back would be possible too. Have updated the collada plugin (ReaderWriterDAE.cpp) to use the map to handle options and have attached the changes. The stuff in daeReader.h and daeWriter.h are just cosmetic changes to get rid of a warning."
This commit is contained in:
parent
7679b96b30
commit
41ce67600e
@ -122,7 +122,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; }
|
||||
|
||||
/** Sets a plugindata value PluginData with a string */
|
||||
void setPluginData(const std::string& s, void* v) { _pluginData[s] = v; }
|
||||
void setPluginData(const std::string& s, void* v) const { _pluginData[s] = v; }
|
||||
|
||||
/** Get a value from the PluginData */
|
||||
void* getPluginData(const std::string& s) { return _pluginData[s]; }
|
||||
@ -135,7 +135,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
}
|
||||
|
||||
/** Remove a value from the PluginData */
|
||||
void removePluginData(const std::string& s) { _pluginData.erase(s); }
|
||||
void removePluginData(const std::string& s) const { _pluginData.erase(s); }
|
||||
|
||||
protected:
|
||||
|
||||
@ -146,7 +146,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
CacheHintOptions _objectCacheHint;
|
||||
|
||||
typedef std::map<std::string,void*> PluginDataMap;
|
||||
PluginDataMap _pluginData;
|
||||
mutable PluginDataMap _pluginData;
|
||||
};
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgDB/ReaderWriter>
|
||||
@ -72,7 +73,13 @@ ReaderWriterDAE::readNode(const std::string& fname,
|
||||
const osgDB::ReaderWriter::Options* options) const
|
||||
{
|
||||
SERIALIZER();
|
||||
|
||||
|
||||
DAE* daeptr = 0L;
|
||||
|
||||
if ( options ) {
|
||||
daeptr = (DAE*) options->getPluginData("DAE");
|
||||
}
|
||||
|
||||
std::string ext( osgDB::getLowerCaseFileExtension(fname) );
|
||||
if( ! acceptsExtension(ext) ) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
@ -81,10 +88,14 @@ ReaderWriterDAE::readNode(const std::string& fname,
|
||||
|
||||
osg::notify(osg::INFO) << "ReaderWriterDAE( \"" << fileName << "\" )" << std::endl;
|
||||
|
||||
if (_dae == NULL)
|
||||
_dae = new DAE();
|
||||
|
||||
if (daeptr == NULL) {
|
||||
if (_dae == NULL)
|
||||
_dae = new DAE();
|
||||
daeptr = _dae;
|
||||
}
|
||||
|
||||
osgdae::daeReader daeReader(_dae);
|
||||
osgdae::daeReader daeReader(daeptr) ;
|
||||
std::string fileURI( osgDB::convertFileNameToUnixStyle(fileName) );
|
||||
if ( ! daeReader.convert( fileURI ) )
|
||||
{
|
||||
@ -92,6 +103,17 @@ ReaderWriterDAE::readNode(const std::string& fname,
|
||||
return ReadResult::ERROR_IN_READING_FILE;
|
||||
}
|
||||
|
||||
if ( options ) {
|
||||
// return DAE* used
|
||||
options->setPluginData("DAE", daeptr);
|
||||
// and filename document was stored as in database, does not have to be
|
||||
// the same as fname
|
||||
options->setPluginData("DAE-DocumentFileName", ( fileURI[1] == ':' ?
|
||||
(void*) new std::auto_ptr<std::string>(new std::string('/'+fileURI)) :
|
||||
(void*) new std::auto_ptr<std::string>(new std::string(fileURI)) )
|
||||
);
|
||||
}
|
||||
|
||||
osg::Node* rootNode( daeReader.getRootNode() );
|
||||
return rootNode;
|
||||
}
|
||||
@ -104,9 +126,15 @@ ReaderWriterDAE::writeNode( const osg::Node& node,
|
||||
{
|
||||
SERIALIZER();
|
||||
|
||||
DAE* daeptr = 0L;
|
||||
|
||||
std::string ext( osgDB::getLowerCaseFileExtension(fname) );
|
||||
if( ! acceptsExtension(ext) ) return WriteResult::FILE_NOT_HANDLED;
|
||||
|
||||
if ( options ) {
|
||||
daeptr = (DAE*) options->getPluginData("DAE");
|
||||
}
|
||||
|
||||
// Process options
|
||||
bool usePolygon(false);
|
||||
if( options )
|
||||
@ -129,10 +157,13 @@ ReaderWriterDAE::writeNode( const osg::Node& node,
|
||||
}
|
||||
}
|
||||
|
||||
if (_dae == NULL)
|
||||
_dae = new DAE();
|
||||
if (daeptr == NULL) {
|
||||
if (_dae == NULL)
|
||||
_dae = new DAE();
|
||||
daeptr = _dae;
|
||||
}
|
||||
|
||||
osgdae::daeWriter daeWriter(_dae, fname, usePolygon );
|
||||
osgdae::daeWriter daeWriter(daeptr, fname, usePolygon );
|
||||
daeWriter.setRootNode( node );
|
||||
const_cast<osg::Node*>(&node)->accept( daeWriter );
|
||||
|
||||
@ -145,6 +176,17 @@ ReaderWriterDAE::writeNode( const osg::Node& node,
|
||||
}
|
||||
}
|
||||
|
||||
if ( options ) {
|
||||
// return DAE* used
|
||||
options->setPluginData("DAE", daeptr);
|
||||
|
||||
// saving filename so read and write work the same way,
|
||||
// this could be skipped since write does not currently modify the
|
||||
// filename which load might do (under windows for example)
|
||||
options->setPluginData("DAE-DocumentFileName", (void*) new
|
||||
std::auto_ptr<std::string>(new std::string(fname)));
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ protected:
|
||||
AuthoringTool m_AuthoringTool;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -242,7 +242,7 @@ private: //members
|
||||
std::string uniquify( const std::string &name );
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -251,6 +251,26 @@ BEGIN_OBJECT_REFLECTOR(osgDB::ReaderWriter::Options)
|
||||
__CacheHintOptions__getObjectCacheHint,
|
||||
"Get whether the Registry::ObjectCache should be used by default. ",
|
||||
"");
|
||||
I_Method2(void, setPluginData, IN, const std::string &, s, IN, void *, v,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void__setPluginData__C5_std_string_R1__void_P1,
|
||||
"Sets a plugindata value PluginData with a string. ",
|
||||
"");
|
||||
I_Method1(void *, getPluginData, IN, const std::string &, s,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void_P1__getPluginData__C5_std_string_R1,
|
||||
"Get a value from the PluginData. ",
|
||||
"");
|
||||
I_Method1(const void *, getPluginData, IN, const std::string &, s,
|
||||
Properties::NON_VIRTUAL,
|
||||
__C5_void_P1__getPluginData__C5_std_string_R1,
|
||||
"Get a value from the PluginData. ",
|
||||
"");
|
||||
I_Method1(void, removePluginData, IN, const std::string &, s,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void__removePluginData__C5_std_string_R1,
|
||||
"Remove a value from the PluginData. ",
|
||||
"");
|
||||
I_SimpleProperty(const std::string &, DatabasePath,
|
||||
0,
|
||||
__void__setDatabasePath__C5_std_string_R1);
|
||||
@ -263,6 +283,10 @@ BEGIN_OBJECT_REFLECTOR(osgDB::ReaderWriter::Options)
|
||||
I_SimpleProperty(const std::string &, OptionString,
|
||||
__C5_std_string_R1__getOptionString,
|
||||
__void__setOptionString__C5_std_string_R1);
|
||||
I_IndexedProperty(void *, PluginData,
|
||||
__void_P1__getPluginData__C5_std_string_R1,
|
||||
__void__setPluginData__C5_std_string_R1__void_P1,
|
||||
0);
|
||||
END_REFLECTOR
|
||||
|
||||
BEGIN_ENUM_REFLECTOR(osgDB::ReaderWriter::ReadResult::ReadStatus)
|
||||
|
Loading…
Reference in New Issue
Block a user