From Boris Bralo, addition of support for osgSim::LightPoint's into TXP

plugin.
This commit is contained in:
Robert Osfield
2003-09-07 14:18:22 +00:00
parent 507c9c4cf2
commit cf1fe8edc2
8 changed files with 243 additions and 6 deletions

View File

@@ -2102,6 +2102,9 @@ Package=<4>
Begin Project Dependency
Project_Dep_Name Core osgUtil
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgSim
End Project Dependency
}}}
###############################################################################

View File

@@ -37,7 +37,7 @@ CXXFILES =\
INC += -I$(THISDIR)
LIBS += $(OSG_LIBS) $(OTHER_LIBS)
LIBS += -losgSim $(OSG_LIBS) $(OTHER_LIBS)
PLUGIN_TARGET_BASENAME = txp
include $(TOPDIR)/Make/cygwin_plugin_def

View File

@@ -63,6 +63,9 @@ bool TerrapageNode::loadDatabase()
// Note: Should be checking the return values
txpArchive->LoadModels();
// Note: Should be checking the return values
txpArchive->LoadLightAttributes();
// get the exents of the archive
const trpgHeader *head = txpArchive->GetHeader();
trpg2dPoint sw,ne;

View File

@@ -23,6 +23,13 @@
#include <osgDB/WriteFile>
#include <osgDB/FileNameUtils>
#include <osgSim/Sector>
#include <osgSim/LightPoint>
#include <osgSim/LightPointNode>
#include <osgSim/BlinkSequence>
#include <osg/Point>
#include <osg/BlendFunc>
#include "trpage_geom.h"
#include "trpage_read.h"
#include "trpage_write.h"
@@ -369,6 +376,113 @@ void TrPageArchive::LoadMaterials()
}
}
void TrPageArchive::LoadLightAttributes()
{
int num;
lightTable.GetNumLightAttrs(num);
for ( int attr_num = 0; attr_num < num; attr_num++ ){
trpgLightAttr* ref = const_cast<trpgLightAttr*>(lightTable.GetLightAttrRef(attr_num));
osgSim::LightPointNode* osgLight = new osgSim::LightPointNode();
osg::Point* osgPoint = new osg::Point();
osgSim::LightPoint lp ;
lp._on = true;
trpgColor col;
ref->GetFrontColor(col);
lp._color = osg::Vec4(col.red, col.green,col.blue, 1.0);
float64 inten;
ref->GetFrontIntensity(inten);
lp._intensity = inten;
trpgLightAttr::PerformerAttr perfAttr;
ref->GetPerformerAttr(perfAttr);
// point part
osgPoint->setSize(perfAttr.actualSize);
osgPoint->setMaxSize(perfAttr.maxPixelSize);
osgPoint->setMinSize(perfAttr.minPixelSize);
osgPoint->setFadeThresholdSize(perfAttr.transparentFallofExp);
//numbers that are going to appear are "experimental"
osgPoint->setDistanceAttenuation(osg::Vec3(0.0001, 0.0005, 0.00000025));
// osgPoint->setDistanceAttenuation(osg::Vec3(1.0, 0.0, 1.0));
osg::StateSet* stateSet = new osg::StateSet();
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
stateSet->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON);
stateSet->setAttributeAndModes(osgPoint, osg::StateAttribute::ON );
stateSet->setAttributeAndModes(new osg::BlendFunc, osg::StateAttribute::ON);
osgLight->setMaxPixelSize(perfAttr.maxPixelSize);
osgLight->setMinPixelSize(perfAttr.minPixelSize);
// float64 clamp;
// ref->GetPerformerTpClamp(clamp);
// osgLight->setMaxVisibleDistance2(clamp);
trpg3dPoint normal;
ref->GetNormal(normal);
// lp._radius = clamp;
trpgLightAttr::LightDirectionality direc;
ref->GetDirectionality(direc);
if( direc == trpgLightAttr::trpg_Unidirectional){
osgSim::AzimElevationSector* sec = new osgSim::AzimElevationSector();
float64 tmp;
ref->GetHLobeAngle(tmp);
float64 tmpfade;
ref->GetLobeFalloff(tmpfade);
sec->setAzimuthRange(-tmp/2.0,tmp/2.0,tmpfade);
ref->GetVLobeAngle(tmp);
sec->setElevationRange(0,tmp, tmpfade);
lp._sector = sec;
osgLight->addLightPoint(lp);
}
else if( direc == trpgLightAttr::trpg_Bidirectional ){
osgSim::AzimElevationSector* front = new osgSim::AzimElevationSector();
float64 tmp;
ref->GetHLobeAngle(tmp);
float64 tmpfade;
ref->GetLobeFalloff(tmpfade);
front->setAzimuthRange(-tmp/2.0,tmp/2.0,tmpfade);
ref->GetVLobeAngle(tmp);
front->setElevationRange(0,tmp, tmpfade);
lp._sector = front;
osgLight->addLightPoint(lp);
osgSim::AzimElevationSector* back = new osgSim::AzimElevationSector();
back->setAzimuthRange(osg::PI-tmp/2.0,osg::PI+tmp/2.0,tmpfade);
back->setElevationRange(0,tmp, tmpfade);
lp._sector = back;
osgLight->addLightPoint(lp);
}
else{
osgLight->addLightPoint(lp);
}
AddLightAttribute(osgLight, stateSet, osg::Vec3(normal.x,normal.y,normal.z));
}
}
void TrPageArchive::AddLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback, const osg::Vec3& att)
{
DefferedLightAttribute la;
la.lightPoint = lpn;
la.fallback = fallback;
la.attitude = att;
lightAttrTable.push_back(la);
}
bool TrPageArchive::LoadModels()
{
int numModel;

View File

@@ -35,8 +35,19 @@
#include <vector>
#include <memory> // for auto_ptr
namespace osgSim{
class LightPointNode;
}
namespace txp
{
// this one handles different placement of light direction in osg and terrapage
struct DefferedLightAttribute{
// light point at (0,0,0) looking in (0,0,0) direction
osg::ref_ptr<osgSim::LightPointNode> lightPoint;
osg::ref_ptr<osg::StateSet> fallback;
osg::Vec3 attitude;
};
/// main class for loading terrapage archives
class TrPageArchive : public trpgr_Archive
{
@@ -53,7 +64,15 @@ namespace txp
/// Load and create models, usualy OpenFlight models
bool LoadModels();
void LoadLightAttributes();
void AddLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback , const osg::Vec3& attitude);
DefferedLightAttribute& GetLightAttribute(std::size_t i) {
return lightAttrTable[i];
};
/** Load a TXP tile and
@param x Tile location input - x dimension.
@param y Tile location input - y dimension.
@@ -100,6 +119,9 @@ namespace txp
std::vector< osg::ref_ptr<osg::Texture2D> > m_textures;
std::vector< osg::ref_ptr<osg::StateSet> > m_gstates;
std::vector< osg::ref_ptr<osg::Node> > m_models;
// light attributes vector
std::vector<DefferedLightAttribute> lightAttrTable;
std::string m_alternate_path;
trpgMemReadBuffer buf;
};

View File

@@ -35,6 +35,10 @@
#include <osg/Light>
#include <osg/Notify>
#include <osg/PolygonOffset>
#include <osg/MatrixTransform>
#include <osgSim/LightPointNode>
#include <osg/Point>
#include "TrPageParser.h"
#include "TrPageArchive.h"
@@ -867,6 +871,76 @@ void* tileHeaderRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
}
//----------------------------------------------------------------------------
//
// light Reader Class
//
//----------------------------------------------------------------------------
lightRead::lightRead (TrPageParser *in_parse)
{
parse = in_parse;
}
//----------------------------------------------------------------------------
void* lightRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
{
trpgLight light;
if (!light.Read(buf))
return NULL;
int attr_index;
light.GetAttrIndex(attr_index);
DefferedLightAttribute& dla = parse->GetLightAttribute(attr_index);
osgSim::LightPointNode* node = dla.lightPoint.get();
uint32 nvert;
light.GetNumVertices(nvert);
if( node->getLightPoint(0)._sector.valid() ) // osgSim::LigthPoint is a must
{
for(unsigned int i = 0; i < nvert; i++){
trpg3dPoint pt;
light.GetVertex(i, pt);
osg::Matrix matrix;
// matrix.makeTranslate(pt.x,pt.y,pt.z);
matrix.makeRotate(osg::Quat(0.0,dla.attitude));
matrix.setTrans(pt.x,pt.y,pt.z);
osg::MatrixTransform* trans = new osg::MatrixTransform();
trans->setMatrix(matrix);
trans->addChild(node);
parse->AddIntoSceneGraph(trans);
}
}
else { //Fall back to osg::Points
Vec3Array* vertices = new Vec3Array(nvert);
Vec4Array* colors = new Vec4Array(nvert);
for(unsigned int i = 0; i < nvert; i++){
trpg3dPoint pt;
light.GetVertex(i, pt);
(*vertices)[i] = osg::Vec3(pt.x,pt.y,pt.z);
(*colors)[i] = node->getLightPoint(0)._color;
}
osg::Geometry* geom = new osg::Geometry();
geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::POINTS,0,nvert));
geom->setVertexArray(vertices);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
geom->setUseDisplayList(false);
geom->setStateSet(dla.fallback.get());
GeodeGroup *top = parse->GetCurrTop();
Geode *geode = top->GetGeode();
geode->addDrawable(geom);
}
return (void *) 1;
}
/* ********************************** */
//----------------------------------------------------------------------------
@@ -889,6 +963,9 @@ TrPageParser::TrPageParser(TrPageArchive* parent)
AddCallback(TRPG_MODELREF,new modelRefRead(this));
AddCallback(TRPG_LAYER,new layerRead(this));
AddCallback(TRPGTILEHEADER,new tileHeaderRead(this));
AddCallback(TRPG_LIGHT,new lightRead(this));
// AddCallback(TRPGLIGHTATTR,new lightAttrRead(this));
// AddCallback(TRPGLIGHTTABLE,new lightTableRead(this));
}
//----------------------------------------------------------------------------
@@ -1250,3 +1327,8 @@ Layer *TrPageParser::GetCurrLayer()
{
return currLayer;
}
DefferedLightAttribute& TrPageParser::GetLightAttribute(int idx)
{
return parent_->GetLightAttribute(idx);
}

View File

@@ -34,9 +34,11 @@
#include <vector>
#include "trpage_read.h"
namespace txp
{
class TrPageArchive;
struct DefferedLightAttribute;
// Group ID Info
// Used to keep track of which groups are which IDs for parents
@@ -155,8 +157,9 @@ namespace txp
int getBillboardType() { return billboard_type; }
void setBillboardCenter(trpg3dPoint center) { billboard_center = center; }
osg::Vec3 getBillboardCenter() { return osg::Vec3(billboard_center.x, billboard_center.y, billboard_center.z); }
DefferedLightAttribute& GetLightAttribute(int attr_index);
protected:
// Called on start children
bool StartChildren(void *);
@@ -231,7 +234,7 @@ namespace txp
// Geometry Geometry
// It is tested on this kind of archive and it works.
// nick@terrex.com
std::vector<osg::Node*> deadNodes;
std::vector<osg::Node*> deadNodes;
};
// Gets local texture via the image helper
@@ -311,6 +314,16 @@ namespace txp
protected:
TrPageParser*parse;
};
//----------------------------------------------------------------------------
class lightRead: public trpgr_Callback {
public:
lightRead(TrPageParser*in_parse);
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TrPageParser*parse;
};
} // namespace txp
#endif

View File

@@ -157,7 +157,7 @@ bool OSGPageManager::EndThread()
// then wait for the the thread to stop running.
while(pagingThread.isRunning())
{
std::cout<<"Waiting for TXP pager thread to cancel"<<std::endl;
osg::notify(osg::INFO)<<"Waiting for TXP pager thread to cancel"<<std::endl;
OpenThreads::Thread::YieldCurrentThread();
}