From Paul Martz, added support for OpenFlight15.8 LightPointSystems

This commit is contained in:
Robert Osfield
2004-04-10 11:30:16 +00:00
parent 5c01b5118e
commit ae7ceae631
13 changed files with 268 additions and 15 deletions

View File

@@ -35,6 +35,7 @@ CXXFILES =\
LightPointRecord.cpp\
VertexPoolRecords.cpp\
LightPointPaletteRecords.cpp\
LightPointSystemRecord.cpp\
LightSourcePaletteRecord.cpp\
flt.cpp\
LightSourceRecord.cpp\

View File

@@ -0,0 +1,36 @@
#include "flt.h"
#include "Registry.h"
#include "LightPointSystemRecord.h"
using namespace flt;
////////////////////////////////////////////////////////////////////
//
// LightPointSystemRecord
//
////////////////////////////////////////////////////////////////////
RegisterRecordProxy<LightPointSystemRecord> g_LightPointSystemProxy;
LightPointSystemRecord::LightPointSystemRecord()
{
}
// virtual
LightPointSystemRecord::~LightPointSystemRecord()
{
}
// virtual
void LightPointSystemRecord::endian()
{
SLightPointSystem* ltPtSys = (SLightPointSystem*)getData();
ENDIAN( ltPtSys->intensity );
ENDIAN( ltPtSys->animationState );
ENDIAN( ltPtSys->flags );
}

View File

@@ -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

View File

@@ -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); }

View File

@@ -33,6 +33,7 @@
#include <osgSim/MultiSwitch>
#include <osgSim/DOFTransform>
#include <osgSim/LightPointNode>
#include <osgSim/LightPointSystem>
#include <osgSim/Sector>
#include <osgSim/BlinkSequence>
@@ -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<osgSim::LightPointSystem> 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; i<system->getNumChildren(); i++)
{
osg::Node* child = system->getChild( i );
if (osgSim::LightPointNode* lpn = dynamic_cast<osgSim::LightPointNode*>(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();

View File

@@ -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);

View File

@@ -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

View File

@@ -12,6 +12,7 @@
*/
#include <osgSim/LightPointNode>
#include <osgSim/LightPointSystem>
#include "LightPointDrawable.h"
@@ -27,7 +28,7 @@
namespace osgSim
{
osg::StateSet* getSingletonLightPointStateSet()
osg::StateSet* getSingletonLightPointSystemSet()
{
static osg::ref_ptr<osg::StateSet> 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];

View File

@@ -41,8 +41,8 @@ public:
void copyBackToGeometry() {}
class Triangle;
class Edge;
struct Triangle;
struct Edge;
typedef std::vector<float> FloatList;