Panda3D

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 
00047 PUBLISHED:
00048 
00049   enum DataType { DT_face_normals = 0,
00050                   DT_last_transformation };
00051 
00052   OdeTriMeshData(const NodePath& model, bool use_normals = false);
00053   virtual ~OdeTriMeshData();
00054 
00055   void destroy();
00056   
00057   // INLINE void set(int data_id, void* in_data);
00058   // INLINE void* get(int data_id);
00059   // INLINE void get_buffer(unsigned char** buf, int* buf_len) const;
00060   // INLINE void set_buffer(unsigned char* buf);
00061   // INLINE void update();
00062   virtual void write(ostream &out = cout, unsigned int indent=0) const;
00063   void write_faces(ostream &out) const;
00064 
00065 public: 
00066   INLINE void build_single(const void* vertices, int vertex_stride, int vertex_count, \
00067                            const void* indices, int index_count, int tri_stride);
00068   INLINE void build_single1(const void* vertices, int vertex_stride, int vertex_count, \
00069                             const void* indices, int index_count, int tri_stride, \
00070                             const void* normals);
00071   INLINE void build_double(const void* vertices, int vertex_stride, int vertex_count, \
00072                            const void* indices, int index_count, int tri_stride);
00073   INLINE void build_double1(const void* vertices, int vertex_stride, int vertex_count, \
00074                             const void* indices, int index_count, int tri_stride, \
00075                             const void* normals);
00076 
00077   // Temporarily commenting these two out--ODE had an API change from
00078   // (int *indices) to (dTriIndex *indices).  But since there's no
00079   // #define that indicates the ODE version, we don't have any way to
00080   // automatically put the right symbol in here.  However, we're not
00081   // using these methods right now anyway.
00082 
00083   /*
00084   INLINE void build_simple(const dReal* vertices, int vertex_count, \
00085                            const int* indices, int index_count);
00086   INLINE void build_simple1(const dReal* vertices, int vertex_count, \
00087                             const int* indices, int index_count, \
00088                             const int* normals);
00089   */
00090   INLINE void preprocess();
00091 
00092   INLINE dTriMeshDataID get_id() const;
00093 
00094 private:
00095   void process_model(const NodePath& model, bool &use_normals);
00096   void process_geom_node(const GeomNode *geomNode);
00097   void process_geom(const Geom *geom);
00098   void process_primitive(const GeomPrimitive *primitive, 
00099                          CPT(GeomVertexData) vData);
00100   void analyze(const GeomNode *geomNode);
00101   void analyze(const Geom *geom);
00102   void analyze(const GeomPrimitive *geom);
00103 
00104   OdeTriMeshData(const OdeTriMeshData &other);
00105   void operator = (const OdeTriMeshData &other);
00106   
00107 protected:
00108   struct StridedVertex{
00109     dReal Vertex[3];
00110   };  
00111   struct StridedTri{
00112     int Indices[3];
00113   };
00114   struct FaceNormal{
00115     dVector3 Normal;
00116   };
00117 
00118   dTriMeshDataID _id;
00119   StridedVertex *_vertices;
00120   StridedTri *_faces;
00121   FaceNormal *_normals;
00122 
00123   unsigned int _num_vertices;
00124   unsigned int _num_faces;
00125 
00126 public:
00127   static TypeHandle get_class_type() {
00128     return _type_handle;
00129   }
00130   static void init_type() {
00131     TypedReferenceCount::init_type();
00132     register_type(_type_handle, "OdeTriMeshData",
00133                   TypedReferenceCount::get_class_type());
00134   }
00135   virtual TypeHandle get_type() const {
00136     return get_class_type();
00137   }
00138   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00139 
00140 private:
00141   static TypeHandle _type_handle;
00142 };
00143 
00144 #include "odeTriMeshData.I"
00145 
00146 #endif
 All Classes Functions Variables Enumerations