Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/bam/eggToBam.cxx

Go to the documentation of this file.
00001 // Filename: eggToBam.cxx
00002 // Created by:  drose (28Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "eggToBam.h"
00020 
00021 #include "config_util.h"
00022 #include "bamFile.h"
00023 #include "load_egg_file.h"
00024 #include "config_egg2pg.h"
00025 #include "config_gobj.h"
00026 #include "config_chan.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: EggToBam::Constructor
00030 //       Access: Public
00031 //  Description:
00032 ////////////////////////////////////////////////////////////////////
00033 EggToBam::
00034 EggToBam() :
00035   EggToSomething("Bam", ".bam", true, false)
00036 {
00037   set_program_description
00038     ("This program reads Egg files and outputs Bam files, the binary format "
00039      "suitable for direct loading of animation and models into Panda.");
00040 
00041   // -f is always in effect for egg2bam.  It doesn't make sense to
00042   // provide it as an option to the user.
00043   remove_option("f");
00044 
00045   add_path_replace_options();
00046   add_path_store_options();
00047 
00048   add_option
00049     ("fl", "flag", 0,
00050      "Specifies whether to flatten the egg hierarchy after it is loaded.  "
00051      "If flag is zero, the egg hierarchy will not be flattened, but will "
00052      "instead be written to the bam file exactly as it is.  If flag is "
00053      "non-zero, the hierarchy will be flattened so that unnecessary nodes "
00054      "(usually group nodes with only one child) are eliminated.  The default "
00055      "if this is not specified is taken from the egg-flatten Configrc "
00056      "variable.",
00057      &EggToBam::dispatch_int, &_has_egg_flatten, &_egg_flatten);
00058 
00059   add_option
00060     ("ls", "", 0,
00061      "Writes a scene graph listing to standard output after the egg "
00062      "file has been loaded, showing the nodes that will be written out.",
00063      &EggToBam::dispatch_none, &_ls);
00064 
00065   add_option
00066     ("C", "quality", 0,
00067      "Specify the quality level for lossy channel compression.  If this "
00068      "is specified, the animation channels will be compressed at this "
00069      "quality level, which is normally an integer value between 0 and 100, "
00070      "inclusive, where higher numbers produce larger files with greater "
00071      "quality.  Generally, 95 is the highest useful quality level.  Use "
00072      "-NC (described below) to disable channel compression.  If neither "
00073      "option is specified, the default comes from the Configrc file.",
00074      &EggToBam::dispatch_int, &_has_compression_quality, &_compression_quality);
00075 
00076   add_option
00077     ("NC", "", 0,
00078      "Turn off lossy compression of animation channels.  Channels will be "
00079      "written exactly as they are, losslessly.",
00080      &EggToBam::dispatch_none, &_compression_off);
00081 
00082   redescribe_option
00083     ("cs",
00084      "Specify the coordinate system of the resulting " + _format_name +
00085      " file.  This may be "
00086      "one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'.  The default "
00087      "is z-up.");
00088 
00089   _force_complete = true;
00090   _egg_flatten = 0;
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: EggToBam::run
00095 //       Access: Public
00096 //  Description:
00097 ////////////////////////////////////////////////////////////////////
00098 void EggToBam::
00099 run() {
00100   if (_has_egg_flatten) {
00101     // If the user specified some -fl, we need to set the
00102     // corresponding Configrc variable.
00103     egg_flatten = (_egg_flatten != 0);
00104   }
00105 
00106   if (_compression_off) {
00107     // If the user specified -NC, turn off channel compression.
00108     compress_channels = false;
00109 
00110   } else if (_has_compression_quality) {
00111     // Otherwise, if the user specified a compression quality with -C,
00112     // use that quality level.
00113     compress_channels = true;
00114     compress_chan_quality = _compression_quality;
00115   }
00116 
00117   if (!_got_coordinate_system) {
00118     // If the user didn't specify otherwise, ensure the coordinate
00119     // system is Z-up.
00120     _data.set_coordinate_system(CS_zup_right);
00121   }
00122 
00123   PT(PandaNode) root = load_egg_data(_data);
00124   if (root == (PandaNode *)NULL) {
00125     nout << "Unable to build scene graph from egg file.\n";
00126     exit(1);
00127   }
00128   
00129   if (_ls) {
00130     root->ls(nout, 0);
00131   }
00132   
00133   // This should be guaranteed because we pass false to the
00134   // constructor, above.
00135   nassertv(has_output_filename());
00136   
00137   Filename filename = get_output_filename();
00138   filename.make_dir();
00139   nout << "Writing " << filename << "\n";
00140   BamFile bam_file;
00141   if (!bam_file.open_write(filename)) {
00142     nout << "Error in writing.\n";
00143     exit(1);
00144   }
00145   
00146   if (!bam_file.write_object(root)) {
00147     nout << "Error in writing.\n";
00148       exit(1);
00149   }
00150 }
00151 
00152 ////////////////////////////////////////////////////////////////////
00153 //     Function: EggToBam::handle_args
00154 //       Access: Protected, Virtual
00155 //  Description: Does something with the additional arguments on the
00156 //               command line (after all the -options have been
00157 //               parsed).  Returns true if the arguments are good,
00158 //               false otherwise.
00159 ////////////////////////////////////////////////////////////////////
00160 bool EggToBam::
00161 handle_args(ProgramBase::Args &args) {
00162   // If the user specified a path store option, we need to set the
00163   // bam-texture-mode Configrc variable directly to support this
00164   // (otherwise the bam code will do what it wants to do anyway).
00165   if (_got_path_store) {
00166     bam_texture_mode = BTM_unchanged;
00167   } else {
00168     // Otherwise, the default path store is absolute; then the
00169     // bam-texture-mode can do the appropriate thing to it.
00170     _path_replace->_path_store = PS_absolute;
00171   }
00172 
00173   return EggToSomething::handle_args(args);
00174 }
00175 
00176 
00177 int main(int argc, char *argv[]) {
00178   EggToBam prog;
00179   prog.parse_command_line(argc, argv);
00180   prog.run();
00181   return 0;
00182 }

Generated on Fri May 2 03:16:52 2003 for Panda-Tool by doxygen1.3