Panda3D

Loading...
Searching...
No Matches
eggToSomething.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file eggToSomething.cxx
10 * @author drose
11 * @date 2000-02-15
12 */
13
14#include "eggToSomething.h"
15
16/**
17 * The first parameter to the constructor should be the one-word name of the
18 * file format that is to be read, for instance "OpenFlight" or "Alias". It's
19 * just used in printing error messages and such.
20 */
21 EggToSomething::
22 EggToSomething(const std::string &format_name,
23 const std::string &preferred_extension,
24 bool allow_last_param, bool allow_stdout) :
25 EggConverter(format_name, preferred_extension, allow_last_param,
26 allow_stdout)
27{
28 clear_runlines();
29 if (_allow_last_param) {
30 add_runline("[opts] input.egg output" + _preferred_extension);
31 }
32 add_runline("[opts] -o output" + _preferred_extension + " input.egg");
33 if (_allow_stdout) {
34 add_runline("[opts] input.egg >output" + _preferred_extension);
35 }
36
37 std::string o_description;
38
39 if (_allow_stdout) {
40 if (_allow_last_param) {
41 o_description =
42 "Specify the filename to which the resulting " + format_name +
43 " file will be written. "
44 "If this option is omitted, the last parameter name is taken to be the "
45 "name of the output file, or standard output is used if there are no "
46 "other parameters.";
47 } else {
48 o_description =
49 "Specify the filename to which the resulting " + format_name +
50 " file will be written. "
51 "If this option is omitted, the " + format_name +
52 " file is written to standard output.";
53 }
54 } else {
55 if (_allow_last_param) {
56 o_description =
57 "Specify the filename to which the resulting " + format_name +
58 " file will be written. "
59 "If this option is omitted, the last parameter name is taken to be the "
60 "name of the output file.";
61 } else {
62 o_description =
63 "Specify the filename to which the resulting " + format_name +
64 " file will be written.";
65 }
66 }
67
68 redescribe_option("o", o_description);
69
70 redescribe_option
71 ("cs",
72 "Specify the coordinate system of the resulting " + _format_name +
73 " file. This may be "
74 "one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default "
75 "is the same coordinate system as the input egg file. If this is "
76 "different from the input egg file, a conversion will be performed.");
77
78 _input_units = DU_invalid;
79 _output_units = DU_invalid;
80}
81
82/**
83 * Adds -ui and -uo as valid options for this program. If the user specifies
84 * -uo and -ui, or just -uo and the program specifies -ui by setting
85 * _input_units, the indicated units conversion will be automatically applied
86 * before writing out the egg file.
87 */
88 void EggToSomething::
89 add_units_options() {
90 add_option
91 ("ui", "units", 40,
92 "Specify the units of the input egg file. If this is "
93 "specified, the vertices in the egg file will be scaled as "
94 "necessary to make the appropriate units conversion; otherwise, "
95 "the vertices will be left as they are.",
96 &EggToSomething::dispatch_units, nullptr, &_input_units);
97
98 add_option
99 ("uo", "units", 40,
100 "Specify the units of the resulting " + _format_name +
101 " file. Normally, the default units for the format are used.",
102 &EggToSomething::dispatch_units, nullptr, &_output_units);
103}
104
105/**
106 * Applies the scale indicated by the input and output units to the indicated
107 * egg file. This is normally done automatically when the file is read in.
108 */
109 void EggToSomething::
110apply_units_scale(EggData *data) {
111
112 // [gjeon] since maya's internal unit is fixed to cm and when we can't
113 // change UI unit without affecting data we need to convert data to cm for
114 // now this will be set later to proper output unit user provided by using
115 // MayaApi::set_units() in eggToMaya.cxx
116 DistanceUnit output_units = _output_units;
117 if (_format_name == "Maya")
118 _output_units = DU_centimeters;
119
120 if (_output_units != DU_invalid && _input_units != DU_invalid &&
121 _input_units != _output_units) {
122 nout << "Converting from " << format_long_unit(_input_units)
123 << " to " << format_long_unit(_output_units) << "\n";
124 double scale = convert_units(_input_units, _output_units);
125 data->transform(LMatrix4d::scale_mat(scale));
126 }
127 _output_units = output_units;
128}
129
130/**
131 * Performs any processing of the egg file that is appropriate after reading
132 * it in.
133 *
134 * Normally, you should not need to call this function directly; it is called
135 * automatically at startup.
136 */
137 void EggToSomething::
138pre_process_egg_file() {
139 apply_units_scale(_data);
140 EggConverter::pre_process_egg_file();
141}
142
143/**
144 * Does something with the additional arguments on the command line (after all
145 * the -options have been parsed). Returns true if the arguments are good,
146 * false otherwise.
147 */
148 bool EggToSomething::
149handle_args(ProgramBase::Args &args) {
150 if (!check_last_arg(args, 1)) {
151 return false;
152 }
153
154 return EggConverter::handle_args(args);
155}
EggConverter::EggConverter
EggConverter(const std::string &format_name, const std::string &preferred_extension=std::string(), bool allow_last_param=true, bool allow_stdout=true)
The first parameter to the constructor should be the one-word name of the alien file format that is t...
Definition eggConverter.cxx:24
EggData
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition eggData.h:37
EggReader::pre_process_egg_file
virtual void pre_process_egg_file()
Performs any processing of the egg file that is appropriate after reading it in.
Definition eggReader.cxx:149
EggToSomething::add_units_options
void add_units_options()
Adds -ui and -uo as valid options for this program.
Definition eggToSomething.cxx:89
EggToSomething::EggToSomething
EggToSomething(const std::string &format_name, const std::string &preferred_extension=std::string(), bool allow_last_param=true, bool allow_stdout=true)
The first parameter to the constructor should be the one-word name of the file format that is to be r...
Definition eggToSomething.cxx:22
format_long_unit
string format_long_unit(DistanceUnit unit)
Returns the string representing the full name (plural) for the given unit.
Definition distanceUnit.cxx:67
convert_units
double convert_units(DistanceUnit from, DistanceUnit to)
Returns the scaling factor that must be applied to convert from units of "from" to "to".
Definition distanceUnit.cxx:213
DistanceUnit
DistanceUnit
This enumerated type lists all the kinds of units we're likely to come across in model conversion pro...
Definition distanceUnit.h:23
eggToSomething.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.