Panda3D
meshDrawer.I
1 // Filename: meshDrawer.I
2 // Created by: treeform (19dec08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "lpoint2.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: MeshDrawer::Constructor
19 // Access: Published
20 // Description: Creates the MeshDrawer low level system.
21 ////////////////////////////////////////////////////////////////////
22 INLINE MeshDrawer::
24  _root = NodePath("MeshDrawer");
25  _at_start = 0;
26  _bv = NULL;
27  _vertex = NULL;
28  _normal = NULL;
29  _uv = NULL;
30  _color = NULL;
31  _budget = 5000;
32  _vdata = NULL;
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: MeshDrawer::Destructor
37 // Access: Published
38 // Description: Destroys the MeshDrawer low level system.
39 ////////////////////////////////////////////////////////////////////
40 INLINE MeshDrawer::
42  _root.remove_node();
43  if (_vertex != NULL) delete _vertex;
44  if (_normal != NULL) delete _normal;
45  if (_uv != NULL) delete _uv;
46  if (_color != NULL) delete _color;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: MeshDrawer::get_root
51 // Access: Published
52 // Description: Returns the root NodePath. You should use this node
53 // to reparent mesh drawer onto the scene
54 // might also want to disable depth draw or enable
55 // transparency.
56 ////////////////////////////////////////////////////////////////////
59  return _root;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: MeshDrawer::set_budget
64 // Access: Published
65 // Description: Sets the total triangle budget of the drawer.
66 // This will not be exceeded. Don't set some thing too
67 // large because it will be slow
68 ////////////////////////////////////////////////////////////////////
69 INLINE void MeshDrawer::
70 set_budget(int total_budget) {
71  _budget = total_budget;
72  generator(_budget);
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: MeshDrawer::get_budget()
77 // Access: Published
78 // Description: Gets the total triangle budget of the drawer
79 ////////////////////////////////////////////////////////////////////
80 INLINE int MeshDrawer::
82  return _budget;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: MeshDrawer::tri
87 // Access: Published
88 // Description: Draws a triangle with the given parameters.
89 ////////////////////////////////////////////////////////////////////
90 INLINE void MeshDrawer::tri(const LVector3 &v1, const LVector4 &c1, const LVector2 &uv1,
91  const LVector3 &v2, const LVector4 &c2, const LVector2 &uv2,
92  const LVector3 &v3, const LVector4 &c3, const LVector2 &uv3) {
93 
94  if( _clear_index > _end_clear_index) return;
95 
96  _vertex->add_data3(v1);
97  _color->add_data4(c1);
98  _uv->add_data2(uv1);
99 
100  _vertex->add_data3(v2);
101  _color->add_data4(c2);
102  _uv->add_data2(uv2);
103 
104  _vertex->add_data3(v3);
105  _color->add_data4(c3);
106  _uv->add_data2(uv3);
107 
108  _clear_index += 1;
109 }
void set_budget(int budget)
Sets the total triangle budget of the drawer.
Definition: meshDrawer.I:70
void add_data2(PN_stdfloat x, PN_stdfloat y)
Sets the write row to a particular 2-component value, and advances the write row. ...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
void add_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w)
Sets the write row to a particular 4-component value, and advances the write row. ...
MeshDrawer()
Creates the MeshDrawer low level system.
Definition: meshDrawer.I:23
void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the write row to a particular 3-component value, and advances the write row. ...
This is a four-component vector distance.
Definition: lvector4.h:91
NodePath get_root()
Returns the root NodePath.
Definition: meshDrawer.I:58
void tri(const LVector3 &v1, const LVector4 &c1, const LVector2 &uv1, const LVector3 &v2, const LVector4 &c2, const LVector2 &uv2, const LVector3 &v3, const LVector4 &c3, const LVector2 &uv3)
Draws a triangle with the given parameters.
Definition: meshDrawer.I:90
This is a two-component vector offset.
Definition: lvector2.h:91
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
Definition: nodePath.cxx:757
~MeshDrawer()
Destroys the MeshDrawer low level system.
Definition: meshDrawer.I:41
int get_budget()
Gets the total triangle budget of the drawer.
Definition: meshDrawer.I:81
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165