From 0475f06d9b52c6bc0bd4348cc65973db804ca2d2 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Sat, 10 Dec 2005 04:06:07 +0000 Subject: [PATCH] yyepe! finally figured out the multitexture and uvset connection: this fix will enable artists to view imported multitextures --- pandatool/src/maya/mayaShaderColorDef.cxx | 30 ++++++- pandatool/src/maya/mayaShaderColorDef.h | 2 + pandatool/src/mayaegg/mayaToEggConverter.cxx | 95 ++++++++++++++------ pandatool/src/mayaegg/mayaToEggConverter.h | 9 +- 4 files changed, 104 insertions(+), 32 deletions(-) diff --git a/pandatool/src/maya/mayaShaderColorDef.cxx b/pandatool/src/maya/mayaShaderColorDef.cxx index a9403937d0..79543b0525 100644 --- a/pandatool/src/maya/mayaShaderColorDef.cxx +++ b/pandatool/src/maya/mayaShaderColorDef.cxx @@ -224,6 +224,26 @@ reset_maya_texture(const Filename &texture) { return false; } + +//////////////////////////////////////////////////////////////////// +// Function: MayaShaderColorDef::strip_prefix +// Access: Private +// Description: Maya puts a prefix on shader nameswhen files are +// imported. This routine strips that out before writing +// egg file. //This was a hack: not needed anymore +//////////////////////////////////////////////////////////////////// +string MayaShaderColorDef:: +strip_prefix(string full_name) { + string axed_name; + size_t cut_point = full_name.find(":"); + if (cut_point != string::npos) { + axed_name = full_name.substr(cut_point+1); + maya_cat.spam() << "stripped from: " << full_name << "-> to: " << axed_name << endl; + return axed_name; + } + return full_name; +} + //////////////////////////////////////////////////////////////////// // Function: MayaShaderColorDef::read_surface_color // Access: Private @@ -258,6 +278,14 @@ read_surface_color(MayaShader *shader, MObject color, bool trans) { _has_texture = false; set_string_attribute(color, "fileTextureName", ""); } + /* + // Asad: testcode + bool file_has_alpha = false; + get_bool_attribute(color, "fileHasAlpha", file_has_alpha); + if (file_has_alpha) { + maya_cat.info() << _texture_filename << " : has alpha" << endl; + } + */ } get_vec2f_attribute(color, "coverage", _coverage); @@ -265,7 +293,7 @@ read_surface_color(MayaShader *shader, MObject color, bool trans) { get_angle_attribute(color, "rotateFrame", _rotate_frame); get_bool_attribute(color, "alphaIsLuminance", _alpha_is_luminance); - + get_bool_attribute(color, "mirror", _mirror); get_bool_attribute(color, "stagger", _stagger); get_bool_attribute(color, "wrapU", _wrap_u); diff --git a/pandatool/src/maya/mayaShaderColorDef.h b/pandatool/src/maya/mayaShaderColorDef.h index e35e524bfa..72ca3cf5b3 100755 --- a/pandatool/src/maya/mayaShaderColorDef.h +++ b/pandatool/src/maya/mayaShaderColorDef.h @@ -38,6 +38,8 @@ public: MayaShaderColorDef(); MayaShaderColorDef(MayaShaderColorDef&); ~MayaShaderColorDef(); + + string strip_prefix(string full_name); LMatrix3d compute_texture_matrix() const; bool has_projection() const; diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index c2d42dffc7..b90a40361e 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -1672,16 +1672,52 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, } } - vector_string uvset_names; MStringArray maya_uvset_names; status = mesh.getUVSetNames(maya_uvset_names); if (!status) { status.perror("MFnMesh getUVSetNames not found"); - //return; } + _uvset_names.clear(); for (size_t ui=0; uiget_color_def(); } @@ -1779,9 +1815,9 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, // Go thru all the texture references for this primitive and set uvs mayaegg_cat.debug() << "shader->_color.size is " << shader->_color.size() << endl; mayaegg_cat.debug() << "primitive->tref.size is " << egg_poly->get_num_textures() << endl; - for (size_t ti=0; ti< uvset_names.size(); ++ti) { + for (size_t ti=0; ti< _uvset_names.size(); ++ti) { // get the eggTexture pointer - string colordef_uv_name = uvset_name= uvset_names[ti]; + string colordef_uv_name = uvset_name= _uvset_names[ti]; mayaegg_cat.debug() << "--uvset_name :" << uvset_name << endl; if (uvset_name == "map1") // this is the name to look up by in maya @@ -2220,6 +2256,23 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface, return false; } +//////////////////////////////////////////////////////////////////// +// Function: MayaShader::find_uv_link +// Access: Private +// Description: given the texture name, find corresponding uvLink +//////////////////////////////////////////////////////////////////// +string MayaToEggConverter:: +find_uv_link(string match) { + // find the index of this string in the _tex_names + int idx = 0; + vector_string::iterator vi; + for (vi = _tex_names.begin(); vi != _tex_names.end(); ++vi, ++idx) { + if (vi->find(match) != string::npos) { + return _uvset_names[idx]; + } + } + return "error"; +} //////////////////////////////////////////////////////////////////// // Function: MayaShader::set_shader_attributes @@ -2232,7 +2285,7 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface, //////////////////////////////////////////////////////////////////// void MayaToEggConverter:: set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, - const MItMeshPolygon *pi, const vector_string &uvset_names) { + const MItMeshPolygon *pi) { //mayaegg_cat.spam() << " set_shader_attributes : begin\n"; @@ -2246,24 +2299,12 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, mayaegg_cat.spam() << "slot " << i << ":got color_def: " << color_def << endl; if (color_def->_has_texture || trans_def._has_texture) { EggTexture tex(shader.get_name(), ""); - string uvset_name = color_def->_texture_name; - // look for this name in maya's uvset_names - if (uvset_names.size()){ - if (uvset_name.length()) { - uvset_name.resize(uvset_name.length() - 1); - } - mayaegg_cat.spam() << "looking for uvset_name: " << uvset_name << " "; - for (size_t uvi = 0; uvi < uvset_names.size(); ++uvi){ - if (uvset_names[uvi].find(uvset_name) != string::npos) { - uvset_name = uvset_names[uvi]; - mayaegg_cat.spam() << "found maya uvset_name: " << uvset_name << endl; - } - } - } - - maya_cat.debug() << "got shader name:" << shader.get_name() << endl; - maya_cat.debug() << "ssa:texture name[" << i << "]: " << color_def->_texture_name << endl; - + mayaegg_cat.debug() << "got shader name:" << shader.get_name() << endl; + mayaegg_cat.debug() << "ssa:texture name[" << i << "]: " << color_def->_texture_name << endl; + + string uvset_name = find_uv_link(color_def->_texture_name); + mayaegg_cat.debug() << "ssa:corresponding uvset name is " << uvset_name << endl; + if (color_def->_has_texture) { // If we have a texture on color, apply it as the filename. //mayaegg_cat.debug() << "ssa:got texture name" << color_def->_texture_filename << endl; @@ -2338,10 +2379,6 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, if (tex.get_env_type() == EggTexture::ET_modulate) { tex.set_alpha_mode(EggRenderMode::AM_off); // Force alpha to be 'off' } - /* - if (!color_def->_alpha_is_luminance) - tex.set_alpha_mode(EggRenderMode::AM_off); // Force alpha to be 'off' - */ } } } else { // trans_def._has_texture diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index 3d622c62ec..c37a1c9a54 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -140,8 +140,8 @@ private: // void set_shader_attributes(EggPrimitive &primitive, // const MayaShader &shader); void set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, - const MItMeshPolygon *pi = NULL, - const vector_string &uvset_names = vector_string()); + const MItMeshPolygon *pi = NULL); + //const vector_string &uvset_names = vector_string()); void apply_texture_properties(EggTexture &tex, const MayaShaderColorDef &color_def); bool compare_texture_properties(EggTexture &tex, @@ -149,8 +149,13 @@ private: bool reparent_decals(EggGroupNode *egg_parent); + string find_uv_link(string match); + string _program_name; + vector_string _uvset_names; + vector_string _tex_names; + bool _from_selection; typedef pvector Globs; Globs _subsets;