将 Maya ASCII 导入游戏

发布于 2024-07-27 13:55:17 字数 702 浏览 6 评论 0原文

我目前正在为我的独立游戏创建一个基于导入的管道,使用 Maya ASCII .ma 作为源格式,并使用我自己的物理和图形格式作为输出。 我将在 Maya 内部保留诸如运动范围属性之类的内容,例如铰链关节。 其他类型的需要大量调整的参数最终会出现在单独的源文件中(可能是 .ini,用于质量、弹簧常数、物理引擎的强度等)。

因此,输入是一个 .ma 和一个 .ini,输出是一个 .physical 和几个 .mesh 文件(每个几何体/材质一个 .mesh 文件)。

我也可能会使用 Python 3.1 重新格式化数据,并且我已经找到了一些可以读取基本 Maya ASCII 的 LGPL 2.1 代码。 我可能还会在开发过程中使用 Python 来启动该平台。 游戏是用C++开发的。

对于这一切,您有什么建议反对的吗? 对可能存在缺陷的事情的快速总结:

  • 基于导入的管道(不是基于导出的)?
  • 玛雅(不是 3DS)?
  • Maya ASCII .ma(不是 .mb)?
  • .ini(不是.xml)?
  • Maya 中的运动属性与 .ini 中的“freak-tweak”属性分离(并非全部在 Maya 中)?
  • Python 3.1 用于构建数据(不是嵌入式 C++)?

编辑:如果您对如何实现物理/图形导入/导出工具链有更好的建议,我将不胜感激。

I am currently working on creating an import-based pipeline for my indie game using Maya ASCII .ma as source format and my own format for physics and graphics as output. I'll keep stuff like range-of-motion attributes inside Maya, such as for a hinge joint. Other types of parameters that needs a lot of tweaks end up in separate source files (possibly .ini for stuff like mass, spring constants, strength of physical engines and the like).

The input is thus one .ma and one .ini, and the output is, among other things, one .physics and several .mesh files (one .mesh file per geometry/material).

I am also probably going to use Python 3.1 to reformat the data, and I already found some LGPL 2.1 code that reads basic Maya ASCII. I'll probably also use Python to launch the platform during development. Game is developed in C++.

Is there anything in all of this which you would advice against? A quick summary of things that might be flawed:

  • Import-based pipeline (not export-based)?
  • Maya (not 3DS)?
  • Maya ASCII .ma (not .mb)?
  • .ini (not .xml)?
  • Separation of motion attibutes in Maya and "freak-tweak" attributes in .ini (not all in Maya)?
  • Python 3.1 for building data (not embedded C++)?

Edit: if you have a better suggestion of how to implement the physics/graphics import/export tool chain, I'd appreciate the input.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁憨憨 2024-08-03 13:55:17

如果你真的想这样做,你应该注意一些事情。 主要的一点是,这可能比您最初预期的更麻烦。 其他一些是:

  • Maya .ma(至少直到当前的 v.2010)由 mel 构建。 Mel 是图灵完备的,但用节点描述分层场景的方式比“代码”要直接得多。
  • 尽早添加错误处理,否则稍后你会后悔的。
  • 您必须处理许多不同的节点,其中变换是迄今为止最令人讨厌的节点。 其他类型包括网格、材质(许多不同类型)、“着色器引擎”和文件(例如纹理)。
  • .ma 仅描述形状和调整; 但很少定义原始顶点。 我选择在 .ma 中保留一个小的“导出”脚本,以避免必须以与 Maya 完全相同的方式生成所有图元。 事后看来,这是正确的做法。 否则你必须能够做类似的事情
    1. “创建球体”,
    2. “以这样那样的半径将软选择从这里移动到那里”,以及
    3. “移动顶点 252 xyz 单位”(所有顶点均隐式定义)。
  • Maya 定义网格的多边形; 你可能想交流
    rt 到三角形。
  • 某种类型的节点上存在的所有参数都是显式或隐式定义的。 您必须知道它们的默认值(隐式定义时),
  • 基本上,对象是由变换、网格和基元定义的。 变换是网格的父级。 变换包含缩放、旋转、平移、枢轴平移等等。 网格链接到基元,反之亦然。 该基元具有类型(“polyCube”)和尺寸(“宽度、高度、深度”)。
  • 节点可能具有“多重继承”。 例如,多次实例化的网格具有单个网格(和单个基元),但有多个父级(变换)。
  • 节点变换的计算方式如下(请参阅 Maya xform 文档 了解更多信息):

vrt = getattr("rpt")
rt = mat4.translation(vrt)
...
m = t * rt * rpi * r * ar * rp * st * spi * sh * s * sp
  • 我围绕物理构建引擎,因此游戏引擎希望将网格放置在物理形状上,但在建模时我希望相反。 这是为了使其在未来的应用中保持通用(“没有物理的网格”)。 这个小小的决定给我带来了巨大的转变痛苦。 温习了线性代数。 缩放、旋转、平移和剪切问题; 你能想到的,我都吃过。
  • 我在 cgkit 的 Maya 解析器上构建了导入工具。 谢谢马蒂亚斯·巴斯!
  • 如果您打算做类似的事情,我强烈建议您先查看我的转换器写你自己的。 这个“小”项目花了我痛苦的三个月才达到基本的工作状态。

