Panda3D
mayaToEggConverter.h
1 // Filename: mayaToEggConverter.h
2 // Created by: drose (10Nov99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MAYATOEGGCONVERTER_H
16 #define MAYATOEGGCONVERTER_H
17 
18 #include "pandatoolbase.h"
19 #include "somethingToEggConverter.h"
20 #include "mayaNodeTree.h"
21 
22 #include "mayaApi.h"
23 #include "mayaShaders.h"
24 #include "mayaShaderColorDef.h"
25 #include "eggTextureCollection.h"
26 #include "distanceUnit.h"
27 #include "coordinateSystem.h"
28 #include "globPattern.h"
29 #include "pvector.h"
30 #include "vector_string.h"
31 
32 #include "pre_maya_include.h"
33 #include <maya/MDagPath.h>
34 #include <maya/MItMeshPolygon.h>
35 #include "post_maya_include.h"
36 
37 class EggData;
38 class EggGroup;
39 class EggTable;
40 class EggVertexPool;
41 class EggNurbsCurve;
42 class EggPrimitive;
43 class EggXfmSAnim;
44 class MayaShaderColorDef;
45 
46 class MObject;
47 class MDagPath;
48 class MFnDagNode;
49 class MFnNurbsSurface;
50 class MFnNurbsCurve;
51 class MFnMesh;
52 class MPointArray;
53 class MFloatArray;
54 
55 ////////////////////////////////////////////////////////////////////
56 // Class : MayaToEggConverter
57 // Description : This class supervises the construction of an EggData
58 // structure from a single Maya file, or from the data
59 // already in the global Maya model space.
60 //
61 // Note that since the Maya API presents just one global
62 // model space, it is not possible to simultaneously
63 // load two distinct Maya files.
64 ////////////////////////////////////////////////////////////////////
66 public:
67  MayaToEggConverter(const string &program_name = "");
69  virtual ~MayaToEggConverter();
70 
72 
73  virtual string get_name() const;
74  virtual string get_extension() const;
75  virtual string get_additional_extensions() const;
76 
77  virtual bool convert_file(const Filename &filename);
78  virtual DistanceUnit get_input_units();
79 
80  void clear_subroots();
81  void add_subroot(const GlobPattern &glob);
82 
83  void clear_subsets();
84  void add_subset(const GlobPattern &glob);
85 
86  void clear_excludes();
87  void add_exclude(const GlobPattern &glob);
88 
89  void clear_ignore_sliders();
90  void add_ignore_slider(const GlobPattern &glob);
91  bool ignore_slider(const string &name) const;
92 
93  void clear_force_joints();
94  void add_force_joint(const GlobPattern &glob);
95  bool force_joint(const string &name) const;
96 
97  void set_from_selection(bool from_selection);
98 
99  bool convert_maya();
100 
101  void clear();
102 
103  bool open_api(bool revert_directory=true);
104  void close_api();
105 
106 private:
107  bool convert_flip(double start_frame, double end_frame,
108  double frame_inc, double output_frame_rate);
109 
110  bool convert_char_model();
111  bool convert_char_chan(double start_frame, double end_frame,
112  double frame_inc, double output_frame_rate);
113  bool convert_hierarchy(EggGroupNode *egg_root);
114  bool process_model_node(MayaNodeDesc *node_desc);
115 
116  void get_transform(MayaNodeDesc *node_desc, const MDagPath &dag_path,
117  EggGroup *egg_group);
118  void get_joint_transform(const MDagPath &dag_path, EggGroup *egg_group);
119  void apply_lod_attributes(EggGroup *egg_group, MFnDagNode &lod_group);
120 
121  // I ran into core dumps trying to pass around a MFnMesh object by
122  // value. From now on, all MFn* objects will be passed around by
123  // reference.
124  // void make_tex_names(const MFnMesh &mesh, const MObject &mesh_object);
125 
126  void make_nurbs_surface(MayaNodeDesc *node_desc,
127  const MDagPath &dag_path,
128  MFnNurbsSurface &surface,
129  EggGroup *group);
130  EggNurbsCurve *make_trim_curve(const MFnNurbsCurve &curve,
131  const string &nurbs_name,
132  EggGroupNode *egg_group,
133  int trim_curve_index);
134  void make_nurbs_curve(const MDagPath &dag_path,
135  const MFnNurbsCurve &curve,
136  EggGroup *group);
137  void make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path,
138  const MFnMesh &mesh, EggGroup *egg_group,
139  MayaShader *default_shader = NULL);
140  void make_locator(const MDagPath &dag_path, const MFnDagNode &dag_node,
141  EggGroup *egg_group);
142  void make_camera_locator(const MDagPath &dag_path, const MFnDagNode &dag_node,
143  EggGroup *egg_group);
144  void make_light_locator(const MDagPath &dag_path, const MFnDagNode &dag_node,
145  EggGroup *egg_group);
146  bool get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
147  pvector<EggGroup *> &joints, MFloatArray &weights);
148  bool get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface,
149  pvector<EggGroup *> &joints, MFloatArray &weights);
150  void apply_texture_uvprops(EggTexture &tex,
151  const MayaShaderColorDef &color_def);
152  void apply_texture_blendtype(EggTexture &tex,
153  const MayaShaderColorDef &color_def);
154  void apply_texture_filename(EggTexture &tex,
155  const MayaShaderColorDef &color_def);
156  void apply_texture_alpha_filename(EggTexture &tex,
157  const MayaShaderColorDef &color_def);
158  bool compare_texture_uvprops(EggTexture &tex,
159  const MayaShaderColorDef &color_def);
160  bool reparent_decals(EggGroupNode *egg_parent);
161  void set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader,
162  bool mesh = false);
163  void set_shader_modern(EggPrimitive &primitive, const MayaShader &shader,
164  bool mesh);
165  void set_shader_legacy(EggPrimitive &primitive, const MayaShader &shader,
166  bool mesh);
167  void set_vertex_color(EggVertex &vert, MItMeshPolygon &pi, int vert_index, const MayaShader *shader, const LColor &color);
168 
169  void set_vertex_color_legacy(EggVertex &vert, MItMeshPolygon &pi, int vert_index, const MayaShader *shader, const LColor &color);
170 
171  void set_vertex_color_modern(EggVertex &vert, MItMeshPolygon &pi, int vert_index, const MayaShader *shader, const LColor &color);
172 
173  int round(double value);
174 
175  string _program_name;
176 
177  bool _from_selection;
178  string _subroot;
179  typedef pvector<GlobPattern> Globs;
180  Globs _subsets;
181  Globs _subroots;
182  Globs _excludes;
183  Globs _ignore_sliders;
184  Globs _force_joints;
185 
186  MayaNodeTree _tree;
187 
188 public:
189  MayaShaders _shaders;
190  EggTextureCollection _textures;
191  PT(MayaApi) _maya;
192 
193  bool _polygon_output;
194  double _polygon_tolerance;
195  bool _respect_maya_double_sided;
196  bool _always_show_vertex_color;
197  bool _keep_all_uvsets;
198  bool _convert_cameras;
199  bool _convert_lights;
200  bool _round_uvs;
201  bool _legacy_shader;
202 
203 
204  enum TransformType {
205  TT_invalid,
206  TT_all,
207  TT_model,
208  TT_dcs,
209  TT_none,
210  };
211  TransformType _transform_type;
212 
213  static TransformType string_transform_type(const string &arg);
214 };
215 
216 
217 #endif
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
void add_subset(const GlobPattern &glob)
Adds a name pattern to the list of subset nodes.
bool open_api(bool revert_directory=true)
Attempts to open the Maya API if it was not already open, and returns true if successful, or false if there is an error.
void clear_subsets()
Empties the list of subset nodes added via add_subset().
static TransformType string_transform_type(const string &arg)
Returns the TransformType value corresponding to the indicated string, or TT_invalid.
virtual string get_name() const
Returns the English name of the file type this converter supports.
void close_api()
Closes the Maya API, if it was previously opened.
bool ignore_slider(const string &name) const
Returns true if the indicated name is on the list of sliders to ignore, false otherwise.
Describes a complete tree of maya nodes for conversion.
Definition: mayaNodeTree.h:40
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
virtual DistanceUnit get_input_units()
This may be called after convert_file() has been called and returned true, indicating a successful co...
bool convert_maya()
Fills up the egg_data structure according to the global maya model data.
This is a collection of textures by TRef name.
Collects the set of MayaShaders that have been encountered so far.
Definition: mayaShaders.h:32
void clear()
Frees all of the Maya pointers kept within this object, in preparation for loading a new scene or rel...
virtual string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(), that are recognized by this converter.
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
void clear_force_joints()
Empties the list of force_joints added via add_force_joint().
virtual string get_extension() const
Returns the common extension of the file type this converter supports.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition: eggGroup.h:36
void clear_excludes()
Empties the list of excluded nodes added via add_exclude().
Describes a single instance of a node in the Maya scene graph, relating it to the corresponding egg s...
Definition: mayaNodeDesc.h:43
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This defines the various attributes that Maya may associate with the "color" channel for a particular...
void clear_ignore_sliders()
Empties the list of ignore_sliders added via add_ignore_slider().
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
This corresponds to an <Xfm$Anim_S$> entry, which is a collection of up to nine <S$Anim> entries that...
Definition: eggXfmSAnim.h:33
Corresponds to a single "shader" in Maya.
Definition: mayaShader.h:35
A parametric NURBS curve.
Definition: eggNurbsCurve.h:28
void clear_subroots()
Empties the list of subroot nodes added via add_subroot().
bool force_joint(const string &name) const
Returns true if the indicated name is on the list of DAG nodes to treat as a joint, false otherwise.
This class supervises the construction of an EggData structure from a single Maya file...
This corresponds to a.
Definition: eggTable.h:31
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
void add_force_joint(const GlobPattern &glob)
Adds a name pattern to the list of force_joints.
void set_from_selection(bool from_selection)
Sets the flag that indicates whether the currently selected Maya geometry will be converted...
This is a base class for a family of converter classes that manage a conversion from some file type t...
void add_subroot(const GlobPattern &glob)
Adds a name pattern to the list of subroot nodes.
virtual SomethingToEggConverter * make_copy()
Allocates and returns a new copy of the converter.
A collection of vertices.
Definition: eggVertexPool.h:46
This class presents a wrapper around the global Maya interface.
Definition: mayaApi.h:33
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.
void add_ignore_slider(const GlobPattern &glob)
Adds a name pattern to the list of ignore_sliders.
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
Definition: globPattern.h:37
void add_exclude(const GlobPattern &glob)
Adds a name pattern to the list of excluded nodes.