LightWrap++
AC++wrapperfortheLightWave3DSDK
meshinfo.h
Go to the documentation of this file.
1 #ifndef LWPP_MESHINFO_H
2 #define LWPP_MESHINFO_H
3 
4 #include <lwpp/debug.h>
5 #include <lwmeshes.h>
6 
7 namespace lwpp
8 {
9  class MeshPointScan;
10  class MeshPolygonScan;
13  class MeshInfo
14  {
15  protected:
16  LWMeshInfoID mesh;
17  const bool destroy;
18  MeshInfo(const MeshInfo &from) : mesh(from.mesh), destroy(false) {;}
19  MeshInfo& operator=(const MeshInfo &from)
20  {
21  if (this != &from)
22  {
23  mesh = from.mesh;
24  }
25  return *this;
26  }
27  public:
29 
34  MeshInfo(const LWMeshInfoID _mesh = 0, bool _destroy = false) : mesh(_mesh), destroy(_destroy) {;}
35  void setMeshInfo(const LWMeshInfoID _mesh)
36  {
37  mesh = _mesh;
38  }
39  ~MeshInfo(void)
40  {
41  if ((mesh) && (destroy) && (mesh->destroy != 0)) mesh->destroy(mesh);
42  }
43  int numPoints(void) const {return mesh->numPoints(mesh);}
44  int numPolygons(void) const {return mesh->numPolygons(mesh);}
45  size_t scanPoints(LWPntScanFunc *func, void *userData) const {return mesh->scanPoints(mesh, func, userData);}
46  size_t scanPolys(LWPolScanFunc *func, void *userData) const {return mesh->scanPolys(mesh, func, userData);}
47  void pntBasePos(LWPntID pnt, LWFVector pos) const {mesh->pntBasePos(mesh, pnt, pos);}
48  void pntOtherPos(LWPntID pnt, LWFVector pos) const {mesh->pntOtherPos(mesh, pnt, pos);}
49  void pntOtherPos(LWPntID pnt, LWDVector pos) const {
50  LWFVector tPos;
51  mesh->pntOtherPos(mesh, pnt, tPos);
52  pos[0] = (double)tPos[0];
53  pos[1] = (double)tPos[1];
54  pos[2] = (double)tPos[2];
55  }
56  void *pntVLookup(LWID id, const char*name) const {return mesh->pntVLookup(mesh, id, name);}
57  void *pntVLookup(LWID id, const std::string &name) const {return pntVLookup(id, name.c_str());}
58  int pntVSelect(void *vmap) const {return mesh->pntVSelect(mesh, vmap);}
59  bool pntVGet(LWPntID pnt, float *vector) const {return (mesh->pntVGet(mesh, pnt, vector) != 0);}
60  LWID polType(LWPolID id) const {return mesh->polType(mesh, id);}
61  int polSize(LWPolID id) const {return mesh->polSize(mesh, id);}
62  LWPntID polVertex(LWPolID id, int n) const {return mesh->polVertex(mesh, id, n);}
63  inline const char *polTag(LWPolID id, LWID tag) const {return mesh->polTag(mesh, id, tag);}
64  bool pntVPGet(LWPntID pnt, LWPolID pol, float *vector) const {return (mesh->pntVPGet(mesh, pnt, pol, vector) != 0);}
65  unsigned int polFlags(LWPolID pol) const {return mesh->polFlags(mesh, pol);}
66  int pntVIDGet(LWPntID pnt, float *vector, void *vmap) const {return mesh->pntVIDGet(mesh, pnt, vector, vmap);}
67  int pntVPIDGet(LWPntID pnt, LWPolID pol, float *vector, void *vmap) const {return mesh->pntVPIDGet(mesh, pnt, pol, vector, vmap);}
68  bool polBaseNormal(LWPolID polID, LWFVector out){ return (mesh->polBaseNormal(mesh, polID, out) != 0);}
69  bool polOtherNormal(LWPolID polID, LWFVector out){ return (mesh->polOtherNormal(mesh, polID, out) != 0);}
70  LWMeshIteratorID createMeshIterator(int type){ return (mesh->createMeshIterator(mesh, type)); }
71  void destroyMeshIterator(LWMeshIteratorID mid){ mesh->destroyMeshIterator(mesh, mid); }
72  LWPolID iterateMesh(LWMeshIteratorID mid){ return (LWPolID)(mesh->iterateMesh(mesh, mid)); }
73  LWPntID iterateMeshPnt(LWMeshIteratorID mid){ return (LWPntID)(mesh->iterateMesh(mesh, mid)); }
74  void resetMeshIterator(LWMeshIteratorID mid){ mesh->resetMeshIterator(mesh, mid); }
75 
76  int scanPolys(MeshPolygonScan *scanner);
77  bool isValid(void) const {return (mesh != 0);}
78  };
79 
81 
86 
88  {
89  protected:
94  virtual int scanFunc(LWPntID id) = 0;
95  public:
96  MeshPointScan (MeshInfo *_mi) : mi(_mi) {;}
97  static int LWPntScanFunc (void *userData, LWPntID id)
98  {
99  MeshPointScan *mps = static_cast<MeshPointScan *>(userData);
100  return mps->scanFunc(id);
101  }
102  };
103 
105 
110 
112  {
113  protected:
115  LWPolID polygon;
117  /*
118  * @return true to abort the scan
119  */
120  virtual bool evaluate() = 0;
122 
127  bool scanFunc(LWPolID id) {polygon = id; return evaluate();}
129  LWID polType(void) const {return mi->polType(polygon);}
130  int polSize(void) const {return mi->polSize(polygon);}
131  LWPntID polVertex(int n) const {return mi->polVertex(polygon,n);}
132  inline const char*polTag(LWID tag) const {return mi->polTag(polygon, tag);}
133  int pntVPGet(LWPntID pnt, float *vector) const {return mi->pntVPGet(pnt, polygon, vector);}
134  unsigned int polFlags(void) const {return mi->polFlags(polygon);}
135  int pntVPIDGet(LWPntID pnt, float *vector, void *vmap) const {return mi->pntVPIDGet(pnt, polygon, vector, vmap);}
136 
137  public:
138  virtual ~MeshPolygonScan() {;}
139  void setMeshInfo(MeshInfo *_mi) {mi = _mi;}
141  static size_t LWPolyScanFunc (void *userData, LWPolID id)
142  {
143  MeshPolygonScan *mps = static_cast<MeshPolygonScan *>(userData);
144  return mps->scanFunc(id);
145  }
146  };
147 }
148 
149 #endif //LWPP_MESHINFO_H