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