From af80d5616583f8c94e67dc47992c325dbbcf0383 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Fri, 7 Dec 2007 05:25:07 +0000 Subject: [PATCH] fixed bug in uvset handling --- pandatool/src/maya/mayaShader.cxx | 2 +- pandatool/src/maya/mayaShaderColorDef.cxx | 2 +- pandatool/src/maya/mayaShaders.cxx | 2 +- pandatool/src/mayaegg/mayaToEggConverter.cxx | 90 ++++++-------------- 4 files changed, 27 insertions(+), 69 deletions(-) diff --git a/pandatool/src/maya/mayaShader.cxx b/pandatool/src/maya/mayaShader.cxx index c27d071ca3..8f2c300eb0 100644 --- a/pandatool/src/maya/mayaShader.cxx +++ b/pandatool/src/maya/mayaShader.cxx @@ -256,7 +256,7 @@ bind_uvsets(MayaFileToUVSetMap &map) { MayaShaderColorDef *def = _all_maps[i]; MayaFileToUVSetMap::iterator p = map.find(def->_texture_name); if (p == map.end()) { - def->_uvset_name = "default"; + def->_uvset_name = "map1"; } else { def->_uvset_name = (*p).second; } diff --git a/pandatool/src/maya/mayaShaderColorDef.cxx b/pandatool/src/maya/mayaShaderColorDef.cxx index 9e134ca0bd..e717b10ea6 100644 --- a/pandatool/src/maya/mayaShaderColorDef.cxx +++ b/pandatool/src/maya/mayaShaderColorDef.cxx @@ -77,7 +77,7 @@ MayaShaderColorDef() { _keep_color = false; // classic mode overwrites color: new mode retains color with a 3rd layer _keep_alpha = false; _interpolate = false; - _uvset_name = "default"; + _uvset_name = "map1"; _map_uvs = NULL; } diff --git a/pandatool/src/maya/mayaShaders.cxx b/pandatool/src/maya/mayaShaders.cxx index 0bcf8ed64b..b389885f0a 100644 --- a/pandatool/src/maya/mayaShaders.cxx +++ b/pandatool/src/maya/mayaShaders.cxx @@ -171,7 +171,7 @@ find_shader_for_shading_engine(MObject engine) { // Function: MayaShaders::find_uv_link // Access: Public // Description: Returns the current mapping from file to uvset -// for the given file texture name. +// for the given file texture name. //////////////////////////////////////////////////////////////////// string MayaShaders:: find_uv_link(const string &match) { diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 119fa3d4d8..1f695662dc 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -1803,38 +1803,6 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, _shaders.bind_uvsets(mesh.object()); - // MStringArray maya_uvset_names; - // status = mesh.getUVSetNames(maya_uvset_names); - // if (!status) { - // status.perror("MFnMesh getUVSetNames not found"); - // } - // MObjectArray moa; - // _tex_names.clear(); - // _uvset_names.clear(); - // for (size_t ui=0; uiadd_child(egg_poly); @@ -1925,7 +1893,6 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, vert.set_normal(n3d); } - string uvset_name(""); // Go thru all the texture references for this primitive and set uvs if (mayaegg_cat.is_debug()) { if (shader != (MayaShader *)NULL) { @@ -1935,58 +1902,52 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, } for (size_t ti=0; ti< _shaders._uvset_names.size(); ++ti) { // get the eggTexture pointer - string colordef_uv_name = uvset_name= _shaders._uvset_names[ti]; + string uvset_name(_shaders._uvset_names[ti]); + string panda_uvset_name = uvset_name; + if (panda_uvset_name == "map1") { + panda_uvset_name = "default"; + } if (mayaegg_cat.is_debug()) { mayaegg_cat.debug() << "--uvset_name :" << uvset_name << endl; } - if (uvset_name == "map1") // this is the name to look up by in maya - colordef_uv_name = "default"; - // get the shader color def that matches this EggTexture // Asad: optimizing uvset: to discard unused uvsets. This for // loop figures out which ones are unused. - // - MayaShaderColorDef *color_def = NULL; - bool found = false; + + bool keep_uv = keep_all_uvsets; + bool project_uv = false; + TexCoordd uv_projection; + if (shader != (MayaShader *)NULL) { - for (size_t tj = 0; tj < shader->_color.size(); ++tj) { - color_def = shader->get_color_def(tj); - if (color_def->_uvset_name == colordef_uv_name) { + for (size_t tj = 0; tj < shader->_all_maps.size(); ++tj) { + MayaShaderColorDef *def = shader->_all_maps[tj]; + if (def->_uvset_name == uvset_name) { if (mayaegg_cat.is_debug()) { mayaegg_cat.debug() << "matched colordef idx: " << tj << endl; } - found = true; + keep_uv = true; + if (def->has_projection()) { + project_uv = true; + uv_projection = def->project_uv(p3d, centroid); + } break; } } - - if (!found && shader->_transparency._uvset_name == colordef_uv_name) { - if (mayaegg_cat.is_debug()) { - mayaegg_cat.debug() << "matched colordef to transparency\n"; - } - color_def = &shader->_transparency; - found = true; - } } // if uvset is not used don't add it to the vertex - if (!found && !keep_all_uvsets) { + if (!keep_uv) { if (mayaegg_cat.is_spam()) { mayaegg_cat.spam() << "discarding unused uvset " << uvset_name << endl; } continue; } - nassertv(color_def != (MayaShaderColorDef *)NULL); - if (mayaegg_cat.is_debug()) { - mayaegg_cat.debug() << "color_def->uvset_name :" << color_def->_uvset_name << endl; - } - if (color_def->has_projection()) { + if (project_uv) { // If the shader has a projection, use it instead of the // polygon's built-in UV's. - vert.set_uv(colordef_uv_name, - color_def->project_uv(p3d, centroid)); + vert.set_uv(panda_uvset_name, uv_projection); } else { // Get the UV's from the polygon. float2 uvs; @@ -2011,12 +1972,12 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, mayaegg_cat.debug() << "after rounding uvs[1]: " << uvs[1] << endl; } } - vert.set_uv(colordef_uv_name, TexCoordd(uvs[0], uvs[1])); + vert.set_uv(panda_uvset_name, TexCoordd(uvs[0], uvs[1])); } } } } - + if (!ignore_vertex_color) { if (mayaegg_cat.is_spam()) { mayaegg_cat.spam() << "poly_color = " << poly_color << endl; @@ -2737,10 +2698,7 @@ set_shader_legacy(EggPrimitive &primitive, const MayaShader &shader, if (mesh) { if (uvset_name.find("not found") == -1) { primitive.add_texture(new_tex); - if (uvset_name == "map1") // this is the name to look up by in maya - color_def->_uvset_name.assign("default"); - else - color_def->_uvset_name.assign(uvset_name.c_str()); + color_def->_uvset_name.assign(uvset_name.c_str()); new_tex->set_uv_name(color_def->_uvset_name); if (i == (int)shader._color.size()-1 && is_decal) { dummy_uvset_name.assign(color_def->_uvset_name);