35 PN_stdfloat randFloat() {
36 return ((PN_stdfloat)rand() / (PN_stdfloat)RAND_MAX);
42 void MeshDrawer::generator(
int budget) {
55 for (
int i = 0; i < budget; i++) {
56 for (
int vert = 0; vert < 3; vert++) {
57 LVector3 vec3 = LVector3(randFloat()+1000,randFloat(),randFloat())*.001;
58 LVector4 vec4 = LVector4(1,1,1,randFloat());
59 LVector2 vec2 = LVector2(0,randFloat());
60 tvertex.set_data3(vec3);
61 tcolor.set_data4(vec4);
63 tnormal.set_data3(vec3);
70 _prim->add_next_vertices(budget * 3);
71 _prim->close_primitive();
72 _geom =
new Geom(_vdata);
73 _geom->add_primitive(_prim);
74 if (_geomnode ==
nullptr) {
75 _geomnode =
new GeomNode(
"__MeshDrawer_GeomNode");
78 _geomnode->remove_all_geoms();
80 _geomnode->add_geom(_geom);
81 _last_clear_index = budget;
101 _b1 = - _right - _up;
104 _b4 = - _right + _up;
107 if (_vertex !=
nullptr)
delete _vertex;
108 if (_normal !=
nullptr)
delete _normal;
109 if (_uv !=
nullptr)
delete _uv;
110 if (_color !=
nullptr)
delete _color;
112 if (_vdata ==
nullptr) {
120 _dprim = _prim->decompose();
123 _start_clear_index = 0;
124 _end_clear_index = _budget;
125 _clear_index = _start_clear_index;
135 for(
int i = _clear_index ; i < _last_clear_index; i ++ ) {
141 _last_clear_index = _clear_index;
144 delete _vertex; _vertex =
nullptr;
145 delete _uv; _uv =
nullptr;
146 delete _normal; _normal =
nullptr;
147 delete _color; _color =
nullptr;
156 const LVector4 &color, PN_stdfloat rotation) {
158 rotation = rotation / 57.29578;
160 LVector3 v1 = pos + _b1*size*sin(rotation) + _b2*size*cos(rotation);
161 LVector3 v2 = pos + _b2*size*sin(rotation) + _b3*size*cos(rotation);
162 LVector3 v3 = pos + _b3*size*sin(rotation) + _b4*size*cos(rotation);
163 LVector3 v4 = pos + _b4*size*sin(rotation) + _b1*size*cos(rotation);
165 PN_stdfloat u = frame.get_x();
166 PN_stdfloat v = frame.get_y();
167 PN_stdfloat us = frame.get_z();
168 PN_stdfloat vs = frame.get_w();
171 v1, color, LVector2(u,v),
172 v2, color, LVector2(u+us,v),
173 v3, color, LVector2(u+us,v+vs));
175 v3, color, LVector2(u+us,v+vs),
176 v4, color, LVector2(u,v+vs),
177 v1, color, LVector2(u,v));
185 const LVector4 &frame2, PN_stdfloat blend, PN_stdfloat size,
const LVector4 &color, PN_stdfloat rotation) {
188 PN_stdfloat original_w = c2.get_w();
189 c2.set_w((1.f-blend)*original_w);
190 particle(pos,frame1,size,c2,rotation);
191 c2.set_w(blend*original_w);
192 particle(pos,frame2,size,c2,rotation);
201 const LVector4 &_color) {
203 LVector3 v1 = pos + _b1*size;
204 LVector3 v2 = pos + _b2*size;
205 LVector3 v3 = pos + _b3*size;
206 LVector3 v4 = pos + _b4*size;
208 PN_stdfloat u = frame.get_x();
209 PN_stdfloat v = frame.get_y();
210 PN_stdfloat us = frame.get_z();
211 PN_stdfloat vs = frame.get_w();
214 v1, _color, LVector2(u,v),
215 v2, _color, LVector2(u+us,v),
216 v3, _color, LVector2(u+us,v+vs));
218 v3, _color, LVector2(u+us,v+vs),
219 v4, _color, LVector2(u,v+vs),
220 v1, _color, LVector2(u,v));
229 PN_stdfloat thickness,
const LVector4 &color) {
240 PN_stdfloat thickness,
const LVector4 &color) {
242 PN_stdfloat u = frame.get_x();
243 PN_stdfloat v = frame.get_y();
244 PN_stdfloat us = frame.get_z();
245 PN_stdfloat vs = frame.get_w();
247 LVector3 v1 = start - _up*thickness;
248 LVector3 v2 = stop - _up*thickness;
249 LVector3 v3 = stop + _up*thickness;
250 LVector3 v4 = start + _up*thickness;
252 tri(v1, color, LVector2(u,v),
253 v2, color, LVector2(u+us,v),
254 v3, color, LVector2(u+us,v+vs));
255 tri(v3, color, LVector2(u+us,v+vs),
256 v4, color, LVector2(u,v+vs),
257 v1, color, LVector2(u,v));
259 v1 = start - _right*thickness;
260 v2 = stop - _right*thickness;
261 v3 = stop + _right*thickness;
262 v4 = start + _right*thickness;
264 tri(v1, color, LVector2(u,v),
265 v2, color, LVector2(u+us,v),
266 v3, color, LVector2(u+us,v+vs));
267 tri(v3, color, LVector2(u+us,v+vs),
268 v4, color, LVector2(u,v+vs),
269 v1, color, LVector2(u,v));
282 const LVector4 &frame, PN_stdfloat thickness_start,
const LVector4 &color_start,
283 PN_stdfloat thickness_stop,
const LVector4 &color_stop) {
285 PN_stdfloat u = frame.get_x();
286 PN_stdfloat v = frame.get_y();
287 PN_stdfloat us = frame.get_z();
288 PN_stdfloat vs = frame.get_w();
290 LVector3 v1 = start - _up*thickness_start;
291 LVector3 v2 = stop - _up*thickness_stop;
292 LVector3 v3 = stop + _up*thickness_stop;
293 LVector3 v4 = start + _up*thickness_start;
295 tri(v1, color_start, LVector2(u,v),
296 v2, color_stop, LVector2(u+us,v),
297 v3, color_stop, LVector2(u+us,v+vs));
298 tri(v3, color_stop, LVector2(u+us,v+vs),
299 v4, color_start, LVector2(u,v+vs),
300 v1, color_start, LVector2(u,v));
302 v1 = start - _right*thickness_start;
303 v2 = stop - _right*thickness_stop;
304 v3 = stop + _right*thickness_stop;
305 v4 = start + _right*thickness_start;
307 tri(v1, color_start, LVector2(u,v),
308 v2, color_stop, LVector2(u+us,v),
309 v3, color_stop, LVector2(u+us,v+vs));
310 tri(v3, color_stop, LVector2(u+us,v+vs),
311 v4, color_start, LVector2(u,v+vs),
312 v1, color_start, LVector2(u,v));
320 const LVector3 &pos,
const LVector4 &frame, PN_stdfloat size,
const LVector4 &_color,
321 int seed,
int number, PN_stdfloat distance) {
323 LVector3 relative_pos;
324 for(
int i = 0; i < number; i++) {
325 relative_pos = LVector3(randFloat()-.5f,randFloat()-.5f,randFloat()-.5f);
326 relative_pos.normalize();
327 relative_pos *= randFloat()*distance;
328 particle(relative_pos+pos,frame,size,_color,randFloat()*360.0f);
336 void MeshDrawer::stream(
const LVector3 &start,
const LVector3 &stop,
const LVector4 &frame, PN_stdfloat size,
const LVector4 &_color,
337 int number, PN_stdfloat offset) {
339 offset = offset-floor(offset);
340 LVector3 relative_pos = stop;
341 LVector3 vec = stop - start;
342 PN_stdfloat distance = vec.length();
344 for(
int i = 0; i < number; i++) {
345 relative_pos = start + vec * ((i+offset)*(distance/PN_stdfloat(number)));
346 billboard(relative_pos,frame,size,_color);
361 LVector4 color = LVector4(1,1,1,1);
372 for(
int j=0; j<geomNode->get_num_geoms(); j++) {
373 CPT(
Geom) geom = geomNode->get_geom(j);
377 for (
size_t k = 0; k < geom->get_num_primitives(); ++k) {
382 for(
int p=0; p < _prim->get_num_primitives();p++) {
383 int s = _prim->get_primitive_start(p);
384 int e = _prim->get_primitive_end(p);
388 for(
int idx=s; idx<e; idx++) {
389 int vidx = _prim->get_vertex(idx);
393 current_node_path,prim_vertex_reader->
get_data3());
394 uv[indx_over] = prim_uv_reader->
get_data2();
396 if (indx_over > 2)
break;
400 tri(vec[0],color,uv[0],
405 if( _clear_index > _end_clear_index)
return;
408 delete prim_vertex_reader;
409 delete prim_uv_reader;
422 PN_stdfloat thickness,
const LVector4 &color) {
444 _last_thickness = thickness;
450 LVector3 start = _last_pos;
454 LPoint2 cam_start2d = LVector2();
456 LPoint2 cam_stop2d = LVector2();
459 DCAST_INTO_V(camera, _camera.
node());
462 lens->
project(cam_start3d, cam_start2d);
463 lens->project(cam_stop3d, cam_stop2d);
465 LVector2 dif = cam_stop2d - cam_start2d;
466 PN_stdfloat rotation = atan2(dif.get_x(),dif.get_y());
468 LVector3 now_v1 = start + _b1*(PN_stdfloat)(thickness*sin(rotation)) + _b2*(PN_stdfloat)(thickness*cos(rotation));
469 LVector3 now_v4 = start + _b4*(PN_stdfloat)(thickness*sin(rotation)) + _b1*(PN_stdfloat)(thickness*cos(rotation));
470 LVector3 now_v2 = stop + _b2*(PN_stdfloat)(thickness*sin(rotation)) + _b3*(PN_stdfloat)(thickness*cos(rotation));
471 LVector3 now_v3 = stop + _b3*(PN_stdfloat)(thickness*sin(rotation)) + _b4*(PN_stdfloat)(thickness*cos(rotation));
485 LVector3 v1 = _last_v1;
486 LVector3 v2 = (_last_v2+now_v1)/2.0f;
487 LVector3 v3 = (_last_v3+now_v4)/2.0f;
488 LVector3 v4 = _last_v4;
491 PN_stdfloat u = frame.get_x();
492 PN_stdfloat v = frame.get_y();
493 PN_stdfloat us = frame.get_z();
494 PN_stdfloat vs = frame.get_w();
496 tri(v1, _last_color, LVector2(u,v),
497 v2, color, LVector2(u+us,v),
498 v3, color, LVector2(u+us,v+vs));
499 tri(v3, color, LVector2(u+us,v+vs),
500 v4, _last_color, LVector2(u,v+vs),
501 v1, _last_color, LVector2(u,v));
511 _last_thickness = thickness;
522 PN_stdfloat u = frame.get_x();
523 PN_stdfloat v = frame.get_y();
524 PN_stdfloat us = frame.get_z();
525 PN_stdfloat vs = frame.get_w();
527 tri(_last_v1, _last_color, LVector2(u,v),
528 _last_v2, color, LVector2(u+us,v),
529 _last_v3, color, LVector2(u+us,v+vs));
530 tri(_last_v3, color, LVector2(u+us,v+vs),
531 _last_v4, _last_color, LVector2(u,v+vs),
532 _last_v1, _last_color, LVector2(u,v));
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void segment(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color)
Draws a segment a line with a thickness.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePathCollection find_all_matches(const std::string &path) const
Returns the complete set of all NodePaths that begin with this NodePath and can be extended by path.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void explosion(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color, int seed, int number, PN_stdfloat distance)
Draws number of particles in a sphere like emitter.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool unclean_set_num_rows(int n)
This method behaves like set_num_rows(), except the new data is not initialized.
LVector3 get_relative_vector(const NodePath &other, const LVecBase3 &vec) const
Given that the indicated vector is in the coordinate system of the other node, returns the same vecto...
A base class for any number of different kinds of lenses, linear and otherwise.
void billboard(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color)
Draws a billboard - particle with no rotation.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void end()
Finish the drawing and clearing off the remaining vertexes.
const LVecBase2 & get_data2()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
get_error_type
If is_empty() is true, this returns a code that represents the reason why the NodePath is empty.
Lens * get_lens(int index=0) const
Returns a pointer to the particular Lens associated with this LensNode, or NULL if there is not yet a...
bool project(const LPoint3 &point3d, LPoint3 &point2d) const
Given a 3-d point in space, determine the 2-d point this maps to, in the range (-1,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_name
Returns the name of the referenced node.
get_path
Returns the nth NodePath in the collection.
void stream(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat size, const LVector4 &color, int number, PN_stdfloat offset)
Draws a number of particles in a big line with a shift dictated by the offset.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
const LVecBase3 & get_data3()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void blended_particle(const LVector3 &pos, const LVector4 &frame1, const LVector4 &frame2, PN_stdfloat blend, PN_stdfloat size, const LVector4 &color, PN_stdfloat rotation)
Works just like particle but accepts 2 frames and a blend (from 0 to 1) component between them Frame ...
LPoint3 get_pos() const
Retrieves the translation component of the transform.
void cross_segment(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color)
Draws a segment a line with a thickness.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
void particle(const LVector3 &pos, const LVector4 &frame, PN_stdfloat size, const LVector4 &color, PN_stdfloat rotation)
Draws a particle that is sort of like a bill board but has an extra rotation component.
PandaNode * node() const
Returns the referenced node of the path.
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
Defines a series of disconnected triangles.
void link_segment_end(const LVector4 &frame, const LVector4 &color)
Finish drawing linked segments, needs at least two calls to link_segment before it can end the linked...
get_num_paths
Returns the number of NodePaths in the collection.
void set_row_unsafe(int row)
Sets the start row to the indicated value, without internal checks.
LPoint3 get_relative_point(const NodePath &other, const LVecBase3 &point) const
Given that the indicated point is in the coordinate system of the other node, returns the same point ...
TypeHandle is the identifier used to differentiate C++ class types.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
void begin(NodePath camera, NodePath render)
Pass the current camera node and the root node.
void uneven_segment(const LVector3 &start, const LVector3 &stop, const LVector4 &frame, PN_stdfloat thickness_start, const LVector4 &color_start, PN_stdfloat thickness_stop, const LVector4 &color_stop)
Draws a segment a line with different thickness and color on both sides.
void geometry(NodePath node)
Draws the geometry that is inside this node path into the MeshDrawer object.
void link_segment(const LVector3 &pos, const LVector4 &frame, PN_stdfloat thickness, const LVector4 &color)
Stars or continues linked segment.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node that holds Geom objects, renderable pieces of geometry.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object provides the functionality of both a GeomVertexReader and a GeomVertexWriter,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a set of zero or more NodePaths.