public void PlayAnimation(AnimationClip anim, float transitionTime) { Animation = anim; foreach (var node in skeletonNodeList) { var name = node.Name; AnimationNodeChannel channel; anim.Channels.TryGetValue(name, out channel); BlendNode newBlendNode = null; if (channel == null) { newBlendNode = new PoseBlendNode(node); } else { newBlendNode = new AnimationBlendNode(channel); } newBlendNode.FadingOut = BlendNodes[name]; newBlendNode.TotalTransitionTime = transitionTime; BlendNodes[name] = newBlendNode; } }
void FbxsdkLoadAnimations(FBXScene scene, AnimationClipCreateInfo[] clips) { const double FRAMES_PER_SECOND = 30; if (clips == null) return; List<FBXNode> fbxNodeList = new List<FBXNode>(); FbxsdkFindAllAnimatedNodes(scene, scene.GetRootNode(), fbxNodeList); if (fbxNodeList.Count == 0) { Debug.Log("Don't have animation data"); return; } foreach (var clipCreateInfo in clips) { var start = clipCreateInfo.Start; var frameCount = clipCreateInfo.End - start + 1; var clip = new AnimationClip(); clip.Name = clipCreateInfo.Name; clip.SecondsPerFrame = 1 / FRAMES_PER_SECOND; clip.Duration = frameCount / FRAMES_PER_SECOND; foreach (var fbxNode in fbxNodeList) { var channel = new AnimationNodeChannel(frameCount); channel.Clip = clip; for (int i = 0; i < frameCount; ++i) { channel.Frames[i] = FbxsdkConvertMatrix(fbxNode.EvaluateLocalTransform(start + i)); } clip.Channels[fbxNode.GetName()] = channel; } AnimationClips[clip.Name] = clip; } }