📄 publishedinterface.cpp
字号:
//get a pointer to the export interface
IPhysiqueExport *phyExport = (IPhysiqueExport *)mod->GetInterface(I_PHYINTERFACE);
//get a pointer to the export context interface
IPhyContextExport *mcExport = (IPhyContextExport *)phyExport->GetContextInterface(node);
if (vertIndex < 0 || vertIndex >= mcExport->GetNumberVertices())
throw MAXException("The vertex index is not in the valid range");
Point3 offset = Point3(0,0,0);
IPhyVertexExport* vi = mcExport->GetVertexInterface(vertIndex);
if (vi)
{
int type = vi->GetVertexType();
switch (type)
{
case RIGID_NON_BLENDED_TYPE:
case RIGID_BLENDED_TYPE:
case FLOATING_TYPE:
break;
case DEFORMABLE_NON_BLENDED_TYPE:
offset = ((IPhyDeformableOffsetVertex*)vi)->GetDeformOffsetVector(t);
break;
case DEFORMABLE_BLENDED_TYPE:
throw MAXException("Not a currently supported type");
break;
}
mcExport->ReleaseVertexInterface(vi);
}
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return offset;
}
float IPhysiqueInterface::GetVertexWeight(INode* node, int vertIndex, int boneIndex, bool rigid, bool blending, ReferenceTarget* mod)
{
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
//get a pointer to the export interface
IPhysiqueExport *phyExport = (IPhysiqueExport *)mod->GetInterface(I_PHYINTERFACE);
//get a pointer to the export context interface
IPhyContextExport *mcExport = (IPhyContextExport *)phyExport->GetContextInterface(node);
mcExport->ConvertToRigid(rigid);
mcExport->AllowBlending(blending);
if (vertIndex < 0 || vertIndex >= mcExport->GetNumberVertices())
throw MAXException("The vertex index is not in the valid range");
//Point3 offset = Point3(0,0,0);
//Tab<Point3> offsetTab;
//offsetTab.ZeroCount();
int count = 0, i = 0;
float normalizedWeight = 0.0f, totalWeight = 0.0f, weight = 0.0f;
float tempFloat;
IPhyVertexExport* vi = mcExport->GetVertexInterface(vertIndex);
if (vi)
{
int type = vi->GetVertexType();
switch (type)
{
case RIGID_NON_BLENDED_TYPE:
case DEFORMABLE_NON_BLENDED_TYPE:
count = 1;
normalizedWeight = 1.0f;
break;
case RIGID_BLENDED_TYPE:
count = ((IPhyBlendedRigidVertex*)vi)->GetNumberNodes();
for (i=0;i<count;i++)
{
tempFloat = ((IPhyBlendedRigidVertex*)vi)->GetWeight(i);
if (i == boneIndex) normalizedWeight = tempFloat;
}
break;
case DEFORMABLE_BLENDED_TYPE:
throw MAXException("Not a currently supported type");
break;
case FLOATING_TYPE:
normalizedWeight = 0.0f;
for (i=0;i<((IPhyFloatingVertex*)vi)->GetNumberNodes();i++)
{
tempFloat = ((IPhyFloatingVertex*)vi)->GetWeight(i, weight);
if (count + i == boneIndex) normalizedWeight = tempFloat;
totalWeight += weight;
}
count = count+i;
if (totalWeight != 0)
normalizedWeight = normalizedWeight/totalWeight;
break;
}
mcExport->ReleaseVertexInterface(vi);
}
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
if (boneIndex < 0 || boneIndex >= count)
throw MAXException("The bone index is not in the valid range");
return normalizedWeight;
}
bool IPhysiqueInterface::SetFigureMode(INode* node, bool state, ReferenceTarget* mod)
{
int i = 0, x = 0;
INode* bone;
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
IPhysiqueExport *phyExport = (IPhysiqueExport *)mod->GetInterface(I_PHYINTERFACE);
IPhyContextExport *mcExport = (IPhyContextExport *)phyExport->GetContextInterface(node);
int numverts = mcExport->GetNumberVertices();
for (i = 0; i<numverts; i++)
{
IPhyVertexExport* vi = mcExport->GetVertexInterface(i);
if (vi) {
int type = vi->GetVertexType();
switch (type)
{
case RIGID_BLENDED_TYPE:
for (x = 0; x<((IPhyBlendedRigidVertex*)vi)->GetNumberNodes(); x++)
{
bone = ((IPhyBlendedRigidVertex*)vi)->GetNode(x);
if (BipedFigureMode(bone, state))
{
mcExport->ReleaseVertexInterface(vi);
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return true;
}
}
break;
case RIGID_TYPE:
bone = ((IPhyRigidVertex*)vi)->GetNode();
if (BipedFigureMode(bone, state))
{
mcExport->ReleaseVertexInterface(vi);
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return true;
}
break;
case DEFORMABLE_TYPE:
bone = ((IPhyDeformableOffsetVertex*)vi)->GetNode();
if (BipedFigureMode(bone, state))
{
mcExport->ReleaseVertexInterface(vi);
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return true;
}
break;
case FLOATING_TYPE:
for (x = 0; x<((IPhyFloatingVertex*)vi)->GetNumberNodes(); x++)
{
bone = ((IPhyFloatingVertex*)vi)->GetNode(x);
if (BipedFigureMode(bone, state))
{
mcExport->ReleaseVertexInterface(vi);
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return true;
}
}
break;
default: break;
}
}
mcExport->ReleaseVertexInterface(vi);
}
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return false;
}
bool IPhysiqueInterface::BipedFigureMode(INode* node, bool state)
{
if (node->IsRootNode()) return false;
Control* c = node->GetTMController();
if ((c->ClassID() == BIPSLAVE_CONTROL_CLASS_ID) ||
(c->ClassID() == BIPBODY_CONTROL_CLASS_ID) ||
(c->ClassID() == FOOTPRINT_CLASS_ID))
{
IBipedExport *iBiped = (IBipedExport *) c->GetInterface(I_BIPINTERFACE);
if (iBiped)
{
//iBiped->RemoveNonUniformScale((BOOL)state);
if (state) iBiped->BeginFigureMode(0);
else iBiped->EndFigureMode(0);
Control* iMaster = (Control *) c->GetInterface(I_MASTER);
iMaster->NotifyDependents(FOREVER, PART_TM, REFMSG_CHANGE);
c->ReleaseInterface(I_MASTER,iMaster);
c->ReleaseInterface(I_BIPINTERFACE,iBiped);
return true;
}
}
return false;
}
bool IPhysiqueInterface::AttachToNode(INode* node, INode* rootNode, ReferenceTarget* mod, TimeValue t)
{
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
IPhysiqueImport *phyImport = (IPhysiqueImport *)mod->GetInterface(I_PHYIMPORT);
bool val = false;
if (phyImport->AttachRootNode(rootNode, t))
val = true;
mod->ReleaseInterface(I_PHYIMPORT, phyImport);
return val;
}
bool IPhysiqueInterface::Initialize(INode* node, INode* rootNode, ReferenceTarget* mod, TimeValue t)
{
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
IPhysiqueImport *phyImport = (IPhysiqueImport *)mod->GetInterface(I_PHYIMPORT);
bool val = false;
if (phyImport->InitializePhysique(rootNode, t))
val = true;
mod->ReleaseInterface(I_PHYIMPORT, phyImport);
return val;
}
void IPhysiqueInterface::LockVertex(INode* node, int vertexIndex, ReferenceTarget* mod)
{
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
IPhysiqueImport *phyImport = (IPhysiqueImport *)mod->GetInterface(I_PHYIMPORT);
IPhyContextImport *mcImport = (IPhyContextImport *)phyImport->GetContextInterface(node);
IPhyVertexImport *vi = mcImport->SetVertexInterface(vertexIndex, RIGID_BLENDED_TYPE);
vi->LockVertex(TRUE);
mcImport->ReleaseVertexInterface(vi);
phyImport->ReleaseContextInterface(mcImport);
mod->ReleaseInterface(I_PHYIMPORT, phyImport);
}
void IPhysiqueInterface::UnLockVertex(INode* node, int vertexIndex, ReferenceTarget* mod)
{
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
IPhysiqueImport *phyImport = (IPhysiqueImport *)mod->GetInterface(I_PHYIMPORT);
IPhyContextImport *mcImport = (IPhyContextImport *)phyImport->GetContextInterface(node);
IPhyVertexImport *vi = mcImport->SetVertexInterface(vertexIndex, RIGID_BLENDED_TYPE);
vi->LockVertex(FALSE);
mcImport->ReleaseVertexInterface(vi);
phyImport->ReleaseContextInterface(mcImport);
mod->ReleaseInterface(I_PHYIMPORT, phyImport);
}
void IPhysiqueInterface::SetVertexBone(INode* node, int vertexIndex, INode* bone, float weight, bool clear, ReferenceTarget* mod)
{
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
IPhysiqueImport *phyImport = (IPhysiqueImport *)mod->GetInterface(I_PHYIMPORT);
IPhyContextImport *mcImport = (IPhyContextImport *)phyImport->GetContextInterface(node);
IPhyVertexImport *viImport = mcImport->SetVertexInterface(vertexIndex, RIGID_BLENDED_TYPE);
int numverts = mcImport->GetNumberVertices();
if (!clear) //if you don't clear it check to see if it already exists
{
Tab<INode*> bones = GetVertexBones(node, vertexIndex, true, true, mod);
Tab<float> weights;
weights.ZeroCount();
bool exists = false;
int i;
for(i=0;i<bones.Count();i++)
{
if (bone == bones[i])
{
exists = true;
break;
}
}
if (exists)
{
//store the weights
for(i=0;i<bones.Count();i++)
{
float curWeight = GetVertexWeight(node, vertexIndex, i, true, true, mod);
weights.Append(1, &weight);
}
for(i=0;i<bones.Count();i++)
{
bool tempClear = false;
if (i==0)
tempClear = true; //clear the first time through
float curWeight;
if (bone == bones[i])
curWeight = weight;
else curWeight = weights[i];
//int type = viImport->GetVertexType();
((IPhyBlendedRigidVertexImport*)viImport)->SetWeightedNode(bone, curWeight, tempClear);
}
}
else
{
((IPhyBlendedRigidVertexImport*)viImport)->SetWeightedNode(bone, weight, FALSE);
}
}
else ((IPhyBlendedRigidVertexImport*)viImport)->SetWeightedNode(bone, weight, TRUE);
mcImport->ReleaseVertexInterface(viImport);
phyImport->ReleaseContextInterface(mcImport);
mod->ReleaseInterface(I_PHYIMPORT, phyImport);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -