소스 검색

fixed a crash bug regarding uvLink

Asad M. Zaman 20 년 전
부모
커밋
d4f5097fbd
2개의 변경된 파일76개의 추가작업 그리고 54개의 파일을 삭제
  1. 74 54
      pandatool/src/mayaegg/mayaToEggConverter.cxx
  2. 2 0
      pandatool/src/mayaegg/mayaToEggConverter.h

+ 74 - 54
pandatool/src/mayaegg/mayaToEggConverter.cxx

@@ -1576,6 +1576,78 @@ make_nurbs_curve(const MDagPath &, const MFnNurbsCurve &curve,
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaShader::find_uv_link
+//       Access: Private
+//  Description: given the texture name, find corresponding uvLink
+////////////////////////////////////////////////////////////////////
+string MayaToEggConverter::
+find_uv_link(string match) {
+  // find the index of this string in the _tex_names
+  int idx = 0;
+  vector_string::iterator vi;
+  mayaegg_cat.spam() << "ful: looking for " << match << endl;
+  for (vi = _tex_names.begin(); vi != _tex_names.end(); ++vi, ++idx) {
+    mayaegg_cat.spam() << "ful:" << idx << ":stored_name is " << vi->c_str() << endl;
+    if (vi->find(match) != string::npos) {
+      return _uvset_names[idx];
+    }
+  }
+  mayaegg_cat.spam() << "ful: did not find " << match << endl;
+  return "not found";
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaToEggConverter::store_tex_names
+//       Access: Private
+//  Description: check the uvsets and see what texture these are 
+//               connected to. set_shader_attribute will use this
+//               information to write eggTexture
+////////////////////////////////////////////////////////////////////
+void MayaToEggConverter::
+make_tex_names(const MFnMesh &mesh, const MObject &mesh_object) {
+
+  // test the connection editor to gather the uvLink to the texture name
+  MFnDependencyNode dn(mesh_object);
+  MStringArray mresult;
+  MPlugArray pla;
+
+  _tex_names.clear();
+  dn.getConnections(pla);
+  mayaegg_cat.spam() << "number of connections: " << pla.length() << endl;
+  string uv1("uvLink -query -uvSet ");
+  uv1.append(mesh.name().asChar());
+  uv1.append(".uvSet[0].uvSetName");
+  MGlobal::executeCommand(MString(uv1.c_str()), mresult);
+  string tcat;
+  for (size_t k=0; k<mresult.length(); ++k) {
+    maya_cat.spam() << "found uvLink to texture: " << mresult[k].asChar() << endl;
+    tcat.append(mresult[k].asChar());
+  }
+  maya_cat.debug() << "saving string to look up uvset: " << tcat << endl;
+  _tex_names.push_back(tcat);
+  for (size_t j=0; j<pla.length(); ++j) {
+    MPlug pl = pla[j];
+    //maya_cat.info() << pl.name() << " is(pl) " << pl.node().apiTypeStr() << endl;
+    string tn;
+    string ts = pl.name().asChar();
+    if (ts.find("uvSetName") != string::npos) {
+      string execString = "uvLink -query -uvSet " + ts;
+      //maya_cat.info() << "executing command: " << execString << "\n";
+      MGlobal::executeCommand(MString(execString.c_str()), mresult);
+      for (size_t k=0; k<mresult.length(); ++k) {
+        maya_cat.spam() << "found uvLink to texture: " << mresult[k].asChar() << endl;
+        tcat.append(mresult[k].asChar());
+      }
+      // save unique of this string
+      if (find_uv_link(tcat) == "not found") {
+        maya_cat.debug() << "saving string: " << tcat << endl;
+        _tex_names.push_back(tcat);
+      }
+    }
+  } 
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaToEggConverter::make_polyset
 //     Function: MayaToEggConverter::make_polyset
 //       Access: Private
 //       Access: Private
@@ -1683,42 +1755,8 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path,
     _uvset_names.push_back(maya_uvset_names[ui].asChar());
     _uvset_names.push_back(maya_uvset_names[ui].asChar());
   }
   }
 
 
-  // test the connection editor to gather the link to the texture name
-  MFnDependencyNode dn(mesh_object);
-  MStringArray mresult;
-  MPlugArray pla;
-
-  _tex_names.clear();
-  dn.getConnections(pla);
-  mayaegg_cat.spam() << "number of connections: " << pla.length() << endl;
-  string uv1("uvLink -query -uvSet ");
-  uv1.append(mesh.name().asChar());
-  uv1.append(".uvSet[0].uvSetName");
-  MGlobal::executeCommand(MString(uv1.c_str()), mresult);
-  string tcat;
-  for (size_t k=0; k<mresult.length(); ++k) {
-    maya_cat.spam() << "found uvLink to texture: " << mresult[k].asChar() << endl;
-    tcat.append(mresult[k].asChar());
-  }
-  maya_cat.debug() << "saving string to look up uvset: " << tcat << endl;
-  _tex_names.push_back(tcat);
-  for (size_t j=0; j<pla.length(); ++j) {
-    MPlug pl = pla[j];
-    //maya_cat.info() << pl.name() << " is(pl) " << pl.node().apiTypeStr() << endl;
-    string tn;
-    string ts = pl.name().asChar();
-    if (ts.find("uvSetName") != string::npos) {
-      string execString = "uvLink -query -uvSet " + ts;
-      //maya_cat.info() << "executing command: " << execString << "\n";
-      MGlobal::executeCommand(MString(execString.c_str()), mresult);
-      for (size_t k=0; k<mresult.length(); ++k) {
-        maya_cat.spam() << "found uvLink to texture: " << mresult[k].asChar() << endl;
-        tcat.append(mresult[k].asChar());
-      }
-      maya_cat.debug() << "saving string: " << tcat << endl;
-      _tex_names.push_back(tcat);
-    }
-  }
+  // Get the tex_names that are connected to those uvnames
+  make_tex_names(mesh, mesh_object);
 
 
   while (!pi.isDone()) {
   while (!pi.isDone()) {
     EggPolygon *egg_poly = new EggPolygon;
     EggPolygon *egg_poly = new EggPolygon;
@@ -2256,24 +2294,6 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface,
   return false;
   return false;
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: MayaShader::find_uv_link
-//       Access: Private
-//  Description: given the texture name, find corresponding uvLink
-////////////////////////////////////////////////////////////////////
-string MayaToEggConverter::
-find_uv_link(string match) {
-  // find the index of this string in the _tex_names
-  int idx = 0;
-  vector_string::iterator vi;
-  for (vi = _tex_names.begin(); vi != _tex_names.end(); ++vi, ++idx) {
-    if (vi->find(match) != string::npos) {
-      return _uvset_names[idx];
-    }
-  }
-  return "error";
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaShader::set_shader_attributes
 //     Function: MayaShader::set_shader_attributes
 //       Access: Private
 //       Access: Private

+ 2 - 0
pandatool/src/mayaegg/mayaToEggConverter.h

@@ -117,6 +117,8 @@ private:
   // I ran into core dumps trying to pass around a MFnMesh object by
   // I ran into core dumps trying to pass around a MFnMesh object by
   // value.  From now on, all MFn* objects will be passed around by
   // value.  From now on, all MFn* objects will be passed around by
   // reference.
   // reference.
+  void make_tex_names(const MFnMesh &mesh, const MObject &mesh_object);
+
   void make_nurbs_surface(MayaNodeDesc *node_desc,
   void make_nurbs_surface(MayaNodeDesc *node_desc,
                           const MDagPath &dag_path, 
                           const MDagPath &dag_path, 
                           MFnNurbsSurface &surface,
                           MFnNurbsSurface &surface,