My name is Leigh and I just started working for MySapient based in Newcastle, currently a junior tools programmer :D.
I'm modifying an old max exporter plugin to work with max 2009 and all has been going well, but now I am having some troubles with exporting data from a Morpher Modifier on the model.
I manage to identify that the model has a morpher modifier and get a hold of it, i then cast it into a MorphR3*, but if i try and access the chanBank vector, it's empty, i thought it was supposed to get initialised with 100 channels, even if you hadn't actually applied any channels on the model yet and they would just be inactive channels. I can't find any functions for setting up the chanBank vector?
There looks to be a lovely MorphControl Class in the SDK reference, which would be perfect for exporting as it appears you can get morph targets using it from simple functions, but i can't find how to get a hold of the class from my INode?
Sorry for the length of this post! It's doing my nutt! lol
Here is some code that i have at the moment:-
int _PSXExport::WriteMorphModifierTargets(void *data, FILE *stream)
{
ObjectEntry *oe = (ObjectEntry *)data;
/* Grab the first morph-modifier only */
MorphR3 *mpMorphMod;
if((mpMorphMod=_GetMorphMod(oe->entry->node)))
{
/* We fond one! */
/* MorphR3 (chanBank is a 100-length array of morphChannel classes.) */
int nI;
/* First, count the active channels */
unsigned long nMChannels= 0;
for(nI=0;nI<100;nI++)
{
/* Only write out active channels */
if(mpMorphMod->chanBank[nI].mActive)
{ //This is what dies as chanBank has no elements!
nMChannels++;
}
}
WRTERR(&nMChannels,4);
/* Now, write out the morph-target for each active channel */
int nNumPoints = -1; // Used to check to see if number of points the same.
for(nI=0;nI<100;nI++)
{
/* Only write out active channels */
if(mpMorphMod->chanBank[nI].mActive)
{
TCHAR szBuf[1024];
PsxOeWithMc owmc(oe, &(mpMorphMod->chanBank[nI]), nI);
if(nNumPoints==-1)
{
if(oe->tpTri)
{
if(owmc.m_mcpMorphChannel->mNumPoints != oe->tpTri->mesh.getNumVerts())
{
_stprintf(szBuf, "The Node's mesh \"%s\" Has %d points, but the first morph target #%d has %d points.",
oe->entry->name, oe->tpTri->mesh.getNumVerts(), nI, owmc.m_mcpMorphChannel->mNumPoints);
LOGALERT(_T("Error!"),szBuf);
if(!G_bSuppressPrompts) {MessageBox(GetActiveWindow(), szBuf, _T("Error!"), MB_OK | MB_ICONSTOP);}
return 0;
}
}
// TODO: Patches and splines(?)
}
else
{
if(owmc.m_mcpMorphChannel->mNumPoints != nNumPoints)
{
_stprintf(szBuf, "The Node \"%s\" Has at least one morph-target (Morph-Channel #%d) with a different number of vertices (%d where the others have %d).\nThis one could have the wrong number of vertices, or the others could have the wrong number of vertices.",
oe->entry->name, nI, owmc.m_mcpMorphChannel->mNumPoints, nNumPoints);
LOGALERT(_T("Error!"),szBuf);
if(!G_bSuppressPrompts) {MessageBox(GetActiveWindow(), szBuf, _T("Error!"), MB_OK | MB_ICONSTOP);}
return 0;
}
}
nNumPoints = owmc.m_mcpMorphChannel->mNumPoints;
/* Write out the morph-target for this morph-channel */
if(WriteChunk(MORPHTARGET, stream, &owmc, NULL /* data2 */) == 0)
return 0;
}
}
}
return(1);
}
And the _GetMorphMod function is :-
static MorphR3 * _GetMorphMod(INode *npNode)
{
Object *pObj = npNode->GetObjectRef();
IDerivedObject *pDerObj = NULL;
Modifier *pMod = NULL;
if( pObj->SuperClassID() == GEN_DERIVOB_CLASS_ID)
{
pDerObj = (IDerivedObject *) pObj;
/* Find the first morph-modifier in the object's modifier-stack */
int nModIndex;
int nNumModifiers = pDerObj->NumModifiers();
for(nModIndex = 0 ; nModIndex < nNumModifiers ; nModIndex++ )
{
pMod = pDerObj->GetModifier(nModIndex);
if(pMod->ClassID() == MR3_CLASS_ID)
{
/* We've found one! */
MorphR3* pMorphR3 = (MorphR3*)pMod;
return pMorphR3; /* Just one modifier */
}
}
}
return NULL;
}











