Bladeren bron

aggressively clear directory texture name

David Rose 21 jaren geleden
bovenliggende
commit
17164ac827
3 gewijzigde bestanden met toevoegingen van 59 en 2 verwijderingen
  1. 4 2
      pandatool/src/maya/mayaShaderColorDef.cxx
  2. 52 0
      pandatool/src/maya/maya_funcs.cxx
  3. 3 0
      pandatool/src/maya/maya_funcs.h

+ 4 - 2
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", "");
       }
     }
 

+ 52 - 0
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

+ 3 - 0
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);