bool hasSkeleton(Selection& sel, bool recurse) { // iterate over selection for (int i = 0; i < sel.GetCount(); ++i) { X3DObject obj(sel[i]); bool ret = hasSkeleton(obj, recurse); if (ret) return ret; } return false; }
XSIPLUGINCALLBACK CStatus OutputMaterials( Selection& in_sel ) { // prepare the mtl file Project prj = app.GetActiveProject(); Scene scn = prj.GetActiveScene(); CString tmpLocation = Get3DCoatParam( L"tempLocation" ).GetValue(); ULONG npos = tmpLocation.ReverseFindString(L"."); CString substr = tmpLocation.GetSubString(0, npos+1); CString strOut = substr + L"mtl"; //app.LogMessage(L"strOut:" + strOut); std::ofstream matfw; matfw.open(strOut.GetAsciiString(), std::ios_base::out | std::ios_base::trunc); if (matfw.is_open()) { CRefArray tempMats; for(int i=0; i< in_sel.GetCount(); i++) { X3DObject xobj(in_sel.GetItem(i)); // Get a geometry accessor from the selected object Primitive prim = xobj.GetActivePrimitive(); PolygonMesh mesh = prim.GetGeometry(); if (!mesh.IsValid()) return CStatus::False; CGeometryAccessor ga = mesh.GetGeometryAccessor(); // get the material objects used by the mesh CRefArray materials = ga.GetMaterials(); for (LONG n=0; n < materials.GetCount(); n++) { bar.PutStatusText( L"materials" ); Material mat(materials[n]); bool inMats = false; //app.LogMessage(CString(n) +L" : "+ CString(i)+ L" :" + mat.GetName()); for(int m = 0; m < tempMats.GetCount(); m++) { Material tmat(tempMats[m]); if(mat.GetName() == tmat.GetName()) { inMats = true; break; } } //app.LogMessage(CString(inMats)); if(!inMats) { CString string = L"newmtl " + mat.GetName() + L"\n"; matfw << string.GetAsciiString(); Parameter surf = mat.GetParameters().GetItem(L"surface"); Shader lShader(surf.GetSource()); //app.LogMessage(L"shader: " + lShader.GetFullName()); //app.LogMessage(L"shader: " + lShader.GetProgID()); if ( lShader.GetProgID() == L"Softimage.material-phong.1" ) { float r, g, b, a; lShader.GetColorParameterValue(L"ambient", r, g, b, a ); CString ka = L"Ka " + FormatNumber(r) + L" " + FormatNumber(g) + L" " + FormatNumber(b); lShader.GetColorParameterValue(L"diffuse", r, g, b, a ); CString kd = L"Kd " + FormatNumber(r) + L" " + FormatNumber(g) + L" " + FormatNumber(b); lShader.GetColorParameterValue(L"specular", r, g, b, a ); CString ks = L"Ks " + FormatNumber(r) + L" " + FormatNumber(g) + L" " + FormatNumber(b); float ns = lShader.GetParameterValue(L"shiny"); float d = 1.0f; CValue illum = 2; matfw << ka.GetAsciiString(); matfw << "\n"; matfw << kd.GetAsciiString(); matfw << "\n"; matfw << ks.GetAsciiString(); matfw << "\n"; matfw << "Ns "; matfw << FormatNumber(ns).GetAsciiString(); matfw << "\n"; matfw << "d "; matfw << FormatNumber(d).GetAsciiString(); matfw << "\n"; matfw << "illum "; matfw << illum.GetAsText().GetAsciiString(); matfw << "\n"; Parameter diff = lShader.GetParameters().GetItem(L"diffuse"); Shader lImageD(diff.GetSource()); if (lImageD.GetProgID() == L"Softimage.txt2d-image-explicit.1") { Parameter tex = lImageD.GetParameters().GetItem(L"tex"); ImageClip2 lTextureD(tex.GetSource()); //app.LogMessage( L"Found texture shader: " + lTexture.GetFullName() + L", Class: " + lTexture.GetClassIDName() + L", Type: " + lTexture.GetType() ); app.LogMessage(L"texture GetFileName: " + lTextureD.GetFileName()); matfw << "map_Kd "; matfw << lTextureD.GetFileName().GetAsciiString(); matfw << "\n"; } Parameter spec = lShader.GetParameters().GetItem(L"specular"); Shader lImageS(spec.GetSource()); if (lImageS.GetProgID() == L"Softimage.txt2d-image-explicit.1") { Parameter tex = lImageD.GetParameters().GetItem(L"tex"); ImageClip2 lTextureS(tex.GetSource()); //app.LogMessage( L"Found texture shader: " + lTexture.GetFullName() + L", Class: " + lTexture.GetClassIDName() + L", Type: " + lTexture.GetType() ); //app.LogMessage(L"texture GetFileName: " + lTexture.GetFileName()); matfw << "map_Ks "; matfw << lTextureS.GetFileName().GetAsciiString(); matfw << "\n"; } } tempMats.Add(mat); matfw << "\n"; matfw << "\n"; } } } matfw.close(); } return CStatus::OK; }