2002-02-08 17:30:02 +08:00
|
|
|
/* ************************
|
|
|
|
Copyright Terrain Experts Inc.
|
|
|
|
Terrain Experts Inc (TERREX) reserves all rights to this source code
|
2002-03-09 18:51:09 +08:00
|
|
|
unless otherwise specified in writing by the President of TERREX.
|
2002-02-08 17:30:02 +08:00
|
|
|
This copyright may be updated in the future, in which case that version
|
|
|
|
supercedes this one.
|
|
|
|
-------------------
|
|
|
|
Terrex Experts Inc.
|
2002-03-09 18:51:09 +08:00
|
|
|
4400 East Broadway #314
|
|
|
|
Tucson, AZ 85711
|
2002-02-08 17:30:02 +08:00
|
|
|
info@terrex.com
|
2002-03-09 18:51:09 +08:00
|
|
|
Tel: (520) 323-7990
|
2002-02-08 17:30:02 +08:00
|
|
|
************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _txpage_scene_h_
|
|
|
|
// {secret}
|
|
|
|
#define _txpage_scene_h_
|
|
|
|
|
|
|
|
/* trpage_scene.h
|
2002-02-10 18:42:55 +08:00
|
|
|
Scene Graph definition.
|
|
|
|
This is a small scene graph we use for testing.
|
|
|
|
It's not intended to replace the scene graph you may already be using.
|
|
|
|
You do not need to translate from this scene graph structure to your own,
|
|
|
|
at run-time. Instead, use this file and trpage_scene.cpp as a guideline
|
|
|
|
for how to read TerraPage format into your own scene graph.
|
2002-02-08 17:30:02 +08:00
|
|
|
*/
|
|
|
|
|
2002-11-25 05:36:05 +08:00
|
|
|
#include <osgTXP/trpage_geom.h>
|
2002-02-08 17:30:02 +08:00
|
|
|
|
|
|
|
/*
|
2002-02-10 18:42:55 +08:00
|
|
|
{group:Demonstration Scene Graph}
|
|
|
|
*/
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgMBR {
|
|
|
|
public:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgMBR(void);
|
|
|
|
~trpgMBR(void) { };
|
2002-03-09 18:51:09 +08:00
|
|
|
bool isValid(void) const;
|
|
|
|
void Reset(void);
|
2002-02-10 18:42:55 +08:00
|
|
|
void AddPoint(const trpg3dPoint &);
|
|
|
|
void AddPoint(double,double,double);
|
|
|
|
void GetMBR(trpg3dPoint &ll,trpg3dPoint &ur) const;
|
2002-03-09 18:51:09 +08:00
|
|
|
trpg3dPoint GetLL(void) const;
|
|
|
|
trpg3dPoint GetUR(void) const;
|
2002-02-10 18:42:55 +08:00
|
|
|
void Union(const trpgMBR &);
|
|
|
|
// bool Overlap(const trpgMBR &) const;
|
|
|
|
bool Overlap(const trpg2dPoint &ll, const trpg2dPoint &ur) const;
|
|
|
|
// bool Within(const trpg3dPoint &) const
|
|
|
|
bool Within(const trpg2dPoint &) const;
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
inline bool inRange(double minv,double maxv,double val) const { return (val >= minv && val <= maxv); }
|
|
|
|
bool valid;
|
|
|
|
trpg3dPoint ll,ur;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Node
|
|
|
|
// Simple Scenegraph node used for read testing
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadNode {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
virtual ~trpgReadNode(void) { };
|
|
|
|
virtual bool isGroupType(void) = 0;
|
|
|
|
virtual int GetType(void) { return type; }
|
|
|
|
virtual trpgMBR GetMBR(void) const { return trpgMBR(); }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
int type;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Group Base
|
|
|
|
// Base class for all group nodes
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadGroupBase : public trpgReadNode {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
virtual ~trpgReadGroupBase(void);
|
2002-02-10 18:42:55 +08:00
|
|
|
void AddChild(trpgReadNode *);
|
2002-03-09 18:51:09 +08:00
|
|
|
bool isGroupType(void) { return true; }
|
|
|
|
int GetNumChildren(void) { return children.size(); }
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgReadNode *GetChild(int i) { return children[i]; }
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgMBR GetMBR(void) const;
|
2002-02-10 18:42:55 +08:00
|
|
|
void unRefChild(int i);
|
2002-03-09 18:51:09 +08:00
|
|
|
void unRefChildren(void);
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgMBR mbr;
|
2002-03-09 18:51:09 +08:00
|
|
|
void DeleteChildren(void);
|
|
|
|
std::vector<trpgReadNode *> children;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Geometry
|
|
|
|
// The leaf for this scene graph
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadGeometry : public trpgReadNode {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadGeometry(void) { type = TRPG_GEOMETRY; }
|
|
|
|
~trpgReadGeometry(void) { };
|
|
|
|
bool isGroupType(void) { return false; }
|
|
|
|
trpgGeometry *GetData(void) { return &data; }
|
|
|
|
trpgMBR GetMBR(void) const;
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgMBR mbr;
|
|
|
|
trpgGeometry data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Tile Header
|
|
|
|
// One per tile. Info about what materials and models are used
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadTileHeader : public trpgReadNode {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadTileHeader(void) { type = TRPGTILEHEADER; }
|
|
|
|
~trpgReadTileHeader(void) { };
|
|
|
|
bool isGroupType(void) { return false; }
|
|
|
|
trpgTileHeader *GetData(void) { return &data; }
|
|
|
|
trpgMBR GetMBR(void) const { trpgMBR mbr; return mbr; };
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgTileHeader data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Group
|
|
|
|
// Simple group structure
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadGroup : public trpgReadGroupBase {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadGroup(void) { type = TRPG_GROUP; }
|
|
|
|
~trpgReadGroup(void) { };
|
|
|
|
trpgGroup *GetData(void) { return &data; }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgGroup data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Attach
|
|
|
|
// Should be the top of a higher LOD tile
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadAttach : public trpgReadGroupBase {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadAttach(void) { type = TRPG_ATTACH; }
|
|
|
|
~trpgReadAttach(void) { };
|
|
|
|
trpgAttach *GetData(void) { return &data; }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgAttach data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read billboard
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadBillboard : public trpgReadGroupBase {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadBillboard(void) { type = TRPG_BILLBOARD; }
|
|
|
|
~trpgReadBillboard(void) { };
|
|
|
|
trpgBillboard *GetData(void) { return &data; }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgBillboard data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read LOD
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadLod : public trpgReadGroupBase {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadLod(void) { type = TRPG_LOD; }
|
|
|
|
~trpgReadLod(void) { };
|
|
|
|
trpgLod *GetData(void) { return &data; }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgLod data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Layer
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadLayer : public trpgReadGroupBase {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadLayer(void) { type = TRPG_LAYER; }
|
|
|
|
~trpgReadLayer(void) { };
|
|
|
|
trpgLayer *GetData(void) { return &data; }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgLayer data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Transform
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadTransform : public trpgReadGroupBase {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadTransform(void) { type = TRPG_TRANSFORM; }
|
|
|
|
~trpgReadTransform(void) { };
|
|
|
|
trpgTransform *GetData(void) { return &data; }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgTransform data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Read Model Reference
|
2002-02-10 18:42:55 +08:00
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgReadModelRef : public trpgReadGroupBase {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadModelRef(void) { type = TRPG_MODELREF; }
|
|
|
|
~trpgReadModelRef(void) { };
|
|
|
|
trpgModelRef *GetData(void) { return &data; }
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
trpgModelRef data;
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Scene Graph Parser
|
2002-02-10 18:42:55 +08:00
|
|
|
Parses a read buffer and returns a full scenegraph.
|
|
|
|
You don't want to use this if you're reading into your own scenegraph.
|
|
|
|
Instead, you'll want to sublcass trpgSceneParser, which is a helper
|
|
|
|
class to keep track of pushes and pops and implement the same functionality
|
|
|
|
that trpgSceneGraphParser has for your own scene graph.
|
|
|
|
*/
|
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_EXDECL class TX_CLDECL trpgSceneGraphParser : public trpgSceneParser {
|
|
|
|
public:
|
2002-03-09 18:51:09 +08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
typedef std::map<int,trpgReadGroupBase *> GroupMap;
|
2002-02-08 17:30:02 +08:00
|
|
|
#else
|
2002-04-16 23:21:24 +08:00
|
|
|
typedef std::map<int,trpgReadGroupBase *,std::less<int> > GroupMap;
|
2002-02-08 17:30:02 +08:00
|
|
|
#endif
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgSceneGraphParser(void);
|
|
|
|
virtual ~trpgSceneGraphParser(void) { };
|
2002-02-10 18:42:55 +08:00
|
|
|
// Call this instead of Parse()
|
|
|
|
// Deleting it is your responsibility
|
|
|
|
trpgReadNode *ParseScene(trpgReadBuffer &,GroupMap &);
|
2002-03-09 18:51:09 +08:00
|
|
|
trpgReadGroupBase *GetCurrTop(void); // Get the current parent object
|
|
|
|
trpgReadTileHeader *GetTileHeaderRef(void);
|
2002-02-10 18:42:55 +08:00
|
|
|
|
|
|
|
// For use by the helpers only
|
2002-03-09 18:51:09 +08:00
|
|
|
GroupMap *GetGroupMap(void);
|
2002-02-08 17:30:02 +08:00
|
|
|
protected:
|
2002-02-10 18:42:55 +08:00
|
|
|
bool StartChildren(void *);
|
|
|
|
bool EndChildren(void *);
|
|
|
|
trpgReadNode *currTop; // Current parent group
|
|
|
|
trpgReadNode *top; // Top of everything
|
|
|
|
GroupMap *gmap;
|
|
|
|
trpgReadTileHeader tileHead; // Tile header gets read into here
|
2002-02-08 17:30:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Test Archive
|
2002-02-10 18:42:55 +08:00
|
|
|
Utility function that loads and tests all tiles.
|
|
|
|
The only reason you'd want to call this is to test a TerraPage archive
|
|
|
|
you'd written.
|
|
|
|
*/
|
|
|
|
// {group:Demonstration Scene Graph}
|
2002-02-08 17:30:02 +08:00
|
|
|
TX_CPPDECL bool trpgTestArchive(trpgr_Archive &);
|
|
|
|
|
|
|
|
#endif
|