简体   繁体   English

使用Python执行GameFbxExporter Maya

[英]Execute GameFbxExporter Maya with Python

I need to export thousand of files with the GameFbXExporter Plugin from Maya, and I was wondering if there was any way to script those exports, knowing that the parameters are fine in every files. 我需要使用Maya的GameFbXExporter插件导出数千个文件,并且我想知道是否有任何方法可以编写这些导出脚本,因为知道每个文件中的参数都很好。 All I need to do is fill the path section and the name of the exported file in FBX, then launching the export itself with the plugin. 我需要做的就是在FBX中填写路径部分和导出文件的名称,然后使用插件启动导出本身。

I'm kind of lost and doesn't know how to do this. 我有点迷茫,不知道该怎么做。 Could someone help me understand how to reach that please? 有人可以帮我理解如何实现吗?

Thank you 谢谢

The game exporter is written in MEL, so you can interact with it from Python using the maya.mel module. 游戏导出器是用MEL编写的,因此您可以使用maya.mel模块从Python与它进行交互。 This will open the dialog, for example: 这将打开对话框,例如:

import maya.mel as mel
mel.eval("gameFbxExporter();")

Unfortunately a quick look at the actual game exporter scripts (which are in your maya install directory in the scripts/others directory -- they all start with the prefix "gameFBX") make it look like the UI is hopelessly entangled with the actual act of exporting; 不幸的是,快速浏览一下实际的游戏导出器脚本(位于scripts/others目录中的maya安装目录中-它们都以前缀“ gameFBX”开头)使UI看起来像是无可救药地纠缠了出口; it doesn't seem to expose anything which actually just exports the current file in a batch friendly way. 它似乎没有公开实际上只是以批处理友好的方式导出当前文件的任何内容。

The operative procedure is called gameExp_FBXExport , defined in "gameFbxExporter.mel." 该操作过程称为gameExp_FBXExport ,在“ gameFbxExporter.mel”中定义。 It appears like the actual business of exporting is actually delegated to the regular FBX plugin -- all the other stuff in the game exporter is just managing fbx presets, selecting parts of the scene to export (if you have the scenes set that way) and then calling the fbx plugin. 看起来实际的出口业务实际上是委派给常规的FBX插件-游戏导出器中的所有其他内容都只是在管理fbx预设,选择要导出的部分场景(如果您以这种方式设置了场景)和然后调用fbx插件。 So, you may be able to batch the process using Python by looping over your files and calling FBXExport() from Python. 因此,您可以通过遍历文件并从Python调用FBXExport()来使用Python批处理该过程。 This will export file to FBX: 这会将文件导出到FBX:

 import maya.cmds as cmds
 cmds.FBXExport('-file', 'path/to/file.fbx')

It will just use whatever FBX settings are currently active, so you will need to be confident that the files are correctly set up. 它只会使用当前处于活动状态的FBX设置,因此您需要确信文件设置正确。 You'll be tempted to write it as cmds.FBXExport(f='path/to/file') but that won't work -- the FBX plugin commands don't use regular python syntax. 您将很容易将其编写为cmds.FBXExport(f='path/to/file')但这不起作用cmds.FBXExport(f='path/to/file')插件命令不使用常规的python语法。

If your current settings rely on the export-selected functionality you'll need to figure out how to cache the correct selections -- if you're using the "export selections set" functionality you should be able to have your exporter find the set by name and the select it before exporting. 如果您当前的设置依赖于导出选择的功能,则需要弄清楚如何缓存正确的选择-如果您使用的是“导出选择集”功能,则应该可以让导出器通过以下方式找到设置名称,然后在导出之前选择它。

 cmds.select("name_of_selection_set")
 cmds.FBXExport('-file', 'path/to/file.fbx')

You can use the other FBX plugin commands -- documented here to inspect and manipulate the settings in your files as you go along. 您可以使用此处记录的其他FBX插件命令来检查和操作文件中的设置。

Most professional users don't use the GameExport pipeline precisely because it's very opaque and not batch friendly. 大多数专业用户不完全使用GameExport管道,因为它非常不透明并且不批处理。 In the long run you'll probably want to write a simple system that provides standard settings for different file types and exports the FBXes directly without the GameExporter - while it's a not-trivial project it's going to be easier to maintain and expand than hacking your way around the edges of Autodesk's version which is, frankly, pretty lame. 从长远来看,您可能需要编写一个简单的系统,为不同的文件类型提供标准设置,并在不使用GameExporter的情况下直接导出FBX。尽管这是一个不平凡的项目,但它的维护和扩展将比黑客攻击更容易。坦率地说,这很Auto脚,绕过Autodesk版本的边缘。

If you're not already familiar with it http://tech-artists.org/ is a great place to look for pipeline help and advice. 如果您还不熟悉它,那么http://tech-artists.org/是寻求管道帮助和建议的好地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM