LoginSignup
12
2

More than 1 year has passed since last update.

Unity<=>Maya受け渡せるカスタムアトリビュートまとめ

Last updated at Posted at 2022-12-05

QualiArts Advent Calendar 2022 の6日目の記事になります。

はじめに

ゲーム開発においてDCCツールでアニメーションを作成し、ゲームエンジンに取り込むフローは一般的です。
さらにFBXファイルを使用してアニメーションを受け渡す場合、オブジェクトの移動/回転/拡縮のキーが打たれるのが基本的だと思います。

ただしプロジェクト次第では、特殊なアニメーションをカスタムアトリビュートとして受け渡す需要があります。
今回は、Unity<=>Maya間におけるカスタムアトリビュートについて記述します。

Maya

オブジェクトを選択し、修正 →アトリビュートの追加 から設定ウィンドウを読み出します。
アトリビュート名とデータ型を選択して追加します。

vector, int, string, float, boolean, enumの6つのデータ型を選択することができます。
通常のグラフエディタで確認することができます。

スクリプトから設定することで、"stringArray"など複雑なデータ型も指定することができますが、グラフエディタでは表示されません。
修正→アトリビュートの修正からアトリビュートの存在を確認することはできます。

cmds.addAttr('pCube1', ln='customStringArray', dt='stringArray')
cmds.setAttr('pCube1.customStringArray', 3, "a", "b", "c", type="stringArray")

Unity

FBXのImportオプションのAnimationm→AnimatedCustomPopertiesにチェックを付けることでカスタムアトリビュートを有効にできます。

さてAnimationClipを見てみましょう。

...Floatしか来てないですね、なぜでしょうか。。。

Fbxをインポートした際に呼ばれるAssetPostprocessorのOnPostprocessGameObjectWithUserPropertiesと、
OnPostprocessGameObjectWithAnimatedUserPropertiesを確認してみます。

CustomPropertyMotionImporter.cs

using UnityEngine;
using UnityEditor;

public class CustomPropertyMotionImporter : AssetPostprocessor
{
    void OnPostprocessGameObjectWithUserProperties(GameObject go, string[] propNames, System.Object[] values)
    {
        Debug.Log("=====UserProperties=====");
        foreach (var propName in propNames)
            Debug.Log(propName);
    }

    void OnPostprocessGameObjectWithAnimatedUserProperties(GameObject go, EditorCurveBinding[] bindings)
    {
        Debug.Log("=====AnimatedUserProperties=====");
        foreach (var b in bindings)
        {
            Debug.Log(b.propertyName);
        }
    }
}

こちらの結果が得られました。

=====UserProperties=====
currentUVSet
customVector
customInt
customString
customFloat
customBoolean
customEnum
=====AnimatedUserProperties=====
customFloat

つまり、アトリビュート名を取得できるか、カーブが取得できるかは別だということです。
更にStringArrayのような複雑なデータ型はアトリビュート名すら取得することができませんでした。

データ型 アトリビュート名 カーブ
Float
Vector ×
Int ×
String ×
Boolean ×
Enum ×
StringArray × ×

まとめ

Mayaでカスタムアトリビュートを設定する方法、Unityでカスタムアトリビュートを取得する方法と、データ型による違いを記述しました。
実用的なものはFloatのみであり少しさみしく感じましたが、アトリビュート名を工夫することで特殊な需要を満たせすことができるかもしれません。

Unity単体、Maya単体での記事はありますが、連携に関する記事はあまり見当たりません。
この記事がゲーム開発の一助になれば幸いです。

12
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
2