Updates to TXP plugin from Nick.

This commit is contained in:
Robert Osfield
2004-01-02 17:30:05 +00:00
parent bf9af3f940
commit 3034112577
13 changed files with 788 additions and 612 deletions

View File

@@ -142,14 +142,11 @@ TXPArchive *ReaderWriterTXP::getArchive(int id, const std::string& dir)
return NULL;
}
/*
// We load the models on demand
if (archive->loadModels() == false)
{
ReaderWriterTXPERROR("getArchive()") << "failed to load models from archive: \"" << archiveName << "\"" << std::endl;
return NULL;
}
*/
if (archive->loadLightAttributes() == false)
{

View File

@@ -1,17 +1,17 @@
/* **************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The basic code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
/***************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
*****************************************************************************/
/* **************************************************************************
* OpenSceneGraph loader for Terrapage format database
/***************************************************************************
* OpenSceneGraph loader for Terrapage format database
* by Boris Bralo 2002
*
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
@@ -45,25 +45,28 @@
namespace txp
{
class TXPArchive;
class ReaderWriterTXP : public osgDB::ReaderWriter
class TXPArchive;
class ReaderWriterTXP : public osgDB::ReaderWriter
{
public:
virtual const char* className()
{
public:
virtual const char* className() { return "TXP Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
{
return osgDB::equalCaseInsensitive(extension,"txp");
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
protected:
TXPArchive *getArchive(int id, const std::string&);
std::map< int,osg::ref_ptr<TXPArchive> > _archives;
static int _archiveId;
};
return "TXP Reader/Writer";
}
virtual bool acceptsExtension(const std::string& extension)
{
return osgDB::equalCaseInsensitive(extension,"txp");
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
protected:
TXPArchive *getArchive(int id, const std::string&);
std::map< int,osg::ref_ptr<TXPArchive> > _archives;
static int _archiveId;
};
} // namespace

View File

@@ -95,7 +95,7 @@ bool TXPArchive::openFile(const std::string& archiveName)
return true;
}
bool TXPArchive::loadMaterial(int ix)
bool TXPArchive::loadMaterial(int /*ix*/)
{
return false;
}
@@ -580,7 +580,11 @@ bool TXPArchive::getTileInfo(int x, int y, int lod, TileInfo& info)
return false;
}
osg::Group* TXPArchive::getTileContent(int x, int y, int lod)
osg::Group* TXPArchive::getTileContent(
int x, int y, int lod,
double realMinRange,
double realMaxRange,
double usedMaxRange)
{
if (_parser.get() == 0)
{
@@ -594,6 +598,6 @@ osg::Group* TXPArchive::getTileContent(int x, int y, int lod)
return new osg::Group;
}
osg::Group *tileGroup = _parser->parseScene(buf,_gstates,_models);
osg::Group *tileGroup = _parser->parseScene(buf,_gstates,_models,realMinRange,realMaxRange,usedMaxRange);
return tileGroup;
}

View File

