Panda3D

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