AnimJ converter
From Resonite Wiki
More actions
Created by Vertix, Published on discord here written in Python.
"a very simple unity -> animj converter that seems to work well" Won't map the blendshapes but it is sorted so the slots you get will be deterministic. it's very straightforward, this only handles animations of type linear however.
No support can be provided, however if anyone wants to make this work better they are welcome, along with updating documentation or code. Or even using it as the basis for a converter for the UnitySDK.
Code:
import json
import argparse
from unityparser import UnityDocument
parser = argparse.ArgumentParser("anim_to_animj", description="Convert Unity animations to Resonite AnimJ")
parser.add_argument("input", help="The input file to convert")
parser.add_argument("output", default="output.animj", help="The location of the output file")
args = parser.parse_args()
anim = UnityDocument.load_yaml(args.input, try_preserve_types=True)
clip = anim.get(class_name="AnimationClip")
def convert(clip):
tracks = []
for curve in clip.m_FloatCurves:
keyframes = []
for keyframe in curve["curve"]["m_Curve"]:
keyframes.append({
"time": keyframe["time"],
"value": keyframe["value"] / 100,
"interpolation": "Linear",
})
tracks.append({
"trackType": "Curve",
"valueType": "float",
"data": {
"node": curve["path"],
"property": curve["attribute"],
"keyframes": keyframes
}
})
tracks = sorted(tracks, key=lambda d: d["data"]["node"] + d["data"]["property"])
result = {
"name": clip.m_Name,
"tracks": tracks,
}
return result
converted = convert(clip)
with open(args.output, "w") as f:
json.dump(converted, f, indent=" ")
See also
- AnimJ
- <link to unity here>