void Exporter::ExportMaterialList() { int numMtls = mtlList.Count(); for (int i=0; i<numMtls; i++) { MaxMaterial *maxm=new MaxMaterial; rsm->MaxMaterialList.Add(maxm); DumpMaterial(maxm,mtlList.GetMtl(i), i, -1, 0); } }
//----------------------------------------------------------------------- void ExportMaterials() { // get total num of materials const int matCount = ExporterMAX::GetExporter()->GetIGame()->GetRootMaterialCount(); for (int index = 0; index < matCount; ++index) { IGameMaterial *pMat = ExporterMAX::GetExporter()->GetIGame()->GetRootMaterial(index); if (pMat){ DumpMaterial(pMat); } } }
void XsiExp::ExportMaterial( INode * node, int indentLevel) { Mtl * mtl = node->GetMtl(); TSTR indent = GetIndent(indentLevel+1); // If the node does not have a material, export the wireframe color if (mtl) { int mtlID = mtlList.GetMtlID(mtl); if (mtlID >= 0) { DumpMaterial( mtl, mtlID, 0, indentLevel); } } else { DWORD c = node->GetWireColor(); fprintf(pStream,"%sSI_Material {\n", indent.data()); fprintf(pStream,"%s\t%.6f;%.6f;%.6f;%.6f;;\n", indent.data(), GetRValue(c)/255.0f, GetGValue(c)/255.0f, GetBValue(c)/255.0f, 1.0f); // diffuse fprintf(pStream,"%s\t%.6f;\n", indent.data(), 0.0f ); // specular power fprintf(pStream,"%s\t%.6f;%.6f;%.6f;;\n", indent.data(), 0.0f, 0.0f, 0.0f); // specular fprintf(pStream,"%s\t%.6f;%.6f;%.6f;;\n", indent.data(), 0.0f, 0.0f, 0.0f); // emissive fprintf(pStream,"%s\t%.6f;\n", indent.data(), 0.0f ); // ? fprintf(pStream,"%s\t%.6f;%.6f;%.6f;;\n", // ambient indent.data(), 0.0f, 0.0f, 0.0f); fprintf(pStream,"%s}\n", indent.data()); } }
void Exporter::DumpMaterial(MaxMaterial *maxm,Mtl* mtl, int mtlID, int subNo, int indentLevel) { int i; TimeValue t = GetStaticFrame(); if (!mtl) return; // for(i=0;i<indentLevel;i++) { log(" "); } // log("material %s adding. type : ",mtl->GetName()); // We know the Standard material, so we can get some extra info if (mtl->ClassID() == Class_ID(DMTL_CLASS_ID, 0)) { // top level & standard material // log("standard \n"); StdMat* std = (StdMat*)mtl; MaxStdMaterial *stdm=new MaxStdMaterial; strcpy(stdm->name,mtl->GetName()); stdm->Ambient=rvector(std->GetAmbient(t)); stdm->Ambient.x=-stdm->Ambient.x; stdm->Diffuse=rvector(std->GetDiffuse(t)); stdm->Diffuse.x=-stdm->Diffuse.x; stdm->Specular=rvector(std->GetSpecular(t)); stdm->Specular.x=-stdm->Specular.x; // 축의 바뀜때문에 만들어 놓은.. 으흑.. stdm->TwoSide=std->GetTwoSided(); if(std->GetTransparencyType()==TRANSP_ADDITIVE) stdm->ShadeMode=RSSHADEMODE_ADD; else stdm->ShadeMode=RSSHADEMODE_NORMAL; if(rsm->MaxStdMaterialList.GetByName(stdm->name)==-1) // 이미 있는 standard material 이면 더하지 않음. { rsm->MaxStdMaterialList.Add(stdm); stdm->RMLIndex=rsm->MaxStdMaterialList.GetCount()-1; for (i=0; i<mtl->NumSubTexmaps(); i++) { Texmap* subTex = mtl->GetSubTexmap(i); float amt = 1.0f; if (subTex) { // If it is a standard material we can see if the map is enabled. if (mtl->ClassID() == Class_ID(DMTL_CLASS_ID, 0)) { if (!((StdMat*)mtl)->MapEnabled(i)) continue; amt = ((StdMat*)mtl)->GetTexmapAmt(i, 0); } DumpTexture(stdm, subTex, mtl->ClassID(), i, amt, indentLevel+1); } } } else { delete stdm; } maxm->nSubMaterial=1; maxm->SubMaterials=new int[1]; maxm->SubMaterials[0]=rsm->MaxStdMaterialList.GetByName(mtl->GetName()); } if (mtl->NumSubMtls() > 0) { // log("multi/sub ( count : %d )\n",mtl->NumSubMtls()); maxm->nSubMaterial=mtl->NumSubMtls(); maxm->SubMaterials=new int[maxm->nSubMaterial]; maxm->pSubMaterials=new MaxMaterial*[maxm->nSubMaterial]; for (i=0; i<mtl->NumSubMtls(); i++) { Mtl* subMtl = mtl->GetSubMtl(i); if (subMtl) { maxm->pSubMaterials[i]=new MaxMaterial; DumpMaterial(maxm->pSubMaterials[i],subMtl, 0, i, indentLevel+1); if(subMtl->ClassID() == Class_ID(DMTL_CLASS_ID, 0)) { maxm->SubMaterials[i]= rsm->MaxStdMaterialList.GetByName(subMtl->GetName()); } else maxm->SubMaterials[i]= maxm->pSubMaterials[i]->SubMaterials[0]; } else { maxm->pSubMaterials[i]=NULL; maxm->SubMaterials[i]=-1; } } } }
void XsiExp::DumpMaterial(Mtl * mtl, int mtlID, int subNo, int indentLevel) { if (!mtl) { return; } TSTR indent = GetIndent(indentLevel+1); if (mtl->NumSubMtls() > 0) { for (int i = 0; i < mtl->NumSubMtls(); i++) { Mtl* subMtl = mtl->GetSubMtl(i); if (subMtl) { DumpMaterial( subMtl, 0, i, indentLevel); } } } else { TimeValue t = GetStaticFrame(); // Note about material colors: // This is only the color used by the interactive renderer in MAX. // To get the color used by the scanline renderer, we need to evaluate // the material using the mtl->Shade() method. // Since the materials are procedural there is no real "diffuse" color for a MAX material // but we can at least take the interactive color. fprintf(pStream,"%sSI_Material {\n", indent.data()); fprintf(pStream,"%s\t%.6f;%.6f;%.6f;%.6f;;\n", indent.data(), mtl->GetDiffuse(t).r, mtl->GetDiffuse(t).g, mtl->GetDiffuse(t).b, 1.0 - mtl->GetXParency(t) ); fprintf(pStream,"%s\t%.6f;\n", indent.data(), mtl->GetShinStr(t) ); fprintf(pStream,"%s\t%.6f;%.6f;%.6f;;\n", indent.data(), mtl->GetSpecular(t).r, mtl->GetSpecular(t).g, mtl->GetSpecular(t).b ); fprintf(pStream,"%s\t%.6f;%.6f;%.6f;;\n", indent.data(), 0.0f, 0.0f, 0.0f); // emissive fprintf(pStream,"%s\t%.6f;\n", indent.data(), 0.0f); // ? fprintf(pStream,"%s\t%.6f;%.6f;%.6f;;\n\n", indent.data(), mtl->GetAmbient(t).r, mtl->GetAmbient(t).g, mtl->GetAmbient(t).b ); for (int i = 0; i < mtl->NumSubTexmaps(); i++) { Texmap * subTex = mtl->GetSubTexmap(i); float amt = 1.0f; if (subTex) { // If it is a standard material we can see if the map is enabled. if (mtl->ClassID() == Class_ID(DMTL_CLASS_ID, 0)) { if (!((StdMat*)mtl)->MapEnabled(i)) { continue; } amt = ((StdMat*)mtl)->GetTexmapAmt(i, 0); } DumpTexture(subTex, mtl->ClassID(), i, amt, indentLevel+1); } } fprintf(pStream,"%s}\n", indent.data()); } }