34 static const LVecBase4 uv_range = LVecBase4(0.0f, 1.0f, 0.0f, 1.0f);
37 operator << (std::ostream &out, PGFrameStyle::Type type) {
39 case PGFrameStyle::T_none:
42 case PGFrameStyle::T_flat:
45 case PGFrameStyle::T_bevel_out:
46 return out <<
"bevel_out";
48 case PGFrameStyle::T_bevel_in:
49 return out <<
"bevel_in";
51 case PGFrameStyle::T_groove:
52 return out <<
"groove";
54 case PGFrameStyle::T_ridge:
55 return out <<
"ridge";
57 case PGFrameStyle::T_texture_border:
58 return out <<
"texture_border";
61 return out <<
"**unknown(" << (int)type <<
")**";
71 LPoint2 center((frame[0] + frame[1]) / 2.0f,
72 (frame[2] + frame[3]) / 2.0f);
73 LVecBase4 scaled_frame
74 ((frame[0] - center[0]) * _visible_scale[0] + center[0],
75 (frame[1] - center[0]) * _visible_scale[0] + center[0],
76 (frame[2] - center[1]) * _visible_scale[1] + center[1],
77 (frame[3] - center[1]) * _visible_scale[1] + center[1]);
88 return LVecBase4(scaled_frame[0] + _width[0],
89 scaled_frame[1] - _width[0],
90 scaled_frame[2] + _width[1],
91 scaled_frame[3] - _width[1]);
98 output(std::ostream &out)
const {
99 out << _type <<
" color = " << _color <<
" width = " << _width;
100 if (_visible_scale != LVecBase2(1.0f, 1.0f)) {
120 PN_stdfloat x_scale = x.length();
123 PN_stdfloat z_scale = z.length();
125 _width[0] *= x_scale;
126 _width[1] *= z_scale;
137 case T_texture_border:
157 LPoint2 center((frame[0] + frame[1]) / 2.0f,
158 (frame[2] + frame[3]) / 2.0f);
159 LVecBase4 scaled_frame
160 ((frame[0] - center[0]) * _visible_scale[0] + center[0],
161 (frame[1] - center[0]) * _visible_scale[0] + center[0],
162 (frame[2] - center[1]) * _visible_scale[1] + center[1],
163 (frame[3] - center[1]) * _visible_scale[1] + center[1]);
170 new_node = generate_flat_geom(scaled_frame);
174 new_node = generate_bevel_geom(scaled_frame,
false);
178 new_node = generate_bevel_geom(scaled_frame,
true);
182 new_node = generate_groove_geom(scaled_frame,
true);
186 new_node = generate_groove_geom(scaled_frame,
false);
189 case T_texture_border:
190 new_node = generate_texture_border_geom(scaled_frame);
197 if (new_node !=
nullptr && _color[3] != 1.0f) {
199 new_node->set_attrib(TransparencyAttrib::make(TransparencyAttrib::M_alpha));
210 generate_flat_geom(
const LVecBase4 &frame) {
213 PN_stdfloat left = frame[0];
214 PN_stdfloat right = frame[1];
215 PN_stdfloat bottom = frame[2];
216 PN_stdfloat top = frame[3];
226 (
"PGFrame", format, Geom::UH_static);
229 vertex.
add_data3(LPoint3::rfu(left, 0.0f, top));
230 vertex.
add_data3(LPoint3::rfu(left, 0.0f, bottom));
231 vertex.
add_data3(LPoint3::rfu(right, 0.0f, top));
232 vertex.
add_data3(LPoint3::rfu(right, 0.0f, bottom));
238 bottom = uv_range[2];
249 strip->add_next_vertices(4);
250 strip->close_primitive();
252 CPT(
RenderState) state = RenderState::make(ColorAttrib::make_flat(_color), -1);
254 state = state->set_attrib(TextureAttrib::make(
get_texture()));
257 geom->add_primitive(strip);
258 gnode->add_geom(geom, state);
267 generate_bevel_geom(
const LVecBase4 &frame,
bool in) {
292 PN_stdfloat left = frame[0];
293 PN_stdfloat right = frame[1];
294 PN_stdfloat bottom = frame[2];
295 PN_stdfloat top = frame[3];
297 PN_stdfloat cx = (left + right) * 0.5;
298 PN_stdfloat cy = (top + bottom) * 0.5;
300 PN_stdfloat inner_left = min(left + _width[0], cx);
301 PN_stdfloat inner_right = max(right - _width[0], cx);
302 PN_stdfloat inner_bottom = min(bottom + _width[1], cy);
303 PN_stdfloat inner_top = max(top - _width[1], cy);
305 PN_stdfloat left_color_scale = 1.2;
306 PN_stdfloat right_color_scale = 0.8;
307 PN_stdfloat bottom_color_scale = 0.7;
308 PN_stdfloat top_color_scale = 1.3;
311 right_color_scale = 1.2;
312 left_color_scale = 0.8;
313 top_color_scale = 0.7;
314 bottom_color_scale = 1.3;
318 LColor cleft(min(_color[0] * left_color_scale, (PN_stdfloat)1.0),
319 min(_color[1] * left_color_scale, (PN_stdfloat)1.0),
320 min(_color[2] * left_color_scale, (PN_stdfloat)1.0),
323 LColor cright(min(_color[0] * right_color_scale, (PN_stdfloat)1.0),
324 min(_color[1] * right_color_scale, (PN_stdfloat)1.0),
325 min(_color[2] * right_color_scale, (PN_stdfloat)1.0),
328 LColor cbottom(min(_color[0] * bottom_color_scale, (PN_stdfloat)1.0),
329 min(_color[1] * bottom_color_scale, (PN_stdfloat)1.0),
330 min(_color[2] * bottom_color_scale, (PN_stdfloat)1.0),
333 LColor ctop(min(_color[0] * top_color_scale, (PN_stdfloat)1.0),
334 min(_color[1] * top_color_scale, (PN_stdfloat)1.0),
335 min(_color[2] * top_color_scale, (PN_stdfloat)1.0),
346 (
"PGFrame", format, Geom::UH_static);
353 vertex.add_data3(LPoint3::rfu(right, 0.0f, bottom));
354 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_bottom));
355 vertex.add_data3(LPoint3::rfu(left, 0.0f, bottom));
356 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_bottom));
357 vertex.add_data3(LPoint3::rfu(left, 0.0f, top));
358 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_top));
359 vertex.add_data3(LPoint3::rfu(right, 0.0f, top));
360 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_top));
361 color.add_data4(cbottom);
362 color.add_data4(cbottom);
363 color.add_data4(cbottom);
364 color.add_data4(cbottom);
365 color.add_data4(cleft);
366 color.add_data4(cleft);
367 color.add_data4(ctop);
368 color.add_data4(ctop);
370 strip->add_next_vertices(8);
371 strip->close_primitive();
374 vertex.add_data3(LPoint3::rfu(right, 0.0f, bottom));
375 vertex.add_data3(LPoint3::rfu(right, 0.0f, top));
376 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_bottom));
377 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_top));
378 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_bottom));
379 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_top));
380 color.add_data4(cright);
381 color.add_data4(cright);
382 color.add_data4(cright);
383 color.add_data4(cright);
384 color.add_data4(_color);
385 color.add_data4(_color);
387 strip->add_next_vertices(6);
388 strip->close_primitive();
389 strip->set_shade_model(Geom::SM_flat_last_vertex);
393 PN_stdfloat left = uv_range[0];
394 PN_stdfloat right = uv_range[1];
395 PN_stdfloat bottom = uv_range[2];
396 PN_stdfloat top = uv_range[3];
398 PN_stdfloat cx = (left + right) * 0.5;
399 PN_stdfloat cy = (top + bottom) * 0.5;
401 PN_stdfloat inner_left = min(left + _uv_width[0], cx);
402 PN_stdfloat inner_right = max(right - _uv_width[0], cx);
403 PN_stdfloat inner_bottom = min(bottom + _uv_width[1], cy);
404 PN_stdfloat inner_top = max(top - _uv_width[1], cy);
407 texcoord.add_data2(right, bottom);
408 texcoord.add_data2(inner_right, inner_bottom);
409 texcoord.add_data2(left, bottom);
410 texcoord.add_data2(inner_left, inner_bottom);
411 texcoord.add_data2(left, top);
412 texcoord.add_data2(inner_left, inner_top);
413 texcoord.add_data2(right, top);
414 texcoord.add_data2(inner_right, inner_top);
416 texcoord.add_data2(right, bottom);
417 texcoord.add_data2(right, top);
418 texcoord.add_data2(inner_right, inner_bottom);
419 texcoord.add_data2(inner_right, inner_top);
420 texcoord.add_data2(inner_left, inner_bottom);
421 texcoord.add_data2(inner_left, inner_top);
424 geom->add_primitive(strip);
427 state = RenderState::make(ShadeModelAttrib::make(ShadeModelAttrib::M_flat),
428 ColorAttrib::make_vertex());
430 state = state->set_attrib(TextureAttrib::make(
get_texture()));
432 gnode->add_geom(geom, state);
441 generate_groove_geom(
const LVecBase4 &frame,
bool in) {
478 PN_stdfloat left = frame[0];
479 PN_stdfloat right = frame[1];
480 PN_stdfloat bottom = frame[2];
481 PN_stdfloat top = frame[3];
483 PN_stdfloat cx = (left + right) * 0.5;
484 PN_stdfloat cy = (top + bottom) * 0.5;
486 PN_stdfloat mid_left = min(left + 0.5f * _width[0], cx);
487 PN_stdfloat mid_right = max(right - 0.5f * _width[0], cx);
488 PN_stdfloat mid_bottom = min(bottom + 0.5f * _width[1], cy);
489 PN_stdfloat mid_top = max(top - 0.5f * _width[1], cy);
491 PN_stdfloat inner_left = min(left + _width[0], cx);
492 PN_stdfloat inner_right = max(right - _width[0], cx);
493 PN_stdfloat inner_bottom = min(bottom + _width[1], cy);
494 PN_stdfloat inner_top = max(top - _width[1], cy);
496 PN_stdfloat left_color_scale = 1.2;
497 PN_stdfloat right_color_scale = 0.8f;
498 PN_stdfloat bottom_color_scale = 0.7f;
499 PN_stdfloat top_color_scale = 1.3;
502 right_color_scale = 1.2;
503 left_color_scale = 0.8f;
504 top_color_scale = 0.7f;
505 bottom_color_scale = 1.3;
509 LColor cleft(min(_color[0] * left_color_scale, (PN_stdfloat)1.0),
510 min(_color[1] * left_color_scale, (PN_stdfloat)1.0),
511 min(_color[2] * left_color_scale, (PN_stdfloat)1.0),
514 LColor cright(min(_color[0] * right_color_scale, (PN_stdfloat)1.0),
515 min(_color[1] * right_color_scale, (PN_stdfloat)1.0),
516 min(_color[2] * right_color_scale, (PN_stdfloat)1.0),
519 LColor cbottom(min(_color[0] * bottom_color_scale, (PN_stdfloat)1.0),
520 min(_color[1] * bottom_color_scale, (PN_stdfloat)1.0),
521 min(_color[2] * bottom_color_scale, (PN_stdfloat)1.0),
524 LColor ctop(min(_color[0] * top_color_scale, (PN_stdfloat)1.0),
525 min(_color[1] * top_color_scale, (PN_stdfloat)1.0),
526 min(_color[2] * top_color_scale, (PN_stdfloat)1.0),
536 (
"PGFrame", format, Geom::UH_static);
543 vertex.add_data3(LPoint3::rfu(right, 0.0f, bottom));
544 vertex.add_data3(LPoint3::rfu(mid_right, 0.0f, mid_bottom));
545 vertex.add_data3(LPoint3::rfu(left, 0.0f, bottom));
546 vertex.add_data3(LPoint3::rfu(mid_left, 0.0f, mid_bottom));
547 vertex.add_data3(LPoint3::rfu(left, 0.0f, top));
548 vertex.add_data3(LPoint3::rfu(mid_left, 0.0f, mid_top));
549 vertex.add_data3(LPoint3::rfu(right, 0.0f, top));
550 vertex.add_data3(LPoint3::rfu(mid_right, 0.0f, mid_top));
551 color.add_data4(cbottom);
552 color.add_data4(cbottom);
553 color.add_data4(cbottom);
554 color.add_data4(cbottom);
555 color.add_data4(cleft);
556 color.add_data4(cleft);
557 color.add_data4(ctop);
558 color.add_data4(ctop);
560 strip->add_next_vertices(8);
561 strip->close_primitive();
564 vertex.add_data3(LPoint3::rfu(mid_right, 0.0f, mid_bottom));
565 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_bottom));
566 vertex.add_data3(LPoint3::rfu(mid_left, 0.0f, mid_bottom));
567 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_bottom));
568 vertex.add_data3(LPoint3::rfu(mid_left, 0.0f, mid_top));
569 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_top));
570 vertex.add_data3(LPoint3::rfu(mid_right, 0.0f, mid_top));
571 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_top));
572 color.add_data4(ctop);
573 color.add_data4(ctop);
574 color.add_data4(ctop);
575 color.add_data4(ctop);
576 color.add_data4(cright);
577 color.add_data4(cright);
578 color.add_data4(cbottom);
579 color.add_data4(cbottom);
581 strip->add_next_vertices(8);
582 strip->close_primitive();
585 vertex.add_data3(LPoint3::rfu(right, 0.0f, bottom));
586 vertex.add_data3(LPoint3::rfu(right, 0.0f, top));
587 vertex.add_data3(LPoint3::rfu(mid_right, 0.0f, mid_bottom));
588 vertex.add_data3(LPoint3::rfu(mid_right, 0.0f, mid_top));
589 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_bottom));
590 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_top));
591 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_bottom));
592 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_top));
593 color.add_data4(cright);
594 color.add_data4(cright);
595 color.add_data4(cright);
596 color.add_data4(cright);
597 color.add_data4(cleft);
598 color.add_data4(cleft);
599 color.add_data4(_color);
600 color.add_data4(_color);
602 strip->add_next_vertices(8);
603 strip->close_primitive();
605 strip->set_shade_model(Geom::SM_flat_last_vertex);
609 PN_stdfloat left = uv_range[0];
610 PN_stdfloat right = uv_range[1];
611 PN_stdfloat bottom = uv_range[2];
612 PN_stdfloat top = uv_range[3];
614 PN_stdfloat cx = (left + right) * 0.5;
615 PN_stdfloat cy = (top + bottom) * 0.5;
617 PN_stdfloat mid_left = min(left + 0.5f * _width[0], cx);
618 PN_stdfloat mid_right = max(right - 0.5f * _width[0], cx);
619 PN_stdfloat mid_bottom = min(bottom + 0.5f * _width[1], cy);
620 PN_stdfloat mid_top = max(top - 0.5f * _width[1], cy);
622 PN_stdfloat inner_left = min(left + _width[0], cx);
623 PN_stdfloat inner_right = max(right - _width[0], cx);
624 PN_stdfloat inner_bottom = min(bottom + _width[1], cy);
625 PN_stdfloat inner_top = max(top - _width[1], cy);
628 texcoord.add_data2(right, bottom);
629 texcoord.add_data2(mid_right, mid_bottom);
630 texcoord.add_data2(left, bottom);
631 texcoord.add_data2(mid_left, mid_bottom);
632 texcoord.add_data2(left, top);
633 texcoord.add_data2(mid_left, mid_top);
634 texcoord.add_data2(right, top);
635 texcoord.add_data2(mid_right, mid_top);
637 texcoord.add_data2(mid_right, mid_bottom);
638 texcoord.add_data2(inner_right, inner_bottom);
639 texcoord.add_data2(mid_left, mid_bottom);
640 texcoord.add_data2(inner_left, inner_bottom);
641 texcoord.add_data2(mid_left, mid_top);
642 texcoord.add_data2(inner_left, inner_top);
643 texcoord.add_data2(mid_right, mid_top);
644 texcoord.add_data2(inner_right, inner_top);
646 texcoord.add_data2(right, bottom);
647 texcoord.add_data2(right, top);
648 texcoord.add_data2(mid_right, mid_bottom);
649 texcoord.add_data2(mid_right, mid_top);
650 texcoord.add_data2(inner_right, inner_bottom);
651 texcoord.add_data2(inner_right, inner_top);
652 texcoord.add_data2(inner_left, inner_bottom);
653 texcoord.add_data2(inner_left, inner_top);
657 geom->add_primitive(strip);
659 CPT(
RenderState) state = RenderState::make(ShadeModelAttrib::make(ShadeModelAttrib::M_flat),
660 ColorAttrib::make_vertex());
662 state = state->set_attrib(TextureAttrib::make(
get_texture()));
664 gnode->add_geom(geom, state);
673 generate_texture_border_geom(
const LVecBase4 &frame) {
691 PN_stdfloat left = frame[0];
692 PN_stdfloat right = frame[1];
693 PN_stdfloat bottom = frame[2];
694 PN_stdfloat top = frame[3];
696 PN_stdfloat cx = (left + right) * 0.5;
697 PN_stdfloat cy = (top + bottom) * 0.5;
699 PN_stdfloat inner_left = min(left + _width[0], cx);
700 PN_stdfloat inner_right = max(right - _width[0], cx);
701 PN_stdfloat inner_bottom = min(bottom + _width[1], cy);
702 PN_stdfloat inner_top = max(top - _width[1], cy);
712 (
"PGFrame", format, Geom::UH_static);
717 vertex.add_data3(LPoint3::rfu(left, 0.0f, top));
718 vertex.add_data3(LPoint3::rfu(left, 0.0f, inner_top));
719 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, top));
720 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_top));
722 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, top));
723 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_top));
724 vertex.add_data3(LPoint3::rfu(right, 0.0f, top));
725 vertex.add_data3(LPoint3::rfu(right, 0.0f, inner_top));
727 vertex.add_data3(LPoint3::rfu(left, 0.0f, inner_bottom));
728 vertex.add_data3(LPoint3::rfu(left, 0.0f, bottom));
729 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, inner_bottom));
730 vertex.add_data3(LPoint3::rfu(inner_left, 0.0f, bottom));
732 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, inner_bottom));
733 vertex.add_data3(LPoint3::rfu(inner_right, 0.0f, bottom));
734 vertex.add_data3(LPoint3::rfu(right, 0.0f, inner_bottom));
735 vertex.add_data3(LPoint3::rfu(right, 0.0f, bottom));
739 PN_stdfloat left = uv_range[0];
740 PN_stdfloat right = uv_range[1];
741 PN_stdfloat bottom = uv_range[2];
742 PN_stdfloat top = uv_range[3];
744 PN_stdfloat cx = (left + right) * 0.5;
745 PN_stdfloat cy = (top + bottom) * 0.5;
747 PN_stdfloat inner_left = min(left + _uv_width[0], cx);
748 PN_stdfloat inner_right = max(right - _uv_width[0], cx);
749 PN_stdfloat inner_bottom = min(bottom + _uv_width[1], cy);
750 PN_stdfloat inner_top = max(top - _uv_width[1], cy);
755 texcoord.add_data2(left, top);
756 texcoord.add_data2(left, inner_top);
757 texcoord.add_data2(inner_left, top);
758 texcoord.add_data2(inner_left, inner_top);
760 texcoord.add_data2(inner_right, top);
761 texcoord.add_data2(inner_right, inner_top);
762 texcoord.add_data2(right, top);
763 texcoord.add_data2(right, inner_top);
765 texcoord.add_data2(left, inner_bottom);
766 texcoord.add_data2(left, bottom);
767 texcoord.add_data2(inner_left, inner_bottom);
768 texcoord.add_data2(inner_left, bottom);
770 texcoord.add_data2(inner_right, inner_bottom);
771 texcoord.add_data2(inner_right, bottom);
772 texcoord.add_data2(right, inner_bottom);
773 texcoord.add_data2(right, bottom);
779 strip->add_consecutive_vertices(0, 8);
780 strip->close_primitive();
783 strip->add_vertex(1);
784 strip->add_vertex(8);
785 strip->add_vertex(3);
786 strip->add_vertex(10);
787 strip->add_vertex(5);
788 strip->add_vertex(12);
789 strip->add_vertex(7);
790 strip->add_vertex(14);
791 strip->close_primitive();
794 strip->add_consecutive_vertices(8, 8);
795 strip->close_primitive();
797 CPT(
RenderState) state = RenderState::make(ColorAttrib::make_flat(_color), -1);
799 state = state->set_attrib(TextureAttrib::make(
get_texture()));
803 geom->add_primitive(strip);
804 gnode->add_geom(geom, state);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LVecBase4 get_internal_frame(const LVecBase4 &frame) const
Computes the size of the internal frame, given the indicated external frame, appropriate for this kin...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_data2(PN_stdfloat x, PN_stdfloat y)
Sets the write row to a particular 2-component value, and advances the write row.
Defines a series of triangle strips.
bool has_texture() const
Returns true if a texture has been applied to the frame.
Texture * get_texture() const
Returns the texture that has been applied to the frame, or NULL if no texture has been applied.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const LVecBase2 & get_visible_scale() const
Returns the scale factor on the visible representation of the frame, in the X and Y directions.
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...
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.
NodePath generate_into(const NodePath &parent, const LVecBase4 &frame, int sort=0)
Generates geometry representing a frame of the indicated size, and parents it to the indicated node,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
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.
PT(PandaNode) PGFrameStyle
Generates the GeomNode appropriate to a T_flat frame.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
bool xform(const LMatrix4 &mat)
Applies the indicated transform to the FrameStyle.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
A node that holds Geom objects, renderable pieces of geometry.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.