00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef ODETRIMESHDATA_H
00016 #define ODETRIMESHDATA_H
00017
00018 #include "pandabase.h"
00019 #include "typedReferenceCount.h"
00020 #include "luse.h"
00021
00022 #include "ode_includes.h"
00023
00024 #include "nodePathCollection.h"
00025 #include "geomNode.h"
00026 #include "geomVertexData.h"
00027 #include "geomVertexReader.h"
00028 #include "geomTriangles.h"
00029 #include "geomTristrips.h"
00030
00031
00032
00033
00034
00035 class EXPCL_PANDAODE OdeTriMeshData : public TypedReferenceCount {
00036 public:
00037 static void link_data(dGeomID id, PT(OdeTriMeshData) data);
00038 static PT(OdeTriMeshData) get_data(dGeomID id);
00039 static void unlink_data(dGeomID id);
00040 static void remove_data(OdeTriMeshData *data);
00041 static void print_data(const string &marker);
00042
00043 private:
00044 typedef pmap<dGeomID, PT(OdeTriMeshData)> TriMeshDataMap;
00045 static TriMeshDataMap *_tri_mesh_data_map;
00046 static INLINE TriMeshDataMap &get_tri_mesh_data_map();
00047
00048 PUBLISHED:
00049
00050 enum DataType { DT_face_normals = 0,
00051 DT_last_transformation };
00052
00053 OdeTriMeshData(const NodePath& model, bool use_normals = false);
00054 virtual ~OdeTriMeshData();
00055
00056 void destroy();
00057
00058
00059
00060
00061
00062
00063 virtual void write(ostream &out = cout, unsigned int indent=0) const;
00064 void write_faces(ostream &out) const;
00065
00066 public:
00067 INLINE void build_single(const void* vertices, int vertex_stride, int vertex_count, \
00068 const void* indices, int index_count, int tri_stride);
00069 INLINE void build_single1(const void* vertices, int vertex_stride, int vertex_count, \
00070 const void* indices, int index_count, int tri_stride, \
00071 const void* normals);
00072 INLINE void build_double(const void* vertices, int vertex_stride, int vertex_count, \
00073 const void* indices, int index_count, int tri_stride);
00074 INLINE void build_double1(const void* vertices, int vertex_stride, int vertex_count, \
00075 const void* indices, int index_count, int tri_stride, \
00076 const void* normals);
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 INLINE void preprocess();
00092
00093 INLINE dTriMeshDataID get_id() const;
00094
00095 private:
00096 void process_model(const NodePath& model, bool &use_normals);
00097 void process_geom_node(const GeomNode *geomNode);
00098 void process_geom(const Geom *geom);
00099 void process_primitive(const GeomPrimitive *primitive,
00100 CPT(GeomVertexData) vData);
00101 void analyze(const GeomNode *geomNode);
00102 void analyze(const Geom *geom);
00103 void analyze(const GeomPrimitive *geom);
00104
00105 OdeTriMeshData(const OdeTriMeshData &other);
00106 void operator = (const OdeTriMeshData &other);
00107
00108 protected:
00109 struct StridedVertex{
00110 dReal Vertex[3];
00111 };
00112 struct StridedTri{
00113 int Indices[3];
00114 };
00115 struct FaceNormal{
00116 dVector3 Normal;
00117 };
00118
00119 dTriMeshDataID _id;
00120 StridedVertex *_vertices;
00121 StridedTri *_faces;
00122 FaceNormal *_normals;
00123
00124 unsigned int _num_vertices;
00125 unsigned int _num_faces;
00126
00127 public:
00128 static TypeHandle get_class_type() {
00129 return _type_handle;
00130 }
00131 static void init_type() {
00132 TypedReferenceCount::init_type();
00133 register_type(_type_handle, "OdeTriMeshData",
00134 TypedReferenceCount::get_class_type());
00135 }
00136 virtual TypeHandle get_type() const {
00137 return get_class_type();
00138 }
00139 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00140
00141 private:
00142 static TypeHandle _type_handle;
00143 };
00144
00145 #include "odeTriMeshData.I"
00146
00147 #endif