eggAttributes.I 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // Filename: eggAttributes.I
  2. // Created by: drose (16Jan99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: EggAttributes::has_normal
  20. // Access: Published
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE bool EggAttributes::
  24. has_normal() const {
  25. return (_flags & F_has_normal) != 0;
  26. }
  27. ////////////////////////////////////////////////////////////////////
  28. // Function: EggAttributes::get_normal
  29. // Access: Published
  30. // Description:
  31. ////////////////////////////////////////////////////////////////////
  32. INLINE const Normald &EggAttributes::
  33. get_normal() const {
  34. nassertr(has_normal(), _normal);
  35. return _normal;
  36. }
  37. ////////////////////////////////////////////////////////////////////
  38. // Function: EggAttributes::set_normal
  39. // Access: Published
  40. // Description:
  41. ////////////////////////////////////////////////////////////////////
  42. INLINE void EggAttributes::
  43. set_normal(const Normald &normal) {
  44. _normal = normal;
  45. _flags |= F_has_normal;
  46. }
  47. ////////////////////////////////////////////////////////////////////
  48. // Function: EggAttributes::clear_normal
  49. // Access: Published
  50. // Description:
  51. ////////////////////////////////////////////////////////////////////
  52. INLINE void EggAttributes::
  53. clear_normal() {
  54. _flags &= ~F_has_normal;
  55. }
  56. ////////////////////////////////////////////////////////////////////
  57. // Function: EggAttributes::matches_normal
  58. // Access: Published
  59. // Description: Returns true if this normal matches that of the other
  60. // EggAttributes object, include the morph list.
  61. ////////////////////////////////////////////////////////////////////
  62. INLINE bool EggAttributes::
  63. matches_normal(const EggAttributes &other) const {
  64. if (((_flags ^ other._flags) & F_has_normal) != 0) {
  65. return false;
  66. }
  67. if (!has_normal()) {
  68. return true;
  69. }
  70. return (get_normal() == other.get_normal() &&
  71. _dnormals.compare_to(other._dnormals) == 0);
  72. }
  73. ////////////////////////////////////////////////////////////////////
  74. // Function: EggAttributes::copy_normal
  75. // Access: Published
  76. // Description: Sets this normal to be the same as the other's,
  77. // include morphs. If the other has no normal, this
  78. // clears the normal.
  79. ////////////////////////////////////////////////////////////////////
  80. INLINE void EggAttributes::
  81. copy_normal(const EggAttributes &other) {
  82. if (!other.has_normal()) {
  83. clear_normal();
  84. } else {
  85. set_normal(other.get_normal());
  86. _dnormals = other._dnormals;
  87. }
  88. }
  89. ////////////////////////////////////////////////////////////////////
  90. // Function: EggAttributes::has_color
  91. // Access: Published
  92. // Description:
  93. ////////////////////////////////////////////////////////////////////
  94. INLINE bool EggAttributes::
  95. has_color() const {
  96. return (_flags & F_has_color) != 0;
  97. }
  98. ////////////////////////////////////////////////////////////////////
  99. // Function: EggAttributes::get_color
  100. // Access: Published
  101. // Description: Returns the color set on this particular attribute.
  102. // If there is no color set, returns white.
  103. ////////////////////////////////////////////////////////////////////
  104. INLINE Colorf EggAttributes::
  105. get_color() const {
  106. if (has_color()) {
  107. return _color;
  108. } else {
  109. return Colorf(1.0, 1.0, 1.0, 1.0);
  110. }
  111. }
  112. ////////////////////////////////////////////////////////////////////
  113. // Function: EggAttributes::
  114. // Access: Published
  115. // Description:
  116. ////////////////////////////////////////////////////////////////////
  117. INLINE void EggAttributes::
  118. set_color(const Colorf &color) {
  119. _color = color;
  120. _flags |= F_has_color;
  121. }
  122. ////////////////////////////////////////////////////////////////////
  123. // Function: EggAttributes::
  124. // Access: Published
  125. // Description:
  126. ////////////////////////////////////////////////////////////////////
  127. INLINE void EggAttributes::
  128. clear_color() {
  129. _flags &= ~F_has_color;
  130. }
  131. ////////////////////////////////////////////////////////////////////
  132. // Function: EggAttributes::matches_color
  133. // Access: Published
  134. // Description: Returns true if this color matches that of the other
  135. // EggAttributes object, include the morph list.
  136. ////////////////////////////////////////////////////////////////////
  137. INLINE bool EggAttributes::
  138. matches_color(const EggAttributes &other) const {
  139. if (((_flags ^ other._flags) & F_has_color) != 0) {
  140. return false;
  141. }
  142. if (!has_color()) {
  143. return true;
  144. }
  145. return (get_color() == other.get_color() &&
  146. _drgbas.compare_to(other._drgbas) == 0);
  147. }
  148. ////////////////////////////////////////////////////////////////////
  149. // Function: EggAttributes::copy_color
  150. // Access: Published
  151. // Description: Sets this color to be the same as the other's,
  152. // include morphs. If the other has no color, this
  153. // clears the color.
  154. ////////////////////////////////////////////////////////////////////
  155. INLINE void EggAttributes::
  156. copy_color(const EggAttributes &other) {
  157. if (!other.has_color()) {
  158. clear_color();
  159. } else {
  160. set_color(other.get_color());
  161. _drgbas = other._drgbas;
  162. }
  163. }
  164. ////////////////////////////////////////////////////////////////////
  165. // Function: EggAttributes::sorts_less_than
  166. // Access: Published
  167. // Description: An ordering operator to compare two vertices for
  168. // sorting order. This imposes an arbitrary ordering
  169. // useful to identify unique vertices.
  170. ////////////////////////////////////////////////////////////////////
  171. INLINE bool EggAttributes::
  172. sorts_less_than(const EggAttributes &other) const {
  173. return compare_to(other) < 0;
  174. }