凌雪
2018-07-30
来源 :网络
阅读 1633
评论 0
摘要:本文将带你了解Maya教程之初接触,希望本文对大家学Maya有所帮助
本文将带你了解Maya教程之初接触,希望本文对大家学Maya有所帮助
最近在学习maya api相关知识,书和教程看了不少,今天正好来练兵,也算是进入csdn的第一篇博文吧。
</pre><p></p><p></p><p>最近项目里要用一个查找x轴对称点的功能。分别写了三段代码:</p><p></p><p>maya.cmds:</p><pre name="code">def getOppsiteVertex_mayacmds(): sel = cmds.filterExpand( ex=True, sm=31 ) obj = sel[0].split('.')[0] verNum = cmds.polyEvaluate(obj,vertex=1) ret = [] for i in sel: pos = cmds.pointPosition(i,l=1) for j in xrange(verNum): pos_1 = cmds.pointPosition(obj+'.vtx['+str(j)+']') if math.fabs(-pos_1[0]-pos[0])<0.01 and math.fabs(pos_1[1]-pos[1])<0.01 and math.fabs(pos_1[2]-pos[2])<0.01: ret.append(j) break return ret
maya python api :
def findOpoVertex_pythonApi(): ret = [] mSel = om.MSelectionList() om.MGlobal.getActiveSelectionList(mSel) mDagPath = om.MDagPath() component = om.MObject() mSel.getDagPath(0,mDagPath,component) meshIter = om.MItMeshVertex(mDagPath,component) while(not meshIter.isDone()): pt = om.MPoint() pt = meshIter.position(om.MSpace.kObject) meshIter_1 = om.MItMeshVertex(mDagPath) while(not meshIter_1.isDone()): pt_1 = om.MPoint() pt_1 = meshIter_1.position(om.MSpace.kObject) if math.fabs(-pt.x-pt_1.x)<0.01 and math.fabs(pt.y-pt_1.y) <0.01 and math.fabs(pt.z-pt_1.z)<0.01 : ret.append(meshIter_1.index()) break meshIter_1.next() meshIter.next() return ret
c++ api:
#include <maya/MSimple.h>#include<maya/MGlobal.h>#include<maya/MDagPath.h>#include<maya/MSelectionList.h>#include<maya/MFnDagNode.h>#include<maya/MIOStream.h>#include<maya/MFnMesh.h>#include<maya/MFloatPointArray.h>#include<maya/MString.h>#include<maya/MItSelectionList.h>#include<maya/MItMeshVertex.h>#include<maya/MStringArray.h> DeclareSimpleCommand(pickExample,"xdh","1.0");MStatus pickExample::doIt(const MArgList &args){ MStatus stat = MS::kSuccess; MSelectionList selection; MGlobal::getActiveSelectionList(selection); MDagPath dagPath,dagPath_1; MObject component,component_1; MItSelectionList iter(selection); selection.getDagPath(0,dagPath,component); MItMeshVertex meshIter(dagPath,component,&stat); MStringArray verIndexArray; if(stat == MS::kSuccess) { for(;!meshIter.isDone();meshIter.next()) { MPoint pt = meshIter.position(MSpace::kObject); MItMeshVertex meshIter_1(dagPath); for(;!meshIter_1.isDone();meshIter_1.next()) { MPoint pt_1 = meshIter_1.position(MSpace::kObject); if (abs(-pt.x-pt_1.x)<0.01 && abs(pt.y-pt_1.y)<0.01 && abs(pt.z-pt_1.z)<0.01) { verIndexArray.append(MString("")+meshIter_1.index()); break; } } } } setResult(verIndexArray); return MS::kSuccess; }
然后在maya里跑了下,三种方式写出来的速度对比。
模型一:球模型,总共382个顶点,选择了76个。
结果如图:
使用 maya.cmds耗时 0.5秒
使用python api 耗时 0.238秒
使用c++ api 耗时 0.0625秒
模型二:球模型,总共6242个顶点,选择641个顶点。
结果如图:
使用 maya.cmds耗时 80秒
使用python api 耗时 32秒
使用c++ api 耗时 0.31秒
模型三:球模型,总共24962个顶点,选择472个顶点。
结果如图:
使用 maya.cmds耗时 236秒
使用python api 耗时 95秒
使用c++ api 耗时 0.8秒
后记:
1.三种方式,效率高下立判。
2.csdn的博客真好,贴代码,贴图片都好方便 ^ ^
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Maya频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号