public void FbxsdkLoadAnimations(string fileName, AnimationClipCreateInfo[] clips)
        {
            var filePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FbxsdkFilePath), fileName);

            var scene = FBXScene.Load(filePath);
            if (scene == null) return;

            FbxsdkLoadAnimations(scene, clips);
        }
        public static SkinnedMesh CreateWithFbxsdk(Device device, string filePath, AnimationClipCreateInfo[] clips)
        {
            var scene = FBXScene.Load(filePath);
            if (scene == null) return null;

            var skinnedMesh = new SkinnedMesh(device);
            skinnedMesh.FbxsdkFilePath = filePath;

            var meshDict = new Dictionary<SkeletonNode, FBXMesh>();
            skinnedMesh.FbxsdkBuildHierachy(scene.GetRootNode(), null, meshDict);
            skinnedMesh.FbxsdkLoadSubmeshes(meshDict);
            skinnedMesh.FbxsdkLoadAnimations(scene, clips);

            skinnedMesh.skeleton.UpdateDebugDrawBone();
            skinnedMesh.CreateControls();

            return skinnedMesh;
        }
        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;
            }
        }
Example #4
0
 public void Add(string name, long start, long end)
 {
     var info = new AnimationClipCreateInfo(name, start, end);
     Items.Add(info);
 }