00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "eggWriter.h"
00016
00017 #include "string_utils.h"
00018 #include "compose_matrix.h"
00019 #include "globPattern.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 EggWriter::
00041 EggWriter(bool allow_last_param, bool allow_stdout) :
00042 WithOutputFile(allow_last_param, allow_stdout, false)
00043 {
00044
00045
00046 _preferred_extension = ".egg";
00047
00048 clear_runlines();
00049 if (_allow_last_param) {
00050 add_runline("[opts] output.egg");
00051 }
00052 add_runline("[opts] -o output.egg");
00053 if (_allow_stdout) {
00054 add_runline("[opts] >output.egg");
00055 }
00056
00057 string o_description;
00058
00059 if (_allow_stdout) {
00060 if (_allow_last_param) {
00061 o_description =
00062 "Specify the filename to which the resulting egg file will be written. "
00063 "If this option is omitted, the last parameter name is taken to be the "
00064 "name of the output file, or standard output is used if there are no "
00065 "other parameters.";
00066 } else {
00067 o_description =
00068 "Specify the filename to which the resulting egg file will be written. "
00069 "If this option is omitted, the egg file is written to standard output.";
00070 }
00071 } else {
00072 if (_allow_last_param) {
00073 o_description =
00074 "Specify the filename to which the resulting egg file will be written. "
00075 "If this option is omitted, the last parameter name is taken to be the "
00076 "name of the output file.";
00077 } else {
00078 o_description =
00079 "Specify the filename to which the resulting egg file will be written.";
00080 }
00081 }
00082
00083 add_option
00084 ("o", "filename", 50, o_description,
00085 &EggWriter::dispatch_filename, &_got_output_filename, &_output_filename);
00086
00087 redescribe_option
00088 ("cs",
00089 "Specify the coordinate system of the resulting egg file. This may be "
00090 "one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default is "
00091 "y-up.");
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 EggWriter *EggWriter::
00108 as_writer() {
00109 return this;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void EggWriter::
00125 post_process_egg_file() {
00126 if (_got_transform) {
00127 nout << "Applying transform matrix:\n";
00128 _transform.write(nout, 2);
00129 LVecBase3d scale, hpr, translate;
00130 if (decompose_matrix(_transform, scale, hpr, translate,
00131 _data->get_coordinate_system())) {
00132 nout << "(scale " << scale << ", hpr " << hpr << ", translate "
00133 << translate << ")\n";
00134 }
00135 _data->transform(_transform);
00136 }
00137
00138 if (_make_points) {
00139 nout << "Making points\n";
00140 _data->make_point_primitives();
00141 }
00142
00143 bool needs_remove = false;
00144
00145 switch (_normals_mode) {
00146 case NM_strip:
00147 nout << "Stripping normals.\n";
00148 _data->strip_normals();
00149 needs_remove = true;
00150 break;
00151
00152 case NM_polygon:
00153 nout << "Recomputing polygon normals.\n";
00154 _data->recompute_polygon_normals();
00155 needs_remove = true;
00156 break;
00157
00158 case NM_vertex:
00159 nout << "Recomputing vertex normals.\n";
00160 _data->recompute_vertex_normals(_normals_threshold);
00161 needs_remove = true;
00162 break;
00163
00164 case NM_preserve:
00165
00166 break;
00167 }
00168
00169 if (_got_tbnall) {
00170 needs_remove |= _data->recompute_tangent_binormal(GlobPattern("*"));
00171 } else {
00172 if (_got_tbnauto) {
00173 needs_remove |= _data->recompute_tangent_binormal_auto();
00174 }
00175 needs_remove |= _data->recompute_tangent_binormal(_tbn_names);
00176 }
00177
00178 if (needs_remove) {
00179 _data->remove_unused_vertices(true);
00180 }
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 void EggWriter::
00193 write_egg_file() {
00194 post_process_egg_file();
00195 _data->write_egg(get_output());
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 bool EggWriter::
00207 handle_args(ProgramBase::Args &args) {
00208 if (!check_last_arg(args, 0)) {
00209 return false;
00210 }
00211
00212 if (!args.empty()) {
00213 nout << "Unexpected arguments on command line:\n";
00214 Args::const_iterator ai;
00215 for (ai = args.begin(); ai != args.end(); ++ai) {
00216 nout << (*ai) << " ";
00217 }
00218 nout << "\r";
00219 return false;
00220 }
00221
00222 if (!_got_path_directory && _got_output_filename) {
00223
00224 _path_replace->_path_directory = _output_filename.get_dirname();
00225 }
00226
00227 return true;
00228 }
00229
00230
00231
00232
00233
00234
00235 bool EggWriter::
00236 post_command_line() {
00237 if (!_allow_stdout && !_got_output_filename) {
00238 nout << "You must specify the filename to write with -o.\n";
00239 return false;
00240 }
00241
00242 append_command_comment(_data);
00243
00244 return EggSingleBase::post_command_line();
00245 }