- 浏览: 205231 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
悲梦天下:
楼主,有些视频到一半就没声音了,怎么破!!!
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 5356两年多前我需要解决uv重叠的问题,当时觉得是一个挺有挑 ... -
GPU, Python and Maya
2013-06-27 17:32 3139Here an example how to use pyop ... -
sierpinski triangle 2d maya plug-in(with python API 2.0)
2012-11-07 16:55 2339因为python API 2.0可用的类很少,OpenMaya ... -
sierpinski triangle 2d in maya(with python API 2.0)
2012-10-22 20:41 2029在国庆前我刚好完成手上的工作,有两三天的空闲,于是就去 ... -
mel,cmds,python API哪个更快?
2012-09-13 14:37 3957昨天偶然的跟同事谈论 ... -
Maya Python API 2.0 - MGlobal
2012-08-31 18:07 2313MGlobal是一个静态类,提供通用的API涵数. 包括获取m ... -
Maya Python API 2.0 - MSelectionList
2012-07-09 14:03 2546从Maya2012开始我们迎来了新的Python API, ... -
createDynamicCache v0.1
2011-01-09 13:57 1704createDynamicCache是我的第二个maya ... -
geomShader
2010-09-29 14:26 1259geomShader.py是使用API编写maya材质的简单的 ... -
run time dynamic node
2010-09-14 23:51 1077大概一个月前我就写好了,但一直没时间整理,这个节点和我以前写的 ... -
Helix2Cmd
2010-08-28 16:39 1375不知道大家还记不记得之前的helixCmd,这个helix2C ... -
迭代所选的组件(component)
2010-04-26 21:36 1700我们已经知道如何对物体进行选择,但如果对象是compone ... -
API中的选择操作
2010-04-25 18:06 1691我们已经知道如何使用API获取当前所选物体,但单是获取当前 ... -
使用API获取当前所选物体
2010-03-03 20:28 1932获取当前所选物体,是在编写工具时经常用到的,我们来看看API和 ... -
circleNode.py
2009-11-23 21:12 1794自定义节点 使用方法 在脚本编辑器中的python面板执行c ... -
basicObjectSet.py
2009-11-18 20:14 1198这是一个自定义节点和命令都同时存在的一个例子。 basi ... -
animCubeNode.py
2009-11-13 22:54 1406一个节点例子。该节点有一个time输入属性用来连接时间或设置关 ... -
zoomCameraCmd
2009-11-08 14:57 1079helixCmd是一个带命令参数的命令,但执行之后是无法撤销的 ... -
sineNode.py
2009-10-29 21:03 1250前面的helloWorldCmd.py和helixCmd.py ... -
helixCmd.py
2009-10-25 22:13 2044之前的helloWorldCmd.py只是 ...
相关推荐
ta_lib-0.5.1-cp312-cp312-win32.whl
课程设计 在线实时的斗兽棋游戏,时间赶,粗暴的使用jQuery + websoket 实现实时H5对战游戏 + java.zip课程设计
ta_lib-0.5.1-cp310-cp310-win_amd64.whl
基于springboot+vue物流系统源码数据库文档.zip
GEE训练教程——Landsat5、8和Sentinel-2、DEM和各2哦想指数下载
知识图谱
333498005787635解决keil下载失败的文件.zip
【微信机器人原理与实现】 微信机器人是通过模拟微信客户端的行为,自动处理消息、发送消息的程序。在Python中实现微信机器人的主要库是WeChatBot,它提供了丰富的接口,允许开发者方便地进行微信消息的接收与发送。这个项目标题中的"基于python实现的微信机器人源码"指的是使用Python编程语言编写的微信机器人程序。 1. **Python基础**:Python是一种高级编程语言,以其简洁的语法和强大的功能深受开发者喜爱。在实现微信机器人时,你需要熟悉Python的基本语法、数据类型、函数、类以及异常处理等概念。 2. **微信API与WeChatBot库**:微信为开发者提供了微信公共平台和微信开放平台,可以获取到必要的API来实现机器人功能。WeChatBot库是Python中一个用于微信开发的第三方库,它封装了微信的API,简化了消息处理的流程。使用WeChatBot,开发者可以快速搭建起一个微信机器人。 3. **微信OAuth2.0授权**:为了能够接入微信,首先需要通过OAuth2.0协议获取用户的授权。用户授权后,机器人可以获取到微信用户的身份信息,从而进行
基于springboot实验室研究生信息管理系统源码数据库文档.zip
张力控制,色标跟踪,多轴同步,电子凸轮,横切等工艺控制案例。
在Python编程环境中,处理Microsoft Word文档是一项常见的任务。Python提供了几个库来实现这一目标,如`python-docx`,它可以让我们创建、修改和操作.docx文件。本教程将重点介绍如何利用Python进行Word文档的合并、格式转换以及转换为PDF。 1. **合并Word文档(merge4docx)** 合并多个Word文档是一项实用的功能,特别是在处理大量报告或文档集合时。在Python中,可以使用`python-docx`库实现。我们需要导入`docx`模块,然后读取每个文档并将其内容插入到主文档中。以下是一个基本示例: ```python from docx import Document def merge4docx(file_list, output_file): main_doc = Document() for file in file_list: doc = Document(file) for paragraph in doc.paragraphs: main_doc.add_paragraph(paragraph.text) m
基于springboot+Javaweb的二手图书交易系统源码数据库文档.zip
基于springboot餐品美食论坛源码数据库文档.zip
基于springboot亚运会志愿者管理系统源码数据库文档.zip
使用WPF的数据样式绑定,切换对象数据值来完成控件动态切换背景渐变动画效果。 使用动画样式渲染比线程修改性能消耗更低更稳定
基于SpringBoot的企业客源关系管理系统源码数据库文档.zip
基于springboot+vue的桂林旅游网站系统源码数据库文档.zip
基于springboot嗨玩旅游网站源码数据库文档.zip
基于springboot的流浪动物管理系统源码数据库文档.zip
基于springboot课件通中小学教学课件共享平台源码数据库文档.zip