meshDrawer.I 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include "lpoint2.h"
  15. ////////////////////////////////////////////////////////////////////
  16. // Function: MeshDrawer::Constructor
  17. // Access: Published
  18. // Description: Creates the MeshDrawer low level system.
  19. ////////////////////////////////////////////////////////////////////
  20. INLINE MeshDrawer::
  21. MeshDrawer() {
  22. _root = NodePath("MeshDrawer");
  23. _at_start = 0;
  24. _bv = NULL;
  25. _vertex = NULL;
  26. _normal = NULL;
  27. _uv = NULL;
  28. _color = NULL;
  29. _budget = 5000;
  30. }
  31. ////////////////////////////////////////////////////////////////////
  32. // Function: MeshDrawer::Destructor
  33. // Access: Published
  34. // Description: Destroys the MeshDrawer low level system.
  35. ////////////////////////////////////////////////////////////////////
  36. INLINE MeshDrawer::
  37. ~MeshDrawer() {
  38. _root.remove_node();
  39. if (_vertex != NULL) delete _vertex;
  40. if (_normal != NULL) delete _normal;
  41. if (_uv != NULL) delete _uv;
  42. if (_color != NULL) delete _color;
  43. }
  44. ////////////////////////////////////////////////////////////////////
  45. // Function: MeshDrawer::get_root
  46. // Access: Published
  47. // Description: Returns the root NodePath. You should use this node
  48. // to reparent mesh drawer onto the scene
  49. // might also want to disable depth draw or enable
  50. // transparency.
  51. ////////////////////////////////////////////////////////////////////
  52. INLINE NodePath MeshDrawer::
  53. get_root() {
  54. return _root;
  55. }
  56. ////////////////////////////////////////////////////////////////////
  57. // Function: MeshDrawer::set_budget
  58. // Access: Published
  59. // Description: Sets the total triangle budget of the drawer.
  60. // This will not be exceeded. Don't set some thing too
  61. // large because it will be slow
  62. ////////////////////////////////////////////////////////////////////
  63. INLINE void MeshDrawer::
  64. set_budget(int total_budget) {
  65. _budget = total_budget;
  66. generator(_budget);
  67. }
  68. ////////////////////////////////////////////////////////////////////
  69. // Function: MeshDrawer::get_budget()
  70. // Access: Published
  71. // Description: Gets the total triangle budget of the drawer
  72. ////////////////////////////////////////////////////////////////////
  73. INLINE int MeshDrawer::
  74. get_budget() {
  75. return _budget;
  76. }
  77. ////////////////////////////////////////////////////////////////////
  78. // Function: MeshDrawer::tri
  79. // Access: Published
  80. // Description: Draws a triangle with the given parameters.
  81. ////////////////////////////////////////////////////////////////////
  82. INLINE void MeshDrawer::tri(const LVector3 &v1, const LVector4 &c1, const LVector2 &uv1,
  83. const LVector3 &v2, const LVector4 &c2, const LVector2 &uv2,
  84. const LVector3 &v3, const LVector4 &c3, const LVector2 &uv3) {
  85. if( _clear_index > _end_clear_index) return;
  86. _vertex->add_data3(v1);
  87. _color->add_data4(c1);
  88. _uv->add_data2(uv1);
  89. _vertex->add_data3(v2);
  90. _color->add_data4(c2);
  91. _uv->add_data2(uv2);
  92. _vertex->add_data3(v3);
  93. _color->add_data4(c3);
  94. _uv->add_data2(uv3);
  95. _clear_index += 1;
  96. }