15 #if defined(WIN32_VC) || defined(WIN64_VC)
18 #include "mayaToEgg_server.h"
19 #include "mayaToEggConverter.h"
20 #include "config_mayaegg.h"
21 #include "config_maya.h"
22 #include "globPattern.h"
36 add_path_replace_options();
37 add_path_store_options();
43 set_program_brief(
"convert Maya model files to .egg");
44 set_program_description
45 (
"This program converts Maya model files to egg. Static and animatable "
46 "models can be converted, with polygon or NURBS output. Animation tables "
47 "can also be generated to apply to an animatable model.");
51 "Generate polygon output only. Tesselate all NURBS surfaces to "
52 "polygons via the built-in Maya tesselator. The tesselation will "
53 "be based on the tolerance factor given by -ptol.",
54 &MayaToEggServer::dispatch_none, &_polygon_output);
57 (
"ptol",
"tolerance", 0,
58 "Specify the fit tolerance for Maya polygon tesselation. The smaller "
59 "the number, the more polygons will be generated. The default is "
61 &MayaToEggServer::dispatch_double, NULL, &_polygon_tolerance);
65 "Respect the Maya \"double sided\" rendering flag to indicate whether "
66 "polygons should be double-sided or single-sided. Since this flag "
67 "is set to double-sided by default in Maya, it is often better to "
68 "ignore this flag (unless your modelers are diligent in turning it "
69 "off where it is not desired). If this flag is not specified, the "
70 "default is to treat all polygons as single-sided, unless an "
71 "egg object type of \"double-sided\" is set.",
72 &MayaToEggServer::dispatch_none, &_respect_maya_double_sided);
75 (
"suppress-vcolor",
"", 0,
76 "Ignore vertex color for geometry that has a texture applied. "
77 "(This is the way Maya normally renders internally.) The egg flag "
78 "'vertex-color' may be applied to a particular model to override "
79 "this setting locally.",
80 &MayaToEggServer::dispatch_none, &_suppress_vertex_color);
84 "Convert all UV sets on all vertices, even those that do not appear "
85 "to be referenced by any textures.",
86 &MayaToEggServer::dispatch_none, &_keep_all_uvsets);
90 "round up uv coordinates to the nearest 1/100th. i.e. -0.001 becomes"
91 "0.0; 0.444 becomes 0.44; 0.778 becomes 0.78.",
92 &MayaToEggServer::dispatch_none, &_round_uvs);
96 "Specifies which transforms in the Maya file should be converted to "
97 "transforms in the egg file. The option may be one of all, model, "
98 "dcs, or none. The default is model, which means only transforms on "
99 "nodes that have the model flag or the dcs flag are preserved.",
100 &MayaToEggServer::dispatch_transform_type, NULL, &_transform_type);
103 (
"subroot",
"name", 0,
104 "Specifies that only a subroot of the geometry in the Maya file should "
105 "be converted; specifically, the geometry under the node or nodes whose "
106 "name matches the parameter (which may include globbing characters "
107 "like * or ?). This parameter may be repeated multiple times to name "
108 "multiple roots. If it is omitted altogether, the entire file is "
110 &MayaToEggServer::dispatch_vector_string, NULL, &_subroots);
113 (
"subset",
"name", 0,
114 "Specifies that only a subset of the geometry in the Maya file should "
115 "be converted; specifically, the geometry under the node or nodes whose "
116 "name matches the parameter (which may include globbing characters "
117 "like * or ?). This parameter may be repeated multiple times to name "
118 "multiple roots. If it is omitted altogether, the entire file is "
120 &MayaToEggServer::dispatch_vector_string, NULL, &_subsets);
123 (
"exclude",
"name", 0,
124 "Specifies that a subset of the geometry in the Maya file should "
125 "not be converted; specifically, the geometry under the node or nodes whose "
126 "name matches the parameter (which may include globbing characters "
127 "like * or ?). This parameter may be repeated multiple times to name "
129 &MayaToEggServer::dispatch_vector_string, NULL, &_excludes);
132 (
"ignore-slider",
"name", 0,
133 "Specifies the name of a slider (blend shape deformer) that maya2egg "
134 "should not process. The slider will not be touched during conversion "
135 "and it will not become a part of the animation. This "
136 "parameter may including globbing characters, and it may be repeated "
138 &MayaToEggServer::dispatch_vector_string, NULL, &_ignore_sliders);
141 (
"force-joint",
"name", 0,
142 "Specifies the name of a DAG node that maya2egg "
143 "should treat as a joint, even if it does not appear to be a Maya joint "
144 "and does not appear to be animated.",
145 &MayaToEggServer::dispatch_vector_string, NULL, &_force_joints);
149 "Increase verbosity. More v's means more verbose.",
150 &MayaToEggServer::dispatch_count, NULL, &_verbose);
153 (
"legacy-shaders",
"", 0,
154 "Use this flag to turn off modern (Phong) shader generation"
155 "and treat all shaders as if they were Lamberts (legacy).",
156 &MayaToEggServer::dispatch_none, &_legacy_shader);
162 remove_option(
"noabs");
165 _polygon_tolerance = 0.01;
166 _transform_type = MayaToEggConverter::TT_model;
174 nout <<
"Initializing Maya...\n";
175 if (!dummy->open_api()) {
176 nout <<
"Unable to initialize Maya.\n";
199 void MayaToEggServer::
206 maya_cat->set_severity(NS_spam);
207 mayaegg_cat->set_severity(NS_spam);
208 }
else if (_verbose >= 2) {
209 maya_cat->set_severity(NS_debug);
210 mayaegg_cat->set_severity(NS_debug);
211 }
else if (_verbose >= 1) {
212 maya_cat->set_severity(NS_info);
213 mayaegg_cat->set_severity(NS_info);
219 if (_got_output_filename) {
220 _output_filename.make_absolute();
221 _path_replace->_path_directory.make_absolute();
227 converter._polygon_output = _polygon_output;
228 converter._polygon_tolerance = _polygon_tolerance;
229 converter._respect_maya_double_sided = _respect_maya_double_sided;
230 converter._always_show_vertex_color = !_suppress_vertex_color;
231 converter._keep_all_uvsets = _keep_all_uvsets;
232 converter._round_uvs = _round_uvs;
233 converter._transform_type = _transform_type;
234 converter._legacy_shader = _legacy_shader;
236 vector_string::const_iterator si;
237 if (!_subroots.empty()) {
238 converter.clear_subroots();
239 for (si = _subroots.begin(); si != _subroots.end(); ++si) {
244 if (!_subsets.empty()) {
245 converter.clear_subsets();
246 for (si = _subsets.begin(); si != _subsets.end(); ++si) {
251 if (!_excludes.empty()) {
252 converter.clear_excludes();
253 for (si = _excludes.begin(); si != _excludes.end(); ++si) {
258 if (!_ignore_sliders.empty()) {
259 converter.clear_ignore_sliders();
260 for (si = _ignore_sliders.begin(); si != _ignore_sliders.end(); ++si) {
265 if (!_force_joints.empty()) {
266 converter.clear_force_joints();
267 for (si = _force_joints.begin(); si != _force_joints.end(); ++si) {
273 apply_parameters(converter);
276 if (!_got_coordinate_system) {
277 _coordinate_system = converter._maya->get_coordinate_system();
279 _data->set_coordinate_system(_coordinate_system);
281 converter.set_egg_data(_data);
283 if (!converter.convert_file(_input_filename)) {
284 nout <<
"Errors in conversion.\n";
292 if (_input_units == DU_invalid) {
293 _input_units = converter.get_input_units();
297 append_command_comment(_data);
304 _polygon_tolerance = 0.01;
306 _transform_type = MayaToEggConverter::TT_model;
309 _input_units = DU_invalid;
310 _output_units = DU_invalid;
312 _ignore_sliders.clear();
313 _force_joints.clear();
314 _got_transform =
false;
316 _normals_mode = NM_preserve;
317 _normals_threshold = 0.0;
318 _got_start_frame =
false;
319 _got_end_frame =
false;
320 _got_frame_inc =
false;
321 _got_neutral_frame =
false;
322 _got_input_frame_rate =
false;
323 _got_output_frame_rate =
false;
324 _got_output_filename =
false;
325 _merge_externals =
false;
327 _got_tbnauto =
false;
328 _got_transform =
false;
329 _coordinate_system = CS_yup_right;
331 _program_args.clear();
333 _animation_convert = AC_none;
334 _character_name =
"";
344 bool MayaToEggServer::
345 dispatch_transform_type(
const string &opt,
const string &arg,
void *var) {
346 MayaToEggConverter::TransformType *ip = (MayaToEggConverter::TransformType *)var;
349 if ((*ip) == MayaToEggConverter::TT_invalid) {
350 nout <<
"Invalid type for -" << opt <<
": " << arg <<
"\n"
351 <<
"Valid types are all, model, dcs, and none.\n";
378 _clients.insert(con);
386 _clients.erase(connection);
408 vector<char *> buffers;
412 for ( i = 0; i < argc; i++ ) {
422 char ** cargv = (
char**) malloc(
sizeof(
char**) * argc);
428 for ( i = 0; i < argc; i++) {
430 const char * cptr = vargv[i].c_str();
432 char * buffer = (
char*) malloc(vargv[i].capacity()+1);
434 strcpy(buffer, cptr);
439 buffers.push_back(buffer);
458 vector<char *>::iterator vi;
459 for ( vi = buffers.begin() ; vi != buffers.end(); vi++) {
466 Clients::iterator ci;
467 for (ci = _clients.begin(); ci != _clients.end(); ++ci) {
473 int main(
int argc,
char *argv[]) {
482 PT(
Connection) rend = prog.qManager->open_TCP_server_rendezvous(4242, 50);
483 if (rend.is_null()) {
484 nout <<
"port opened fail";
bool close_connection(const PT(Connection)&connection)
Terminates a UDP or TCP socket previously opened.
A specific kind of Datagram, especially for sending across or receiving from a network.
static TransformType string_transform_type(const string &arg)
Returns the TransformType value corresponding to the indicated string, or TT_invalid.
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
This flavor of ConnectionManager will queue up all of the reset-connection messages from the Connecti...
void add_animation_options()
Adds options appropriate to animation packages.
void add_normals_options()
Adds -no, -np, etc.
void poll()
Checks for any network activity and handles it, if appropriate, and then returns. ...
void close_output()
Closes the output stream previously opened by get_output().
void clear()
Frees all of the Maya pointers kept within this object, in preparation for loading a new scene or rel...
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
This is the primary interface into all the egg data, and the root of the egg file structure...
static void force_yield()
Suspends the current thread for the rest of the current epoch.
string get_string()
Extracts a variable-length string.
bool get_reset_connection(PT(Connection)&connection)
If a previous call to reset_connection_available() returned true, this function will return informati...
void poll()
Explicitly polls the available sockets to see if any of them have any noise.
bool data_available()
Returns true if a datagram is available on the queue; call get_data() to extract the datagram...
static const LMatrix4d & ident_mat()
Returns an identity matrix.
bool reset_connection_available() const
Returns true if one of the readers/writers/listeners reported a connection reset recently.
bool new_connection_available()
Returns true if a new connection was recently established; the connection information may then be ret...
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
void write_egg_file()
Writes out the egg file as the normal result of the program.
This class supervises the construction of an EggData structure from a single Maya file...
bool get_data(NetDatagram &result)
If a previous call to data_available() returned true, this function will return the datagram that has...
bool add_connection(Connection *connection)
Adds a new socket to the list of sockets the ConnectionReader will monitor.
This flavor of ConnectionReader will read from its sockets and queue up all of the datagrams read for...
void add_transform_options()
Adds -TS, -TT, etc.
This is the general base class for a file-converter program that reads some model file format and gen...
A class to retrieve the individual data elements previously stored in a Datagram. ...
Represents a single TCP or UDP socket for input or output.
bool get_new_connection(PT(Connection)&rendezvous, NetAddress &address, PT(Connection)&new_connection)
If a previous call to new_connection_available() returned true, this function will return information...
void add_units_options()
Adds -ui and -uo as valid options for this program.
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound...
This flavor of ConnectionListener will queue up all of the TCP connections it established for later d...