好酷屋

maya履带动画绑定插件代码

好酷屋

发布于2023-04-20

好酷屋教程网小编为您收集和整理了maya履带动画绑定插件代码的相关教程:下面的maya履带动画api源码,需要大家自己在vs里编译。//首先是头文件代码://头文件名称:glideDeformer.h#ifndefglideDeformer_h#defineglideD

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

//首先是头文件代码://头文件名称:glideDeformer.h#ifndefglideDeformer_h#defineglideDeformer_h#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#includeclassglideDeformer:publicMpxDeformerNode{public:glideDeformer(){};virtual~glideDeformer(){};staticvoid*creator(){returnnewglideDeformer;};staticMStatusinitializeAttr();virtualMStatusdeform(MDataBlock&block,MItGeometry&iter,constMMatrix&mat,unsignedintmultiIndex);boolgetClosestUVparam(Mpoint&point,MFnNurbsSurface&surfaceFn,MObjectsurfaceData,double&paramU,double&paramV);boolgetpointFroamSurfacepoint(Mpoint&point,MFnNurbsSurface&surfaceFn,MObjectsurfaceData,double&paramU,double&paramV,Mpoint&outpoint);boolgetpointAfterDeformed(Mpoint&pointInSurfaceMatrix,MFnNurbsSurface&surfaceFn,MObjectsurfaceData,double&paramU,double&paramV,Mpoint&pointAffterDeformed);staticMStringnodeName;staticMTypeIdnodeId;staticMObjectglide;staticMObjectfixedBase;staticMObjectaimDirection;staticMObjectdrivenSurface;staticMObjectbaseSurface;};#endif//Cpp文件#include”glideDeformer.h”MStringglideDeformer::nodeName=MString(“glideDeformer”);MTypeIdglideDeformer::nodeId=MTypeId(0x87031);MObjectglideDeformer::glide;MObjectglideDeformer::fixedBase;MObjectglideDeformer::aimDirection;MObjectglideDeformer::drivenSurface;MObjectglideDeformer::baseSurface;usingstd::cout;usingstd::endl;MStatusglideDeformer::initializeAttr(){MFnNumericAttributenumattr;MFnTypedAttributetypedattr;MFnEnumAttributeenumattr;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);//addAttribtueaddAttribute(glide);addAttribute(fixedBase);addAttribute(drivenSurface);addAttribute(baseSurface);addAttribute(aimDirection);attributeAffects(glide,outputGeom);attributeAffects(fixedBase,outputGeom);attributeAffects(aimDirection,outputGeom);attributeAffects(drivenSurface,outputGeom);attributeAffects(baseSurface,outputGeom);returnMS::kSuccess;};boolglideDeformer::getClosestUVparam(Mpoint&point,MFnNurbsSurface&surfaceFn,MObjectsurfaceData,double&paramU,double&paramV){surfaceFn.setObject(surfaceData);Mpointtmppoint=surfaceFn.closestpoint(point,0,0,false,0.001,MSpace::kWorld);MStatusstat=surfaceFn.getparamAtpoint(tmppoint,paramU,paramV,true,MSpace::kWorld,0.001);returntrue;};boolglideDeformer::getpointFroamSurfacepoint(Mpoint&point,MFnNurbsSurface&surfaceFn,MObjectsurfaceData,double&paramU,double&paramV,Mpoint&outpoint){surfaceFn.setObject(surfaceData);MVectortangentU;MVectortangentV;MVectornormal;Mpointsurfacepoint;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();doublematrix={{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}};MMatrixsurfacepointMatrix=MMatrix(matrix);//cout<<“baseSurfacepointMatrix:”<<surfacepointmatrix<<endl;outpoint=point*surfacepointMatrix.inverse();//cout<<"pointInSurfaceMatrixposition:"<<outpoint<<endl;returntrue;};boolglideDeformer::getpointAfterDeformed(Mpoint&pointInSurfaceMatrix,MFnNurbsSurface&surfaceFn,MObjectsurfaceData,double&paramU,double&paramV,Mpoint&pointAffterDeformed){surfaceFn.setObject(surfaceData);MVectortangentU;MVectortangentV;MVectornormal;Mpointsurfacepoint;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();doublematrix={{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}};MMatrixsurfacepointMatrix=MMatrix(matrix);//cout<<"drivenSurfacepointMatrix:"<<surfacepointmatrix<<endl;pointAffterDeformed=pointInSurfaceMatrix*surfacepointMatrix;//cout<<"pointAffterDeformedposition:"<<pointaffterdeformed<<endl;returntrue;};MStatusglideDeformer::deform(MDataBlock&block,MItGeometry&iter,constMMatrix&mat,unsignedintmultiIndex){//cout<<"deform()方法调用…"<<endl;MDataHandleenvelopehandle=block.inputValue(envelope);MDataHandleglidehandle=block.inputValue(glide);MDataHandlefixedBasehandle=block.inputValue(fixedBase);MDataHandleaimDirectionhandle=block.inputValue(aimDirection);floatenvelopevalue=envelopehandle.asFloat();floatglidevalue=glidehandle.asFloat();shortaimDirectionvalue=aimDirectionhandle.asShort();boolfixedBasevalue=fixedBasehandle.asBool();if(envelopevalue==0.0){//cout<<"envelope值为0,跳过deform方法…"<<endl;returnMS::kSuccess;};MDataHandledrivenSurfacehandle=block.inputValue(drivenSurface);MDataHandlebaseSurfacehandle=block.inputValue(baseSurface);MFnNurbsSurfaceDatasurfaceDataFn;MFnNurbsSurfacesurfaceFn;MObjectdrivenSurfaceData=drivenSurfacehandle.asNurbsSurface();MObjectbaseSurfaceData=baseSurfacehandle.asNurbsSurface();MObjectdrivenSurfaceObj=surfaceDataFn.create();MObjectbaseSurfaceObj=surfaceDataFn.create();surfaceFn.setObject(drivenSurfaceData);surfaceFn.copy(drivenSurfaceObj);intdrivenSurfaceCvU=surfaceFn.numCVsInU();intdrivenSurfaceCvV=surfaceFn.numCVsInV();surfaceFn.setObject(baseSurfaceData);surfaceFn.copy(baseSurfaceObj);intbaseSurfaceCvU=surfaceFn.numCVsInU();intbaseSurfaceCvV=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不正确,变形不产生…");returnMS::kSuccess;};if(drivenSurfaceCvU!=baseSurfaceCvU||drivenSurfaceCvV!=baseSurfaceCvV){//cout<<"drivenSurface与baseSurface不匹配,变形不产生…"<<endl;MGlobal::displayWarning("drivenSurface与baseSurface不匹配,变形不产生…");returnMS::kSuccess;};Mpointpt;MpointptAfterDeformed;MpointpointInSurfacepointMatrix;doubleparamU;doubleparamV;doublenewparamU;doublenewparamV;intindex;floatweight;booltest;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:"<<pt<<endl;

</pt<<endl;</endl;</weight<<endl;</index<<endl;</endl;</endl;</endl;</drivensurfacecvu<<"  "<<drivensurfacecvv<<"  "<<basesurfacecvu<<"  "<<basesurfacecvv<<" "<<endl;</endl;</endl;</pointaffterdeformed<<endl;</surfacepointmatrix<<endl;</outpoint<<endl;</surfacepointmatrix<<endl;

以上就是好酷屋教程网小编为您收集和整理的maya履带动画绑定插件代码相关内容,如果对您有帮助,请帮忙分享这篇文章^_^

本文来源: https://www.haoku5.com/IT/6440cf7d8d29a26e1509897e.html

相关推荐

    热门专题