王氏教育吧 关注:311贴子:2,627
  • 1回复贴,共1

maya履带动画绑定插件代码,需要来取

只看楼主收藏回复

下面的maya履带动画 api源码,需要大家自己在vs里编译。

//首先是头文件代码:
//头文件名称:glideDeformer.h
#ifndef glideDeformer_h
#define glideDeformer_h
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
class glideDeformer:public MPxDeformerNode
{
public:
glideDeformer(){};
virtual
~glideDeformer(){};
static
void * creator(){return new glideDeformer;};
static
MStatus initializeAttr();
virtual
MStatus deform(MDataBlock
&block, MItGeometry &iter, const MMatrix &mat, unsigned
int multiIndex);
bool
getClosestUVParam(MPoint & point,MFnNurbsSurface &
surfaceFn,MObject surfaceData,double & paramU,double &
paramV);
bool
getPointFroamSurfacePoint(MPoint & point,MFnNurbsSurface
& surfaceFn,MObject surfaceData,double & paramU,double
& paramV,MPoint & outPoint);
bool
getPointAfterDeformed(MPoint &
pointInSurfaceMatrix,MFnNurbsSurface & surfaceFn,MObject
surfaceData,double & paramU,double & paramV,MPoint &
pointAffterDeformed);
static
MString nodeName;
static
MTypeId nodeId;
static
MObject glide;
static
MObject fixedBase;
static
MObject aimDirection;
static
MObject drivenSurface;
static
MObject baseSurface;
};
#endif
//CPP文件
#include "glideDeformer.h"
MString glideDeformer::nodeName=MString("glideDeformer");
MTypeId glideDeformer::nodeId=MTypeId(0x87031);
MObject glideDeformer::glide;
MObject glideDeformer::fixedBase;
MObject glideDeformer::aimDirection;
MObject glideDeformer::drivenSurface;
MObject glideDeformer::baseSurface;
using std::cout;
using std::endl;
MStatus glideDeformer::initializeAttr()
{
MFnNumericAttribute
numattr;
MFnTypedAttribute
typedattr;
MFnEnumAttribute
enumattr;
glide=numattr.create("glide","gld",MFnNumericData::kFloat,0.0);
numattr.setKeyable(true);
numattr.setStorable(true);
fixedBase=numattr.create("fixedBase","fxb",MFnNumericData::kBoolean,0);
numattr.setKeyable(true);
numattr.setStorable(true);
aimDirection=enumattr.create("aimDirection","adr",0);
enumattr.addField("directionU",0);
enumattr.addField("directionV",1);
enumattr.setKeyable(true);
enumattr.setStorable(true);
drivenSurface=typedattr.create("drivenSurface","dsf",MFnData::kNurbsSurface);
typedattr.setStorable(false);
baseSurface=typedattr.create("baseSurface","bsf",MFnData::kNurbsSurface);
typedattr.setStorable(false);
//addAttribtue
addAttribute(glide);
addAttribute(fixedBase);
addAttribute(drivenSurface);
addAttribute(baseSurface);
addAttribute(aimDirection);
attributeAffects(glide,outputGeom);
attributeAffects(fixedBase,outputGeom);
attributeAffects(aimDirection,outputGeom);
attributeAffects(drivenSurface,outputGeom);
attributeAffects(baseSurface,outputGeom);
return
MS::kSuccess;
};
bool glideDeformer::getClosestUVParam(MPoint &
point,MFnNurbsSurface & surfaceFn,MObject surfaceData,double
& paramU,double & paramV)
{
surfaceFn.setObject(surfaceData);
MPoint
tmpPoint=surfaceFn.closestPoint(point,0,0,false,0.001,MSpace::kWorld);
MStatus
stat=surfaceFn.getParamAtPoint(tmpPoint,paramU,paramV,true,MSpace::kWorld,0.001);
return
true;
};
bool glideDeformer::getPointFroamSurfacePoint(MPoint &
point,MFnNurbsSurface & surfaceFn,MObject surfaceData,double
& paramU,double & paramV,MPoint & outPoint)
{
surfaceFn.setObject(surfaceData);
MVector
tangentU;
MVector
tangentV;
MVector
normal;
MPoint
surfacePoint;
surfaceFn.getPointAtParam(paramU,paramV,surfacePoint,MSpace::kWorld);
normal=surfaceFn.normal(paramU,paramV,MSpace::kWorld);
surfaceFn.getTangents(paramU,paramV,tangentU,tangentV,MSpace::kWorld);
tangentU.normalize();
tangentV.normalize();
normal.normalize();
double
matrix[4][4]={{tangentU.x,tangentU.y,tangentU.z,0.0},{normal.x,normal.y,normal.z,0.0},{tangentV.x,tangentV.y,tangentV.z,0.0},{surfacePoint.x,surfacePoint.y,surfacePoint.z,1.0}};
MMatrix
surfacePointMatrix=MMatrix(matrix);
//cout<<"baseSurfacePointMatrix:"<<surfacepointmatrix<<endl;
outPoint=point*surfacePointMatrix.inverse();
//cout<<"pointInSurfaceMatrixPosition:"<<outpoint<<endl;
return
true;
};
bool glideDeformer::getPointAfterDeformed(MPoint &
pointInSurfaceMatrix,MFnNurbsSurface & surfaceFn,MObject
surfaceData,double & paramU,double & paramV,MPoint &
pointAffterDeformed)
{
surfaceFn.setObject(surfaceData);
MVector
tangentU;
MVector
tangentV;
MVector
normal;
MPoint
surfacePoint;
surfaceFn.getPointAtParam(paramU,paramV,surfacePoint,MSpace::kWorld);
normal=surfaceFn.normal(paramU,paramV,MSpace::kWorld);
surfaceFn.getTangents(paramU,paramV,tangentU,tangentV,MSpace::kWorld);
tangentU.normalize();
tangentV.normalize();
normal.normalize();
double
matrix[4][4]={{tangentU.x,tangentU.y,tangentU.z,0.0},{normal.x,normal.y,normal.z,0.0},{tangentV.x,tangentV.y,tangentV.z,0.0},{surfacePoint.x,surfacePoint.y,surfacePoint.z,1.0}};
MMatrix
surfacePointMatrix=MMatrix(matrix);
//cout<<"drivenSurfacePointMatrix:"<<surfacepointmatrix<<endl;
pointAffterDeformed=pointInSurfaceMatrix*surfacePointMatrix;
//cout<<"pointAffterDeformedPosition:"<<pointaffterdeformed<<endl;
return
true;
};
MStatus glideDeformer::deform(MDataBlock
&block, MItGeometry & iter, const MMatrix &mat,
unsigned int multiIndex)
{
//cout<<"deform()方法调用..."<<endl;
MDataHandle
envelopehandle=block.inputValue(envelope);
MDataHandle
glidehandle=block.inputValue(glide);
MDataHandle
fixedBasehandle=block.inputValue(fixedBase);
MDataHandle
aimDirectionhandle=block.inputValue(aimDirection);
float
envelopevalue=envelopehandle.asFloat();
float
glidevalue=glidehandle.asFloat();
short
aimDirectionvalue=aimDirectionhandle.asShort();
bool
fixedBasevalue=fixedBasehandle.asBool();
if
(envelopevalue==0.0)
{
//cout<<"envelope值为0,跳过deform方法..."<<endl;
return
MS::kSuccess;
};
MDataHandle
drivenSurfacehandle=block.inputValue(drivenSurface);
MDataHandle
baseSurfacehandle=block.inputValue(baseSurface);
MFnNurbsSurfaceData
surfaceDataFn;
MFnNurbsSurface
surfaceFn;
MObject
drivenSurfaceData=drivenSurfacehandle.asNurbsSurface();
MObject
baseSurfaceData=baseSurfacehandle.asNurbsSurface();
MObject
drivenSurfaceObj=surfaceDataFn.create();
MObject
baseSurfaceObj=surfaceDataFn.create();
surfaceFn.setObject(drivenSurfaceData);
surfaceFn.copy(drivenSurfaceObj);
int
drivenSurfaceCvU=surfaceFn.numCVsInU();
int
drivenSurfaceCvV=surfaceFn.numCVsInV();
surfaceFn.setObject(baseSurfaceData);
surfaceFn.copy(baseSurfaceObj);
int
baseSurfaceCvU=surfaceFn.numCVsInU();
int
baseSurfaceCvV=surfaceFn.numCVsInV();
cout<<drivensurfacecvu<<" "<<drivensurfacecvv<<" "<<basesurfacecvu<<" "<<basesurfacecvv<<" "<<endl;
if
(drivenSurfaceCvU==0||drivenSurfaceCvV==0||drivenSurfaceCvU==0||baseSurfaceCvU==0||baseSurfaceCvV==0)
{
//cout<<"drivenSurface或baseSurface不正确,变形不产生..."<<endl;
MGlobal::displayWarning("drivenSurface或baseSurface不正确,变形不产生...");
return
MS::kSuccess;
};
if
(drivenSurfaceCvU!=baseSurfaceCvU||drivenSurfaceCvV!=baseSurfaceCvV)
{
//cout<<"drivenSurface与baseSurface不匹配,变形不产生..."<<endl;
MGlobal::displayWarning("drivenSurface与baseSurface不匹配,变形不产生...");
return
MS::kSuccess;
};
MPoint
pt;
MPoint
ptAfterDeformed;
MPoint
pointInSurfacePointMatrix;
double
paramU;
double
paramV;
double
newParamU;
double
newParamV;
int
index;
float
weight;
bool
test;
if
(fixedBasevalue==false)
{
//cout<<"履带模式..."<<endl;
for(iter.reset();!iter.isDone();iter.next())
{
index=iter.index();
//cout<<"index:"<<index<<endl;
weight=weightValue(block,multiIndex,index);
//cout<<"weight:"<<weight<<endl;
if
(weight==0)
{
//cout<<"权重为0,此点变形不产生..."<<endl;
continue;
};
pt=iter.position(MSpace::kObject);
pt=pt*mat;
//cout<<"position:"<</endl;
</weight<<endl;
</index<<endl;
</endl;
</endl;
</endl;
</drivensurfacecvu<<" "<<drivensurfacecvv<<" "<<basesurfacecvu<<" "<<basesurfacecvv<<" "<<endl;
</endl;
</endl;
</pointaffterdeformed<<endl;
</surfacepointmatrix<<endl;
</outpoint<<endl;
</surfacepointmatrix<<endl;


IP属地:广东1楼2022-03-08 09:57回复
    看不到啊,大佬


    IP属地:重庆来自Android客户端2楼2024-07-10 21:00
    回复