From 68a147ef6291e267e61ab70fe6df1fbefede32a4 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Fri, 25 Mar 2005 20:26:05 +0000 Subject: [PATCH] changed mayaegg to incorporate jason's multiple uvsets and single texture --- pandatool/src/mayaegg/mayaToEggConverter.cxx | 83 +++++++++++++++++--- pandatool/src/mayaegg/mayaToEggConverter.h | 4 +- 2 files changed, 72 insertions(+), 15 deletions(-) diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 7e6c6d0dc0..a3d9c12092 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -1650,14 +1650,16 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, } } - MStringArray uvset_names; - status = mesh.getUVSetNames(uvset_names); + pvector uvset_names; + MStringArray maya_uvset_names; + status = mesh.getUVSetNames(maya_uvset_names); if (!status) { status.perror("MFnMesh getUVSetNames not found"); //return; } - for (size_t ui=0; uiget_color_def(); } @@ -1750,11 +1752,12 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, vert.set_normal(n3d); } - string uv_name(""); + string uvset_name(""); if (color_def != (MayaShaderColorDef *)NULL && color_def->_has_texture) { // 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; + /* old method for (int ti=0; ti< egg_poly->get_num_textures(); ++ti) { // get the eggTexture pointer EggTexture *tex_p = egg_poly->get_texture(ti); @@ -1790,6 +1793,41 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, } } } + */ + for (size_t ti=0; ti< uvset_names.size(); ++ti) { + // get the eggTexture pointer + 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 + colordef_uv_name = "default"; + + // get the shader color def that matches this EggTexture + 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) { + mayaegg_cat.debug() << "matched colordef idx: " << tj << endl; + break; + } + } + mayaegg_cat.debug() << "color_def->uvset_name :" << color_def->_uvset_name << endl; + if (color_def->has_projection()) { + // 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)); + } else { + // Get the UV's from the polygon. + float2 uvs; + MString uv_mstring(uvset_name.c_str()); + status = pi.getUV(i, uvs, &uv_mstring); + if (!status) { + status.perror("MItMeshPolygon::getUV"); + } else { + vert.set_uv(colordef_uv_name, TexCoordd(uvs[0], uvs[1])); + } + } + } } if (!ignore_vertex_color) { @@ -2203,7 +2241,8 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface, // egg primitive. //////////////////////////////////////////////////////////////////// void MayaToEggConverter:: -set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const MItMeshPolygon *pi) { +set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, + const MItMeshPolygon *pi, const pvector uvset_names) { //mayaegg_cat.spam() << " set_shader_attributes : begin\n"; @@ -2217,6 +2256,18 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const M 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_texture_name << endl; @@ -2313,13 +2364,18 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const M _textures.create_unique_texture(tex, ~0); //_textures.create_unique_texture(tex, ~EggTexture::E_tref_name); - if (pi && shader._color.size() > 1) { + //if (pi && shader._color.size() > 1) { + if (pi) { // see if the uvset_name exists for this polygon, if yes, add the texture to primitive if (pi->hasUVs(MString(uvset_name.c_str()))) { primitive.add_texture(new_tex); - color_def->_uvset_name.assign(uvset_name.c_str()); - new_tex->set_uv_name(color_def->_texture_name); - } else { + 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()); + //new_tex->set_uv_name(color_def->_texture_name); + new_tex->set_uv_name(color_def->_uvset_name); + }/* else { // if the uvset is under different name, try taking out the // numeric from the uv name. This was a compromise to support // one uvset but different layered texture for layer1 texture @@ -2328,11 +2384,12 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const M if (pi->hasUVs(MString(uvset_name.c_str()))) { primitive.add_texture(new_tex); color_def->_uvset_name.assign(uvset_name.c_str()); - new_tex->set_uv_name(color_def->_texture_name); + //new_tex->set_uv_name(color_def->_texture_name); + new_tex->set_uv_name(color_def->_uvset_name); } else { mayaegg_cat.debug() << "ssa: didn't find uvset_name: " << uvset_name << endl; } - } + }*/ } else { primitive.add_texture(new_tex); new_tex->set_uv_name(color_def->_uvset_name); diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index 9dcdff9f68..01fcb1268f 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -136,8 +136,8 @@ private: pvector &joints, MFloatArray &weights); // void set_shader_attributes(EggPrimitive &primitive, // const MayaShader &shader); - void set_shader_attributes(EggPrimitive &primitive, - const MayaShader &shader, const MItMeshPolygon *pi=NULL); + void set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, + const MItMeshPolygon *pi=NULL, const pvector uvset_names=NULL); void apply_texture_properties(EggTexture &tex, const MayaShaderColorDef &color_def); bool compare_texture_properties(EggTexture &tex,