xFileVertex.cxx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file xFileVertex.cxx
  10. * @author drose
  11. * @date 2001-06-19
  12. */
  13. #include "xFileVertex.h"
  14. #include "eggVertex.h"
  15. #include "eggPrimitive.h"
  16. #include "config_xfile.h"
  17. /**
  18. *
  19. */
  20. XFileVertex::
  21. XFileVertex() {
  22. _has_color = false;
  23. _has_uv = false;
  24. _point.set(0.0, 0.0, 0.0);
  25. _uv.set(0.0, 0.0);
  26. _color.set(1.0f, 1.0f, 1.0f, 1.0f);
  27. }
  28. /**
  29. * Sets the structure up from the indicated egg data.
  30. */
  31. void XFileVertex::
  32. set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
  33. LVertexd pos = egg_vertex->get_pos3();
  34. if (xfile_one_mesh) {
  35. // If this is going into one big mesh, we must ensure every vertex is in
  36. // world coordinates.
  37. pos = pos * egg_prim->get_vertex_frame();
  38. } else {
  39. // Otherwise, we ensure the vertex is in local coordinates.
  40. pos = pos * egg_prim->get_vertex_to_node();
  41. }
  42. _point = pos;
  43. if (egg_vertex->has_uv()) {
  44. LTexCoordd uv = egg_vertex->get_uv();
  45. if (egg_prim->has_texture()) {
  46. // Check if there's a texture matrix on the texture.
  47. EggTexture *egg_tex = egg_prim->get_texture();
  48. if (egg_tex->has_transform2d()) {
  49. uv = uv * egg_tex->get_transform2d();
  50. }
  51. }
  52. _uv[0] = uv[0];
  53. // Windows draws the UV's upside-down.
  54. _uv[1] = 1.0 - uv[1];
  55. _has_uv = true;
  56. }
  57. if (egg_vertex->has_color()) {
  58. _color = egg_vertex->get_color();
  59. _has_color = true;
  60. } else if (egg_prim->has_color()) {
  61. _color = egg_prim->get_color();
  62. _has_color = true;
  63. }
  64. }
  65. /**
  66. *
  67. */
  68. int XFileVertex::
  69. compare_to(const XFileVertex &other) const {
  70. int ct;
  71. ct = _point.compare_to(other._point);
  72. if (ct == 0) {
  73. ct = _uv.compare_to(other._uv);
  74. }
  75. if (ct == 0) {
  76. ct = _color.compare_to(other._color);
  77. }
  78. return ct;
  79. }