From Mike Weiblen, added new rot, scale and trans pseudo loaders.
This commit is contained in:
@@ -71,12 +71,19 @@ std::string osgDB::getLowerCaseFileExtension(const std::string& filename)
|
||||
}
|
||||
|
||||
|
||||
// strip one level of extension from the filename.
|
||||
std::string osgDB::getNameLessExtension(const std::string& fileName)
|
||||
{
|
||||
std::string::size_type dot = fileName.find_last_of('.');
|
||||
if (dot==std::string::npos) return fileName;
|
||||
return std::string(fileName.begin(),fileName.begin()+dot);
|
||||
}
|
||||
|
||||
|
||||
std::string osgDB::getStrippedName(const std::string& fileName)
|
||||
{
|
||||
std::string simpleName = getSimpleFileName(fileName);
|
||||
std::string::size_type dot = simpleName.find_last_of('.');
|
||||
if (dot==std::string::npos) return simpleName;
|
||||
return std::string(simpleName.begin(),simpleName.begin()+dot);
|
||||
return getNameLessExtension( simpleName );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
/* file: src/osgGL2/ProgramObject.cpp
|
||||
* author: Mike Weiblen 2003-12-27
|
||||
* author: Mike Weiblen 2004-02-04
|
||||
*
|
||||
* See http://www.3dlabs.com/opengl2/ for more information regarding
|
||||
* the OpenGL Shading Language.
|
||||
@@ -56,7 +56,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& operator()() { return _text; }
|
||||
friend std::ostream& operator<< ( std::ostream& o, const InfoLog& log )
|
||||
{
|
||||
return o << log._text;
|
||||
}
|
||||
|
||||
private:
|
||||
InfoLog();
|
||||
@@ -338,7 +341,7 @@ void ProgramObject::PerContextProgObj::build()
|
||||
if( _dirty )
|
||||
{
|
||||
InfoLog log( _extensions.get(), _glProgObjHandle );
|
||||
osg::notify(osg::WARN) << "glLinkProgram FAILED:\n" << log() << std::endl;
|
||||
osg::notify(osg::WARN) << "glLinkProgram FAILED:\n" << log << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,7 +536,7 @@ void ShaderObject::PerContextShaderObj::build()
|
||||
{
|
||||
InfoLog log( _extensions.get(), _glShaderObjHandle );
|
||||
osg::notify(osg::WARN) << _shadObj->getTypename() <<
|
||||
" glCompileShader FAILED:\n" << log() << std::endl;
|
||||
" glCompileShader FAILED:\n" << log << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
src/osgPlugins/rot/GNUmakefile
Normal file
13
src/osgPlugins/rot/GNUmakefile
Normal file
@@ -0,0 +1,13 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ReaderWriterROT.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(OTHER_LIBS)
|
||||
|
||||
TARGET_BASENAME = rot
|
||||
include $(TOPDIR)/Make/cygwin_plugin_def
|
||||
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
112
src/osgPlugins/rot/ReaderWriterROT.cpp
Normal file
112
src/osgPlugins/rot/ReaderWriterROT.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial
|
||||
* applications, as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*/
|
||||
|
||||
/* file: src/osgPlugins/rot/ReaderWriterROT.cpp
|
||||
* author: Mike Weiblen http://mew.cx/ 2004-04-25
|
||||
* copyright: (C) 2004 Michael Weiblen
|
||||
* license: OpenSceneGraph Public License (OSGPL)
|
||||
*/
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define EXTENSION_NAME "rot"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* An OSG reader plugin for the rotation pseudo-loader.
|
||||
*/
|
||||
class ReaderWriterROT : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
ReaderWriterROT() { }
|
||||
|
||||
virtual const char* className() { return "rotation pseudo-loader"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension)
|
||||
{
|
||||
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
|
||||
}
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName,
|
||||
const osgDB::ReaderWriter::Options* /*options*/)
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if( !acceptsExtension(ext) )
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO) << "ReaderWriterROT( \"" << fileName << "\" )" << std::endl;
|
||||
|
||||
// strip the pseudo-loader extension
|
||||
std::string tmpName = osgDB::getNameLessExtension( fileName );
|
||||
|
||||
// get the next "extension", which actually contains the pseudo-loader parameters
|
||||
std::string params = osgDB::getFileExtension( tmpName );
|
||||
if( params.empty() )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
// strip the "params extension", which must leave a sub-filename.
|
||||
std::string subFileName = osgDB::getNameLessExtension( tmpName );
|
||||
if( subFileName == tmpName )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
osg::notify(osg::INFO) << EXTENSION_NAME " params = \"" << params << "\"" << std::endl;
|
||||
|
||||
int h, p, r;
|
||||
int count = sscanf( params.c_str(), "%d,%d,%d", &h, &p, &r );
|
||||
if( count != 3 )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
// recursively load the subfile.
|
||||
osg::Node *node = osgDB::readNodeFile( subFileName );
|
||||
if( !node )
|
||||
{
|
||||
// propagate the read failure upwards
|
||||
osg::notify(osg::WARN) << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
osg::MatrixTransform *xform = new osg::MatrixTransform;
|
||||
xform->setDataVariance( osg::Object::STATIC );
|
||||
xform->setMatrix( osg::Matrix::rotate(
|
||||
osg::DegreesToRadians( static_cast<float>(r) ), osg::Vec3( 0, 1, 0 ),
|
||||
osg::DegreesToRadians( static_cast<float>(p) ), osg::Vec3( 1, 0, 0 ),
|
||||
osg::DegreesToRadians( static_cast<float>(h) ), osg::Vec3( 0, 0, 1 ) ));
|
||||
xform->addChild( node );
|
||||
return xform;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Add ourself to the Registry to instantiate the reader/writer.
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterROT> g_readerWriter_ROT_Proxy;
|
||||
|
||||
/*EOF*/
|
||||
|
||||
13
src/osgPlugins/scale/GNUmakefile
Normal file
13
src/osgPlugins/scale/GNUmakefile
Normal file
@@ -0,0 +1,13 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ReaderWriterSCALE.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(OTHER_LIBS)
|
||||
|
||||
TARGET_BASENAME = scale
|
||||
include $(TOPDIR)/Make/cygwin_plugin_def
|
||||
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
123
src/osgPlugins/scale/ReaderWriterSCALE.cpp
Normal file
123
src/osgPlugins/scale/ReaderWriterSCALE.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial
|
||||
* applications, as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*/
|
||||
|
||||
/* file: src/osgPlugins/scale/ReaderWriterSCALE.cpp
|
||||
* author: Mike Weiblen http://mew.cx/ 2004-04-25
|
||||
* copyright: (C) 2004 Michael Weiblen
|
||||
* license: OpenSceneGraph Public License (OSGPL)
|
||||
*/
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define EXTENSION_NAME "scale"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* An OSG reader plugin for the scaling pseudo-loader.
|
||||
*/
|
||||
class ReaderWriterSCALE : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
ReaderWriterSCALE() { }
|
||||
|
||||
virtual const char* className() { return "scaling pseudo-loader"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension)
|
||||
{
|
||||
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
|
||||
}
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName,
|
||||
const osgDB::ReaderWriter::Options* /*options*/)
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if( !acceptsExtension(ext) )
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO) << "ReaderWriterSCALE( \"" << fileName << "\" )" << std::endl;
|
||||
|
||||
// strip the pseudo-loader extension
|
||||
std::string tmpName = osgDB::getNameLessExtension( fileName );
|
||||
|
||||
// get the next "extension", which actually contains the pseudo-loader parameters
|
||||
std::string params = osgDB::getFileExtension( tmpName );
|
||||
if( params.empty() )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
// strip the "params extension", which must leave a sub-filename.
|
||||
std::string subFileName = osgDB::getNameLessExtension( tmpName );
|
||||
if( subFileName == tmpName )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
osg::notify(osg::INFO) << EXTENSION_NAME " params = \"" << params << "\"" << std::endl;
|
||||
|
||||
int sx, sy, sz;
|
||||
int count = sscanf( params.c_str(), "%d,%d,%d", &sx, &sy, &sz );
|
||||
if( count == 1 )
|
||||
{
|
||||
// if only one value supplied, apply uniform scaling
|
||||
sy = sx;
|
||||
sz = sx;
|
||||
}
|
||||
else if( count != 3 )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
// recursively load the subfile.
|
||||
osg::Node *node = osgDB::readNodeFile( subFileName );
|
||||
if( !node )
|
||||
{
|
||||
// propagate the read failure upwards
|
||||
osg::notify(osg::WARN) << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
osg::MatrixTransform *xform = new osg::MatrixTransform;
|
||||
xform->setDataVariance( osg::Object::STATIC );
|
||||
xform->setMatrix( osg::Matrix::scale( sx, sy, sz ) );
|
||||
xform->addChild( node );
|
||||
|
||||
// TODO: should we force GL_NORMALIZE on?
|
||||
// osg::StateSet* ss = xform->getOrCreateStateSet();
|
||||
// ss->setMode( GL_NORMALIZE, osg::StateAttribute::ON );
|
||||
// Or since the scale is static, perhaps renormalization
|
||||
// would be better performed once at loadtime with a
|
||||
// .normalize pseudo-loader?
|
||||
|
||||
return xform;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Add ourself to the Registry to instantiate the reader/writer.
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterSCALE> g_readerWriter_SCALE_Proxy;
|
||||
|
||||
/*EOF*/
|
||||
|
||||
13
src/osgPlugins/trans/GNUmakefile
Normal file
13
src/osgPlugins/trans/GNUmakefile
Normal file
@@ -0,0 +1,13 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ReaderWriterTRANS.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(OTHER_LIBS)
|
||||
|
||||
TARGET_BASENAME = trans
|
||||
include $(TOPDIR)/Make/cygwin_plugin_def
|
||||
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
109
src/osgPlugins/trans/ReaderWriterTRANS.cpp
Normal file
109
src/osgPlugins/trans/ReaderWriterTRANS.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial
|
||||
* applications, as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*/
|
||||
|
||||
/* file: src/osgPlugins/trans/ReaderWriterTRANS.cpp
|
||||
* author: Mike Weiblen http://mew.cx/ 2004-04-25
|
||||
* copyright: (C) 2004 Michael Weiblen
|
||||
* license: OpenSceneGraph Public License (OSGPL)
|
||||
*/
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define EXTENSION_NAME "trans"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* An OSG reader plugin for the translation pseudo-loader.
|
||||
*/
|
||||
class ReaderWriterTRANS : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
ReaderWriterTRANS() { }
|
||||
|
||||
virtual const char* className() { return "translation pseudo-loader"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension)
|
||||
{
|
||||
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
|
||||
}
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName,
|
||||
const osgDB::ReaderWriter::Options* /*options*/)
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if( !acceptsExtension(ext) )
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO) << "ReaderWriterTRANS( \"" << fileName << "\" )" << std::endl;
|
||||
|
||||
// strip the pseudo-loader extension
|
||||
std::string tmpName = osgDB::getNameLessExtension( fileName );
|
||||
|
||||
// get the next "extension", which actually contains the pseudo-loader parameters
|
||||
std::string params = osgDB::getFileExtension( tmpName );
|
||||
if( params.empty() )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
// strip the "params extension", which must leave a sub-filename.
|
||||
std::string subFileName = osgDB::getNameLessExtension( tmpName );
|
||||
if( subFileName == tmpName )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
osg::notify(osg::INFO) << EXTENSION_NAME " params = \"" << params << "\"" << std::endl;
|
||||
|
||||
int tx, ty, tz;
|
||||
int count = sscanf( params.c_str(), "%d,%d,%d", &tx, &ty, &tz );
|
||||
if( count != 3 )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
// recursively load the subfile.
|
||||
osg::Node *node = osgDB::readNodeFile( subFileName );
|
||||
if( !node )
|
||||
{
|
||||
// propagate the read failure upwards
|
||||
osg::notify(osg::WARN) << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
osg::MatrixTransform *xform = new osg::MatrixTransform;
|
||||
xform->setDataVariance( osg::Object::STATIC );
|
||||
xform->setMatrix( osg::Matrix::translate( tx, ty, tz ) );
|
||||
xform->addChild( node );
|
||||
return xform;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Add ourself to the Registry to instantiate the reader/writer.
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterTRANS> g_readerWriter_TRANS_Proxy;
|
||||
|
||||
/*EOF*/
|
||||
|
||||
@@ -165,7 +165,7 @@ void MultiSwitch::expandToEncompassSwitchSet(unsigned int switchSet)
|
||||
_values.resize(switchSet+1);
|
||||
for(unsigned int i=originalSize;i<=switchSet;++i)
|
||||
{
|
||||
ValueList& values = _values[switchSet];
|
||||
ValueList& values = _values[i];
|
||||
values.resize(_children.size(),_newChildDefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user