From 17164ac827659d5c6e06085a9a9e0af5c683a6dd Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 12 Dec 2004 16:08:22 +0000 Subject: [PATCH] aggressively clear directory texture name --- pandatool/src/maya/mayaShaderColorDef.cxx | 6 ++- pandatool/src/maya/maya_funcs.cxx | 52 +++++++++++++++++++++++ pandatool/src/maya/maya_funcs.h | 3 ++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/pandatool/src/maya/mayaShaderColorDef.cxx b/pandatool/src/maya/mayaShaderColorDef.cxx index f783e824b2..1583a7b642 100644 --- a/pandatool/src/maya/mayaShaderColorDef.cxx +++ b/pandatool/src/maya/mayaShaderColorDef.cxx @@ -158,7 +158,7 @@ bool MayaShaderColorDef:: reset_maya_texture(const Filename &texture) { if (_color_object != (MObject *)NULL) { _has_texture = set_string_attribute(*_color_object, "fileTextureName", - texture); + texture.to_os_generic()); _texture = texture; if (!_has_texture) { @@ -198,14 +198,16 @@ read_surface_color(const MayaShader *shader, MObject color) { _color_object = new MObject(color); string filename; _has_texture = get_string_attribute(color, "fileTextureName", filename); + _has_texture = _has_texture && !filename.empty(); if (_has_texture) { _texture = Filename::from_os_specific(filename); if (_texture.is_directory()) { maya_cat.warning() << "Shader " << shader->get_name() << " references texture filename " << filename - << " which is a directory; ignoring.\n"; + << " which is a directory; clearing.\n"; _has_texture = false; + set_string_attribute(color, "fileTextureName", ""); } } diff --git a/pandatool/src/maya/maya_funcs.cxx b/pandatool/src/maya/maya_funcs.cxx index 6ea855c1f2..31086bda89 100644 --- a/pandatool/src/maya/maya_funcs.cxx +++ b/pandatool/src/maya/maya_funcs.cxx @@ -103,6 +103,58 @@ has_attribute(MObject &node, const string &attribute_name) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: remove_attribute +// Description: Removes the named attribute from the indicated Maya +// node. Returns true if successful, false otherwise. +//////////////////////////////////////////////////////////////////// +bool +remove_attribute(MObject &node, const string &attribute_name) { + MStatus status; + MFnDependencyNode node_fn(node, &status); + if (!status) { + maya_cat.error() + << "Object is a " << node.apiTypeStr() << ", not a DependencyNode.\n"; + return false; + } + + MObject attr = node_fn.attribute(attribute_name.c_str(), &status); + if (!status) { + return false; + } + + { + // Just to prove the the attr is, in fact, an Attribute. + // According to the Maya docs, we shouldn't leave the MFnAttribute + // object around while we remove the attribute, though. + MFnAttribute attr_fn(attr, &status); + if (!status) { + maya_cat.error() + << "Attribute " << attribute_name << " on " << node_fn.name() + << " is a " << attr.apiTypeStr() << ", not an Attribute.\n"; + return false; + } + } + + MFnDependencyNode::MAttrClass type = node_fn.attributeClass(attr, &status); + if (!status) { + maya_cat.error() + << "Couldn't get class of attribute " << attribute_name << " on " + << node_fn.name() << ".\n"; + return false; + } + + status = node_fn.removeAttribute(attr, type); + if (!status) { + maya_cat.error() + << "Couldn't remove attribute " << attribute_name << " from " + << node_fn.name() << ".\n"; + return false; + } + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: get_bool_attribute // Description: Extracts the named boolean attribute from the diff --git a/pandatool/src/maya/maya_funcs.h b/pandatool/src/maya/maya_funcs.h index 63f2ee9370..637c54425d 100644 --- a/pandatool/src/maya/maya_funcs.h +++ b/pandatool/src/maya/maya_funcs.h @@ -54,6 +54,9 @@ set_maya_attribute(MObject &node, const string &attribute_name, bool has_attribute(MObject &node, const string &attribute_name); +bool +remove_attribute(MObject &node, const string &attribute_name); + bool get_bool_attribute(MObject &node, const string &attribute_name, bool &value);