Panda3D
|
00001 // Filename: mayaToEggConverter.h 00002 // Created by: drose (10Nov99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef MAYATOEGGCONVERTER_H 00016 #define MAYATOEGGCONVERTER_H 00017 00018 #include "pandatoolbase.h" 00019 #include "somethingToEggConverter.h" 00020 #include "mayaNodeTree.h" 00021 00022 #include "mayaApi.h" 00023 #include "mayaShaders.h" 00024 #include "mayaShaderColorDef.h" 00025 #include "eggTextureCollection.h" 00026 #include "distanceUnit.h" 00027 #include "coordinateSystem.h" 00028 #include "globPattern.h" 00029 #include "pvector.h" 00030 #include "vector_string.h" 00031 00032 #include "pre_maya_include.h" 00033 #include <maya/MDagPath.h> 00034 #include <maya/MItMeshPolygon.h> 00035 #include "post_maya_include.h" 00036 00037 class EggData; 00038 class EggGroup; 00039 class EggTable; 00040 class EggVertexPool; 00041 class EggNurbsCurve; 00042 class EggPrimitive; 00043 class EggXfmSAnim; 00044 class MayaShaderColorDef; 00045 00046 class MObject; 00047 class MDagPath; 00048 class MFnDagNode; 00049 class MFnNurbsSurface; 00050 class MFnNurbsCurve; 00051 class MFnMesh; 00052 class MPointArray; 00053 class MFloatArray; 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Class : MayaToEggConverter 00057 // Description : This class supervises the construction of an EggData 00058 // structure from a single Maya file, or from the data 00059 // already in the global Maya model space. 00060 // 00061 // Note that since the Maya API presents just one global 00062 // model space, it is not possible to simultaneously 00063 // load two distinct Maya files. 00064 //////////////////////////////////////////////////////////////////// 00065 class MayaToEggConverter : public SomethingToEggConverter { 00066 public: 00067 MayaToEggConverter(const string &program_name = ""); 00068 MayaToEggConverter(const MayaToEggConverter ©); 00069 virtual ~MayaToEggConverter(); 00070 00071 virtual SomethingToEggConverter *make_copy(); 00072 00073 virtual string get_name() const; 00074 virtual string get_extension() const; 00075 virtual string get_additional_extensions() const; 00076 00077 virtual bool convert_file(const Filename &filename); 00078 virtual DistanceUnit get_input_units(); 00079 00080 void clear_subroots(); 00081 void add_subroot(const GlobPattern &glob); 00082 00083 void clear_subsets(); 00084 void add_subset(const GlobPattern &glob); 00085 00086 void clear_excludes(); 00087 void add_exclude(const GlobPattern &glob); 00088 00089 void clear_ignore_sliders(); 00090 void add_ignore_slider(const GlobPattern &glob); 00091 bool ignore_slider(const string &name) const; 00092 00093 void clear_force_joints(); 00094 void add_force_joint(const GlobPattern &glob); 00095 bool force_joint(const string &name) const; 00096 00097 void set_from_selection(bool from_selection); 00098 00099 bool convert_maya(); 00100 00101 void clear(); 00102 00103 bool open_api(bool revert_directory=true); 00104 void close_api(); 00105 00106 private: 00107 bool convert_flip(double start_frame, double end_frame, 00108 double frame_inc, double output_frame_rate); 00109 00110 bool convert_char_model(); 00111 bool convert_char_chan(double start_frame, double end_frame, 00112 double frame_inc, double output_frame_rate); 00113 bool convert_hierarchy(EggGroupNode *egg_root); 00114 bool process_model_node(MayaNodeDesc *node_desc); 00115 00116 void get_transform(MayaNodeDesc *node_desc, const MDagPath &dag_path, 00117 EggGroup *egg_group); 00118 void get_joint_transform(const MDagPath &dag_path, EggGroup *egg_group); 00119 void apply_lod_attributes(EggGroup *egg_group, MFnDagNode &lod_group); 00120 00121 // I ran into core dumps trying to pass around a MFnMesh object by 00122 // value. From now on, all MFn* objects will be passed around by 00123 // reference. 00124 // void make_tex_names(const MFnMesh &mesh, const MObject &mesh_object); 00125 00126 void make_nurbs_surface(MayaNodeDesc *node_desc, 00127 const MDagPath &dag_path, 00128 MFnNurbsSurface &surface, 00129 EggGroup *group); 00130 EggNurbsCurve *make_trim_curve(const MFnNurbsCurve &curve, 00131 const string &nurbs_name, 00132 EggGroupNode *egg_group, 00133 int trim_curve_index); 00134 void make_nurbs_curve(const MDagPath &dag_path, 00135 const MFnNurbsCurve &curve, 00136 EggGroup *group); 00137 void make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, 00138 const MFnMesh &mesh, EggGroup *egg_group, 00139 MayaShader *default_shader = NULL); 00140 void make_locator(const MDagPath &dag_path, const MFnDagNode &dag_node, 00141 EggGroup *egg_group); 00142 bool get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh, 00143 pvector<EggGroup *> &joints, MFloatArray &weights); 00144 bool get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface, 00145 pvector<EggGroup *> &joints, MFloatArray &weights); 00146 void apply_texture_uvprops(EggTexture &tex, 00147 const MayaShaderColorDef &color_def); 00148 void apply_texture_blendtype(EggTexture &tex, 00149 const MayaShaderColorDef &color_def); 00150 void apply_texture_filename(EggTexture &tex, 00151 const MayaShaderColorDef &color_def); 00152 void apply_texture_alpha_filename(EggTexture &tex, 00153 const MayaShaderColorDef &color_def); 00154 bool compare_texture_uvprops(EggTexture &tex, 00155 const MayaShaderColorDef &color_def); 00156 bool reparent_decals(EggGroupNode *egg_parent); 00157 void set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, 00158 bool mesh = false); 00159 void set_shader_modern(EggPrimitive &primitive, const MayaShader &shader, 00160 bool mesh); 00161 void set_shader_legacy(EggPrimitive &primitive, const MayaShader &shader, 00162 bool mesh); 00163 void set_vertex_color(EggVertex &vert, MItMeshPolygon &pi, int vert_index, const MayaShader *shader, const LColor &color); 00164 00165 void set_vertex_color_legacy(EggVertex &vert, MItMeshPolygon &pi, int vert_index, const MayaShader *shader, const LColor &color); 00166 00167 void set_vertex_color_modern(EggVertex &vert, MItMeshPolygon &pi, int vert_index, const MayaShader *shader, const LColor &color); 00168 00169 int round(double value); 00170 00171 string _program_name; 00172 00173 bool _from_selection; 00174 string _subroot; 00175 typedef pvector<GlobPattern> Globs; 00176 Globs _subsets; 00177 Globs _subroots; 00178 Globs _excludes; 00179 Globs _ignore_sliders; 00180 Globs _force_joints; 00181 00182 MayaNodeTree _tree; 00183 00184 public: 00185 MayaShaders _shaders; 00186 EggTextureCollection _textures; 00187 PT(MayaApi) _maya; 00188 00189 bool _polygon_output; 00190 double _polygon_tolerance; 00191 bool _respect_maya_double_sided; 00192 bool _always_show_vertex_color; 00193 bool _keep_all_uvsets; 00194 bool _round_uvs; 00195 bool _legacy_shader; 00196 00197 00198 enum TransformType { 00199 TT_invalid, 00200 TT_all, 00201 TT_model, 00202 TT_dcs, 00203 TT_none, 00204 }; 00205 TransformType _transform_type; 00206 00207 static TransformType string_transform_type(const string &arg); 00208 }; 00209 00210 00211 #endif