Panda3D
 All Classes Functions Variables Enumerations
fltToEgg.cxx
00001 // Filename: fltToEgg.cxx
00002 // Created by:  drose (17Apr01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "fltToEgg.h"
00016 
00017 #include "fltToEggConverter.h"
00018 #include "config_flt.h"
00019 #include "pystub.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: FltToEgg::Constructor
00023 //       Access: Public
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 FltToEgg::
00027 FltToEgg() :
00028   SomethingToEgg("MultiGen", ".flt")
00029 {
00030   add_path_replace_options();
00031   add_path_store_options();
00032   add_units_options();
00033   add_normals_options();
00034   add_transform_options();
00035   add_merge_externals_options();
00036 
00037   set_program_description
00038     ("This program converts MultiGen OpenFlight (.flt) files to egg.  Most "
00039      "features of MultiGen that are also recognized by egg are supported.");
00040 
00041   redescribe_option
00042     ("cs",
00043      "Specify the coordinate system of the input " + _format_name +
00044      " file.  Normally, this is z-up.");
00045 
00046   // Does anyone really care about this option?  It's mainly useful
00047   // for debugging the flt2egg logic.
00048   /*
00049   add_option
00050     ("C", "", 0,
00051      "Compose node transforms into a single matrix before writing them to "
00052      "the egg file, instead of writing them as individual scale, rotate, and "
00053      "translate operations.",
00054      &FltToEgg::dispatch_none, &_compose_transforms);
00055   */
00056   _compose_transforms = false;
00057 
00058   _coordinate_system = CS_zup_right;
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: FltToEgg::run
00063 //       Access: Public
00064 //  Description:
00065 ////////////////////////////////////////////////////////////////////
00066 void FltToEgg::
00067 run() {
00068   _data->set_coordinate_system(_coordinate_system);
00069 
00070   FltToEggConverter converter;
00071   converter.set_merge_externals(_merge_externals);
00072   converter.set_egg_data(_data);
00073   converter._compose_transforms = _compose_transforms;
00074   converter._allow_errors = _allow_errors;
00075 
00076   apply_parameters(converter);
00077 
00078 
00079   PT(FltHeader) header = new FltHeader(_path_replace);
00080 
00081   nout << "Reading " << _input_filename << "\n";
00082   FltError result = header->read_flt(_input_filename);
00083   if (result != FE_ok) {
00084     nout << "Unable to read: " << result << "\n";
00085     exit(1);
00086   }
00087 
00088   header->check_version();
00089 
00090 
00091   if (!converter.convert_flt(header)) {
00092     nout << "Errors in conversion.\n";
00093     exit(1);
00094   }
00095 
00096   if (_input_units == DU_invalid) {
00097     _input_units = converter.get_input_units();
00098   }
00099 
00100   write_egg_file();
00101   nout << "\n";
00102 }
00103 
00104 
00105 int main(int argc, char *argv[]) {
00106   // A call to pystub() to force libpystub.so to be linked in.
00107   pystub();
00108 
00109   init_libflt();
00110   FltToEgg prog;
00111   prog.parse_command_line(argc, argv);
00112   prog.run();
00113   return 0;
00114 }
 All Classes Functions Variables Enumerations