MaxToEgg.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. MaxToEgg.cpp
  3. Created by Ken Strickland 02/24/03
  4. Modified and maintained by Corey Revilla, (05/22/03)-(Present)
  5. Carnegie Mellon University, Entetainment Technology Center
  6. */
  7. //Our headers, which in turn includes some Max headers.
  8. #include "MaxToEgg.h"
  9. //Member Function Definitions
  10. /* ~MaxToEgg() - Uninteresting destructor.
  11. */
  12. MaxToEgg::~MaxToEgg()
  13. {
  14. }
  15. /* MaxToEgg() - Constructs a MaxToEgg "application." It sets the types of
  16. options this converter can take and sets up a description of the program.
  17. */
  18. MaxToEgg::MaxToEgg() : SomethingToEgg("3D Studio Max",".max")
  19. {
  20. add_path_replace_options();
  21. add_path_store_options();
  22. add_animation_options();
  23. add_units_options();
  24. add_normals_options();
  25. add_transform_options();
  26. set_program_description("This program converts 3D Studio Max model files to egg.");
  27. /*add_option("p", "", 0,
  28. "Generate polygon output only. Convert scene to triangle mesh "
  29. "before converting.", &MaxToEgg::dispatch_none, &alertOnBegin);*/
  30. add_option("bface", "", 0,
  31. "Export all polygons as double-sided ",
  32. &MaxToEgg::dispatch_none, &doubleSided);
  33. //Fill in the member variables.
  34. pMaxInterface = null;
  35. successfulOutput = false;
  36. confirmExport = true;
  37. doubleSided = false;
  38. }
  39. /* IsSuccessful() - Indicates if conversion was successful.
  40. */
  41. bool MaxToEgg::IsSuccessful()
  42. {
  43. return successfulOutput;
  44. }
  45. char *MaxToEgg::MyClassName()
  46. {
  47. return "MaxToEgg";
  48. }
  49. /* Run() - Runs the conversion. Creates a MaxToEggConverter, populates it
  50. with the scene graph, and then writes out the egg file.
  51. */
  52. void MaxToEgg::Run(ULONG *selection_list, int len)
  53. {
  54. MaxToEggConverter converter;
  55. Logger::FunctionEntry( "MaxToEgg::Run" );
  56. // Now, we fill out the necessary fields of the converter, which does all
  57. // the necessary work.
  58. Logger::Log( MTE, Logger::SAT_DEBUG_SPAM_LEVEL, "Setting Max Interface." );
  59. converter.setMaxInterface( pMaxInterface );
  60. Logger::Log( MTE, Logger::SAT_DEBUG_SPAM_LEVEL,
  61. "Setting converter's egg data." );
  62. converter.set_egg_data( &_data, false );
  63. // applies the parameters from the command line options
  64. apply_parameters(converter);
  65. converter.set_double_sided(doubleSided);
  66. converter.set_selection_list(selection_list, len);
  67. //Now, do the actual file conversion.
  68. if (confirmExport && converter.convert_file(_input_filename)) {
  69. successfulOutput=true;
  70. write_egg_file();
  71. Logger::Log( MTE, Logger::SAT_DEBUG_SPAM_LEVEL, "Egg file written!" );
  72. }
  73. Logger::FunctionExit();
  74. }
  75. /* SetMaxInterface(Interface *) - This is how we know how to traverse the Max
  76. scene graph. For this to be a standalone application, we'd want to be able
  77. to build one of these interfaces for the input file.
  78. */
  79. void MaxToEgg::SetMaxInterface(Interface *pInterface)
  80. {
  81. pMaxInterface = pInterface;
  82. }
  83. bool MaxToEgg::handle_args(Args &args) {
  84. char msg[3072];
  85. //If "auto overwrite" was not checked, ask if the user wishes to overwrite the file
  86. if (_allow_last_param && !_got_output_filename && args.size() > 1) {
  87. _got_output_filename = true;
  88. _output_filename = Filename::from_os_specific(args.back());
  89. args.pop_back();
  90. if (!verify_output_file_safe()) {
  91. sprintf(msg, "Overwrite file \"%s\"?", _output_filename.to_os_specific().c_str());
  92. confirmExport =
  93. ( MessageBox(pMaxInterface->GetMAXHWnd(), msg, "Panda3D Exporter", MB_YESNO | MB_ICONQUESTION)
  94. == IDYES );
  95. }
  96. }
  97. //Attempt to catch if the output file is read-only
  98. if (confirmExport) {
  99. _output_filename.make_dir();
  100. if (access(Filename(_output_filename.get_dirname()).to_os_specific().c_str(), 2) ||
  101. (access(_output_filename.to_os_specific().c_str(), 2) && errno != ENOENT)) {
  102. sprintf(msg, "Error attempting to open \"%s\"\n\nDestination file is in use or read-only", _output_filename.to_os_specific().c_str());
  103. MessageBox(pMaxInterface->GetMAXHWnd(), msg, "Panda3D Exporter", MB_OK | MB_ICONERROR);
  104. confirmExport = false;
  105. }
  106. }
  107. return SomethingToEgg::handle_args(args);
  108. }