int DxStdMtl2::GetMatIndex(Mtl * m_Mtl) { int i; Mtl *Std; StdMat2 * Shader; // MaxShader *Shader, *s; if(m_Mtl->IsMultiMtl()) { Shader = (StdMat2 *)GetRefTarg(); // I use the SubAnims here, as I do not want any NULL material introduced that are not visible to the user // this can happen when you have N materials and you select N+1 mat ID - the material will add a NULL material // to the list to compensate - this screws with the index into the paramblock for(i=0; i < m_Mtl->NumSubs(); i++) { Std = (Mtl*)m_Mtl->SubAnim(i); if(Std!=NULL) { if(Std->NumSubMtls()>0) { for(int j=0; j< Std->NumSubMtls();j++) { Mtl * subMtl = Std->GetSubMtl(j); if(subMtl == Shader) Std = subMtl; } } MSPlugin* plugin = (MSPlugin*)((ReferenceTarget*)Std)->GetInterface(I_MAXSCRIPTPLUGIN); ReferenceTarget * targ = NULL; if(plugin){ targ = plugin->get_delegate(); Std = (Mtl*)targ; } if(Std == Shader) { int id=0; // this gets interesting - the MatID are editable !! must get them from the PAramblock IParamBlock2 * pblock = m_Mtl->GetParamBlock(0); // there is only one if(pblock) { ParamBlockDesc2 * pd = pblock->GetDesc(); for(int j=0;j<pd->count;j++) { if(_tcsicmp(_T("materialIDList"),pd->paramdefs[j].int_name)==0) //not localised { //int id; pblock->GetValue(j,0,id,FOREVER,i); id = id+1; //for some reason this is stored as a zero index, when a 1's based index is used } } pblock->ReleaseDesc(); } return(id); } } } } return(0); }