home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5164 / miletos.7z / meshbsp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2011-04-02  |  1.9 KB  |  98 lines

  1. #ifndef __MILETOS_MESHBSP_H__
  2. #define __MILETOS_MESHBSP_H__
  3.  
  4. //
  5. // Libmiletos
  6. //
  7. // Copyright (C) Lauris Kaplinski 2007
  8. //
  9.  
  10. #include <vector>
  11.  
  12. #include <miletos/uri.h>
  13. #include <miletos/scene.h>
  14. #include <miletos/geometry.h>
  15.  
  16. namespace Miletos {
  17.  
  18. class BSPData;
  19.  
  20. class MeshBSP : public Item {
  21. private:
  22.     // Data container
  23.     BSPData *bdata;
  24.  
  25.     struct Vertex {
  26.         Elea::Vector3f p;
  27.         Elea::Vector3f n;
  28.         Elea::Vector2f td;
  29.         Elea::Vector2f tl;
  30.         Elea::Color4f c;
  31.     };
  32.     // Local list of vertices (original and generated)
  33.     std::vector<Vertex> vertices;
  34.     // Local list of indices (original and generated)
  35.     std::vector<int> indices;
  36.  
  37.     struct Face {
  38.         int matidx;
  39.         int vertexbase;
  40.         int firstindex;
  41.         int nindices;
  42.     };
  43.     // Local 8cleaned and generated) list of faces
  44.     std::vector<Face> faces;
  45.  
  46.     struct FaceList {
  47.         int matidx;
  48.         std::vector<int> faces;
  49.     };
  50.  
  51.     struct Leaf {
  52.         Elea::Cuboid3f bbox;
  53.         std::vector<FaceList> lists;
  54.     };
  55.     // Local version of leaves
  56.     std::vector<Leaf> leaves;
  57.  
  58.     struct Material {
  59.         std::string id;
  60.         int textureidx;
  61.         int lmapidx;
  62.     };
  63.     std::vector<Material> materials;
  64.  
  65.     // Array of texture images
  66.     int _npixblocks;
  67.     NR::PixBlock *_pixblocks;
  68.  
  69.     // Object implementation
  70.     virtual const Type *objectType (void);
  71.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  72.     virtual void release (void);
  73.     virtual void set (const char *attrid, const char *val);
  74.     virtual void update (UpdateCtx *ctx, unsigned int flags);
  75.     // Item implementation
  76.     virtual Sehle::Renderable *show (Sehle::Graph *graph, Sehle::u32 contextmask);
  77.     virtual Item *trace (const Elea::Line3f *wray, unsigned int mask, float *distance);
  78.  
  79.     // Helpers
  80.     void clear (void);
  81.     void resetInternalData (void);
  82.     bool loadData (void);
  83.     void buildMesh (Sehle::StaticMesh *mesh);
  84.     int findLeaf (int nodeidx, const Elea::Vector3f *p);
  85.     bool isVisible (int from, int what);
  86. public:
  87.  
  88.     MeshBSP (void);
  89.  
  90.     // Type system
  91.     static const Type *type (void);
  92. };
  93.  
  94. } // Namespace Miletos
  95.  
  96. #endif
  97.  
  98.