I’m dipping my toes into the 3d parts of unity. I was using blockbench (a model creator used mostly for minecraft) and made all the animations in a json file. how would you get these animations into and actual functional animation?
{ "format_version": "1.8.0", "animations": { "walk.animation": { "loop": true, "animation_length": 1.56, "bones": { "leg": { "rotation": { "0.0": [0, 0, 0], "0.5167": [0, -25, 0], "1.0167": [0, 35, 0], "1.5667": [0, 0, 0] } }, "mid": { "rotation": { "0.5167": [0, 0, 0], "1.2333": [0, 45, 0], "1.5667": [0, 0, 0] } }, "bot": { "rotation": { "0.5167": [0, 0, 0], "1.5667": [0, 0, 0] } }, "leg5": { "rotation": { "0.0833": [0, 0, 0], "0.6333": [0, -70, 0], "1.2333": [0, 25, 0], "1.5667": [0, 0, 0] } }, "mid5": { "rotation": { "0.7667": [0, 0, 0], "1.2333": [0, 35, 0], "1.5667": [0, 0, 0] } }, "bot5": { "rotation": { "0.7667": [0, 0, 0], "1.2333": [0, -25, 0], "1.5667": [0, 0, 0] } }, "leg6": { "rotation": { "0.0": [0, 0, 0], "0.5167": [0, 40, 0], "1.0": [0, -15, 0], "1.5667": [0, 0, 0] } }, "mid6": { "rotation": { "0.5167": [0, 0, 0], "1.0": [0, -20, 0], "1.5667": [0, 0, 0] } }, "bot6": { "rotation": { "0.5167": [0, 0, 0], "1.0": [0, 45, 0], "1.5667": [0, 0, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 0], "0.5167": [0, -60, 0], "1.0": [0, 20, 0], "1.5667": [0, 0, 0] } }, "mid4": { "rotation": { "0.5167": [0, 0, 0], "1.0": [0, 35, 0], "1.5667": [0, 0, 0] } }, "bot4": { "rotation": { "0.5167": [0, 0, 0], "1.0": [0, 20, 0], "1.5667": [0, 0, 0] } }, "leg7": { "rotation": { "0.0833": [0, 0, 0], "0.6833": [0, 40, 0], "1.3667": [0, -25, 0], "1.5667": [0, 0, 0] } }, "mid7": { "rotation": { "0.8": [0, 0, 0], "1.3667": [0, -20, 0], "1.5667": [0, 0, 0] } }, "bot7": { "rotation": { "0.8": [0, 0, 0], "1.3667": [0, 10, 0], "1.5667": [0, 0, 0] } }, "leg3": { "rotation": { "0.0833": [0, 0, 0], "0.6333": [0, -45, 0], "1.3667": [0, 60, 0], "1.5667": [0, 0, 0] } }, "mid3": { "rotation": { "0.7667": [0, 0, 0], "1.3667": [0, 35, 0], "1.5667": [0, 0, 0] } }, "bot3": { "rotation": { "0.7667": [0, 0, 0], "1.3667": [0, 20, 0], "1.5667": [0, 0, 0] } }, "leg8": { "rotation": { "0.0": [0, 0, 0], "0.5167": [0, 40, 0], "1.0": [0, -35, 0], "1.5667": [0, 0, 0] } }, "mid8": { "rotation": { "0.5167": [0, 0, 0], "1.0": [0, -20, 0], "1.5667": [0, 0, 0] } }, "bot8": { "rotation": { "0.5167": [0, 0, 0], "1.0": [0, -15, 0], "1.5667": [0, 0, 0] } }, "leg2": { "rotation": { "0.0833": [0, 0, 0], "0.6": [0, 45, 0], "1.3667": [0, -35, 0], "1.5667": [0, 0, 0] } }, "mid2": { "rotation": { "0.7667": [0, 0, 0], "1.3667": [0, -40, 0], "1.5667": [0, 0, 0] } }, "bot2": { "rotation": { "0.7667": [0, 0, 0], "1.3667": [0, -25, 0], "1.5667": [0, 0, 0] } }, "head": { "scale": { "0.0": [1, 1, 1], "0.6333": [1, 1.2, 1.1], "1.2833": [1, 1, 1] } } } }, "idle.animation": { "loop": true, "animation_length": 6.4, "bones": { "leg": { "rotation": { "0.0": [0, 0, 0], "0.2833": [-20, 0, 0], "0.5667": [0, 0, 0] } }, "leg5": { "rotation": { "1.3167": [0, 0, 0], "1.6": [-15, 0, 0], "1.8833": [0, 0, 0] } }, "leg6": { "rotation": { "1.7167": [0, 0, 0], "2.0": [-20, 0, 0], "2.2833": [0, 0, 0] } }, "leg4": { "rotation": { "0.8833": [0, 0, 0], "1.1667": [-15, 0, 0], "1.4333": [0, 0, 0] } }, "leg7": { "rotation": { "2.1167": [0, 0, 0], "2.4": [-25, 0, 0], "2.6833": [0, 0, 0] } }, "leg3": { "rotation": { "0.4333": [0, 0, 0], "0.7667": [-20, 0, 0], "1.0333": [0, 0, 0] } }, "leg8": { "rotation": { "2.5667": [0, 0, 0], "2.8333": [-15, 0, 0], "3.1167": [0, 0, 0] } }, "leg2": { "rotation": { "2.9667": [0, 0, 0], "3.2333": [-20, 0, 0], "3.5167": [0, 0, 0] } }, "head": { "scale": { "0.0": [1, 1, 1], "0.6333": [1, 1.2, 1.2], "1.2833": [1, 1, 1], "1.9167": [1, 1.2, 1.2], "2.5667": [1, 1, 1], "3.2": [1, 1.2, 1.2], "3.8333": [1, 1, 1], "4.4833": [1, 1.2, 1.2], "5.1167": [1, 1, 1], "5.7667": [1, 1.2, 1.2], "6.4": [1, 1, 1] } } } }, "attack.animation": { "animation_length": 2.6, "bones": { "player": { "rotation": { "0.7833": [0, 0, 0], "2.4": [0, 1800, 0] }, "position": { "0.0": [0, 0, 0], "0.7833": [0, 3, 0], "2.6": [0, 0, 0] }, "scale": { "0.0": [1, 1, 1], "0.3667": [1, 1.3, 1], "0.7667": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [0, 0, 0], "0.1167": [45, 15, 0], "0.7833": [-15, 10, 0], "2.4": [-15, 10, 0], "2.6": [0, 0, 0] } }, "leg5": { "rotation": { "0.0": [0, 0, 0], "0.1167": [40, 10, 10], "0.8": [-15, 35, 0], "2.4": [-15, 35, 0], "2.6": [0, 0, 0] } }, "leg6": { "rotation": { "0.0": [0, 0, 0], "0.1167": [40, -15, -15], "0.7833": [-20, -15, 0], "2.4": [-20, 10, 0], "2.6": [0, 0, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 0], "0.1167": [0, 0, -35], "0.7833": [0, 15, 15], "2.4": [0, 15, 15], "2.6": [0, 0, 0] } }, "leg7": { "rotation": { "0.0": [0, 0, 0], "0.1167": [0, 0, 30], "0.7833": [0, 20, -10], "2.4": [0, 20, -10], "2.6": [0, 0, 0] } }, "leg3": { "rotation": { "0.0": [0, 0, 0], "0.1167": [0, 15, -25], "0.7833": [0, 0, 15], "2.4": [0, 0, 15], "2.6": [0, 0, 0] } }, "leg8": { "rotation": { "0.0": [0, 0, 0], "0.1167": [0, 0, 15], "0.7833": [0, 20, -15], "2.4": [0, 20, -15], "2.6": [0, 0, 0] } }, "leg2": { "rotation": { "0.0": [0, 0, 0], "0.1167": [45, 15, 0], "0.7833": [0, 15, -25], "2.4": [0, 15, -25], "2.6": [0, 0, 0] } }, "head": { "scale": { "0.0": [1, 1, 1], "0.6333": [1, 1.2, 1.2], "1.2833": [1, 1, 1], "1.9167": [1, 1.2, 1.2], "2.5667": [1, 1, 1] } } } }, "jump.animation": { "animation_length": 1.56, "bones": { "player": { "position": { "0.0": [0, 0, 0], "0.7833": [0, 3, 0], "1.5667": [0, 0, 0] }, "scale": { "0.0": [1, 1, 1], "0.3667": [1, 1.2, 1], "0.7667": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [0, 0, 0], "0.2333": [50, 0, 0], "1.3667": [0, 0, 0] } }, "leg5": { "rotation": { "0.0": [0, 0, 0], "0.2333": [20, -10, -40], "1.3667": [0, 0, 0] } }, "leg6": { "rotation": { "0.0": [0, 0, 0], "0.2333": [17, 10, 40], "1.3667": [0, 0, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, -40], "1.3667": [0, 0, 0] } }, "leg7": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, 45], "1.3667": [0, 0, 0] } }, "leg3": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 10, -30], "1.3667": [0, 0, 0] } }, "leg8": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, 35], "1.3667": [0, 0, 0] } }, "mid8": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, -10], "1.3667": [0, 0, 0] } }, "leg2": { "rotation": { "0.0": [0, 0, 0], "0.2333": [40, 0, 0], "1.3667": [0, 0, 0] } } } }, "ink1.animation": { "animation_length": 1.56, "bones": { "player": { "position": { "0.0": [0, 0, 0], "0.7833": [0, 3, 0], "1.5667": [0, 0, 0] }, "scale": { "0.0": [1, 1, 1], "0.3667": [1, 1.2, 1], "0.7667": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [0, 0, 0], "0.2333": [50, 0, 0], "1.3667": [0, 0, 0] } }, "leg5": { "rotation": { "0.0": [0, 0, 0], "0.2333": [20, -10, -40], "1.3667": [0, 0, 0] } }, "leg6": { "rotation": { "0.0": [0, 0, 0], "0.2333": [17, 10, 40], "1.3667": [0, 0, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, -40], "1.3667": [0, 0, 0] } }, "leg7": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, 45], "1.3667": [0, 0, 0] } }, "leg3": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 10, -30], "1.3667": [0, 0, 0] } }, "leg8": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, 35], "1.3667": [0, 0, 0] } }, "mid8": { "rotation": { "0.0": [0, 0, 0], "0.2333": [0, 0, -10], "1.3667": [0, 0, 0] } }, "leg2": { "rotation": { "0.0": [0, 0, 0], "0.2333": [40, 0, 0], "1.3667": [0, 0, 0] } } } }, "hover.animation": { "loop": true, "animation_length": 0.88, "bones": { "player": { "scale": { "0.3167": [1, 1, 1], "0.6333": [1, 0.7, 1], "0.8833": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [55, 25, -25], "0.6333": [-70, 0, 0], "0.8833": [55, 25, -25] } }, "mid": { "rotation": { "0.0": [0, 0, 0], "0.6333": [155, 40, -50], "0.8833": [0, 0, 0] } }, "leg5": { "rotation": { "0.0": [25, -50, -45], "0.6333": [0, -35, 45], "0.8833": [25, -50, -45] } }, "mid5": { "rotation": { "0.0": [0, 0, 0], "0.6333": [65, 55, -25], "0.8833": [0, 0, 0] } }, "leg6": { "rotation": { "0.0": [25, 50, 45], "0.6333": [0, 35, -45], "0.8833": [25, 50, 45] } }, "mid6": { "rotation": { "0.0": [0, 0, 0], "0.6333": [65, -55, 25], "0.8833": [0, 0, 0] } }, "leg4": { "rotation": { "0.0": [-10, -25, -60], "0.6333": [-10, -25, 35], "0.8833": [-10, -25, -60] } }, "mid4": { "rotation": { "0.0": [0, 0, 0], "0.6333": [95, 25, -25], "0.8833": [0, 0, 0] } }, "leg7": { "rotation": { "0.0": [-10, 25, 60], "0.6333": [-10, 25, -35], "0.8833": [-10, 25, 60] } }, "mid7": { "rotation": { "0.0": [0, 0, 0], "0.6333": [95, -25, 25], "0.8833": [0, 0, 0] } }, "leg3": { "rotation": { "0.0": [0, 10, -65], "0.6333": [0, -15, 35], "0.8833": [0, 10, -65] } }, "mid3": { "rotation": { "0.0": [0, 0, 0], "0.6333": [5, 25, -75], "0.8833": [0, 0, 0] } }, "leg8": { "rotation": { "0.0": [0, -10, 65], "0.6333": [0, 15, -35], "0.8833": [0, -10, 65] } }, "mid8": { "rotation": { "0.0": [0, 0, 0], "0.6333": [5, -25, 75], "0.8833": [0, 0, 0] } }, "leg2": { "rotation": { "0.0": [80, 25, 25], "0.6333": [-70, 25, -25], "0.8833": [80, 25, 25] } }, "mid2": { "rotation": { "0.0": [0, 0, 0], "0.6333": [115, -40, 50], "0.8833": [0, 0, 0] } }, "head": { "scale": { "0.0": [1, 1, 1], "0.4333": [1, 1.2, 1.2], "0.8833": [1, 1, 1] } } } }, "forwardswim.animation": { "loop": true, "animation_length": 0.92, "bones": { "player": { "rotation": [60, 0, 0], "scale": { "0.0": [1, 1, 1], "0.2333": [1, 1.4, 1], "0.6833": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [15, 0, -25], "0.3167": [85, 0, -25], "0.9167": [15, 0, -25] } }, "mid": { "rotation": { "0.0": [165, 65, 20], "0.3167": [20, -25, 0], "0.9167": [165, 65, 20] } }, "leg5": { "rotation": { "0.0": [-20, 45, 5], "0.3167": [70, 45, 25], "0.9167": [-20, 45, 5] } }, "mid5": { "rotation": { "0.0": [160, 55, 0], "0.3167": [0, -20, 0], "0.9167": [160, 55, 0] } }, "leg6": { "rotation": { "0.0": [-20, -45, -5], "0.3167": [70, -45, -25], "0.9167": [-20, -40, 5] } }, "mid6": { "rotation": { "0.0": [155, -65, 0], "0.3167": [0, 10, 0], "0.9167": [155, -65, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 35], "0.3167": [-10, -15, -75], "0.9167": [0, 0, 35] } }, "mid4": { "rotation": { "0.0": [160, 60, -5], "0.3167": [0, 0, 0], "0.9167": [160, 60, -5] } }, "leg7": { "rotation": { "0.0": [0, 0, -25], "0.3167": [5, 20, 75], "0.9167": [0, 0, -25] } }, "mid7": { "rotation": { "0.0": [85, -70, 100], "0.3167": [0, 0, 0], "0.9167": [85, -70, 100] } }, "leg3": { "rotation": { "0.0": [0, 0, 45], "0.3167": [40, 0, -75], "0.9167": [0, 0, 45] } }, "mid3": { "rotation": { "0.0": [170, 85, -10], "0.3167": [-35, 20, 0], "0.9167": [170, 85, -10] } }, "leg8": { "rotation": { "0.0": [0, 0, -35], "0.3167": [0, 0, 75], "0.9167": [0, 0, -35] } }, "mid8": { "rotation": { "0.0": [155, -85, 25], "0.3167": [0, 0, 0], "0.9167": [155, -85, 25] } }, "leg2": { "rotation": { "0.0": [0, 0, -75], "0.3167": [90, 5, 45], "0.9167": [0, 0, -75] } }, "mid2": { "rotation": { "0.0": [85, -50, 130], "0.3167": [0, 0, 0], "0.9167": [85, -50, 130] } } } }, "ink2.animation": { "loop": true, "animation_length": 0.92, "bones": { "player": { "rotation": [60, 0, 0], "scale": { "0.0": [1, 1, 1], "0.2333": [1, 1.4, 1], "0.6833": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [15, 0, -25], "0.3167": [85, 0, -25], "0.9167": [15, 0, -25] } }, "mid": { "rotation": { "0.0": [165, 65, 20], "0.3167": [20, -25, 0], "0.9167": [165, 65, 20] } }, "leg5": { "rotation": { "0.0": [-20, 45, 5], "0.3167": [70, 45, 25], "0.9167": [-20, 45, 5] } }, "mid5": { "rotation": { "0.0": [160, 55, 0], "0.3167": [0, -20, 0], "0.9167": [160, 55, 0] } }, "leg6": { "rotation": { "0.0": [-20, -45, -5], "0.3167": [70, -45, -25], "0.9167": [-20, -40, 5] } }, "mid6": { "rotation": { "0.0": [155, -65, 0], "0.3167": [0, 10, 0], "0.9167": [155, -65, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 35], "0.3167": [-10, -15, -75], "0.9167": [0, 0, 35] } }, "mid4": { "rotation": { "0.0": [160, 60, -5], "0.3167": [0, 0, 0], "0.9167": [160, 60, -5] } }, "leg7": { "rotation": { "0.0": [0, 0, -25], "0.3167": [5, 20, 75], "0.9167": [0, 0, -25] } }, "mid7": { "rotation": { "0.0": [85, -70, 100], "0.3167": [0, 0, 0], "0.9167": [85, -70, 100] } }, "leg3": { "rotation": { "0.0": [0, 0, 45], "0.3167": [40, 0, -75], "0.9167": [0, 0, 45] } }, "mid3": { "rotation": { "0.0": [170, 85, -10], "0.3167": [-35, 20, 0], "0.9167": [170, 85, -10] } }, "leg8": { "rotation": { "0.0": [0, 0, -35], "0.3167": [0, 0, 75], "0.9167": [0, 0, -35] } }, "mid8": { "rotation": { "0.0": [155, -85, 25], "0.3167": [0, 0, 0], "0.9167": [155, -85, 25] } }, "leg2": { "rotation": { "0.0": [0, 0, -75], "0.3167": [90, 5, 45], "0.9167": [0, 0, -75] } }, "mid2": { "rotation": { "0.0": [85, -50, 130], "0.3167": [0, 0, 0], "0.9167": [85, -50, 130] } } } }, "backswim.animation": { "loop": true, "animation_length": 0.92, "bones": { "player": { "rotation": [-60, 0, 0], "scale": { "0.0": [1, 1, 1], "0.2333": [1, 1.4, 1], "0.6833": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [15, 0, -25], "0.3167": [85, 0, -25], "0.9167": [15, 0, -25] } }, "mid": { "rotation": { "0.0": [165, 65, 20], "0.3167": [20, -25, 0], "0.9167": [165, 65, 20] } }, "leg5": { "rotation": { "0.0": [-20, 45, 5], "0.3167": [70, 45, 25], "0.9167": [-20, 45, 5] } }, "mid5": { "rotation": { "0.0": [160, 55, 0], "0.3167": [0, -20, 0], "0.9167": [160, 55, 0] } }, "leg6": { "rotation": { "0.0": [-20, -45, -5], "0.3167": [70, -45, -25], "0.9167": [-20, -40, 5] } }, "mid6": { "rotation": { "0.0": [155, -65, 0], "0.3167": [0, 10, 0], "0.9167": [155, -65, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 35], "0.3167": [-10, -15, -75], "0.9167": [0, 0, 35] } }, "mid4": { "rotation": { "0.0": [160, 60, -5], "0.3167": [0, 0, 0], "0.9167": [160, 60, -5] } }, "leg7": { "rotation": { "0.0": [0, 0, -25], "0.3167": [5, 20, 75], "0.9167": [0, 0, -25] } }, "mid7": { "rotation": { "0.0": [85, -70, 100], "0.3167": [0, 0, 0], "0.9167": [85, -70, 100] } }, "leg3": { "rotation": { "0.0": [0, 0, 45], "0.3167": [40, 0, -75], "0.9167": [0, 0, 45] } }, "mid3": { "rotation": { "0.0": [170, 85, -10], "0.3167": [-35, 20, 0], "0.9167": [170, 85, -10] } }, "leg8": { "rotation": { "0.0": [0, 0, -35], "0.3167": [0, 0, 75], "0.9167": [0, 0, -35] } }, "mid8": { "rotation": { "0.0": [155, -85, 25], "0.3167": [0, 0, 0], "0.9167": [155, -85, 25] } }, "leg2": { "rotation": { "0.0": [0, 0, -75], "0.3167": [90, 5, 45], "0.9167": [0, 0, -75] } }, "mid2": { "rotation": { "0.0": [85, -50, 130], "0.3167": [0, 0, 0], "0.9167": [85, -50, 130] } } } }, "ink3.animation": { "loop": true, "animation_length": 0.92, "bones": { "player": { "rotation": [-60, 0, 0], "scale": { "0.0": [1, 1, 1], "0.2333": [1, 1.4, 1], "0.6833": [1, 1, 1] } }, "leg": { "rotation": { "0.0": [15, 0, -25], "0.3167": [85, 0, -25], "0.9167": [15, 0, -25] } }, "mid": { "rotation": { "0.0": [165, 65, 20], "0.3167": [20, -25, 0], "0.9167": [165, 65, 20] } }, "leg5": { "rotation": { "0.0": [-20, 45, 5], "0.3167": [70, 45, 25], "0.9167": [-20, 45, 5] } }, "mid5": { "rotation": { "0.0": [160, 55, 0], "0.3167": [0, -20, 0], "0.9167": [160, 55, 0] } }, "leg6": { "rotation": { "0.0": [-20, -45, -5], "0.3167": [70, -45, -25], "0.9167": [-20, -40, 5] } }, "mid6": { "rotation": { "0.0": [155, -65, 0], "0.3167": [0, 10, 0], "0.9167": [155, -65, 0] } }, "leg4": { "rotation": { "0.0": [0, 0, 35], "0.3167": [-10, -15, -75], "0.9167": [0, 0, 35] } }, "mid4": { "rotation": { "0.0": [160, 60, -5], "0.3167": [0, 0, 0], "0.9167": [160, 60, -5] } }, "leg7": { "rotation": { "0.0": [0, 0, -25], "0.3167": [5, 20, 75], "0.9167": [0, 0, -25] } }, "mid7": { "rotation": { "0.0": [85, -70, 100], "0.3167": [0, 0, 0], "0.9167": [85, -70, 100] } }, "leg3": { "rotation": { "0.0": [0, 0, 45], "0.3167": [40, 0, -75], "0.9167": [0, 0, 45] } }, "mid3": { "rotation": { "0.0": [170, 85, -10], "0.3167": [-35, 20, 0], "0.9167": [170, 85, -10] } }, "leg8": { "rotation": { "0.0": [0, 0, -35], "0.3167": [0, 0, 75], "0.9167": [0, 0, -35] } }, "mid8": { "rotation": { "0.0": [155, -85, 25], "0.3167": [0, 0, 0], "0.9167": [155, -85, 25] } }, "leg2": { "rotation": { "0.0": [0, 0, -75], "0.3167": [90, 5, 45], "0.9167": [0, 0, -75] } }, "mid2": { "rotation": { "0.0": [85, -50, 130], "0.3167": [0, 0, 0], "0.9167": [85, -50, 130] } } } } } }
Well, there are several things you have to solve. First of all the data you’ve posted only contains keyframes without any curve information. So all we can assume is some sort of linear interpolation between those keyframes.
So lets list all the steps you have to take care of:
- Your model has to have unique names for each bone so you can find it without ambiguity.
- You have to determine the relative path to each bone gameobject based on the root object. So the name alone is not enough. That means you have to find the actual bone object and then go up the hierarchy until you reach the root bone and construct a relative path for each bone. How this “path” should look like is explained here.
- Next for each animation in your file of course we want to create a seperate AnimationClip. For each “property” that should be changed in the animation we have to add an AnimationCurve to the clip with the SetCurve method as I mentioned.
- At least the example you have provided seems to only use two different properties (actually 6 since both are Vector3 values): rotation and scale. So for each of them you have to create an animationcurve with keyframes at the specified times. Note that the format seems to have some nasty variations. Specifically in the last animation “ink3.animation” the player bone has a rotation value without a timestamp. I would assume that means the value should be hold on that value during the whole animation.
Some additional notes:
You can not directly animation the localEulerAngles of a transform. You have to convert them to a Quaternion by using Quaternion.Euler(). That also means you would need 4 animation curves for one rotation value since a Quaternion has 4 elements. For the localScale you need 3 curves. Here’s a small snippet that should help you.
Just in case it wasn’t obvious: An animation object in your json object tree contains a sub object called bones. This subobject contains several subobjects for each bone that should be animated. Those bone objects can contain a “scale” and / or “rotation” subobject. Note that here comes the nasty part. The object under the rotation key can be another object or directly an array of values. If it’s an object the keys of that object give you the “animation time” for this keyframe. The value of each key will contain an array with the 3 euler angles or scale values. To read such a dynamic json structure I would recommend my SimpleJSON parser along with the Unity extension file as you can easily deal with the different cases.
The rough setup to read in the necessary data would be something like this:
var root = JSON.Parse(yourJSONText);
foreach(var anim in root["animations"])
{
Debug.Log("Animation name: " + anim.Key);
float animationLength = anim.Value["animation_length"];
foreach(var bone in anim["bones"])
{
Debug.Log(" Bone name: " + bone.Key);
// Here you need access to the actual bone hierarchy to find the actual bone transform
// based on bone.Key and determine the relative path to this bone.
foreach(var property in bone.Value)
{
// property.Key could be "rotation" or "scale", at least based on this example file
Debug.Log("animated property: " + property.Key);
if (property.Value.IsArray)
{
Debug.Log("Single value for property: " + (Vector3)property.Value);
}
else
{
foreach(var frame in property.Value)
{
// key frame for this property at time "frame.Key".
float keyFrameTime = float.Parse(frame.Key);
Vector3 val = (Vector3)frame.Value;
}
}
}
}
}
This should parse all relevant data from the file. Of course you have to create all the relevant Unity objects on the fly. Also when parsing the properties you have to check the property type and either use “localScale” and pass the Vector3 into the animation curve, or if the type is “rotation” you have to use “localRotation” and convert the Vector3 eulerangles into a Quaternion as shown above.
Note that using AnimationClip.SetCurve will create the animationclip “on the fly” which does also work at runtime. However if you want to create a loader for those animations inside the Unity editor, you might want to have a look at the AnimationUtility