00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00030
00031
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
00042
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
00095
00096
00097
00098 void EggToBam::
00099 run() {
00100 if (_has_egg_flatten) {
00101
00102
00103 egg_flatten = (_egg_flatten != 0);
00104 }
00105
00106 if (_compression_off) {
00107
00108 compress_channels = false;
00109
00110 } else if (_has_compression_quality) {
00111
00112
00113 compress_channels = true;
00114 compress_chan_quality = _compression_quality;
00115 }
00116
00117 if (!_got_coordinate_system) {
00118
00119
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
00134
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
00154
00155
00156
00157
00158
00159
00160 bool EggToBam::
00161 handle_args(ProgramBase::Args &args) {
00162
00163
00164
00165 if (_got_path_store) {
00166 bam_texture_mode = BTM_unchanged;
00167 } else {
00168
00169
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 }