Panda3D
 All Classes Functions Variables Enumerations
odeTriMeshData.h
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 
15 #ifndef ODETRIMESHDATA_H
16 #define ODETRIMESHDATA_H
17 
18 #include "pandabase.h"
19 #include "typedReferenceCount.h"
20 #include "luse.h"
21 
22 #include "ode_includes.h"
23 
24 #include "nodePathCollection.h"
25 #include "geomNode.h"
26 #include "geomVertexData.h"
27 #include "geomVertexReader.h"
28 #include "geomTriangles.h"
29 #include "geomTristrips.h"
30 
31 #include "config_ode.h"
32 
33 ////////////////////////////////////////////////////////////////////
34 // Class : OdeTriMeshData
35 // Description :
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDAODE OdeTriMeshData : public TypedReferenceCount {
38 public:
39  static void link_data(dGeomID id, PT(OdeTriMeshData) data);
40  static PT(OdeTriMeshData) get_data(dGeomID id);
41  static void unlink_data(dGeomID id);
42  static void remove_data(OdeTriMeshData *data);
43  static void print_data(const string &marker);
44 
45 private:
47  static TriMeshDataMap *_tri_mesh_data_map;
48  static INLINE TriMeshDataMap &get_tri_mesh_data_map();
49 
50 PUBLISHED:
51 
52  enum DataType { DT_face_normals = 0,
53  DT_last_transformation };
54 
55  OdeTriMeshData(const NodePath& model, bool use_normals = false);
56  virtual ~OdeTriMeshData();
57 
58  void destroy();
59 
60  // INLINE void set(int data_id, void* in_data);
61  // INLINE void* get(int data_id);
62  // INLINE void get_buffer(unsigned char** buf, int* buf_len) const;
63  // INLINE void set_buffer(unsigned char* buf);
64  // INLINE void update();
65 
66  virtual void write(ostream &out = cout, unsigned int indent=0) const;
67  void write_faces(ostream &out) const;
68 
69 public:
70  INLINE void build_single(const void* vertices, int vertex_stride, int vertex_count, \
71  const void* indices, int index_count, int tri_stride);
72  INLINE void build_single1(const void* vertices, int vertex_stride, int vertex_count, \
73  const void* indices, int index_count, int tri_stride, \
74  const void* normals);
75  INLINE void build_double(const void* vertices, int vertex_stride, int vertex_count, \
76  const void* indices, int index_count, int tri_stride);
77  INLINE void build_double1(const void* vertices, int vertex_stride, int vertex_count, \
78  const void* indices, int index_count, int tri_stride, \
79  const void* normals);
80 
81  // Temporarily commenting these two out--ODE had an API change from
82  // (int *indices) to (dTriIndex *indices). But since there's no
83  // #define that indicates the ODE version, we don't have any way to
84  // automatically put the right symbol in here. However, we're not
85  // using these methods right now anyway.
86 
87  /*
88  INLINE void build_simple(const dReal* vertices, int vertex_count, \
89  const int* indices, int index_count);
90  INLINE void build_simple1(const dReal* vertices, int vertex_count, \
91  const int* indices, int index_count, \
92  const int* normals);
93  */
94 
95  INLINE void preprocess();
96 
97  INLINE dTriMeshDataID get_id() const;
98 
99 private:
100  void process_model(const NodePath& model, bool &use_normals);
101  void process_geom_node(const GeomNode *geomNode);
102  void process_geom(const Geom *geom);
103  void process_primitive(const GeomPrimitive *primitive,
104  CPT(GeomVertexData) vData);
105  void analyze(const GeomNode *geomNode);
106  void analyze(const Geom *geom);
107  void analyze(const GeomPrimitive *geom);
108 
109  OdeTriMeshData(const OdeTriMeshData &other);
110  void operator = (const OdeTriMeshData &other);
111 
112 protected:
113  struct StridedVertex {
114  dReal Vertex[3];
115  };
116  struct StridedTri {
117  int Indices[3];
118  };
119  struct FaceNormal {
120  dVector3 Normal;
121  };
122 
123  dTriMeshDataID _id;
124  StridedVertex *_vertices;
125  StridedTri *_faces;
126  FaceNormal *_normals;
127 
128  unsigned int _num_vertices;
129  unsigned int _num_faces;
130 
131 public:
132  static TypeHandle get_class_type() {
133  return _type_handle;
134  }
135  static void init_type() {
136  TypedReferenceCount::init_type();
137  register_type(_type_handle, "OdeTriMeshData",
138  TypedReferenceCount::get_class_type());
139  }
140  virtual TypeHandle get_type() const {
141  return get_class_type();
142  }
143  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
144 
145 private:
146  static TypeHandle _type_handle;
147 };
148 
149 #include "odeTriMeshData.I"
150 
151 #endif
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Definition: geom.h:58
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37