- 浏览: 204794 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
悲梦天下:
楼主,有些视频到一半就没声音了,怎么破!!!
python视频教程 更新22(完) -
schi:
啊,我太傻了,都想到使用uv了,可以有更简单的方法,只要把uv ...
Get Reversed Normal Faces(获取反法线面) [原理] -
schi:
相对Pillow和PySide而言,显示图片opengl就显得 ...
display an image with pyopengl and Pillow -
schi:
我也是今天才偶然想到的,我以后可能用不着了,所有分享给有需要的 ...
Get Reversed Normal Faces(获取反法线面) [原理] -
baiyanbin:
支持楼主原创,关注楼主博客有一阵子了,国内认真认真搞技术的太少 ...
python视频教程 更新22(完)
scanDag命令以depth first(深度优先)或breadth first(广度优先)来迭代整个DAG,输出每个节点的名称和深度等信息,这个命令插件例子中只对相机、灯光、NURBS surfaces进行支持。
在maya的Plug-in Manager中加载scanDagCmd.py,然后你可以随便创建一些相机、灯光、NURBS surfaces,并对它们进行位移等属性调整,然后分别执行
// -d 为深度优先,-b 为广度优先 // 相机 scanDag -d 1 -c 1; // 灯光 scanDag -d 1 -l 1; // NURBS surfaces scanDag -d 1 -l 1; // 或全部一起 scanDag -d 1 -c 1 -l 1 -n 1;
或
import maya.cmds as cmds # 相机 cmds.scanDag(d=1, c=1) # 灯光 cmds.scanDag(d=1, l=1)
你会得到类似的输出结果
Output
Starting Depth First scan of the Dag: Filtering for Cameras
perspShape: camera
dagPath: |persp|perspShape
translation: 28.000000 21.000000 28.000000
rotation: [-0.487616, 0.785398, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 28.000000 21.000000 28.000000
upDirection: -0.331295 0.883452 -0.331295
viewDirection: -0.624695 -0.468521 -0.624695
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
topShape: camera
dagPath: |top|topShape
translation: 0.000000 100.100000 0.000000
rotation: [-1.570796, 0.000000, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 0.000000 100.100000 0.000000
upDirection: 0.000000 0.000000 -1.000000
viewDirection: 0.000000 -1.000000 -0.000000
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
frontShape: camera
dagPath: |front|frontShape
translation: 0.000000 0.000000 100.100000
rotation: [0.000000, -0.000000, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 0.000000 0.000000 100.100000
upDirection: 0.000000 1.000000 0.000000
viewDirection: 0.000000 0.000000 -1.000000
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
sideShape: camera
dagPath: |side|sideShape
translation: 100.100000 0.000000 0.000000
rotation: [-0.000000, 1.570796, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 100.100000 0.000000 0.000000
upDirection: 0.000000 1.000000 0.000000
viewDirection: -1.000000 0.000000 -0.000000
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
// Result: 4 //
perspShape: camera
dagPath: |persp|perspShape
translation: 28.000000 21.000000 28.000000
rotation: [-0.487616, 0.785398, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 28.000000 21.000000 28.000000
upDirection: -0.331295 0.883452 -0.331295
viewDirection: -0.624695 -0.468521 -0.624695
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
topShape: camera
dagPath: |top|topShape
translation: 0.000000 100.100000 0.000000
rotation: [-1.570796, 0.000000, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 0.000000 100.100000 0.000000
upDirection: 0.000000 0.000000 -1.000000
viewDirection: 0.000000 -1.000000 -0.000000
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
frontShape: camera
dagPath: |front|frontShape
translation: 0.000000 0.000000 100.100000
rotation: [0.000000, -0.000000, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 0.000000 0.000000 100.100000
upDirection: 0.000000 1.000000 0.000000
viewDirection: 0.000000 0.000000 -1.000000
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
sideShape: camera
dagPath: |side|sideShape
translation: 100.100000 0.000000 0.000000
rotation: [-0.000000, 1.570796, 0.000000]
scale: [1.000000, 1.000000, 1.000000]
eyePoint: 100.100000 0.000000 0.000000
upDirection: 0.000000 1.000000 0.000000
viewDirection: -1.000000 0.000000 -0.000000
aspectRatio: 1.500000
horizontalFilmAperture: 1.417320
verticalFilmAperture: 0.944880
// Result: 4 //
scanDagCmd.py
# -*- coding: UTF-8 -*- import sys import maya.OpenMaya as om import maya.OpenMayaMPx as ompx # 命令名称 kCmdName = 'scanDag' # 命令参数 kBreadthFlag = '-b' kBreadthFlagLong = 'breadthFirst' kDepthFlag = '-d' kDepthFlagLong = '-depthFirst' kCameraFlag = '-c' kCameraFlagLong = '-cameras' kLightFlag = '-l' kLightFlagLong = '-lights' kNurbsSurfaceFlag = '-n' kNurbsSurfaceFlagLong = '-nurbsSurfaces' kQuietFlag = '-q' kQuietFlagLong = '-quiet' # 定义命令 class ScanDag(ompx.MPxCommand): def __init__(self): super(ScanDag, self).__init__() def doIt(self, args): # 初始化默认变量,防止无参数命令出现 self._traversalType = om.MItDag.kDepthFirst self._filter = om.MFn.kInvalid self._quiet = False self.__parseArgs(args) return self.__doScan() def __parseArgs(self, args): ''' 检查命令所给的参数,并设置相应的变量 ''' argData = om.MArgDatabase(self.syntax(), args) if argData.isFlagSet(kBreadthFlag) or argData.isFlagSet(kBreadthFlagLong): self._traversalType = om.MItDag.kBreadthFirst if argData.isFlagSet(kDepthFlag) or argData.isFlagSet(kDepthFlagLong): self._traversalType = om.MItDag.kDepthFirst if argData.isFlagSet(kCameraFlag) or argData.isFlagSet(kCameraFlagLong): self._filter = om.MFn.kCamera if argData.isFlagSet(kLightFlag) or argData.isFlagSet(kLightFlagLong): self._filter = om.MFn.kLight if argData.isFlagSet(kNurbsSurfaceFlag) or argData.isFlagSet(kNurbsSurfaceFlagLong): self._filter = om.MFn.kNurbsSurface if argData.isFlagSet(kQuietFlag) or argData.isFlagSet(kQuietFlagLong): self._quiet = True return True def __doScan(self): ''' 完成实际的工作 ''' # 创建dag迭代器 dagIterator = om.MItDag(self._traversalType, self._filter) # Scan the entire DAG and output the name and depth of each node # 扫描整个DAG,输出每个节点的名称和深度 if self._traversalType == om.MItDag.kBreadthFirst: if not self._quiet: sys.stdout.write('Starting Breadth First scan of the Dag') else: if not self._quiet: sys.stdout.write('Starting Depth First scan of the Dag') if self._filter == om.MFn.kCamera: if not self._quiet: sys.stdout.write(': Filtering for Cameras\n') elif self._filter == om.MFn.kLight: if not self._quiet: sys.stdout.write(': Filtering for Lights\n') elif self._filter == om.MFn.kNurbsSurface: if not self._quiet: sys.stdout.write(': Filtering for Nurbs Surfaces\n') else: sys.stdout.write('\n') # 对DAG里的每个节点进行迭代 objectCount = 0 while not dagIterator.isDone(): dagPath = om.MDagPath() # 获取节点的DAG路径 dagIterator.getPath(dagPath) # 使用方法集来操作节点 dagNode = om.MFnDagNode(dagPath) # 输出节点的名称,类型,全路径 if not self._quiet: sys.stdout.write('%s: %s\n' % (dagNode.name(), dagNode.typeName())) if not self._quiet: sys.stdout.write(' dagPath: %s\n' % dagPath.fullPathName()) # 判别节点的类型,这里只对相机、灯光、NURBS surfaces进行操作 # 实际上是可以对任意类型,进行相应的操作 objectCount += 1 if dagPath.hasFn(om.MFn.kCamera): camera = om.MFnCamera(dagPath) # Get the translation/rotation/scale data # 获取translation/rotation/scale等数据 self.__printTransformData(dagPath) # Extract some interesting Camera data # 分离一些有趣的相机数据 if not self._quiet: eyePoint = camera.eyePoint(om.MSpace.kWorld) upDirection = camera.upDirection(om.MSpace.kWorld) viewDirection = camera.viewDirection(om.MSpace.kWorld) aspectRatio = camera.aspectRatio() hfa = camera.horizontalFilmAperture() vfa = camera.verticalFilmAperture() sys.stdout.write(" eyePoint: %f %f %f\n" % (eyePoint.x, eyePoint.y, eyePoint.z)) sys.stdout.write(" upDirection: %f %f %f\n" % (upDirection.x, upDirection.y, upDirection.z)) sys.stdout.write(" viewDirection: %f %f %f\n" % (viewDirection.x, viewDirection.y, viewDirection.z)) sys.stdout.write(" aspectRatio: %f\n" % aspectRatio) sys.stdout.write(" horizontalFilmAperture: %f\n" % hfa) sys.stdout.write(" verticalFilmAperture: %f\n" % vfa) elif dagPath.hasFn(om.MFn.kLight): light = om.MFnLight(dagPath) # Get the translation/rotation/scale data # 获取translation/rotation/scale等数据 self.__printTransformData(dagPath) # Extract some interesting Light data # 分离一些有趣的灯光数据 color = om.MColor() color = light.color() if not self._quiet: sys.stdout.write(" color: [%f, %f, %f]\n" % (color.r, color.g, color.b)) color = light.shadowColor() if not self._quiet: sys.stdout.write(" shadowColor: [%f, %f, %f]\n" % (color.r, color.g, color.b)) sys.stdout.write(" intensity: %f\n" % light.intensity()) elif dagPath.hasFn(om.MFn.kNurbsSurface): surface = om.MFnNurbsSurface(dagPath) # Get the translation/rotation/scale data # 获取translation/rotation/scale等数据 self.__printTransformData(dagPath) # Extract some interesting Surface data # 分离一些有趣的NURBS surfaces数据 if not self._quiet: sys.stdout.write(" numCVs: %d * %d\n" % (surface.numCVsInU(), surface.numCVsInV())) sys.stdout.write(" numKnots: %d * %d\n" % (surface.numKnotsInU(), surface.numKnotsInV())) sys.stdout.write(" numSpans: %d * %d\n" % (surface.numSpansInU(), surface.numSpansInV())) else: # Get the translation/rotation/scale data # 获取translation/rotation/scale等数据 self.__printTransformData(dagPath) dagIterator.next() # 返回命令结果,这个结果为所操作的节点的数量值 self.setResult(objectCount) return om.MStatus.kSuccess def __printTransformData(self, dagPath): ''' 获取translation/rotation/scale等数据 ''' # 获取节点的Transform节点 transformNode = dagPath.transform() transform = om.MFnDagNode(transformNode) # 获取Transform的Transformation matrix matrix = om.MTransformationMatrix(transform.transformationMatrix()) if not self._quiet: # 获取节点的位移数值,并输出 translation = matrix.translation(om.MSpace.kWorld) sys.stdout.write(' translation: %f %f %f\n' % (translation.x, translation.y, translation.z)) #rOrder = om.MTransformationMatrix.kXYZ #matrix.getRotation(ptr, rOrder) # 获取节点的旋转数值,并输出 rotateOrder = 0 mquat = matrix.rotation() rot = mquat.asEulerRotation() rot.reorderIt(rotateOrder) if not self._quiet: sys.stdout.write(" rotation: [%f, %f, %f]\n" % (rot.x, rot.y, rot.z)) # 获取节点的缩放数值,并输出 # 这里需要使用MScriptUtil # 因为MTransformationMatrix.getScale() # 的第一个参数是C++里的指针 util = om.MScriptUtil() util.createFromDouble(0.0, 0.0, 0.0) ptr = util.asDoublePtr() matrix.getScale(ptr, om.MSpace.kWorld) scaleX = util.getDoubleArrayItem(ptr, 0) scaleY = util.getDoubleArrayItem(ptr, 1) scaleZ = util.getDoubleArrayItem(ptr, 2) if not self._quiet: sys.stdout.write(' scale: [%f, %f, %f]\n' % (scaleX, scaleY, scaleZ)) # Creator def cmdCreator(): return ompx.asMPxPtr(ScanDag()) # Syntax creator def syntaxCreator(): syntax = om.MSyntax() syntax.addFlag(kBreadthFlag, kBreadthFlagLong, om.MSyntax.kBoolean) syntax.addFlag(kDepthFlag, kDepthFlagLong, om.MSyntax.kBoolean) syntax.addFlag(kCameraFlag, kCameraFlagLong, om.MSyntax.kBoolean) syntax.addFlag(kLightFlag, kLightFlagLong, om.MSyntax.kBoolean) syntax.addFlag(kNurbsSurfaceFlag, kNurbsSurfaceFlagLong, om.MSyntax.kBoolean) syntax.addFlag(kQuietFlag, kQuietFlagLong, om.MSyntax.kBoolean) return syntax # Initialize the script plug-in def initializePlugin(mobj): mplugin = ompx.MFnPlugin(mobj, 'Mack Stone', '3.0', 'Any') try: mplugin.registerCommand(kCmdName, cmdCreator, syntaxCreator) except: sys.stderr.write('Failed to register command: %s\n' % kCmdName) raise # Uninitialize the script plug-in def uninitializePlugin(mobj): mplugin = ompx.MFnPlugin(mobj) try: mplugin.deregisterCommand(kCmdName) except: sys.stderr.write('Failed to unregister command: %s\n' % kCmdName) raise
你可以在devkit\plug-ins中找到scanDagCmd.cpp
在线版本
http://download.autodesk.com/us/maya/2010help/API/scan_dag_cmd_8cpp-example.html
发表评论
-
uv重叠(uv overlap)
2014-06-28 22:28 5329两年多前我需要解决uv重叠的问题,当时觉得是一个挺有挑 ... -
GPU, Python and Maya
2013-06-27 17:32 3131Here an example how to use pyop ... -
sierpinski triangle 2d maya plug-in(with python API 2.0)
2012-11-07 16:55 2336因为python API 2.0可用的类很少,OpenMaya ... -
sierpinski triangle 2d in maya(with python API 2.0)
2012-10-22 20:41 2021在国庆前我刚好完成手上的工作,有两三天的空闲,于是就去 ... -
mel,cmds,python API哪个更快?
2012-09-13 14:37 3948昨天偶然的跟同事谈论 ... -
Maya Python API 2.0 - MGlobal
2012-08-31 18:07 2308MGlobal是一个静态类,提供通用的API涵数. 包括获取m ... -
Maya Python API 2.0 - MSelectionList
2012-07-09 14:03 2541从Maya2012开始我们迎来了新的Python API, ... -
createDynamicCache v0.1
2011-01-09 13:57 1700createDynamicCache是我的第二个maya ... -
geomShader
2010-09-29 14:26 1255geomShader.py是使用API编写maya材质的简单的 ... -
run time dynamic node
2010-09-14 23:51 1072大概一个月前我就写好了,但一直没时间整理,这个节点和我以前写的 ... -
Helix2Cmd
2010-08-28 16:39 1370不知道大家还记不记得之前的helixCmd,这个helix2C ... -
迭代所选的组件(component)
2010-04-26 21:36 1699我们已经知道如何对物体进行选择,但如果对象是compone ... -
API中的选择操作
2010-04-25 18:06 1685我们已经知道如何使用API获取当前所选物体,但单是获取当前 ... -
使用API获取当前所选物体
2010-03-03 20:28 1930获取当前所选物体,是在编写工具时经常用到的,我们来看看API和 ... -
circleNode.py
2009-11-23 21:12 1791自定义节点 使用方法 在脚本编辑器中的python面板执行c ... -
basicObjectSet.py
2009-11-18 20:14 1195这是一个自定义节点和命令都同时存在的一个例子。 basi ... -
animCubeNode.py
2009-11-13 22:54 1405一个节点例子。该节点有一个time输入属性用来连接时间或设置关 ... -
zoomCameraCmd
2009-11-08 14:57 1072helixCmd是一个带命令参数的命令,但执行之后是无法撤销的 ... -
sineNode.py
2009-10-29 21:03 1247前面的helloWorldCmd.py和helixCmd.py ... -
helixCmd.py
2009-10-25 22:13 2042之前的helloWorldCmd.py只是 ...
相关推荐
基于java的贝儿米幼儿教育管理系统答辩PPT.pptx
本压缩包资源说明,你现在往下拉可以看到压缩包内容目录 我是批量上传的基于SpringBoot+Vue的项目,所以描述都一样;有源码有数据库脚本,系统都是测试过可运行的,看文件名即可区分项目~ |Java|SpringBoot|Vue|前后端分离| 开发语言:Java 框架:SpringBoot,Vue JDK版本:JDK1.8 数据库:MySQL 5.7+(推荐5.7,8.0也可以) 数据库工具:Navicat 开发软件: idea/eclipse(推荐idea) Maven包:Maven3.3.9+ 系统环境:Windows/Mac
基于java的消防物资存储系统答辩PPT.pptx
项目经过测试均可完美运行! 环境说明: 开发语言:java jdk:jdk1.8 数据库:mysql 5.7+ 数据库工具:Navicat11+ 管理工具:maven 开发工具:idea/eclipse
项目经过测试均可完美运行! 环境说明: 开发语言:java jdk:jdk1.8 数据库:mysql 5.7+ 数据库工具:Navicat11+ 管理工具:maven 开发工具:idea/eclipse
TA_lib库(whl轮子),直接pip install安装即可,下载即用,非常方便,各个python版本对应的都有。 使用方法: 1、下载下来解压; 2、确保有python环境,命令行进入终端,cd到whl存放的目录,直接输入pip install TA_lib-xxxx.whl就可以安装,等待安装成功,即可使用! 优点:无需C++环境编译,下载即用,方便
使用软件自带的basic脚本编辑制作的脚本 低版本软件无法输出Excel报告,可以通过脚本方式实现这一功能
基于java的就业信息管理系统答辩PPT.pptx
25法理学背诵逻辑.apk.1g
基于java的大学生校园兼职系统答辩PPT.pptx
做到代码,和分析的源数据
本压缩包资源说明,你现在往下拉可以看到压缩包内容目录 我是批量上传的基于SpringBoot+Vue的项目,所以描述都一样;有源码有数据库脚本,系统都是测试过可运行的,看文件名即可区分项目~ |Java|SpringBoot|Vue|前后端分离| 开发语言:Java 框架:SpringBoot,Vue JDK版本:JDK1.8 数据库:MySQL 5.7+(推荐5.7,8.0也可以) 数据库工具:Navicat 开发软件: idea/eclipse(推荐idea) Maven包:Maven3.3.9+ 系统环境:Windows/Mac
项目经过测试均可完美运行! 环境说明: 开发语言:java jdk:jdk1.8 数据库:mysql 5.7+ 数据库工具:Navicat11+ 管理工具:maven 开发工具:idea/eclipse
适用于ensp已经入门人群的学习,有一定难度
基于java的数码论坛系统设计与实现答辩PPT.pptx
tornado-6.4.1-cp38-abi3-macosx_10_9_universal2.whl
基于java的医院信管系统答辩PPT.pptx
项目经过测试均可完美运行! 环境说明: 开发语言:java jdk:jdk1.8 数据库:mysql 5.7+ 数据库工具:Navicat11+ 管理工具:maven 开发工具:idea/eclipse
tornado-4.2.tar.gz
链表 合并两个链表,链表基础操作