Panda3D
 All Classes Functions Variables Enumerations
odeTriMeshData.h
00001 // Filename: odeTriMeshData.h
00002 // Created by:  joswilso (27Dec06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
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 //       Class : OdeTriMeshData
00033 // Description : 
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   // INLINE void set(int data_id, void* in_data);
00059   // INLINE void* get(int data_id);
00060   // INLINE void get_buffer(unsigned char** buf, int* buf_len) const;
00061   // INLINE void set_buffer(unsigned char* buf);
00062   // INLINE void update();
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   // Temporarily commenting these two out--ODE had an API change from
00079   // (int *indices) to (dTriIndex *indices).  But since there's no
00080   // #define that indicates the ODE version, we don't have any way to
00081   // automatically put the right symbol in here.  However, we're not
00082   // using these methods right now anyway.
00083 
00084   /*
00085   INLINE void build_simple(const dReal* vertices, int vertex_count, \
00086                            const int* indices, int index_count);
00087   INLINE void build_simple1(const dReal* vertices, int vertex_count, \
00088                             const int* indices, int index_count, \
00089                             const int* normals);
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
 All Classes Functions Variables Enumerations