📄 publishedinterface.cpp
字号:
for (x = 0; x<rb_vtx->GetNumberNodes(); x++)
{
exists = false;
//get the node by index
bone = rb_vtx->GetNode(x);
//check to see if we already have this bone
for (int z=0;z<bones.Count();z++)
if (bone == bones[z]) exists = true;
//if you didn't find a match add it to the list
if (!exists) bones.Append(1, &bone);
}
break;
//The vertex is a rigid vertex and only assigned to one link
case RIGID_TYPE:
//type-cast the node to the proper calss
r_vtx = (IPhyRigidVertex*)vi;
//get the node
bone = r_vtx->GetNode();
//check to see if the bone is already in the list
for (x = 0;x<bones.Count();x++)
{
if (bone == bones[x]) exists = true;
}
//if you didn't find a match add it to the list
if (!exists) bones.Append(1, &bone);
break;
case FLOATING_TYPE:
f_vtx = (IPhyFloatingVertex*)mcExport->GetVertexInterface(i);
for (x = 0; x<f_vtx->GetNumberNodes(); x++)
{
exists = false;
//get the node by index
bone = f_vtx->GetNode(x);
//check to see if we already have this bone
for (int z=0;z<bones.Count();z++)
if (bone == bones[z]) exists = true;
//if you didn't find a match add it to the list
if (!exists) bones.Append(1, &bone);
}
break;
// Shouldn't make it here because we converted to rigid earlier.
// It should be one of the above two types
default: break;
}
}
}
//release the context interface
phyExport->ReleaseContextInterface(mcExport);
//Release the physique interface
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return bones;
}
int IPhysiqueInterface::GetAPIVersion(INode* node, 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);
int version = phyExport->Version();
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return version;
}
void IPhysiqueInterface::SetInitialPose(INode* node, bool set, 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);
phyExport->SetInitialPose(set);
((ReferenceTarget*)mod)->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
}
int IPhysiqueInterface::GetVertexCount(INode* node, 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);
int vertCount = mcExport->GetNumberVertices();
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return vertCount;
}
int IPhysiqueInterface::GetVertexType(INode* node, int vertIndex, 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);
IPhyVertexExport* vi = mcExport->GetVertexInterface(vertIndex);
if (!vi)
{
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
throw MAXException("No vertex interface found");
}
int type = vi->GetVertexType();
mcExport->ReleaseVertexInterface(vi);
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return type;
}
int IPhysiqueInterface::GetVertexBoneCount(INode* node, int vertIndex, bool rigid, 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);
if (vertIndex < 0 || vertIndex >= mcExport->GetNumberVertices())
throw MAXException("The vertex index is not in the valid range");
mcExport->ConvertToRigid(rigid);
int count = 0;
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;
break;
case RIGID_BLENDED_TYPE:
count += ((IPhyBlendedRigidVertex*)vi)->GetNumberNodes();
break;
case DEFORMABLE_BLENDED_TYPE:
throw MAXException("Not a currently supported type");
break;
case FLOATING_TYPE:
count += ((IPhyFloatingVertex*)vi)->GetNumberNodes();
break;
}
mcExport->ReleaseVertexInterface(vi);
}
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return count;
}
Tab<INode*> IPhysiqueInterface::GetVertexBones(INode* node, int vertIndex, 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");
INode* bone = NULL;
Tab<INode*> bones;
bones.ZeroCount();
int count = 0, i = 0;
IPhyVertexExport* vi = mcExport->GetVertexInterface(vertIndex);
if (vi)
{
int type = vi->GetVertexType();
switch (type)
{
case RIGID_NON_BLENDED_TYPE:
bone = ((IPhyRigidVertex*)vi)->GetNode();
bones.Append(1, &bone);
break;
case RIGID_BLENDED_TYPE:
count = ((IPhyBlendedRigidVertex*)vi)->GetNumberNodes();
for (i=0;i<count;i++)
{
bone = ((IPhyBlendedRigidVertex*)vi)->GetNode(i);
bones.Append(1, &bone);
}
break;
case DEFORMABLE_NON_BLENDED_TYPE:
bone = ((IPhyDeformableOffsetVertex*)vi)->GetNode();
bones.Append(1, &bone);
break;
case DEFORMABLE_BLENDED_TYPE:
throw MAXException("Not a currently supported type");
break;
case FLOATING_TYPE:
count += ((IPhyFloatingVertex*)vi)->GetNumberNodes();
for (i=0;i<count;i++)
{
bone = ((IPhyFloatingVertex*)vi)->GetNode(i);
bones.Append(1, &bone);
}
break;
}
mcExport->ReleaseVertexInterface(vi);
}
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
return bones;
}
INode* IPhysiqueInterface::GetVertexBone(INode* node, int vertIndex, int boneIndex, bool rigid, bool blending, ReferenceTarget* mod)
{
Tab<INode*> bones = GetVertexBones(node, vertIndex, rigid, blending, mod);
if (boneIndex < 0 || boneIndex >= bones.Count())
throw MAXException("The bone index is not in the valid range");
return bones[boneIndex];
}
Point3 IPhysiqueInterface::GetVertexOffset(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;
IPhyVertexExport* vi = mcExport->GetVertexInterface(vertIndex);
if (vi)
{
int type = vi->GetVertexType();
switch (type)
{
case RIGID_NON_BLENDED_TYPE:
offset = ((IPhyRigidVertex*)vi)->GetOffsetVector();
offsetTab.Append(1, &offset);
break;
case RIGID_BLENDED_TYPE:
count = ((IPhyBlendedRigidVertex*)vi)->GetNumberNodes();
for (i=0;i<count;i++)
{
offset = ((IPhyBlendedRigidVertex*)vi)->GetOffsetVector(i);
offsetTab.Append(1, &offset);
}
break;
case DEFORMABLE_NON_BLENDED_TYPE:
offset = ((IPhyDeformableOffsetVertex*)vi)->GetOffsetVector();
offsetTab.Append(1, &offset);
break;
case DEFORMABLE_BLENDED_TYPE:
throw MAXException("Not a currently supported type");
break;
case FLOATING_TYPE:
count += ((IPhyFloatingVertex*)vi)->GetNumberNodes();
for (i=0;i<count;i++)
{
offset = ((IPhyFloatingVertex*)vi)->GetOffsetVector(i);
offsetTab.Append(1, &offset);
}
break;
}
mcExport->ReleaseVertexInterface(vi);
}
phyExport->ReleaseContextInterface(mcExport);
mod->ReleaseInterface(I_PHYINTERFACE, phyExport);
if (boneIndex < 0 || boneIndex >= offsetTab.Count())
throw MAXException("The bone index is not in the valid range");
return offsetTab[boneIndex];
}
Point3 IPhysiqueInterface::GetVertexDeformableOffset(INode* node, int vertIndex, ReferenceTarget* mod, TimeValue t)
{
if (!mod) mod = FindPhysiqueModifier(node, 0);
if (!mod) throw MAXException("No Physique modifier was found on this node");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -