From bdeb391a006a9c2c8c282731647a8410808961d0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 7 May 2004 15:18:59 +0000 Subject: [PATCH] From Mike Weiblen, added new rot, scale and trans pseudo loaders. --- Make/makedirdefs | 4 + VisualStudio/VisualStudio.dsw | 54 +++++++++ VisualStudio/osgPlugins/rot/rot.dsp | 109 ++++++++++++++++++ VisualStudio/osgPlugins/scale/scale.dsp | 109 ++++++++++++++++++ include/osgDB/FileNameUtils | 1 + src/osgDB/FileNameUtils.cpp | 13 ++- src/osgGL2/ProgramObject.cpp | 11 +- src/osgPlugins/rot/GNUmakefile | 13 +++ src/osgPlugins/rot/ReaderWriterROT.cpp | 112 +++++++++++++++++++ src/osgPlugins/scale/GNUmakefile | 13 +++ src/osgPlugins/scale/ReaderWriterSCALE.cpp | 123 +++++++++++++++++++++ src/osgPlugins/trans/GNUmakefile | 13 +++ src/osgPlugins/trans/ReaderWriterTRANS.cpp | 109 ++++++++++++++++++ src/osgSim/MultiSwitch.cpp | 2 +- 14 files changed, 678 insertions(+), 8 deletions(-) create mode 100644 VisualStudio/osgPlugins/rot/rot.dsp create mode 100644 VisualStudio/osgPlugins/scale/scale.dsp create mode 100644 src/osgPlugins/rot/GNUmakefile create mode 100644 src/osgPlugins/rot/ReaderWriterROT.cpp create mode 100644 src/osgPlugins/scale/GNUmakefile create mode 100644 src/osgPlugins/scale/ReaderWriterSCALE.cpp create mode 100644 src/osgPlugins/trans/GNUmakefile create mode 100644 src/osgPlugins/trans/ReaderWriterTRANS.cpp diff --git a/Make/makedirdefs b/Make/makedirdefs index 0d8c6a089..3705b8bbb 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -57,6 +57,10 @@ PLUGIN_DIRS = \ zip\ 3dc\ ive\ + rot\ + scale\ + trans\ + ifeq ($(GDAL_INSTALLED),yes) PLUGIN_DIRS += gdal diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 505c724dd..9e1ee03f1 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -2424,6 +2424,60 @@ Package=<4> ############################################################################### +Project: "osgPlugin scale"=.\osgPlugins\scale\scale.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency +}}} + +############################################################################### + +Project: "osgPlugin trans"=.\osgPlugins\trans\trans.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency +}}} + +############################################################################### + +Project: "osgPlugin scale"=.\osgPlugins\scale\scale.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency +}}} + +############################################################################### + Project: "osgPlugin tga"=.\osgPlugins\tga\tga.dsp - Package Owner=<4> Package=<5> diff --git a/VisualStudio/osgPlugins/rot/rot.dsp b/VisualStudio/osgPlugins/rot/rot.dsp new file mode 100644 index 000000000..a25226d44 --- /dev/null +++ b/VisualStudio/osgPlugins/rot/rot.dsp @@ -0,0 +1,109 @@ +# Microsoft Developer Studio Project File - Name="osgPlugin rot" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=osgPlugin rot - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "rot.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "rot.mak" CFG="osgPlugin rot - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "osgPlugin rot - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "osgPlugin rot - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "osgPlugin rot - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "../../../lib" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_rot.dll" /libpath:"../../../lib" +# SUBTRACT LINK32 /nodefaultlib + +!ELSEIF "$(CFG)" == "osgPlugin rot - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "../../../lib" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /vmg /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIN32" /D "_DEBUG" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /dll /debug /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_rotd.dll" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "osgPlugin rot - Win32 Release" +# Name "osgPlugin rot - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\rot\ReaderWriterROT.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/VisualStudio/osgPlugins/scale/scale.dsp b/VisualStudio/osgPlugins/scale/scale.dsp new file mode 100644 index 000000000..6f4a15792 --- /dev/null +++ b/VisualStudio/osgPlugins/scale/scale.dsp @@ -0,0 +1,109 @@ +# Microsoft Developer Studio Project File - Name="osgPlugin scale" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=osgPlugin scale - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "scale.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "scale.mak" CFG="osgPlugin scale - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "osgPlugin scale - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "osgPlugin scale - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "osgPlugin scale - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "../../../lib" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_scale.dll" /libpath:"../../../lib" +# SUBTRACT LINK32 /nodefaultlib + +!ELSEIF "$(CFG)" == "osgPlugin scale - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "../../../lib" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /vmg /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIN32" /D "_DEBUG" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /dll /debug /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_scaled.dll" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "osgPlugin scale - Win32 Release" +# Name "osgPlugin scale - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\scale\ReaderWriterSCALE.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/include/osgDB/FileNameUtils b/include/osgDB/FileNameUtils index 489cb49fa..8d454b00e 100644 --- a/include/osgDB/FileNameUtils +++ b/include/osgDB/FileNameUtils @@ -24,6 +24,7 @@ extern OSGDB_EXPORT std::string getFilePath(const std::string& filename); extern OSGDB_EXPORT std::string getFileExtension(const std::string& filename); extern OSGDB_EXPORT std::string getLowerCaseFileExtension(const std::string& filename); extern OSGDB_EXPORT std::string getSimpleFileName(const std::string& fileName); +extern OSGDB_EXPORT std::string getNameLessExtension(const std::string& fileName); extern OSGDB_EXPORT std::string getStrippedName(const std::string& fileName); extern OSGDB_EXPORT bool equalCaseInsensitive(const std::string& lhs,const std::string& rhs); diff --git a/src/osgDB/FileNameUtils.cpp b/src/osgDB/FileNameUtils.cpp index b9019ea32..96edb728b 100644 --- a/src/osgDB/FileNameUtils.cpp +++ b/src/osgDB/FileNameUtils.cpp @@ -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 ); } diff --git a/src/osgGL2/ProgramObject.cpp b/src/osgGL2/ProgramObject.cpp index 9910952d9..b7b8f2dab 100644 --- a/src/osgGL2/ProgramObject.cpp +++ b/src/osgGL2/ProgramObject.cpp @@ -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; } } diff --git a/src/osgPlugins/rot/GNUmakefile b/src/osgPlugins/rot/GNUmakefile new file mode 100644 index 000000000..947308572 --- /dev/null +++ b/src/osgPlugins/rot/GNUmakefile @@ -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 diff --git a/src/osgPlugins/rot/ReaderWriterROT.cpp b/src/osgPlugins/rot/ReaderWriterROT.cpp new file mode 100644 index 000000000..78f65b8b1 --- /dev/null +++ b/src/osgPlugins/rot/ReaderWriterROT.cpp @@ -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 +#include +#include + +#include +#include +#include +#include + +#include + +#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(r) ), osg::Vec3( 0, 1, 0 ), + osg::DegreesToRadians( static_cast(p) ), osg::Vec3( 1, 0, 0 ), + osg::DegreesToRadians( static_cast(h) ), osg::Vec3( 0, 0, 1 ) )); + xform->addChild( node ); + return xform; + } +}; + + +// Add ourself to the Registry to instantiate the reader/writer. +osgDB::RegisterReaderWriterProxy g_readerWriter_ROT_Proxy; + +/*EOF*/ + diff --git a/src/osgPlugins/scale/GNUmakefile b/src/osgPlugins/scale/GNUmakefile new file mode 100644 index 000000000..65ddce93a --- /dev/null +++ b/src/osgPlugins/scale/GNUmakefile @@ -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 diff --git a/src/osgPlugins/scale/ReaderWriterSCALE.cpp b/src/osgPlugins/scale/ReaderWriterSCALE.cpp new file mode 100644 index 000000000..be0a4b3aa --- /dev/null +++ b/src/osgPlugins/scale/ReaderWriterSCALE.cpp @@ -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 +#include +#include + +#include +#include +#include +#include + +#include + +#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 g_readerWriter_SCALE_Proxy; + +/*EOF*/ + diff --git a/src/osgPlugins/trans/GNUmakefile b/src/osgPlugins/trans/GNUmakefile new file mode 100644 index 000000000..56f6a8a17 --- /dev/null +++ b/src/osgPlugins/trans/GNUmakefile @@ -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 diff --git a/src/osgPlugins/trans/ReaderWriterTRANS.cpp b/src/osgPlugins/trans/ReaderWriterTRANS.cpp new file mode 100644 index 000000000..719f78118 --- /dev/null +++ b/src/osgPlugins/trans/ReaderWriterTRANS.cpp @@ -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 +#include +#include + +#include +#include +#include +#include + +#include + +#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 g_readerWriter_TRANS_Proxy; + +/*EOF*/ + diff --git a/src/osgSim/MultiSwitch.cpp b/src/osgSim/MultiSwitch.cpp index 0c3f160a0..05ffc6c0e 100644 --- a/src/osgSim/MultiSwitch.cpp +++ b/src/osgSim/MultiSwitch.cpp @@ -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); } }