odeTriMeshData.h 4.5 KB

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