Skip to content

Instantly share code, notes, and snippets.

@polytropoi
Created September 17, 2020 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polytropoi/91c1625826783a3ad283bccf6ffccf30 to your computer and use it in GitHub Desktop.
Save polytropoi/91c1625826783a3ad283bccf6ffccf30 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Siccity.GLTFUtility;
using Animancer;
public class GLTFAnimancerTest : MonoBehaviour
{
public AnimancerComponent animancer;
public GameObject result;
GameObject armature;
AnimationClip[] animClips;
Animator animator;
IEnumerator Start() {
WWW wwwGLTF = new WWW("http://example.com/example.glb"); //your url here
yield return new WaitUntil(()=> wwwGLTF.isDone);
byte[] gltfBytes = null;
gltfBytes = wwwGLTF.bytes;
result = Importer.LoadFromBytes(gltfBytes, new ImportSettings(), out animClips);
yield return new WaitUntil(()=> result != null);
for (int i = 0; i < animClips.Length; i++) {
Debug.Log("gots anim clips named " + animClips[i].name);
}
if (animClips.Length > 0) {
armature = result.transform.Find("armature").gameObject;
animator = armature.AddComponent<Animator>();
animancer = armature.AddComponent<AnimancerComponent>();
animancer.Animator = animator;
PlayAnimation();
}
}
void PlayAnimation() {
Debug.Log("tryna play");
var state = animancer.Play(animClips[0]);
state.Time = 0;
state.Events.OnEnd = OnAnimationEnd;
}
void OnAnimationEnd() {
PlayAnimation();
Debug.Log("animation ended");
}
}
@polytropoi
Copy link
Author

polytropoi commented Sep 17, 2020

loads model using https://github.com/Siccity/GLTFUtility with coroutines, but uses the animation control package Animancer -https://kybernetik.com.au/animancer/ -instead of Unity's legacy internal system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment