https://forum.unity.com/threads/how-to-import-user-defined-attributes-from-fbx-files.409877/
Created
March 14, 2021 16:47
-
-
Save unitycoder/06178c8dba730db057fce3c157ca19cd to your computer and use it in GitHub Desktop.
import user defined attributes from FBX files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEditor; | |
| using System.IO; | |
| class CustomImportProcessor : AssetPostprocessor { | |
| void OnPostprocessGameObjectWithUserProperties(GameObject go, string[] names, System.Object[] values) { | |
| ModelImporter importer = (ModelImporter)assetImporter; | |
| var asset_name = Path.GetFileName(importer.assetPath); | |
| Debug.LogFormat("OnPostprocessGameObjectWithUserProperties(go = {0}) asset = {1}", go.name, asset_name); | |
| string str = null; | |
| Vector3 vec3 = Vector3.zero; | |
| for (int i = 0; i < names.Length; i++) { | |
| var name = names[i]; | |
| var val = values[i]; | |
| switch (name) { | |
| case "StringData": | |
| str = (string)val; | |
| break; | |
| case "VectorData": | |
| vec3 = (Vector3)(Vector4)val; | |
| break; | |
| default: | |
| Debug.LogFormat("Unknown Property : {0} : {1} : {2}", name, val.GetType().Name, val.ToString()); | |
| break; | |
| } | |
| } | |
| if (str != null || vec3 != Vector3.zero) { | |
| var udh = go.AddComponent<UserDataHolder>(); | |
| if (str != null) { | |
| udh.StringData = str; | |
| } | |
| udh.VectorData = vec3; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| public class UserDataHolder : MonoBehaviour { | |
| public string StringData; | |
| public Vector3 VectorData; | |
| } |
Author
Author
- In Maya (or Max...), add your custom attribute (for us, using PascalCase/UpperCamelCase only)
- In Unity, check the box for "Animated Custom Properties" in the FBX import settings
- On the animator you're assigning this clip to in the scene hierarchy, add a parameter that exactly matches -- including case -- the original name given to the custom attribute in your modeling software
https://forum.unity.com/threads/new-fbx-exporter-in-2017-2.499889/page-7#post-3596232
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using dummy transform position for animated alpha value:
http://answers.unity.com/answers/653494/view.html