If you really want to do this, you should be aware of a few things. The main one being that it's probably more of a hassle than you'd first expect. Some others are:

  • Maya .ma (at least until the current v.2010) is built up by mel. Mel is Turing-complete, but the way the hierarchical scene is described in terms of nodes is a lot more straight-forward than “code”.
  • Add error-handling early or you’ll be sorry later.
  • You have to handle a lot of different nodes, where the transforms are by far the most obnoxious ones. Other types include meshes, materials (many different types), “shader engines” and files (such as textures).
  • .ma only describes shapes and tweaks; but very rarely defines raw vertices. I chose to keep a small “export” script inside the .ma to avoid having to generate all primitives exactly the same way as Maya. In hindsight, this was the right way to go. Otherwise you have to be able to do stuff like
    1. “Create sphere”,
    2. “Move soft selection with radius this-and-that from here to there”, and
    3. “Move vertex 252 xyz units” (with all vertices implicitly defined).
  • Maya defines polygons for meshes; you might want to conve
    rt to triangles.
  • All parameters that exist on a certain type of node are either explicitly or implicitly defined. You have to know their default values (when implicitly defined),
  • Basically, an object is defined by a transform, a mesh and a primitive. The transform is parent of the mesh. The transform contains the scaling, rotation, translation, pivot translations, and yet some. The mesh links to a primitive and vice versa. The primitive has a type (“polyCube”) and dimensions (“width, height, depth”).
  • Nodes may have “multiple inheritance”. For instance, a mesh instanced several times has a single mesh (and a single primitive), but multiple parents (the transformations).
  • Node transforms are computed like so (see Maya xform doc for more info):

vrt = getattr("rpt")
rt = mat4.translation(vrt)
...
m = t * rt * rpi * r * ar * rp * st * spi * sh * s * sp
  • I build my engine around physics, so the game engine wants meshes placed on physical shapes, but when modeling I want it the other way around. This to keep it generic for future applications (“meshes without physics”). This tiny decision caused me serious grief in transformations. Linear algebra got a brush-up. Problems in scaling, rotation, translation and shearing; you name it, I've had it.
  • I built my import tool on cgkit’s Maya parser. Thanks Matthias Baas!
  • If you’re going to do something similar I strongly recommend you peeking at my converter before writing your own. This “small” project took me three agonizing months to get to a basic working condition.
初心 2024-08-03 13:55:17

作为人类可读和可写的通用序列化格式,具有出色的 Python 支持(而且,实际上支持任何语言),您可能需要考虑在 ini 文件或 XML 上使用 YAML 或 JSON。

如果您从不手动生成文件,那么 XML 在您的情况下是可以接受的。

JSON 和 YAML 的优点之一是类型:这两种格式都被解析为 Python 列表、字典、浮点数、整数……基本上:健全的 Python 类型。

另外,除非您确定您将使用的每个库都可以在 3.1 上运行,否则由于库可用性问题,您可能需要考虑暂时使用 2.x。

As a general serialization format that's both human readable and human writable, has excellent Python support (and, well, any language support really), you might want to consider using YAML or JSON over ini files or XML.

XML could be acceptable in your case if you never generate files by hand.

One of the advantages of JSON and YAML is typing: both formats are parsed down to Python lists, dictionaries, floats, ints... Basically: sane python types.

Also, unless you're sure that every library you'll ever use works on 3.1, you might want to consider sticking with 2.x for a bit due to library availability issues.

沙沙粒小 2024-08-03 13:55:17

您应该考虑使用基于导出的管道或标准化文件格式(例如 OBJ 或 COLLADA),而不是重新实现 .ma 解析器并复制解释它所需的所有 Maya 内部结构。

.ma/.mb 格式不适合由 Maya 本身以外的任何程序读取,因此 Autodesk 并未付出任何努力来使此过程变得简单。 要 100% 正确地解析它,您需要实现整个 MEL 脚本语言。

我见过的所有基于 Maya 的管道要么首先将内容导出为标准化文件格式,要么在 Maya 中运行 MEL 脚本以使用 MEL 节点接口转储内容。

请注意,Maya 可以在“无头”模式下运行,在该模式下,它会加载场景、执行 MEL 脚本并存在,而无需加载 GUI。 因此在自动化构建系统中使用它是没有问题的。

You should consider using an export-based pipeline or a standardized file format such as OBJ or COLLADA instead of re-implementing a .ma parser and replicating all the Maya internals necessary to interpret it.

The .ma/.mb format is not intended to be read by any program other than Maya itself, so Autodesk does not put any effort into making this an easy process. To parse it 100% correctly you would need to implement the whole MEL scripting language.

All of the Maya-based pipelines I've seen either first export content into a standardized file format, or run MEL scripts within Maya to dump content using the MEL node interfaces.

Note than Maya can be run in a "headless" mode where it loads a scene, executes a MEL script, and exists, without loading the GUI. Thus there is no problem using it within automated build systems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文