diff --git a/VisualStudio/osgPlugins/flt/flt.dsp b/VisualStudio/osgPlugins/flt/flt.dsp index b8816c2ae..f690726ff 100644 --- a/VisualStudio/osgPlugins/flt/flt.dsp +++ b/VisualStudio/osgPlugins/flt/flt.dsp @@ -165,6 +165,10 @@ SOURCE=..\..\..\src\osgPlugins\flt\LightPointRecord.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\flt\LightPointSystemRecord.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\flt\LightPointPaletteRecords.cpp # End Source File # Begin Source File @@ -357,6 +361,10 @@ SOURCE=..\..\..\src\osgPlugins\flt\LightPointRecord.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\flt\LightPointSystemRecord.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\flt\LightPointPaletteRecords.h # End Source File # Begin Source File diff --git a/VisualStudio/osgSim/osgSim.dsp b/VisualStudio/osgSim/osgSim.dsp index c6b5c419a..88e8ff9d4 100644 --- a/VisualStudio/osgSim/osgSim.dsp +++ b/VisualStudio/osgSim/osgSim.dsp @@ -171,6 +171,10 @@ SOURCE=..\..\include\osgSim\LightPoint # End Source File # Begin Source File +SOURCE=..\..\include\osgSim\LightSystem +# End Source File +# Begin Source File + SOURCE=..\..\src\osgSim\LightPointDrawable.h # End Source File # Begin Source File diff --git a/include/osgSim/LightPointNode b/include/osgSim/LightPointNode index 5d4ed78ca..c1f1d711d 100644 --- a/include/osgSim/LightPointNode +++ b/include/osgSim/LightPointNode @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -76,9 +77,13 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node void setMaxVisibleDistance2(float maxVisibleDistance2) { _maxVisibleDistance2 = maxVisibleDistance2; } float getMaxVisibleDistance2() const { return _maxVisibleDistance2; } + + void setLightPointSystem( osgSim::LightPointSystem* lps) { _lightSystem = lps; } + + osgSim::LightPointSystem* getLightPointSystem() { return _lightSystem.get(); } protected: - + ~LightPointNode() {} // used to cache the bouding box of the lightpoints as a tighter @@ -92,8 +97,9 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node float _minPixelSize; float _maxPixelSize; float _maxVisibleDistance2; - - + + osg::ref_ptr _lightSystem; + }; } diff --git a/include/osgSim/LightPointSystem b/include/osgSim/LightPointSystem new file mode 100644 index 000000000..ac680c548 --- /dev/null +++ b/include/osgSim/LightPointSystem @@ -0,0 +1,63 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGSIM_LIGHTPOINTSYSTEM +#define OSGSIM_LIGHTPOINTSYSTEM 1 + +#include + + +namespace osgSim { + + +/* + * LightPointSYSTEM encapsulates animation and intensity state in a single object + * that can be shared by several osgSim::LightPointNodes, thereby allowing an + * application to efficiently control the animation/intensity state of + * several LightPointNodes. + */ +class LightPointSystem : public osg::Object +{ + public : + LightPointSystem() : _intensity( 1.f ), _animationState( ANIMATION_ON ) + { } + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + LightPointSystem( const LightPointSystem& lps, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ) : + osg::Object( lps, copyop ), _intensity( lps._intensity ), _animationState( lps._animationState ) + { } + + META_Object( osgSim, LightPointSystem ) + + typedef enum { + ANIMATION_ON, + ANIMATION_OFF, + ANIMATION_RANDOM + } AnimationState; + + void setIntensity( float intensity ) { _intensity = intensity; } + float getIntensity() const { return _intensity; } + + void setAnimationState( LightPointSystem::AnimationState state ) { _animationState = state; } + LightPointSystem::AnimationState getAnimationState() const { return _animationState; } + + protected: + ~LightPointSystem() {} + + float _intensity; + AnimationState _animationState; +}; + +} + +#endif diff --git a/src/osgPlugins/flt/GNUmakefile b/src/osgPlugins/flt/GNUmakefile index 160dd3f4f..3a9424cd5 100644 --- a/src/osgPlugins/flt/GNUmakefile +++ b/src/osgPlugins/flt/GNUmakefile @@ -35,6 +35,7 @@ CXXFILES =\ LightPointRecord.cpp\ VertexPoolRecords.cpp\ LightPointPaletteRecords.cpp\ + LightPointSystemRecord.cpp\ LightSourcePaletteRecord.cpp\ flt.cpp\ LightSourceRecord.cpp\ diff --git a/src/osgPlugins/flt/LightPointSystemRecord.cpp b/src/osgPlugins/flt/LightPointSystemRecord.cpp new file mode 100644 index 000000000..fd8c4ce21 --- /dev/null +++ b/src/osgPlugins/flt/LightPointSystemRecord.cpp @@ -0,0 +1,36 @@ + +#include "flt.h" +#include "Registry.h" +#include "LightPointSystemRecord.h" + +using namespace flt; + +//////////////////////////////////////////////////////////////////// +// +// LightPointSystemRecord +// +//////////////////////////////////////////////////////////////////// + +RegisterRecordProxy g_LightPointSystemProxy; + +LightPointSystemRecord::LightPointSystemRecord() +{ +} + + +// virtual +LightPointSystemRecord::~LightPointSystemRecord() +{ +} + + +// virtual +void LightPointSystemRecord::endian() +{ + SLightPointSystem* ltPtSys = (SLightPointSystem*)getData(); + + ENDIAN( ltPtSys->intensity ); + ENDIAN( ltPtSys->animationState ); + ENDIAN( ltPtSys->flags ); +} + diff --git a/src/osgPlugins/flt/LightPointSystemRecord.h b/src/osgPlugins/flt/LightPointSystemRecord.h new file mode 100644 index 000000000..1a7cd7f93 --- /dev/null +++ b/src/osgPlugins/flt/LightPointSystemRecord.h @@ -0,0 +1,51 @@ + +#ifndef __FLT_LIGHT_POINT_SYSTEM_RECORD_H +#define __FLT_LIGHT_POINT_SYSTEM_RECORD_H + + +#include "opcodes.h" +#include "Record.h" +#include "RecordVisitor.h" + + +namespace flt { + + +struct SLightPointSystem +{ + SRecHeader RecHeader; + char ident[8]; + float32 intensity; // Child light point node intensity + int32 animationState; // Animation state: 0 -- On + // 1 -- Off + // 3 -- Random + int32 flags; // Flag bits: 0 -- Enable + // 1-31 -- Spare +}; + + +class LightPointSystemRecord : public PrimNodeRecord +{ + public: + + LightPointSystemRecord(); + + virtual Record* clone() const { return new LightPointSystemRecord(); } + virtual const char* className() const { return "LightPointSystemRecord"; } + virtual int classOpcode() const { return LIGHT_PT_SYSTEM_OP; } + virtual void accept(RecordVisitor& rv) { rv.apply(*this); } + + virtual SLightPointSystem* getData() const { return (SLightPointSystem*)_pData; } + + protected: + + virtual ~LightPointSystemRecord(); + + virtual void endian(); +}; + + +}; // end namespace flt + + +#endif diff --git a/src/osgPlugins/flt/RecordVisitor.h b/src/osgPlugins/flt/RecordVisitor.h index fc54a7ca3..465a6a9e4 100644 --- a/src/osgPlugins/flt/RecordVisitor.h +++ b/src/osgPlugins/flt/RecordVisitor.h @@ -33,6 +33,7 @@ class MorphVertexListRecord; class LightSourceRecord; class LightPointRecord; class LightPointIndexRecord; +class LightPointSystemRecord; class SwitchRecord; class ExtensionRecord; class ExternalRecord; @@ -131,6 +132,7 @@ class RecordVisitor virtual void apply(LightSourceRecord& rec) { apply((PrimNodeRecord&)rec); } virtual void apply(LightPointRecord& rec) { apply((PrimNodeRecord&)rec); } virtual void apply(LightPointIndexRecord& rec) { apply((PrimNodeRecord&)rec); } + virtual void apply(LightPointSystemRecord& rec) { apply((PrimNodeRecord&)rec); } virtual void apply(SwitchRecord& rec) { apply((PrimNodeRecord&)rec); } virtual void apply(ExtensionRecord& rec) { apply((PrimNodeRecord&)rec); } virtual void apply(ExternalRecord& rec) { apply((PrimNodeRecord&)rec); } diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 1c3a2b079..8a11dbbcc 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -68,6 +69,7 @@ #include "TransformationRecords.h" #include "ExternalRecord.h" #include "LightPointRecord.h" +#include "LightPointSystemRecord.h" #include "Input.h" #include "GeoSetBuilder.h" #include "LongIDRecord.h" @@ -315,6 +317,9 @@ osg::Group* ConvertFromFLT::visitPrimaryNode(osg::Group& osgParent, PrimNodeReco case INDEXED_LIGHT_PT_OP: visitLightPointIndex(osgParent, (LightPointIndexRecord*)child); break; + case LIGHT_PT_SYSTEM_OP: + osgPrim = visitLightPointSystem(osgParent, (LightPointSystemRecord*)child); + break; case GROUP_OP: osgPrim = visitGroup(osgParent, (GroupRecord*)child); break; @@ -743,7 +748,7 @@ void ConvertFromFLT::visitTexturePalette(osg::Group& , TexturePaletteRecord* rec } -void ConvertFromFLT::visitLtPtAppearancePalette(osg::Group& osgParent, LtPtAppearancePaletteRecord* rec) +void ConvertFromFLT::visitLtPtAppearancePalette(osg::Group& /*osgParent*/, LtPtAppearancePaletteRecord* rec) { SLightPointAppearancePalette* ltPtApp = (SLightPointAppearancePalette*)rec->getData(); LtPtAppearancePool* pool = rec->getFltFile()->getLtPtAppearancePool(); @@ -2358,6 +2363,74 @@ void ConvertFromFLT::visitLightPointIndex(osg::Group& osgParent, LightPointIndex } +// OpenFlight 15.8 (1580) +// Light point systems allow an application to control intensity, animation +// state, and on/off state of all child light point nodes from a single node. +// On/off state implemented with an osgSim::MultiSwitch. Set 0 turns all children +// off, set 1 turns them on. Applications can define other sets if desired, or +// redefine these sets. +// Children LightPointNodes all have a reference to a common LightPointState object +// An application controls intensity and animation state parameters by finding +// the first child of the Light Point System MultiSwitch, calling +// getLightPointState(), and setting intensity and animation state accordingly. +osg::Group* ConvertFromFLT::visitLightPointSystem(osg::Group& osgParent, LightPointSystemRecord* rec) +{ + SLightPointSystem *ltPtSys = (SLightPointSystem*)rec->getData(); + + osgSim::MultiSwitch* system = new osgSim::MultiSwitch; + osg::ref_ptr lightState = new osgSim::LightPointSystem; + + // Attach children + visitAncillary( osgParent, *system, rec )->addChild( system ); + visitPrimaryNode( *system, rec ); + + system->setName( ltPtSys->ident ); + + // Set default sets: 0 for all off, 1 for all on + system->setAllChildrenOn( 1 ); + system->setAllChildrenOff( 0 ); + + // Set initial on/off state + unsigned int initialSet = ( (ltPtSys->flags & 0x80000000) != 0 ) ? 1 : 0; + system->setActiveSwitchSet( initialSet ); + + + lightState->setIntensity( ltPtSys->intensity ); + switch( ltPtSys->animationState ) + { + // Note that OpenFlight 15.8 spec says 0 means on and 1 means off. + // However, if animation is set on in Creator, it stores a 1, and + // a zero is stored for off! So, for now, we ignore the spec... + case 0: + lightState->setAnimationState( osgSim::LightPointSystem::ANIMATION_OFF ); + break; + default: + case 1: + lightState->setAnimationState( osgSim::LightPointSystem::ANIMATION_ON ); + break; + case 2: + lightState->setAnimationState( osgSim::LightPointSystem::ANIMATION_RANDOM ); + break; + } + + // Set light point state in all children + int errorChildren = 0; + for ( unsigned int i=0; igetNumChildren(); i++) + { + osg::Node* child = system->getChild( i ); + if (osgSim::LightPointNode* lpn = dynamic_cast(child)) + lpn->setLightPointSystem (lightState.get() ); + else + // Should never have a non-LightPointNode child + errorChildren++; + } + if (errorChildren > 0) + osg::notify( osg::WARN ) << "ConvertFromFLT::visitLightPointSystem found " << errorChildren << " non-LightPointNode child(ren)." << std::endl; + + return ( (osg::Group*) system ); +} + + void ConvertFromFLT::visitMesh ( osg::Group &parent, GeoSetBuilder *pBuilder, MeshRecord *rec ) { DynGeoSet* dgset = pBuilder->getDynGeoSet(); diff --git a/src/osgPlugins/flt/flt2osg.h b/src/osgPlugins/flt/flt2osg.h index 0ab4e205b..07ee0f23e 100644 --- a/src/osgPlugins/flt/flt2osg.h +++ b/src/osgPlugins/flt/flt2osg.h @@ -50,6 +50,7 @@ class GeneralMatrixRecord; class ExternalRecord; class LightPointRecord; class LightPointIndexRecord; +class LightPointSystemRecord; class VertexListRecord; class LocalVertexPoolRecord; class LongIDRecord; @@ -163,6 +164,7 @@ class ConvertFromFLT void visitLightPoint(GeoSetBuilder* pBuilder, LightPointRecord* rec); void visitLightPoint(osg::Group& osgParent, LightPointRecord* rec); void visitLightPointIndex(osg::Group& osgParent, LightPointIndexRecord* rec); + osg::Group* visitLightPointSystem(osg::Group& osgParent, LightPointSystemRecord* rec); int visitVertexList(GeoSetBuilder* pParent, VertexListRecord* rec); int visitLocalVertexPool(GeoSetBuilder* pBuilder, LocalVertexPoolRecord* rec); diff --git a/src/osgPlugins/flt/opcodes.h b/src/osgPlugins/flt/opcodes.h index 56c86003e..aa95ea1f4 100644 --- a/src/osgPlugins/flt/opcodes.h +++ b/src/osgPlugins/flt/opcodes.h @@ -83,7 +83,7 @@ #define LIGHT_PT_APPEARANCE_PALETTE_OP 128 #define LIGHT_PT_ANIMATION_PALETTE_OP 129 // ignored #define INDEXED_LIGHT_PT_OP 130 -#define LIGHT_PT_SYSTEM_OP 131 // ignored +#define LIGHT_PT_SYSTEM_OP 131 #define INDEXED_STRING_OP 132 // ignored diff --git a/src/osgSim/LightPointNode.cpp b/src/osgSim/LightPointNode.cpp index fd3776776..364417bfd 100644 --- a/src/osgSim/LightPointNode.cpp +++ b/src/osgSim/LightPointNode.cpp @@ -12,6 +12,7 @@ */ #include +#include #include "LightPointDrawable.h" @@ -27,7 +28,7 @@ namespace osgSim { -osg::StateSet* getSingletonLightPointStateSet() +osg::StateSet* getSingletonLightPointSystemSet() { static osg::ref_ptr s_stateset = 0; if (!s_stateset) @@ -44,9 +45,10 @@ osg::StateSet* getSingletonLightPointStateSet() LightPointNode::LightPointNode(): _minPixelSize(0.0f), _maxPixelSize(30.0f), - _maxVisibleDistance2(FLT_MAX) + _maxVisibleDistance2(FLT_MAX), + _lightSystem(0) { - setStateSet(getSingletonLightPointStateSet()); + setStateSet(getSingletonLightPointSystemSet()); } /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ @@ -55,7 +57,8 @@ LightPointNode::LightPointNode(const LightPointNode& lpn,const osg::CopyOp& copy _lightPointList(lpn._lightPointList), _minPixelSize(lpn._minPixelSize), _maxPixelSize(lpn._maxPixelSize), - _maxVisibleDistance2(lpn._maxVisibleDistance2) + _maxVisibleDistance2(lpn._maxVisibleDistance2), + _lightSystem(lpn._lightSystem) { } @@ -260,9 +263,9 @@ void LightPointNode::traverse(osg::NodeVisitor& nv) // delta vector between eyepoint and light point. osg::Vec3 dv(eyePoint-position); - - float intensity = lp._intensity; - + + float intensity = (_lightSystem.valid()) ? _lightSystem->getIntensity() : lp._intensity; + // slip light point if it is intensity is 0.0 or negative. if (intensity<=minimumIntensity) continue; @@ -289,7 +292,11 @@ void LightPointNode::traverse(osg::NodeVisitor& nv) //color *= intensity; // check the blink sequence. - if (lp._blinkSequence.valid()) + bool doBlink = lp._blinkSequence.valid(); + if (doBlink && _lightSystem.valid()) + doBlink = (_lightSystem->getAnimationState() == LightPointSystem::ANIMATION_ON); + + if (doBlink) { osg::Vec4 bs = lp._blinkSequence->color(time,timeInterval); color[0] *= bs[0]; diff --git a/src/osgUtil/Simplifier.cpp b/src/osgUtil/Simplifier.cpp index da29a1d03..2d4bb48ae 100644 --- a/src/osgUtil/Simplifier.cpp +++ b/src/osgUtil/Simplifier.cpp @@ -41,8 +41,8 @@ public: void copyBackToGeometry() {} - class Triangle; - class Edge; + struct Triangle; + struct Edge; typedef std::vector FloatList;