odeTriMeshData.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Filename: odeTriMeshData.h
  2. // Created by: joswilso (27Dec06)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef ODETRIMESHDATA_H
  15. #define ODETRIMESHDATA_H
  16. #include "pandabase.h"
  17. #include "typedReferenceCount.h"
  18. #include "luse.h"
  19. #include "ode_includes.h"
  20. #include "nodePathCollection.h"
  21. #include "geomNode.h"
  22. #include "geomVertexData.h"
  23. #include "geomVertexReader.h"
  24. #include "geomTriangles.h"
  25. #include "geomTristrips.h"
  26. ////////////////////////////////////////////////////////////////////
  27. // Class : OdeTriMeshData
  28. // Description :
  29. ////////////////////////////////////////////////////////////////////
  30. class EXPCL_PANDAODE OdeTriMeshData : public TypedReferenceCount {
  31. public:
  32. static void link_data(dGeomID id, PT(OdeTriMeshData) data);
  33. static PT(OdeTriMeshData) get_data(dGeomID id);
  34. static void unlink_data(dGeomID id);
  35. static void remove_data(OdeTriMeshData *data);
  36. static void print_data(const string &marker);
  37. private:
  38. typedef pmap<dGeomID, PT(OdeTriMeshData)> TriMeshDataMap;
  39. static TriMeshDataMap _tri_mesh_data_map;
  40. PUBLISHED:
  41. enum DataType { DT_face_normals = 0,
  42. DT_last_transformation };
  43. OdeTriMeshData(const NodePath& model, bool use_normals = false);
  44. virtual ~OdeTriMeshData();
  45. void destroy();
  46. // INLINE void set(int data_id, void* in_data);
  47. // INLINE void* get(int data_id);
  48. // INLINE void get_buffer(unsigned char** buf, int* buf_len) const;
  49. // INLINE void set_buffer(unsigned char* buf);
  50. // INLINE void update();
  51. virtual void write(ostream &out = cout, unsigned int indent=0) const;
  52. void write_faces(ostream &out) const;
  53. public:
  54. INLINE void build_single(const void* vertices, int vertex_stride, int vertex_count, \
  55. const void* indices, int index_count, int tri_stride);
  56. INLINE void build_single1(const void* vertices, int vertex_stride, int vertex_count, \
  57. const void* indices, int index_count, int tri_stride, \
  58. const void* normals);
  59. INLINE void build_double(const void* vertices, int vertex_stride, int vertex_count, \
  60. const void* indices, int index_count, int tri_stride);
  61. INLINE void build_double1(const void* vertices, int vertex_stride, int vertex_count, \
  62. const void* indices, int index_count, int tri_stride, \
  63. const void* normals);
  64. // Temporarily commenting these two out--ODE had an API change from
  65. // (int *indices) to (dTriIndex *indices). But since there's no
  66. // #define that indicates the ODE version, we don't have any way to
  67. // automatically put the right symbol in here. However, we're not
  68. // using these methods right now anyway.
  69. /*
  70. INLINE void build_simple(const dReal* vertices, int vertex_count, \
  71. const int* indices, int index_count);
  72. INLINE void build_simple1(const dReal* vertices, int vertex_count, \
  73. const int* indices, int index_count, \
  74. const int* normals);
  75. */
  76. INLINE void preprocess();
  77. INLINE dTriMeshDataID get_id() const;
  78. private:
  79. void process_model(const NodePath& model, bool &use_normals);
  80. void process_geom_node(const GeomNode *geomNode);
  81. void process_geom(const Geom *geom);
  82. void process_primitive(const GeomPrimitive *primitive,
  83. CPT(GeomVertexData) vData);
  84. void analyze(const GeomNode *geomNode);
  85. void analyze(const Geom *geom);
  86. void analyze(const GeomPrimitive *geom);
  87. OdeTriMeshData(const OdeTriMeshData &other);
  88. void operator = (const OdeTriMeshData &other);
  89. protected:
  90. struct StridedVertex{
  91. dReal Vertex[3];
  92. };
  93. struct StridedTri{
  94. int Indices[3];
  95. };
  96. struct FaceNormal{
  97. dVector3 Normal;
  98. };
  99. dTriMeshDataID _id;
  100. StridedVertex *_vertices;
  101. StridedTri *_faces;
  102. FaceNormal *_normals;
  103. unsigned int _num_vertices;
  104. unsigned int _num_faces;
  105. public:
  106. static TypeHandle get_class_type() {
  107. return _type_handle;
  108. }
  109. static void init_type() {
  110. TypedReferenceCount::init_type();
  111. register_type(_type_handle, "OdeTriMeshData",
  112. TypedReferenceCount::get_class_type());
  113. }
  114. virtual TypeHandle get_type() const {
  115. return get_class_type();
  116. }
  117. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  118. private:
  119. static TypeHandle _type_handle;
  120. };
  121. #include "odeTriMeshData.I"
  122. #endif