eggToObj.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Filename: eggToObj.cxx
  2. // Created by: drose (28Feb12)
  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 "eggToObj.h"
  15. #include "pystub.h"
  16. #include "eggPolygon.h"
  17. #include "eggGroupNode.h"
  18. #include "dcast.h"
  19. #include "string_utils.h"
  20. ////////////////////////////////////////////////////////////////////
  21. // Function: EggToObj::Constructor
  22. // Access: Public
  23. // Description:
  24. ////////////////////////////////////////////////////////////////////
  25. EggToObj::
  26. EggToObj() :
  27. EggToSomething("Obj", ".obj", true, false)
  28. {
  29. set_program_description
  30. ("This program converts egg files to obj. It "
  31. "only converts polygon data, with no fancy tricks. "
  32. "Very bare-bones at the moment; not even texture maps are supported.");
  33. redescribe_option
  34. ("cs",
  35. "Specify the coordinate system of the resulting " + _format_name +
  36. " file. Normally, this is z-up.");
  37. add_option
  38. ("C", "", 0,
  39. "Clean out higher-order polygons by subdividing into triangles.",
  40. &EggToObj::dispatch_none, &_triangulate_polygons);
  41. _coordinate_system = CS_zup_right;
  42. _got_coordinate_system = true;
  43. }
  44. ////////////////////////////////////////////////////////////////////
  45. // Function: EggToObj::run
  46. // Access: Public
  47. // Description:
  48. ////////////////////////////////////////////////////////////////////
  49. void EggToObj::
  50. run() {
  51. if (_triangulate_polygons) {
  52. nout << "Triangulating polygons.\n";
  53. int num_produced = _data->triangulate_polygons(~0);
  54. nout << " (" << num_produced << " triangles produced.)\n";
  55. }
  56. EggToObjConverter saver;
  57. saver.set_egg_data(_data);
  58. if (!saver.write_file(get_output_filename())) {
  59. nout << "An error occurred while writing.\n";
  60. exit(1);
  61. }
  62. }
  63. ////////////////////////////////////////////////////////////////////
  64. // Function: EggToObj::handle_args
  65. // Access: Protected, Virtual
  66. // Description: Does something with the additional arguments on the
  67. // command line (after all the -options have been
  68. // parsed). Returns true if the arguments are good,
  69. // false otherwise.
  70. ////////////////////////////////////////////////////////////////////
  71. bool EggToObj::
  72. handle_args(ProgramBase::Args &args) {
  73. return EggToSomething::handle_args(args);
  74. }
  75. int main(int argc, char *argv[]) {
  76. // A call to pystub() to force libpystub.so to be linked in.
  77. pystub();
  78. EggToObj prog;
  79. prog.parse_command_line(argc, argv);
  80. prog.run();
  81. return 0;
  82. }