createDynamicCache是我的第二个maya standalone script,就是cache from command line的API版本。这个script是使用maya python API来写的,除了cache的命令是mel命令。我粗略看了一下maya中的cache命令,发现很复杂,需要很多时间来分析,而且就算我重新使用python来编写也可能达不到我想要的结果,就是我前面所说的在cache时输出进度信息,所以要重写cache命令的话可能会用API写,maya倒是提供了一个XmlGeometryCache.cpp例子,但这个例子太长了还是C++的,有时间再研究研究。
createDynamicCache的用法很简单,你可以使用mayapy.exe来运行它
[color=red]cache存放的位置就是场景的路径下的"cache/场景名称"中,计算完cache后你的场景会另存为"场景名称_cache.ma"[/color]
如果没有给予任何参数,它会输出帮助
[quote]#####################################
## ##
## createDynamicCache v0.1 ##
## Author: Mack Stone ##
## Email: schistone@gmail.com ##
## blog: http://schi.iteye.com ##
## ##
#####################################
usage: MAYA_LOCATION/bin/mayapy.exe creatDynamicCache.py [options] fileName1 fileName2 ...
each file will be loaded and do dynamic cache. The cache files will create in fileName/cache/fileName.
Options:
-h, -help, help print out help.
-nCloth cache all nCloth in the scene.
-nParticle cache all nParticle in the scene.
-Fluid cache all Fluid in the scene.
You can use -nCloth and -nParticle at the same time to cache all nCloth and nParticle in the scene.
Example:
C:\Program Files\Autodesk\Maya2009\bin\mayapy.exe createDynamicCache.py -nCloth -nParticle C:\test\test.ma[/quote]
你也可以使用
[quote]-h, -help, help[/quote]
来得到帮助信息
参数主要有3个
[quote]-nCloth cache all nCloth in the scene. <--> cache场景中所有的nCloth
-nParticle cache all nParticle in the scene. <--> cache场景中所有的nParticle
-Fluid cache all Fluid in the scene. <--> cache场景中所有的Fluid[/quote]
如果你的场景中同时有nCloth和nParticle,你希望它们全都一起进行cache,你可以同时使用“-nCloth”和“-nParticle”这两个参数
如果你有多个文件,你可以进行批量cache
[color=red]最后要注意的是,我不知道是bug还是什么,在cache Fluid时你会失败,你得到的错误信息类似是“'fluidShape1' 不是可cache的节点类型”,pymel和mrv的版本我没试过出现这种情况,但如果你cache的场景版本比你现在使用的maya版本还低的话就能正常进行cache,我还不知道是什么原因。[/color]
使用教学
[url]http://u.115.com/file/f474056d82#[/url]
createDynamicCache.mp4
使用这段代码你可以在玛雅中直接执行
脚本下载(script download)
[url]http://u.115.com/file/f47772c0c3#[/url]
createDynamicCache.zip
如果你对这个工具有好的建议,希望你能告诉我(可以通过email),虽然我未必有时间去改进,源代码暂时不提供(虽然没什么新奇的代码,就让我保留少少的神秘吧)
ps.同时这个脚本也是献给那些和我一样没日没夜的加班的同志,虽然并不能解决你们的加班问题,希望能帮上你的忙。
createDynamicCache的用法很简单,你可以使用mayapy.exe来运行它
C:\Program Files\Autodesk\Maya2009\bin\mayapy.exe createDynamicCache.pyc
[color=red]cache存放的位置就是场景的路径下的"cache/场景名称"中,计算完cache后你的场景会另存为"场景名称_cache.ma"[/color]
如果没有给予任何参数,它会输出帮助
[quote]#####################################
## ##
## createDynamicCache v0.1 ##
## Author: Mack Stone ##
## Email: schistone@gmail.com ##
## blog: http://schi.iteye.com ##
## ##
#####################################
usage: MAYA_LOCATION/bin/mayapy.exe creatDynamicCache.py [options] fileName1 fileName2 ...
each file will be loaded and do dynamic cache. The cache files will create in fileName/cache/fileName.
Options:
-h, -help, help print out help.
-nCloth cache all nCloth in the scene.
-nParticle cache all nParticle in the scene.
-Fluid cache all Fluid in the scene.
You can use -nCloth and -nParticle at the same time to cache all nCloth and nParticle in the scene.
Example:
C:\Program Files\Autodesk\Maya2009\bin\mayapy.exe createDynamicCache.py -nCloth -nParticle C:\test\test.ma[/quote]
你也可以使用
[quote]-h, -help, help[/quote]
来得到帮助信息
参数主要有3个
[quote]-nCloth cache all nCloth in the scene. <--> cache场景中所有的nCloth
-nParticle cache all nParticle in the scene. <--> cache场景中所有的nParticle
-Fluid cache all Fluid in the scene. <--> cache场景中所有的Fluid[/quote]
如果你的场景中同时有nCloth和nParticle,你希望它们全都一起进行cache,你可以同时使用“-nCloth”和“-nParticle”这两个参数
C:\Program Files\Autodesk\Maya2009\bin\mayapy.exe createDynamicCache.py -nCloth -nParticle C:\test\test.ma
如果你有多个文件,你可以进行批量cache
C:\Program Files\Autodesk\Maya2009\bin\mayapy.exe createDynamicCache.py -nCloth C:\test\nClothtest01.ma C:\test\nClothtest02.ma C:\test\nClothtest03.ma C:\test\nClothtest04.ma
[color=red]最后要注意的是,我不知道是bug还是什么,在cache Fluid时你会失败,你得到的错误信息类似是“'fluidShape1' 不是可cache的节点类型”,pymel和mrv的版本我没试过出现这种情况,但如果你cache的场景版本比你现在使用的maya版本还低的话就能正常进行cache,我还不知道是什么原因。[/color]
使用教学
[url]http://u.115.com/file/f474056d82#[/url]
createDynamicCache.mp4
使用这段代码你可以在玛雅中直接执行
# 执行前记得先保存场景
# save your scene before run this script
import subprocess
import maya.cmds as mc
# 你可以更改为"-nParticle"、"-Fluid"
# change to "-nParticle"、"-Fluid" if you need
cacheArg = "-nCloth"
sceneFile = mc.file( q=1, sn=1 )
# 更改createDynamicCache.pyc的路径
# change the path to the createDynamicCache.pyc
cmd = r"mayapy.exe C:\Users\Mack\Desktop\createDynamicCache\2009\createDynamicCache.pyc %s %s" %(cacheArg, sceneFile)
if sceneFile:
# 更改你的maya安装路径
# change the path if you need
subprocess.Popen(cmd, shell=0, cwd=r"C:\Program Files\Autodesk\Maya2009\bin")
脚本下载(script download)
[url]http://u.115.com/file/f47772c0c3#[/url]
createDynamicCache.zip
如果你对这个工具有好的建议,希望你能告诉我(可以通过email),虽然我未必有时间去改进,源代码暂时不提供(虽然没什么新奇的代码,就让我保留少少的神秘吧)
ps.同时这个脚本也是献给那些和我一样没日没夜的加班的同志,虽然并不能解决你们的加班问题,希望能帮上你的忙。