diff --git a/VisualStudio/osgGA/osgGA.dsp b/VisualStudio/osgGA/osgGA.dsp index 43af1b0bf..30ae21c4b 100755 --- a/VisualStudio/osgGA/osgGA.dsp +++ b/VisualStudio/osgGA/osgGA.dsp @@ -1,392 +1,204 @@ # Microsoft Developer Studio Project File - Name="Core osgGA" - Package Owner=<4> - # Microsoft Developer Studio Generated Build File, Format Version 6.00 - # ** DO NOT EDIT ** - - # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - - CFG=Core osgGA - 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 "osgGA.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 "osgGA.mak" CFG="Core osgGA - Win32 Release" - !MESSAGE - !MESSAGE Possible choices for configuration are: - !MESSAGE - !MESSAGE "Core osgGA - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") - !MESSAGE "Core osgGA - 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)" == "Core osgGA - Win32 Release" - - # PROP BASE Use_MFC 0 - # PROP BASE Use_Debug_Libraries 0 - # PROP BASE Output_Dir "../../lib" - # 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 "NDEBUG" /D "_MBCS" /D "_USRDLL" /D "OSGGA_LIBRARY" /D "WIN32" /D "_WINDOWS" /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 glu32.lib opengl32.lib /nologo /dll /pdb:none /machine:I386 /out:"../../bin/osgGA.dll" /libpath:"../../lib" - - !ELSEIF "$(CFG)" == "Core osgGA - 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 "OSGGA_LIBRARY" /D "_WINDOWS" /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 glu32.lib opengl32.lib /nologo /dll /debug /machine:I386 /out:"../../bin/osgGAd.dll" /pdbtype:sept /libpath:"../../lib" - # SUBTRACT LINK32 /pdb:none - - !ENDIF - - # Begin Target - - # Name "Core osgGA - Win32 Release" - # Name "Core osgGA - Win32 Debug" - # Begin Group "Source Files" - - # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" - # Begin Source File - +SOURCE=..\..\src\osgGA\AnimationPathManipulator.cpp +# End Source File +# Begin Source File SOURCE=..\..\src\osgGA\CameraManipulator.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\DriveManipulator.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\FlightManipulator.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\GUIEventHandler.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\GUIEventHandlerVisitor.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\KeySwitchCameraManipulator.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\SetSceneViewVisitor.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\StateSetManipulator.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\TrackballManipulator.cpp - # End Source File - # Begin Source File - - SOURCE=..\..\src\osgGA\Version.cpp - # End Source File - # End Group - # Begin Group "Header Files" - - # PROP Default_Filter ";h;hpp;hxx;hm;inl" - # Begin Source File - +SOURCE=..\..\Include\osgGA\AnimationPathManipulator +# End Source File +# Begin Source File SOURCE=..\..\Include\osgGA\CameraManipulator - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\DriveManipulator - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\Export - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\FlightManipulator - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\GUIActionAdapter - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\GUIEventAdapter - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\GUIEventHandler - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\GUIEventHandlerVisitor - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\KeySwitchCameraManipulator - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\SetSceneViewVisitor - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\StateSetManipulator - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\TrackballManipulator - # End Source File - # Begin Source File - - SOURCE=..\..\Include\osgGA\Version - # End Source File - # 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/osgGA/AnimationPathManipulator b/include/osgGA/AnimationPathManipulator index e8eac3112..0ffa48ffb 100644 --- a/include/osgGA/AnimationPathManipulator +++ b/include/osgGA/AnimationPathManipulator @@ -22,85 +22,32 @@ namespace osgGA{ // px py pz = World position in catesian coordinates // ax ay az aw = Orientation (attitude) defined as a quaternion -class AnimationPathManipulator : public osgGA::CameraManipulator +class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator { public: - AnimationPathManipulator( std::string filename ) - { - _animationPath = new osg::AnimationPath; - _animationPath->setLoopMode(osg::AnimationPath::LOOP); + + AnimationPathManipulator( osg::AnimationPath* animationPath=0 ); - FILE *fp = fopen( filename.c_str(), "r" ); - if( fp == NULL ) - { - osg::notify(osg::WARN) << "AnimationPathManipulator: Cannot open animation path file \"" << filename << "\".\n"; - _valid = false; - return; - } - while( !feof( fp )) - { - double time; - osg::Vec3 position; - osg::Quat rotation; - fscanf( fp, "%lf %f %f %f %f %f %f %f\n", - &time, &position[0], &position[1], &position[2], - &rotation[0], &rotation[1], &rotation[2], &rotation[3] ); + AnimationPathManipulator( const std::string& filename ); + + + void setAnimationPath( osg::AnimationPath* animationPath ) { _animationPath=animationPath; } + + osg::AnimationPath* getAnimationPath() { return _animationPath.get(); } + + const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); } - if( !feof(fp)) - _animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation)); - } - fclose(fp); - _valid = true; - } + bool valid() const { return _animationPath.valid(); } - bool valid() { return _valid; } - - virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us) - { - if( !_valid ) return false; - - us = us; - - bool retval = false; - switch( ea.getEventType() ) - { - case GUIEventAdapter::FRAME: - handleFrame( ea.time() ); - - break; - case GUIEventAdapter::KEYBOARD: - switch( ea.getKey()) - { - default: - retval = false; - } - break; - } - return retval; - } + virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); + private: bool _valid; - void handleFrame( double time ) - { - osg::AnimationPath::ControlPoint cp; - _animationPath->getInterpolatedControlPoint( time, cp ); + void handleFrame( double time ); - osg::Matrix mat; - cp.getMatrix( mat ); - - osg::Vec3 eye(mat(3,0), mat(3,1), mat(3,2)); - mat(3,0) = 0.0; - mat(3,1) = 0.0; - mat(3,2) = 0.0; - osg::Vec3 look = eye + (osg::Vec3(0,1,0) * mat); - osg::Vec3 up = osg::Vec3(0,0,1) * mat; - if( _camera.valid() ) - _camera->setView( eye, look, up ); - } - - osg::AnimationPath *_animationPath; + osg::ref_ptr _animationPath; }; diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 499dc8aef..b304083c8 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -857,15 +857,123 @@ void Geometry::accept(PrimitiveFunctor& functor) { if (!_vertexArray.valid() || _vertexArray->empty()) return; - functor.setVertexArray(_vertexArray->size(),&(_vertexArray->front())); - for(PrimitiveSetList::iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) + if (!_vertexIndices.valid()) { - (*itr)->accept(functor); + functor.setVertexArray(_vertexArray->size(),&(_vertexArray->front())); + + for(PrimitiveSetList::iterator itr=_primitives.begin(); + itr!=_primitives.end(); + ++itr) + { + (*itr)->accept(functor); + } } - + else + { + for(PrimitiveSetList::iterator itr=_primitives.begin(); + itr!=_primitives.end(); + ++itr) + { + PrimitiveSet* primitiveset = itr->get(); + GLenum mode=primitiveset->getMode(); + switch(primitiveset->getType()) + { + case(PrimitiveSet::DrawArraysPrimitiveType): + { + const DrawArrays* drawArray = static_cast(primitiveset); + functor.begin(mode); + + unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst(); + vindexindex(vindex)]); + } + + functor.end(); + break; + } + case(PrimitiveSet::DrawArrayLengthsPrimitiveType): + { + + const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); + unsigned int vindex=drawArrayLengths->getFirst(); + for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); + primItr!=drawArrayLengths->end(); + ++primItr) + { + + functor.begin(mode); + + for(GLsizei primCount=0;primCount<*primItr;++primCount) + { + functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]); + ++vindex; + } + + functor.end(); + + } + break; + } + case(PrimitiveSet::DrawElementsUBytePrimitiveType): + { + const DrawElementsUByte* drawElements = static_cast(primitiveset); + functor.begin(mode); + + unsigned int primCount=0; + for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primCount,++primItr) + { + unsigned int vindex=*primItr; + functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]); + } + + functor.end(); + break; + } + case(PrimitiveSet::DrawElementsUShortPrimitiveType): + { + const DrawElementsUShort* drawElements = static_cast(primitiveset); + functor.begin(mode); + + for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primItr) + { + unsigned int vindex=*primItr; + functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]); + } + + functor.end(); + break; + } + case(PrimitiveSet::DrawElementsUIntPrimitiveType): + { + const DrawElementsUInt* drawElements = static_cast(primitiveset); + functor.begin(mode); + + for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primItr) + { + unsigned int vindex=*primItr; + functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]); + } + + functor.end(); + break; + } + default: + { + break; + } + } + } + } } bool Geometry::verifyBindings() const diff --git a/src/osgGA/AnimationPathManipulator.cpp b/src/osgGA/AnimationPathManipulator.cpp new file mode 100644 index 000000000..abb929e94 --- /dev/null +++ b/src/osgGA/AnimationPathManipulator.cpp @@ -0,0 +1,80 @@ +#include +#include + +using namespace osgGA; + +AnimationPathManipulator::AnimationPathManipulator(osg::AnimationPath* animationPath) +{ + _animationPath = animationPath; +} + +AnimationPathManipulator::AnimationPathManipulator( const std::string& filename ) +{ + _animationPath = osgNew osg::AnimationPath; + _animationPath->setLoopMode(osg::AnimationPath::LOOP); + + FILE *fp = fopen( filename.c_str(), "r" ); + if( fp == NULL ) + { + osg::notify(osg::WARN) << "AnimationPathManipulator: Cannot open animation path file \"" << filename << "\".\n"; + _valid = false; + return; + } + while( !feof( fp )) + { + double time; + osg::Vec3 position; + osg::Quat rotation; + fscanf( fp, "%lf %f %f %f %f %f %f %f\n", + &time, &position[0], &position[1], &position[2], + &rotation[0], &rotation[1], &rotation[2], &rotation[3] ); + + if( !feof(fp)) + _animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation)); + } + fclose(fp); +} + +bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us) +{ + if( !valid() ) return false; + + us = us; + + bool retval = false; + switch( ea.getEventType() ) + { + case GUIEventAdapter::FRAME: + handleFrame( ea.time() ); + + break; + case GUIEventAdapter::KEYBOARD: + switch( ea.getKey()) + { + default: + retval = false; + } + break; + default: + break; + } + return retval; +} + +void AnimationPathManipulator::handleFrame( double time ) +{ + osg::AnimationPath::ControlPoint cp; + _animationPath->getInterpolatedControlPoint( time, cp ); + + osg::Matrix mat; + cp.getMatrix( mat ); + + osg::Vec3 eye(mat(3,0), mat(3,1), mat(3,2)); + mat(3,0) = 0.0; + mat(3,1) = 0.0; + mat(3,2) = 0.0; + osg::Vec3 look = eye + (osg::Vec3(0,1,0) * mat); + osg::Vec3 up = osg::Vec3(0,0,1) * mat; + if( _camera.valid() ) + _camera->setView( eye, look, up ); +} diff --git a/src/osgGA/Makefile b/src/osgGA/Makefile index 18a201492..04e0ae927 100644 --- a/src/osgGA/Makefile +++ b/src/osgGA/Makefile @@ -3,6 +3,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES = \ + AnimationPathManipulator.cpp\ CameraManipulator.cpp\ DriveManipulator.cpp\ FlightManipulator.cpp\ diff --git a/src/osgPlugins/osg/Geometry.cpp b/src/osgPlugins/osg/Geometry.cpp index e9936716a..c5d97e14c 100644 --- a/src/osgPlugins/osg/Geometry.cpp +++ b/src/osgPlugins/osg/Geometry.cpp @@ -99,6 +99,18 @@ bool Geometry_readLocalData(Object& obj, Input& fr) } + if (fr.matchSequence("VertexIndices %w %i {")) + { + ++fr; + IndexArray* indices = dynamic_cast(Array_readLocalData(fr)); + if (indices) + { + geom.setVertexIndices(indices); + iteratorAdvanced = true; + } + } + + Geometry::AttributeBinding normalBinding=Geometry::BIND_OFF; if (fr[0].matchWord("NormalBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),normalBinding)) { @@ -138,6 +150,16 @@ bool Geometry_readLocalData(Object& obj, Input& fr) iteratorAdvanced = true; ++fr; } + if (fr.matchSequence("NormalIndices %w %i {")) + { + ++fr; + IndexArray* indices = dynamic_cast(Array_readLocalData(fr)); + if (indices) + { + geom.setNormalIndices(indices); + iteratorAdvanced = true; + } + } Geometry::AttributeBinding colorBinding=Geometry::BIND_OFF; if (fr[0].matchWord("ColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),colorBinding)) @@ -158,6 +180,18 @@ bool Geometry_readLocalData(Object& obj, Input& fr) } } + if (fr.matchSequence("ColorIndices %w %i {")) + { + ++fr; + IndexArray* indices = dynamic_cast(Array_readLocalData(fr)); + if (indices) + { + geom.setColorIndices(indices); + iteratorAdvanced = true; + } + } + + Geometry::AttributeBinding secondaryColorBinding=Geometry::BIND_OFF; if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding)) { @@ -177,6 +211,16 @@ bool Geometry_readLocalData(Object& obj, Input& fr) } } + if (fr.matchSequence("SecondaryColorIndices %w %i {")) + { + ++fr; + IndexArray* indices = dynamic_cast(Array_readLocalData(fr)); + if (indices) + { + geom.setSecondaryColorIndices(indices); + iteratorAdvanced = true; + } + } Geometry::AttributeBinding fogCoordBinding=Geometry::BIND_OFF; @@ -219,6 +263,18 @@ bool Geometry_readLocalData(Object& obj, Input& fr) ++fr; } + if (fr.matchSequence("FogCoordIndices %w %i {")) + { + ++fr; + IndexArray* indices = dynamic_cast(Array_readLocalData(fr)); + if (indices) + { + geom.setFogCoordIndices(indices); + iteratorAdvanced = true; + } + } + + if (fr.matchSequence("TexCoordArray %i %w %i {")) { int unit=0; @@ -234,6 +290,20 @@ bool Geometry_readLocalData(Object& obj, Input& fr) } + if (fr.matchSequence("TexCoordIndices %i %w %i {")) + { + int unit=0; + fr[1].getInt(unit); + + fr+=2; + IndexArray* indices = dynamic_cast(Array_readLocalData(fr)); + if (indices) + { + geom.setTexCoordIndices(unit,indices); + iteratorAdvanced = true; + } + } + return iteratorAdvanced; } @@ -479,6 +549,40 @@ void Array_writeLocalData(Output& fw, Iterator first, Iterator last,int noItemsP } +template +void Array_writeLocalDataAsInts(Output& fw, Iterator first, Iterator last,int noItemsPerLine=8) +{ + fw.indent() << "{"<(array); fw<(array); fw<getStateSet()getStateSet()) return true; if (rhs->getStateSet()getStateSet()) return false; + if (lhs->getNormalBinding()getNormalBinding()) return true; + if (rhs->getNormalBinding()getNormalBinding()) return false; + if (lhs->getColorBinding()getColorBinding()) return true; if (rhs->getColorBinding()getColorBinding()) return false; - if (lhs->getNormalBinding()getNormalBinding()) return true; - if (rhs->getNormalBinding()getNormalBinding()) return false; - + if (lhs->getSecondaryColorBinding()getSecondaryColorBinding()) return true; + if (rhs->getSecondaryColorBinding()getSecondaryColorBinding()) return false; + + if (lhs->getFogCoordBinding()getFogCoordBinding()) return true; + if (rhs->getFogCoordBinding()getFogCoordBinding()) return false; + if (lhs->getNumTexCoordArrays()getNumTexCoordArrays()) return true; if (rhs->getNumTexCoordArrays()getNumTexCoordArrays()) return false; @@ -1205,7 +1211,11 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); if (geom) { - if (geom->getNumPrimitiveSets()>0) + if (geom->getNumPrimitiveSets()>0 && + geom->getNormalBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET && + geom->getColorBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET && + geom->getSecondaryColorBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET && + geom->getFogCoordBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET) { osg::Geometry::PrimitiveSetList& primitives = geom->getPrimitiveSetList(); unsigned int primNo=0; @@ -1312,6 +1322,10 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom lhs.setColorArray(rhs.getColorArray()); } + // need to implement handle secondary color array. + + // need to implement handle fog coord array. + for(unsigned int unit=0;unit