@@ -1,17 +1,17 @@
/* **************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The basic code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
/***************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
*****************************************************************************/
/* **************************************************************************
* OpenSceneGraph loader for Terrapage format database
/***************************************************************************
* OpenSceneGraph loader for Terrapage format database
* by Boris Bralo 2002
*
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
@@ -47,107 +47,133 @@
namespace txp
{
// this one handles different placement of light direction in osg and terrapage
struct DefferedLightAttribute
// 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;
};
class TXPParser;
class TXPArchive : public trpgr_Archive, public osg::Referenced
{
public:
// Constructor
TXPArchive();
// Opens the archive file and reads the header
bool openFile(const std::string& archiveName);
// Load the materials from the archve
bool loadMaterials();
bool loadMaterial(int ix);
// Load the models from the archive
bool loadModels();
bool loadModel(int ix);
// Load the light attribs from the archive
bool loadLightAttributes();
// Add light attrib
void addLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback , const osg::Vec3& attitude);
// Get light attrib
inline DefferedLightAttribute& getLightAttribute(unsigned int i)
{
// 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;
return _lights[i];
};
class TXPParser;
class TXPArchive : public trpgr_Archive, public osg::Referenced
// Gets some informations for a given tile
struct TileInfo
{
public:
// Constructor
TXPArchive();
// Opens the archive file and reads the header
bool openFile(const std::string& archiveName);
// Load the materials from the archve
bool loadMaterials();
bool loadMaterial(int ix);
// Load the models from the archive
bool loadModels();
bool loadModel(int ix);
// Load the light attribs from the archive
bool loadLightAttributes();
// Add light attrib
void addLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback , const osg::Vec3& attitude);
// Get light attrib
inline DefferedLightAttribute& getLightAttribute(unsigned int i) { return _lights[i]; };
// Gets some informations for a given tile
struct TileInfo
{
osg::Vec3 center;
double minRange;
double maxRange;
float radius;
osg::BoundingBox bbox;
};
bool getTileInfo(int x, int y, int lod, TileInfo& info);
// Set/Get the archive id
inline void setId(int id) { _id = id; }
inline const int& getId() const { return _id; }
// Returns the number of LODs for this archive
inline const int& getNumLODs() const { return _numLODs; }
// Returns the extents of the archive
inline void getExtents(osg::BoundingBox& extents)
{
extents.set(_swExtents.x,_swExtents.y,0.0f,_neExtents.x,_neExtents.y,0.0f);
}
// Returns the origin of the archive
inline void getOrigin(double& x, double& y) { x=_swExtents.x; y=_swExtents.y; }
inline osg::Texture2D* getGlobalTexture(int id) { return _textures[id].get(); }
osg::Group* getTileContent(int x, int y, int lod);
osg::Vec3 center;
double minRange;
double maxRange;
float radius;
osg::BoundingBox bbox;
};
bool getTileInfo(int x, int y, int lod, TileInfo& info);
// Set/Get the archive id
inline void setId(int id)
{
_id = id;
}
inline const int& getId() const
{
return _id;
}
// Returns the number of LODs for this archive
inline const int& getNumLODs() const
{
return _numLODs;
}
// Returns the extents of the archive
inline void getExtents(osg::BoundingBox& extents)
{
extents.set(_swExtents.x,_swExtents.y,0.0f,_neExtents.x,_neExtents.y,0.0f);
}
// Returns the origin of the archive
inline void getOrigin(double& x, double& y)
{
x=_swExtents.x;
y=_swExtents.y;
}
// Returns global texture
inline osg::Texture2D* getGlobalTexture(int id)
{
return _textures[id].get();
}
// Returns scenegraph representing the Tile
osg::Group* getTileContent(
int x,
int y,
int lod,
double realMinRange,
double realMaxRange,
double usedMaxRange);
protected:
protected:
// Destructor
virtual ~TXPArchive();
// Id of the archive
int _id;
// Number of the LODs
int _numLODs;
// Archive extents
trpg2dPoint _swExtents;
trpg2dPoint _neExtents;
// Terra Page Parser
osg::ref_ptr<TXPParser> _parser;
// Textures
std::vector< osg::ref_ptr<osg::Texture2D> > _textures;
// States
std::vector< osg::ref_ptr<osg::StateSet> > _gstates;
// Models
std::vector< osg::ref_ptr<osg::Node> > _models;
// Light attributes vector
std::vector<DefferedLightAttribute> _lights;
};
// Destructor
virtual ~TXPArchive();
// Id of the archive
int _id;
// Number of the LODs
int _numLODs;
// Archive extents
trpg2dPoint _swExtents;
trpg2dPoint _neExtents;
// Terra Page Parser
osg::ref_ptr<TXPParser> _parser;
// Textures
std::vector< osg::ref_ptr<osg::Texture2D> > _textures;
// States
std::vector< osg::ref_ptr<osg::StateSet> > _gstates;
// Models
std::vector< osg::ref_ptr<osg::Node> > _models;
// Light attributes vector
std::vector<DefferedLightAttribute> _lights;
};
} // namespace
#endif // __TXPARCHIVE_H_

View File

@@ -1,17 +1,17 @@
/* **************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The basic code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
/***************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
*****************************************************************************/
/* **************************************************************************
* OpenSceneGraph loader for Terrapage format database
/***************************************************************************
* OpenSceneGraph loader for Terrapage format database
* by Boris Bralo 2002
*
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
@@ -44,55 +44,55 @@
namespace txp
{
class TXPNode : public osg::Group
{
public:
class TXPNode : public osg::Group
{
public:
TXPNode();
TXPNode();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TXPNode(const TXPNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(txp, TXPNode);
virtual void traverse(osg::NodeVisitor& nv);
void setArchiveName(const std::string& archiveName);
void setOptions(const std::string& options);
const std::string& getOptions() const;
const std::string& getArchiveName() const;
bool loadArchive();
TXPArchive* getArchive();
protected:
virtual ~TXPNode();
virtual bool computeBound() const;
void updateEye(osg::NodeVisitor& nv);
void updateSceneGraph();
osg::Node* addPagedLODTile(int x, int y, int lod);
std::string _archiveName;
std::string _options;
osg::ref_ptr<TXPArchive> _archive;
osg::ref_ptr<TXPPageManager> _pageManager;
double _originX;
double _originY;
osg::BoundingBox _extents;
std::vector<osg::Node*> _nodesToAdd;
std::vector<osg::Node*> _nodesToRemove;
};
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TXPNode(const TXPNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(txp, TXPNode);
virtual void traverse(osg::NodeVisitor& nv);
void setArchiveName(const std::string& archiveName);
void setOptions(const std::string& options);
const std::string& getOptions() const;
const std::string& getArchiveName() const;
bool loadArchive();
TXPArchive* getArchive();
protected:
virtual ~TXPNode();
virtual bool computeBound() const;
void updateEye(osg::NodeVisitor& nv);
void updateSceneGraph();
osg::Node* addPagedLODTile(int x, int y, int lod);
std::string _archiveName;
std::string _options;
osg::ref_ptr<TXPArchive> _archive;
osg::ref_ptr<TXPPageManager> _pageManager;
double _originX;
double _originY;
osg::BoundingBox _extents;
std::vector<osg::Node*> _nodesToAdd;
std::vector<osg::Node*> _nodesToRemove;
};
} // namespace

View File

@@ -1,17 +1,17 @@
/* **************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The basic code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
/***************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
*****************************************************************************/
/* **************************************************************************
* OpenSceneGraph loader for Terrapage format database
/***************************************************************************
* OpenSceneGraph loader for Terrapage format database
* by Boris Bralo 2002
*
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
@@ -42,15 +42,15 @@
namespace txp
{
class TXPPageManager : public trpgPageManager, public osg::Referenced
{
public:
TXPPageManager();
protected:
virtual ~TXPPageManager();
};
class TXPPageManager : public trpgPageManager, public osg::Referenced
{
public:
TXPPageManager();
protected:
virtual ~TXPPageManager();
};
} // namespace

View File

@@ -34,7 +34,10 @@ _numBillboardLevels(0),
_underLayerSubgraph(false),
_numLayerLevels(0),
_layerGeode(0),
_defaultMaxAnisotropy(1.0f)
_defaultMaxAnisotropy(1.0f),
_realMinRange(0.0),
_realMaxRange(0.0),
_usedMaxRange(0.0)
{
AddCallback(TRPG_GEOMETRY,new geomRead(this));
AddCallback(TRPG_GROUP,new groupRead(this));
@@ -59,7 +62,8 @@ TXPParser::~TXPParser()
osg::Group *TXPParser::parseScene(
trpgReadBuffer &buf,
std::vector<osg::ref_ptr<osg::StateSet> > &materials,
std::vector<osg::ref_ptr<osg::Node> > &models)
std::vector<osg::ref_ptr<osg::Node> > &models,
double realMinRange, double realMaxRange, double usedMaxRange)
{
if (_archive == 0) return NULL;
@@ -75,6 +79,10 @@ osg::Group *TXPParser::parseScene(
_underLayerSubgraph = false;
_numLayerLevels = 0;
_realMinRange = realMinRange;
_realMaxRange = realMaxRange;
_usedMaxRange = usedMaxRange;
if (!Parse(buf))
{
osg::notify(osg::NOTICE) << "txp::TXPParser::parseScene(): failed to parse the given tile" << std::endl;
@@ -473,7 +481,12 @@ void* lodRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
osgCenter[1] = center.y;
osgCenter[2] = center.z;
osgLod->setCenter(osgCenter);
osgLod->setRange(0,minRange, maxRange );
//osgLod->setRange(0,minRange, maxRange );
osgLod->setRange(
0,
_parse->checkAndGetMinRange(minRange),
_parse->checkAndGetMaxRange(maxRange)
);
// Our LODs are binary so we need to add a group under this LOD and attach stuff
// to that instead of the LOD

View File

@@ -1,17 +1,17 @@
/* **************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The basic code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
/***************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
*****************************************************************************/
/* **************************************************************************
* OpenSceneGraph loader for Terrapage format database
/***************************************************************************
* OpenSceneGraph loader for Terrapage format database
* by Boris Bralo 2002
*
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
@@ -31,6 +31,7 @@
* All Rights Reserved.
*
*****************************************************************************/
#ifndef __TXPPARSER_H_
#define __TXPPARSER_H_
@@ -38,278 +39,387 @@
#include <osg/Texture2D>
#include <osg/StateSet>
#include <osg/Node>
#include <stack>
#include "trpage_read.h"
namespace txp
{
// Gets local texture via the image helper
osg::Texture2D* getLocalTexture(trpgrImageHelper& image_helper, const trpgTexture* tex);
osg::Texture2D* getTemplateTexture(trpgrImageHelper& image_helper, trpgLocalMaterial* locmat, const trpgTexture* tex, int index=0);
// This is group that will has geode node
// It is better since all the geometry children will be
// added into one Geode node as drawables, then having one
// geode node per child
// Means, instad of having
// Group
// +-----------
// | |
// Geode Geode
// | |
// Drawable Drawable
// we will have
// Group
// |
// Geode
// +-----------
// | |
// Drawable Drawable
class GeodeGroup : public osg::Group
// Gets local texture via the image helper
osg::Texture2D* getLocalTexture(trpgrImageHelper& image_helper, const trpgTexture* tex);
osg::Texture2D* getTemplateTexture(trpgrImageHelper& image_helper, trpgLocalMaterial* locmat, const trpgTexture* tex, int index=0);
// This is group that will has geode node
// It is better since all the geometry children will be
// added into one Geode node as drawables, then having one
// geode node per child
// Means, instad of having
// Group
// +-----------
// | |
// Geode Geode
// | |
// Drawable Drawable
// we will have
// Group
// |
// Geode
// +-----------
// | |
// Drawable Drawable
class GeodeGroup : public osg::Group
{
public:
GeodeGroup() : osg::Group(), _geode(NULL)
{};
GeodeGroup(const GeodeGroup& gg,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Group(gg, copyop), _geode(gg._geode)
{};
META_Node(txp, GeodeGroup);
osg::Geode* getGeode()
{
public:
GeodeGroup() : osg::Group(), _geode(NULL) {};
GeodeGroup(const GeodeGroup& gg,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Group(gg, copyop), _geode(gg._geode) {};
META_Node(txp, GeodeGroup);
osg::Geode* getGeode()
{
if (_geode == 0)
{
_geode = new osg::Geode();
addChild(_geode);
}
return _geode;
if (_geode == 0)
{
_geode = new osg::Geode();
addChild(_geode);
}
protected:
osg::Geode* _geode;
};
class TXPArchive;
struct DefferedLightAttribute;
class TXPParser : public trpgSceneParser, public osg::Referenced
{
public:
TXPParser();
// Sets the archive to be parsed
inline void setArchive(TXPArchive* archive) { _archive = archive; }
// Scene parser
osg::Group *parseScene(
trpgReadBuffer &buf,
std::vector<osg::ref_ptr<osg::StateSet> > &materials,
std::vector<osg::ref_ptr<osg::Node> > &models);
// Returns the current Top Group
inline osg::Group* getCurrTop() { return _currentTop ? _currentTop : _root.get(); }
// Sets the group as potentional tile group
inline void setPotentionalTileGroup(osg::Group* grp) { _tileGroups[grp] = 1; }
// Return the current material list (passed in to ParseScene())
inline std::vector<osg::ref_ptr<osg::StateSet> >* getMaterials() { return _materials; }
// New to TerraPage 2.0 - local materials
std::vector<osg::ref_ptr<osg::StateSet> >* getLocalMaterials() { return &_localMaterials; }
// Load local materials
void loadLocalMaterials();
// Return the current model list
std::vector<osg::ref_ptr<osg::Node> >* getModels() { return _models; }
// Request a model to be load
bool requestModel(int ix);
// Return a reference to the tile header (after a tile has been read)
inline trpgTileHeader *getTileHeaderRef() { return &_tileHeader; }
// Returns true if we are under billboard subgraph
inline const bool underBillboardSubgraph() const { return _underBillboardSubgraph; }
// Sets if we are under billboard subgraph
inline void setUnderBillboardSubgraph(bool b) { _underBillboardSubgraph = b; }
// TXP Billboard info
struct TXPBillboardInfo
{
int type;
int mode;
trpg3dPoint center;
trpg3dPoint axis;
};
// Sets info for the last billboard parsed
inline void setLastBillboardInfo(TXPBillboardInfo& info) { _lastBillboardInfo = info; }
// Gets info for the last billboard parsed
inline void getLastBillboardInfo(TXPBillboardInfo& info) { info = _lastBillboardInfo; }
// Gets light attrib
DefferedLightAttribute& getLightAttribute(int ix);
// Returns if we are under layer subgraph
inline const bool underLayerSubgraph() const { return _underLayerSubgraph; }
// Sets if we are under layer subgraph
inline void setUnderLayerSubgraph(bool b) {_underLayerSubgraph = b; }
// Set the current layer geode
inline void setLayerGeode(osg::Geode* layer) { _layerGeode = layer; }
// Returns the current layer geode
inline osg::Geode* getLayerGeode() const { return _layerGeode; }
// default value to use when setting up textures.
void setMaxAnisotropy(float anisotropy) { _defaultMaxAnisotropy = anisotropy; }
float getMaxAnisotropy() const { return _defaultMaxAnisotropy; }
protected:
virtual ~TXPParser();
// Removes any empty groups and LODs
void removeEmptyGroups();
// Called on start children
bool StartChildren(void *);
// Called on end children
bool EndChildren(void *);
// THE archive
TXPArchive *_archive;
// Current parent
osg::Group* _currentTop;
// The root of the til
osg::ref_ptr<osg::Group> _root;
// Parents list
std::stack<osg::Group*> _parents;
// Potentional Tile groups
std::map<osg::Group*,int> _tileGroups;
// Replace the tile lod to regular group
void replaceTileLod(osg::Group*);
// Materials
std::vector<osg::ref_ptr<osg::StateSet> >* _materials;
// Local materials
std::vector<osg::ref_ptr<osg::StateSet> > _localMaterials;
// Model list
std::vector<osg::ref_ptr<osg::Node> >* _models;
// Tile header
trpgTileHeader _tileHeader;
// true if we are under billboard subgraph
bool _underBillboardSubgraph;
// Number of levels below the billboard node
int _numBillboardLevels;
// Last billboard we parsed
TXPBillboardInfo _lastBillboardInfo;
// true if we are under layer subgraph
bool _underLayerSubgraph;
// Numbers of levels below layer subgraph
int _numLayerLevels;
// Our Layer Geode
osg::Geode* _layerGeode;
// default value to use when setting up textures.
float _defaultMaxAnisotropy;
return _geode;
}
protected:
osg::Geode* _geode;
};
// TEMP
osg::Geode* createBoundingBox(int x,int y, int lod);
};
//! callback functions for various scene graph elements
//----------------------------------------------------------------------------
class geomRead : public trpgr_Callback {
public:
geomRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
class TXPArchive;
struct DefferedLightAttribute;
class TXPParser : public trpgSceneParser, public osg::Referenced
{
public:
TXPParser();
// Sets the archive to be parsed
inline void setArchive(TXPArchive* archive)
{
_archive = archive;
}
// Scene parser
osg::Group *parseScene(
trpgReadBuffer &buf,
std::vector<osg::ref_ptr<osg::StateSet> > &materials,
std::vector<osg::ref_ptr<osg::Node> > &models,
double realMinRange, double realMaxRange, double usedMaxRange);
// Returns the current Top Group
inline osg::Group* getCurrTop()
{
return _currentTop ? _currentTop : _root.get();
}
// Sets the group as potentional tile group
inline void setPotentionalTileGroup(osg::Group* grp)
{
_tileGroups[grp] = 1;
}
// Return the current material list (passed in to ParseScene())
inline std::vector<osg::ref_ptr<osg::StateSet> >* getMaterials()
{
return _materials;
}
// New to TerraPage 2.0 - local materials
std::vector<osg::ref_ptr<osg::StateSet> >* getLocalMaterials()
{
return &_localMaterials;
}
// Load local materials
void loadLocalMaterials();
// Return the current model list
std::vector<osg::ref_ptr<osg::Node> >* getModels()
{
return _models;
}
// Request a model to be load
bool requestModel(int ix);
// Return a reference to the tile header (after a tile has been read)
inline trpgTileHeader *getTileHeaderRef()
{
return &_tileHeader;
}
// Returns true if we are under billboard subgraph
inline const bool underBillboardSubgraph() const
{
return _underBillboardSubgraph;
}
// Sets if we are under billboard subgraph
inline void setUnderBillboardSubgraph(bool b)
{
_underBillboardSubgraph = b;
}
// TXP Billboard info
struct TXPBillboardInfo
{
int type;
int mode;
trpg3dPoint center;
trpg3dPoint axis;
};
//----------------------------------------------------------------------------
class groupRead : public trpgr_Callback {
public:
groupRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
// Sets info for the last billboard parsed
inline void setLastBillboardInfo(TXPBillboardInfo& info)
{
_lastBillboardInfo = info;
}
//----------------------------------------------------------------------------
class lodRead : public trpgr_Callback {
public:
lodRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class tileHeaderRead : public trpgr_Callback {
public:
tileHeaderRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class modelRefRead : public trpgr_Callback {
public:
modelRefRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class billboardRead : public trpgr_Callback {
public:
billboardRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class lightRead: public trpgr_Callback {
public:
lightRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
// Gets info for the last billboard parsed
inline void getLastBillboardInfo(TXPBillboardInfo& info)
{
info = _lastBillboardInfo;
}
//----------------------------------------------------------------------------
class layerRead: public trpgr_Callback {
public:
layerRead(TXPParser *in_parse) : _parse(in_parse) {};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
// Gets light attrib
DefferedLightAttribute& getLightAttribute(int ix);
// Returns if we are under layer subgraph
inline const bool underLayerSubgraph() const
{
return _underLayerSubgraph;
}
// Sets if we are under layer subgraph
inline void setUnderLayerSubgraph(bool b)
{
_underLayerSubgraph = b;
}
// Set the current layer geode
inline void setLayerGeode(osg::Geode* layer)
{
_layerGeode = layer;
}
// Returns the current layer geode
inline osg::Geode* getLayerGeode() const
{
return _layerGeode;
}
// default value to use when setting up textures.
void setMaxAnisotropy(float anisotropy)
{
_defaultMaxAnisotropy = anisotropy;
}
float getMaxAnisotropy() const
{
return _defaultMaxAnisotropy;
}
// We need to change the LOD ranges within tiles since
// we have done it for the PagedLODs representing tiles
inline double checkAndGetMinRange(double range)
{
if ((range-_realMinRange) < 0.0001)
return 0.0;
else
return range;
}
inline double checkAndGetMaxRange(double range)
{
if ((range-_realMaxRange) < 0.0001)
return _usedMaxRange;
else
return range;
}
protected:
virtual ~TXPParser();
// Removes any empty groups and LODs
void removeEmptyGroups();
// Called on start children
bool StartChildren(void *);
// Called on end children
bool EndChildren(void *);
// THE archive
TXPArchive *_archive;
// Current parent
osg::Group* _currentTop;
// The root of the tile
osg::ref_ptr<osg::Group> _root;
// Parents list
std::stack<osg::Group*> _parents;
// Potentional Tile groups
std::map<osg::Group*,int> _tileGroups;
// Replace the tile lod to regular group
void replaceTileLod(osg::Group*);
// Materials
std::vector<osg::ref_ptr<osg::StateSet> >* _materials;
// Local materials
std::vector<osg::ref_ptr<osg::StateSet> > _localMaterials;
// Model list
std::vector<osg::ref_ptr<osg::Node> >* _models;
// Tile header
trpgTileHeader _tileHeader;
// true if we are under billboard subgraph
bool _underBillboardSubgraph;
// Number of levels below the billboard node
int _numBillboardLevels;
// Last billboard we parsed
TXPBillboardInfo _lastBillboardInfo;
// true if we are under layer subgraph
bool _underLayerSubgraph;
// Numbers of levels below layer subgraph
int _numLayerLevels;
// Our Layer Geode
osg::Geode* _layerGeode;
// default value to use when setting up textures.
float _defaultMaxAnisotropy;
// LOD ranges to be used when parsing tiles
double _realMinRange;
double _realMaxRange;
double _usedMaxRange;
// TEMP
osg::Geode* createBoundingBox(int x,int y, int lod);
};
//! callback functions for various scene graph elements
//----------------------------------------------------------------------------
class geomRead : public trpgr_Callback
{
public:
geomRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class groupRead : public trpgr_Callback
{
public:
groupRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class lodRead : public trpgr_Callback
{
public:
lodRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class tileHeaderRead : public trpgr_Callback
{
public:
tileHeaderRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class modelRefRead : public trpgr_Callback
{
public:
modelRefRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class billboardRead : public trpgr_Callback
{
public:
billboardRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class lightRead: public trpgr_Callback
{
public:
lightRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
//----------------------------------------------------------------------------
class layerRead: public trpgr_Callback
{
public:
layerRead(TXPParser *in_parse) : _parse(in_parse)
{};
void *Parse(trpgToken tok,trpgReadBuffer &buf);
protected:
TXPParser *_parse;
};
} // namespace
#endif // __TXPPARSER_H_

View File

@@ -5,7 +5,6 @@
using namespace txp;
TXPSeamLOD::TXPSeamLOD() :
Group()
{
@@ -38,7 +37,6 @@ TXPSeamLOD::TXPSeamLOD(const TXPSeamLOD& ttg,const osg::CopyOp& copyop) :
_neighbourTileX = ttg._neighbourTileX;
_neighbourTileY = ttg._neighbourTileY;
_neighbourTileLOD = ttg._neighbourTileLOD;
_tileRef = ttg._tileRef;
_archive = ttg._archive;
}
@@ -47,9 +45,7 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv)
{
if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR && _children.size()==2)
{
float distance = nv.getDistanceToEyePoint(_center,true);
if (distance<_mid)
{
// cap the lod's that can be used to what is available in the adjacent PagedLOD.
@@ -61,10 +57,10 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv)
{
getChild(0)->accept(nv);
}
}
else
{
Group::traverse(nv);
}
}

View File

@@ -1,17 +1,17 @@
/* **************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The basic code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
/***************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
*****************************************************************************/
/* **************************************************************************
* OpenSceneGraph loader for Terrapage format database
/***************************************************************************
* OpenSceneGraph loader for Terrapage format database
* by Boris Bralo 2002
*
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
@@ -31,6 +31,7 @@
* All Rights Reserved.
*
*****************************************************************************/
#ifndef TXPSeamLOD_H
#define TXPSeamLOD_H
@@ -43,48 +44,61 @@
namespace txp
{
class TXPSeamLOD : public osg::Group
{
public:
TXPSeamLOD();
TXPSeamLOD(int x, int y, int lod, const osg::Vec3& center, float dmin, float dmid, float dmax);
TXPSeamLOD(const TXPSeamLOD&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
TXPSeamLOD();
META_Node(txp, TXPSeamLOD);
TXPSeamLOD(int x, int y, int lod, const osg::Vec3& center, float dmin,
float dmid, float dmax);
virtual void traverse(osg::NodeVisitor& nv);
TXPSeamLOD(const TXPSeamLOD&,
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
void setTileRef(bool* b)
{
_tileRef = b;
}
META_Node(txp, TXPSeamLOD);
void setTxpNode(TXPTileNode* txpNode) { _txpNode = txpNode; }
TXPTileNode* getTxpNode() const { return _txpNode; }
virtual void traverse(osg::NodeVisitor& nv);
void setArchive(TXPArchive* ar) { _archive = ar; }
void setTileRef(bool* b)
{
_tileRef = b;
}
void setTxpNode(TXPTileNode* txpNode)
{
_txpNode = txpNode;
}
TXPTileNode* getTxpNode() const
{
return _txpNode;
}
void setArchive(TXPArchive* ar)
{
_archive = ar;
}
protected:
int _neighbourTileX;
int _neighbourTileY;
int _neighbourTileLOD;
int _neighbourTileX;
int _neighbourTileY;
int _neighbourTileLOD;
osg::Vec3 _center;
float _min;
float _mid;
float _max;
osg::Vec3 _center;
bool* _tileRef;
float _min;
float _mid;
float _max;
TXPTileNode* _txpNode;
TXPArchive* _archive;
bool* _tileRef;
TXPTileNode* _txpNode;
TXPArchive* _archive;
};
}
#endif

View File

@@ -147,7 +147,10 @@ bool TXPTileNode::loadTile(int x, int y, int lod)
if (validTile)
{
osg::Group* tileGroup = _archive->getTileContent(x,y,lod);
double realMinRange = info.minRange;
double realMaxRange = info.maxRange;
double usedMaxRange = osg::maximum(info.maxRange,1e7);
osg::Group* tileGroup = _archive->getTileContent(x,y,lod,realMinRange,realMaxRange,usedMaxRange);
// if group has only one child, then simply use its child.
@@ -190,7 +193,7 @@ bool TXPTileNode::loadTile(int x, int y, int lod)
_archive->getId()
);
osg::PagedLOD* pagedLOD = new osg::PagedLOD;
osg::ref_ptr<osg::PagedLOD> pagedLOD = new osg::PagedLOD;
// not use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out.
pagedLOD->addChild(tileGroup,info.minRange,osg::maximum(info.maxRange,1e7));
pagedLOD->setFileName(1,pagedLODfile);
@@ -199,9 +202,9 @@ bool TXPTileNode::loadTile(int x, int y, int lod)
pagedLOD->setRadius(info.radius);
pagedLOD->setNumChildrenThatCannotBeExpired(1);
TileMapper::instance()->insertPagedLOD(x,y,lod,pagedLOD);
TileMapper::instance()->insertPagedLOD(x,y,lod,pagedLOD.get());
addChild(pagedLOD);
addChild(pagedLOD.get());
}
else
{

View File

@@ -1,17 +1,17 @@
/* **************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
/***************************************************************************
* December 2003
*
* This TerraPage loader was re-written in a fashion to use PagedLOD
* to manage paging entirely, also includes a version of Terrex's smart mesh
* adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
* slight modified.
* nick at terrex dot com
*
* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
*****************************************************************************/
/* **************************************************************************
* OpenSceneGraph loader for Terrapage format database
/***************************************************************************
* OpenSceneGraph loader for Terrapage format database
* by Boris Bralo 2002
*
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
@@ -39,29 +39,30 @@
namespace txp
{
class TXPArchive;
class TXPTileNode : public osg::Group
{
public:
TXPTileNode();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TXPTileNode(const TXPTileNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
class TXPArchive;
class TXPTileNode : public osg::Group
{
public:
TXPTileNode();
META_Node(txp, TXPTileNode);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TXPTileNode(const TXPTileNode&,
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
void setArchive(TXPArchive* archive);
bool loadTile(int x, int y, int lod);
META_Node(txp, TXPTileNode);
osg::Node* seamReplacement(osg::Node* child,int x, int y, int level, TXPArchive::TileInfo& info);
void setArchive(TXPArchive* archive);
bool loadTile(int x, int y, int lod);
protected:
virtual ~TXPTileNode();
osg::Node* seamReplacement(osg::Node* child, int x, int y, int level,
TXPArchive::TileInfo& info);
TXPArchive* _archive;
};
protected:
virtual ~TXPTileNode();
TXPArchive* _archive;
};
} // namespace
#endif // __TXPTILENODE_H_

View File

@@ -11,53 +11,62 @@
namespace txp
{
class TileMapper : public osg::Referenced
class TileMapper : public osg::Referenced
{
public:
static TileMapper* instance();
osg::PagedLOD* getPagedLOD(int x, int y, int lod);
void insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod);
void removePagedLOD(int x, int y, int lod);
void prunePagedLOD();
protected:
// Constructor
TileMapper()
{}
// Destructor
virtual ~TileMapper()
{}
struct TileTriple
{
public:
static TileMapper* instance();
osg::PagedLOD* getPagedLOD(int x, int y, int lod);
void insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod);
void removePagedLOD(int x, int y, int lod);
void prunePagedLOD();
protected:
// Constructor
TileMapper() {}
// Destructor
virtual ~TileMapper() {}
struct TileTriple
TileTriple(int ax, int ay, int alod):
x(ax),y(ay),lod(alod)
{}
int x,y,lod;
bool operator < (const TileTriple& rhs) const
{
TileTriple(int ax, int ay, int alod):
x(ax),y(ay),lod(alod) {}
int x,y,lod;
bool operator < (const TileTriple& rhs) const
{
if (x<rhs.x) return true;
if (x>rhs.x) return false;
if (y<rhs.y) return true;
if (y>rhs.y) return false;
if (lod<rhs.lod) return true;
if (lod>rhs.lod) return false;
if (x<rhs.x)
return true;
if (x>rhs.x)
return false;
}
};
typedef std::map< TileTriple, osg::ref_ptr<osg::PagedLOD> > TileMap;
OpenThreads::Mutex _mutex;
TileMap _tileMap;
if (y<rhs.y)
return true;
if (y>rhs.y)
return false;
if (lod<rhs.lod)
return true;
if (lod>rhs.lod)
return false;
return false;
}
};
typedef std::map< TileTriple, osg::ref_ptr<osg::PagedLOD> > TileMap;
OpenThreads::Mutex _mutex;
TileMap _tileMap;
};
} // namespace