Panda3D
 All Classes Functions Variables Enumerations
meshDrawer.h
1 // Filename: meshDrawer.h
2 // Created by: treeform (19dec08)
3 // Changes by: treeform (12jan10)
4 //
5 ////////////////////////////////////////////////////////////////////
6 //
7 // PANDA 3D SOFTWARE
8 // Copyright (c) Carnegie Mellon University. All rights reserved.
9 //
10 // All use of this software is subject to the terms of the revised BSD
11 // license. You should have received a copy of this license along
12 // with this source code in a file named "LICENSE."
13 //
14 ////////////////////////////////////////////////////////////////////
15 
16 #ifndef MESHDRAWER_H
17 #define MESHDRAWER_H
18 
19 #include "pandabase.h"
20 #include "luse.h"
21 #include "pandaNode.h"
22 #include "pointerTo.h"
23 #include "lpoint2.h"
24 #include "lvecBase2.h"
25 #include "pnmImage.h"
26 #include "nodePath.h"
27 #include "texture.h"
28 #include "geomVertexFormat.h"
29 #include "geomVertexArrayFormat.h"
30 #include "geomVertexData.h"
31 #include "geomVertexWriter.h"
32 #include "geomVertexRewriter.h"
33 #include "boundingVolume.h"
34 
35 #include "nodePathCollection.h"
36 
37 #include "geomTristrips.h"
38 #include "geomTriangles.h"
39 #include "geom.h"
40 #include "geomNode.h"
41 #include "nodePath.h"
42 
43 ////////////////////////////////////////////////////////////////////
44 // Class : MeshDrawer
45 // Description : Mesh drawer creates a single geom object that can be
46 // shaped with different draw commands. This is an
47 // efficient way to render bunch of billboards, particles,
48 // fast changing triangles. Its implemented by recycling
49 // same geom over and over again. Max budget specifies
50 // how many triangles are allowed. Some uses of this
51 // class can be : particle system, radar icons, health
52 // bars, 2d icons, 2d ui, bullets, missile trails. Any
53 // that can be drawn with triangles can be drawn with
54 // this class. At the low level this uses the
55 // GeomVertexRewriter's. The internal geom consists of
56 // vertex, normal, uv and color channels.
57 ////////////////////////////////////////////////////////////////////
58 class EXPCL_PANDA_GRUTIL MeshDrawer : public TypedObject {
59 PUBLISHED:
60  INLINE MeshDrawer();
61  INLINE ~MeshDrawer();
62 
63  INLINE void set_budget(int budget);
64  INLINE int get_budget();
65 
66  INLINE NodePath get_root();
67 
68  void begin(NodePath camera, NodePath render);
69  INLINE void tri(const LVector3 &v1, const LVector4 &c1, const LVector2 &uv1,
70  const LVector3 &v2, const LVector4 &c2, const LVector2 &uv2,
71  const LVector3 &v3, const LVector4 &c3, const LVector2 &uv3);
72 
73  void particle(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color, PN_stdfloat rotation);
74  void blended_particle(const LVector3 &pos, const LVector4 &frame1, const LVector4 &frame2,
75  PN_stdfloat blend, PN_stdfloat size, const LVector4 &color, PN_stdfloat rotation);
76  void billboard(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color);
77  void segment(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color);
78  void cross_segment(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color);
79  void uneven_segment(const LVector3 &start, const LVector3 &stop,
80  const LVector4 &frame, PN_stdfloat thickness_start, const LVector4 &color_start,
81  PN_stdfloat thickness_stop, const LVector4 &color_stop);
82 
83  void link_segment(const LVector3 &pos, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color);
84  void link_segment_end(const LVector4 &frame, const LVector4 &color);
85 
86  void explosion(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color,
87  int seed, int number, PN_stdfloat distance);
88  void stream(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat size, const LVector4 &color,
89  int number, PN_stdfloat offset);
90  void geometry(NodePath node);
91  void end();
92 
93 private:
94 
95  // use vars
96  NodePath _root;
97  NodePath _camera, _render;
98  int _budget;
99 
100  // store regeneration geoms & nodes
101  PT(Geom) _geom;
102  PT(GeomNode) _geomnode;
103  PT(GeomVertexData) _vdata;
104  PT(GeomTriangles) _prim;
105  CPT(GeomPrimitive) _dprim;
106 
107  // writers
108  GeomVertexRewriter *_vertex;
109  GeomVertexRewriter *_normal;
110  GeomVertexRewriter *_uv;
111  GeomVertexRewriter *_color;
112 
113  // billboard vectors
114  LVector4 _colorv;
115  LVector3 _normalv;
116  LVector3 _eyePos;
117  LVector3 _b1, _b2, _b3, _b4;
118  LVector3 _up, _right;
119 
120  // clear indexes
121  int _last_clear_index, _start_clear_index, _end_clear_index, _clear_index;
122 
123  // used for curves
124  int _at_start;
125  LVector3 _last_v1,_last_v2,_last_v3,_last_v4,_last_pos;
126  PN_stdfloat _last_thickness;
127  LVector4 _last_color;
128 
129  // bounding volume
130  PT(BoundingVolume) _bv;
131 
132  // private create all the needed geoms
133  void generator(int budget);
134 
135 public:
136  static TypeHandle get_class_type() {
137  return _type_handle;
138  }
139  static void init_type() {
141  register_type(_type_handle, "MeshDrawer",
142  TypedObject::get_class_type());
143  }
144  virtual TypeHandle get_type() const {
145  return get_class_type();
146  }
147  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
148 
149 private:
150  static TypeHandle _type_handle;
151 
152 };
153 
154 #include "meshDrawer.I"
155 
156 #endif /*MESHDRAWER_H*/
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:52
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:98
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
Mesh drawer creates a single geom object that can be shaped with different draw commands.
Definition: meshDrawer.h:58
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Definition: geom.h:58
This is a four-component vector distance.
Definition: lvector4.h:91
This is a two-component vector offset.
Definition: lvector2.h:91
Defines a series of disconnected triangles.
Definition: geomTriangles.h:25
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37
This object provides the functionality of both a GeomVertexReader and a GeomVertexWriter, combined together into one convenient package.