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

2022-03-07
8181
1

下面的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;

 

 

王氏教育作品欣赏-3D
  

 

 

 

本期的maya履带动画绑定插件代码,需要来取,就分享结束啦,如果需要更多建模教程,可以搜索绘学霸。在此,小编给大家推荐绘学霸的3D模型大师班,对建模感兴趣的朋友可以来绘学霸咨询喔。

 

 

 

免责声明:本文内部分内容来自网络,所涉绘画作品及文字版权与著作权归原作者,若有侵权或异议请联系我们处理。
收藏

全部评论

您还没登录

暂无留言,赶紧抢占沙发
王氏教育是国内专业的CG数字艺术设计线上线下学习平台,在王氏教育,有原画、插画、漫画、影视、3D模型等培训课程,也有学习资源下载、行业社区交流。CG数字艺术学习,来王氏教育。
绘学霸iOS端二维码

IOS下载

绘学霸安卓端二维码

安卓下载

绘学霸微信小程序二维码

小程序

版权声明
本网站所有产品设计、功能及展示形式,均已受版权或产权保护,任何公司及个人不得以任何方式复制部分或全部,违者将依法追究责任,特此声明。
热线电话
18026259035
咨询时间:9:00~21:00
在线客服
联系网站客服
客服微信:18026259035
公司地址
中国·广州
广州市海珠区晓港中马路130号之19
绘学霸客户端(权限暂无,用于CG资源与教程交流分享)
王氏教育 王氏教育