Panda3D

meshDrawer.h

00001 // Filename: meshDrawer.h
00002 // Created by:  treeform (19dec08)
00003 // Changes by:  treeform (12jan10)
00004 //
00005 ////////////////////////////////////////////////////////////////////
00006 //
00007 // PANDA 3D SOFTWARE
00008 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00009 //
00010 // All use of this software is subject to the terms of the revised BSD
00011 // license.  You should have received a copy of this license along
00012 // with this source code in a file named "LICENSE."
00013 //
00014 ////////////////////////////////////////////////////////////////////
00015 
00016 #ifndef MESHDRAWER_H
00017 #define MESHDRAWER_H
00018 
00019 #include "pandabase.h"
00020 #include "luse.h"
00021 #include "pandaNode.h"
00022 #include "pointerTo.h"
00023 #include "lpoint2.h"
00024 #include "lvecBase2.h"
00025 #include "pnmImage.h"
00026 #include "nodePath.h"
00027 #include "texture.h"
00028 #include "geomVertexFormat.h"
00029 #include "geomVertexArrayFormat.h"
00030 #include "geomVertexData.h"
00031 #include "geomVertexWriter.h"
00032 #include "geomVertexRewriter.h"
00033 #include "boundingVolume.h"
00034 
00035 #include "nodePathCollection.h"
00036 
00037 #include "geomTristrips.h"
00038 #include "geomTriangles.h"
00039 #include "geom.h"
00040 #include "geomNode.h"
00041 #include "nodePath.h"
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //       Class : MeshDrawer
00045 // Description : Mesh drawer creates a single geom object that can be
00046 //               shaped with different draw commands.  This is an 
00047 //               efficient way to render bunch of billboards, particles, 
00048 //               fast changing triangles.  Its implemented by recycling 
00049 //               same geom over and over again.  Max budget specifies 
00050 //               how many triangles are allowed.  Some uses of this 
00051 //               class can be : particle system, radar icons, health 
00052 //               bars, 2d icons, 2d ui, bullets, missile trails.  Any 
00053 //               that can be drawn with triangles can be drawn with 
00054 //               this class.  At the low level this uses the 
00055 //               GeomVertexRewriter's.  The internal geom consists of 
00056 //               vertex, normal, uv and color channels.
00057 ////////////////////////////////////////////////////////////////////
00058 class EXPCL_PANDA_GRUTIL MeshDrawer : public TypedObject {
00059 PUBLISHED:
00060   INLINE MeshDrawer();
00061   INLINE ~MeshDrawer();
00062 
00063   INLINE void set_budget(int budget);
00064   INLINE int get_budget();
00065 
00066   INLINE NodePath get_root();
00067 
00068   void begin(NodePath camera, NodePath render);
00069   INLINE void tri(LVector3f v1, LVector4f c1, LVector2f uv1,
00070                   LVector3f v2, LVector4f c2, LVector2f uv2,
00071                   LVector3f v3, LVector4f c3, LVector2f uv3);
00072                   
00073   void particle(LVector3f pos, LVector4f frame, float size, LVector4f color, float rotation);
00074   void blended_particle(LVector3f pos, LVector4f frame1, LVector4f frame2,
00075     float blend, float size, LVector4f color, float rotation);
00076   void billboard(LVector3f pos, LVector4f frame, float size, LVector4f color);
00077   void segment(LVector3f start, LVector3f stop, LVector4f frame, float thickness, LVector4f color);
00078   void cross_segment(LVector3f start, LVector3f stop, LVector4f frame, float thickness, LVector4f color);
00079   void uneven_segment(LVector3f start, LVector3f stop,
00080     LVector4f frame, float thickness_start, LVector4f color_start,
00081     float thickness_stop, LVector4f color_stop);
00082 
00083   void link_segment(LVector3f pos, LVector4f frame, float thickness, LVector4f color);
00084   void link_segment_end(LVector4f frame, LVector4f color);
00085 
00086   void explosion(LVector3f pos, LVector4f frame, float size, LVector4f color,
00087     int seed, int number, float distance);
00088   void stream(LVector3f start, LVector3f stop, LVector4f frame, float size, LVector4f color,
00089     int number, float offset);
00090   void geometry(NodePath node);
00091   void end();
00092 
00093 private:
00094 
00095   // use vars
00096   NodePath _root;
00097   NodePath _camera, _render;
00098   int _budget;
00099 
00100   // store regeneration geoms & nodes
00101   PT(Geom) _geom;
00102   PT(GeomNode) _geomnode;
00103   PT(GeomVertexData) _vdata;
00104   PT(GeomTriangles) _prim;
00105   CPT(GeomPrimitive) _dprim;
00106 
00107   // writers
00108   GeomVertexRewriter *_vertex;
00109   GeomVertexRewriter *_normal;
00110   GeomVertexRewriter *_uv;
00111   GeomVertexRewriter *_color;
00112 
00113   // billboard vectors
00114   LVector4f _colorv;
00115   LVector3f _normalv;
00116   LVector3f _eyePos;
00117   LVector3f _b1, _b2, _b3, _b4;
00118   LVector3f _up, _right;
00119 
00120   // clear indexes
00121   int _last_clear_index, _start_clear_index, _end_clear_index, _clear_index;
00122 
00123   // used for curves
00124   int _at_start;
00125   LVector3f _last_v1,_last_v2,_last_v3,_last_v4,_last_pos;
00126   float _last_thickness;
00127   LVector4f _last_color;
00128 
00129   // bounding volume
00130   PT(BoundingVolume) _bv;
00131 
00132   // private create all the needed geoms
00133   void generator(int budget);
00134 
00135 public:
00136   static TypeHandle get_class_type() {
00137     return _type_handle;
00138   }
00139   static void init_type() {
00140     TypedObject::init_type();
00141     register_type(_type_handle, "MeshDrawer",
00142                   TypedObject::get_class_type());
00143   }
00144   virtual TypeHandle get_type() const {
00145     return get_class_type();
00146   }
00147   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00148 
00149 private:
00150   static TypeHandle _type_handle;
00151 
00152 };
00153 
00154 #include "meshDrawer.I"
00155 
00156 #endif /*MESHDRAWER_H*/
 All Classes Functions Variables Enumerations