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(const LVector3 &v1, const LVector4 &c1, const LVector2 &uv1,
00070                   const LVector3 &v2, const LVector4 &c2, const LVector2 &uv2,
00071                   const LVector3 &v3, const LVector4 &c3, const LVector2 &uv3);
00072                   
00073   void particle(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color, PN_stdfloat rotation);
00074   void blended_particle(const LVector3 &pos, const LVector4 &frame1, const LVector4 &frame2,
00075     PN_stdfloat blend, PN_stdfloat size, const LVector4 &color, PN_stdfloat rotation);
00076   void billboard(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color);
00077   void segment(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color);
00078   void cross_segment(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color);
00079   void uneven_segment(const LVector3 &start, const LVector3 &stop,
00080     const LVector4 &frame, PN_stdfloat thickness_start, const LVector4 &color_start,
00081     PN_stdfloat thickness_stop, const LVector4 &color_stop);
00082 
00083   void link_segment(const LVector3 &pos, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color);
00084   void link_segment_end(const LVector4 &frame, const LVector4 &color);
00085 
00086   void explosion(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color,
00087     int seed, int number, PN_stdfloat distance);
00088   void stream(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat size, const LVector4 &color,
00089     int number, PN_stdfloat 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   LVector4 _colorv;
00115   LVector3 _normalv;
00116   LVector3 _eyePos;
00117   LVector3 _b1, _b2, _b3, _b4;
00118   LVector3 _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   LVector3 _last_v1,_last_v2,_last_v3,_last_v4,_last_pos;
00126   PN_stdfloat _last_thickness;
00127   LVector4 _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