From f4054015c4e289f6bcf1462bdf22f51f87fd90d8 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Tue, 6 Dec 2005 01:38:37 +0000 Subject: [PATCH] fixed the bug on multiple blendshape --- pandatool/src/maya/mayaShader.cxx | 2 - pandatool/src/maya/mayaShader.h | 12 -- pandatool/src/maya/mayaShaderColorDef.cxx | 111 +++++++------------ pandatool/src/maya/mayaShaderColorDef.h | 22 +++- pandatool/src/mayaegg/mayaToEggConverter.cxx | 4 +- 5 files changed, 60 insertions(+), 91 deletions(-) diff --git a/pandatool/src/maya/mayaShader.cxx b/pandatool/src/maya/mayaShader.cxx index 61576ea4a5..e78a5a1ef9 100644 --- a/pandatool/src/maya/mayaShader.cxx +++ b/pandatool/src/maya/mayaShader.cxx @@ -50,8 +50,6 @@ MayaShader(MObject engine) { << "Reading shading engine " << get_name() << "\n"; } - _blend_type = BT_unspecified; - bool found_shader = false; MPlug shader_plug = engine_fn.findPlug("surfaceShader"); if (!shader_plug.isNull()) { diff --git a/pandatool/src/maya/mayaShader.h b/pandatool/src/maya/mayaShader.h index 4309449107..48b75e700e 100644 --- a/pandatool/src/maya/mayaShader.h +++ b/pandatool/src/maya/mayaShader.h @@ -53,18 +53,6 @@ public: typedef pvector ColorDef; ColorDef _color; - enum BlendType { - BT_unspecified, - BT_modulate, - BT_decal, - BT_blend, - BT_replace, - BT_add, - BT_blend_color_scale, - }; - - BlendType _blend_type; - private: bool read_surface_shader(MObject shader); }; diff --git a/pandatool/src/maya/mayaShaderColorDef.cxx b/pandatool/src/maya/mayaShaderColorDef.cxx index 9418f77d4a..a9403937d0 100644 --- a/pandatool/src/maya/mayaShaderColorDef.cxx +++ b/pandatool/src/maya/mayaShaderColorDef.cxx @@ -61,6 +61,8 @@ MayaShaderColorDef() { _alpha_is_luminance = false; + _blend_type = BT_unspecified; + _repeat_uv.set(1.0, 1.0); _offset.set(0.0, 0.0); _rotate_uv = 0.0; @@ -98,6 +100,7 @@ MayaShaderColorDef(MayaShaderColorDef ©) { _wrap_u = copy._wrap_u; _wrap_v = copy._wrap_v; + _blend_type = copy._blend_type; _alpha_is_luminance = copy._alpha_is_luminance; _repeat_uv = copy._repeat_uv; @@ -323,67 +326,49 @@ read_surface_color(MayaShader *shader, MObject color, bool trans) { MPlug inputsPlug = layered_fn.findPlug("inputs", &status); MPlug blendModePlug = layered_fn.findPlug("blendMode", &status); - maya_cat.spam() << "*** Start doIt... ***" << endl; - maya_cat.spam() << "inputsPlug Name: " << inputsPlug.name() << endl; - - //maya_cat.spam() << "inputsPlug numElem: " << inputsPlug.numElements() << endl; - maya_cat.spam() << "plug_array numElem: " << color_pa.length() << endl; - int logicalIdx = -1; - // go through the plug array to find the first logical index of blend mode - for (size_t i=0; i -1) { - /* - if (li > 20) { - maya_cat.error() - << "unusual blendmode :" << li << " for :" << layered_fn.name() << endl; - exit(1); - } - */ - logicalIdx = li; - break; - } - } - if (logicalIdx < 0) { - maya_cat.error() - << "Could not retrieve blendMode from: " << layered_fn.name() << endl; - exit(1); - } - // Now that I have the logical index, select the ancestorLogicalIndex - // on the blendModePlug to get the blendMode - status = blendModePlug.selectAncestorLogicalIndex(logicalIdx,inputsPlug); - blendModePlug.getValue(blendValue); - - maya_cat.spam() - << blendModePlug.name() << ": has value " << blendValue << endl; - - MFnEnumAttribute blendModeEnum(blendModePlug); - MString blendName = blendModeEnum.fieldName(blendValue, &status); - switch (blendValue) { - case 1: - shader->_blend_type = MayaShader::BT_decal; - break; - case 6: - shader->_blend_type = MayaShader::BT_modulate; - break; - case 4: - shader->_blend_type = MayaShader::BT_add; - break; - default: - shader->_blend_type = MayaShader::BT_modulate; - } - - maya_cat.info() << layered_fn.name() << ": blendMode used " << blendName << endl; - maya_cat.spam() << "*** END doIt... ***" << endl; - maya_cat.debug() << "number of connections: " << color_pa.length() << endl; bool first = true; + BlendType bt = BT_modulate; for (size_t i=0; i -1) { + // found a blend mode + + maya_cat.spam() << "*** Start doIt... ***" << endl; + maya_cat.spam() << "inputsPlug Name: " << inputsPlug.name() << endl; + + status = blendModePlug.selectAncestorLogicalIndex(li,inputsPlug); + blendModePlug.getValue(blendValue); + + maya_cat.spam() + << blendModePlug.name() << ": has value " << blendValue << endl; + + MFnEnumAttribute blendModeEnum(blendModePlug); + MString blendName = blendModeEnum.fieldName(blendValue, &status); + + switch (blendValue) { + case 1: + bt = BT_decal; + break; + case 6: + bt = BT_modulate; + break; + case 4: + bt = BT_add; + break; + } + maya_cat.info() << layered_fn.name() << ": blendMode used " << blendName << endl; + maya_cat.spam() << "*** END doIt... ***" << endl; + + // advance to the next plug, because that is where the shader info are + pl = color_pa[++i]; + pl.connectedTo(pla, true, false); + } for (size_t j=0; jread_surface_color(shader, pla[j].node()); color_p->_texture_name.assign(pla[j].name().asChar()); + color_p->_blend_type = bt; size_t loc = color_p->_texture_name.find('.',0); if (loc != string::npos) { color_p->_texture_name.resize(loc); @@ -411,6 +397,7 @@ read_surface_color(MayaShader *shader, MObject color, bool trans) { maya_cat.debug() << pl.name().asChar() << " first:connectedTo: " << pla_name << endl; read_surface_color(shader, pla[j].node()); _texture_name.assign(pla[j].name().asChar()); + _blend_type = bt; size_t loc = _texture_name.find('.',0); if (loc != string::npos) { _texture_name.resize(loc); @@ -418,21 +405,7 @@ read_surface_color(MayaShader *shader, MObject color, bool trans) { maya_cat.debug() << "uv_name : " << _texture_name << endl; first = false; } - - // lets see what this is connected to!? - MPlug pl_temp = pla[j]; - MPlugArray pla_temp; - pl_temp.connectedTo(pla_temp, true, false); - maya_cat.debug() << pl_temp.name().asChar() << " connectedTo:" << pla_temp.length() << " plugs\n"; } - /* - string blah; - get_enum_attribute(pl.node(),"blendMode",blah); - maya_cat.info() << "rsc layer: blend mode :" << blah << endl; - float alpha; - get_maya_attribute(pl.node(),"alpha",alpha); - maya_cat.info() << "rsc layer: alpha :" << alpha << endl; - */ } } else { // This shader wasn't understood. diff --git a/pandatool/src/maya/mayaShaderColorDef.h b/pandatool/src/maya/mayaShaderColorDef.h index c0729823a7..e35e524bfa 100755 --- a/pandatool/src/maya/mayaShaderColorDef.h +++ b/pandatool/src/maya/mayaShaderColorDef.h @@ -46,6 +46,18 @@ public: void write(ostream &out) const; + enum BlendType { + BT_unspecified, + BT_modulate, + BT_decal, + BT_blend, + BT_replace, + BT_add, + BT_blend_color_scale, + }; + + BlendType _blend_type; + enum ProjectionType { PT_off, PT_planar, @@ -58,6 +70,11 @@ public: PT_perspective, }; + ProjectionType _projection_type; + LMatrix4d _projection_matrix; + double _u_angle; + double _v_angle; + bool _has_texture; Filename _texture_filename; string _texture_name; @@ -67,11 +84,6 @@ public: bool _has_flat_color; Colord _flat_color; - ProjectionType _projection_type; - LMatrix4d _projection_matrix; - double _u_angle; - double _v_angle; - LVector2f _coverage; LVector2f _translate_frame; double _rotate_frame; diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 0b6ad46cce..00bbc60c7f 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -2331,9 +2331,7 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, // from the texture file. But the top textures may have to strip the alpha if (i!=shader._color.size()-1) { // read the _alpha_is_luminance to figure out env_type - //if (!shader._alpha_is_luminance) - //tex.set_env_type(EggTexture::ET_decal); - tex.set_env_type((EggTexture::EnvType)shader._blend_type); + tex.set_env_type((EggTexture::EnvType)color_def->_blend_type); // multitexture modulate mode may specify, desired alpha on/off if (!color_def->_alpha_is_luminance) tex.set_alpha_mode(EggRenderMode::AM_off); // Force alpha to be 'off'