Example #1
0
        public void Export(STAnimation animation, STSkeleton skeleton, string filePath)
        {
            if (skeleton == null)
            {
                return;
            }

            using (StreamWriter file = new StreamWriter(filePath)) {
                file.WriteLine("animVersion " + header.animVersion + ";");
                file.WriteLine("mayaVersion " + header.mayaVersion + ";");
                file.WriteLine("timeUnit " + header.timeUnit + ";");
                file.WriteLine("linearUnit " + header.linearUnit + ";");
                file.WriteLine("angularUnit " + header.angularUnit + ";");
                file.WriteLine("startTime " + 1 + ";");
                file.WriteLine("endTime " + header.endTime + ";");

                foreach (var group in animation.AnimGroups)
                {
                    var bone = skeleton.SearchBone(group.Name);
                    if (bone == null)
                    {
                        continue;
                    }

                    file.WriteLine("");
                }
            }
        }
Example #2
0
        private void PlaySkeletalAnim(HSFMotionAnimation anim)
        {
            STSkeleton skeleton = Renderer.Scene.Models[0].Skeleton;

            foreach (var container in Runtime.ModelContainers)
            {
                var skel = container.SearchActiveSkeleton();
                if (skel != null)
                {
                    skeleton = skel;
                }
            }

            Console.WriteLine($"skeleton {skeleton != null}");

            if (skeleton == null)
            {
                return;
            }

            if (anim.Frame == 0)
            {
                skeleton.Reset();
            }

            bool Updated = false; // no need to update skeleton of animations that didn't change

            foreach (AnimationNode node in anim.AnimGroups)
            {
                var b = skeleton.SearchBone(node.Name);
                if (b == null)
                {
                    continue;
                }

                Updated = true;

                Vector3    position = b.Position;
                Vector3    scale    = b.Scale;
                Quaternion rotation = b.Rotation;

                if (node.TranslateX.HasKeys)
                {
                    position.X = node.TranslateX.GetFrameValue(anim.Frame) * HSF_Renderer.PreviewScale;
                }
                if (node.TranslateY.HasKeys)
                {
                    position.Y = node.TranslateY.GetFrameValue(anim.Frame) * HSF_Renderer.PreviewScale;
                }
                if (node.TranslateZ.HasKeys)
                {
                    position.Z = node.TranslateZ.GetFrameValue(anim.Frame) * HSF_Renderer.PreviewScale;
                }

                if (node.ScaleX.HasKeys)
                {
                    scale.X = node.ScaleX.GetFrameValue(anim.Frame);
                }
                if (node.ScaleY.HasKeys)
                {
                    scale.Y = node.ScaleY.GetFrameValue(anim.Frame);
                }
                if (node.ScaleZ.HasKeys)
                {
                    scale.Z = node.ScaleZ.GetFrameValue(anim.Frame);
                }

                if (node.RotationX.HasKeys || node.RotationY.HasKeys || node.RotationZ.HasKeys)
                {
                    float x = node.RotationX.HasKeys ? MathHelper.DegreesToRadians(node.RotationX.GetFrameValue(anim.Frame)) : b.EulerRotation.X;
                    float y = node.RotationY.HasKeys ? MathHelper.DegreesToRadians(node.RotationY.GetFrameValue(anim.Frame)) : b.EulerRotation.Y;
                    float z = node.RotationZ.HasKeys ? MathHelper.DegreesToRadians(node.RotationZ.GetFrameValue(anim.Frame)) : b.EulerRotation.Z;
                    rotation = STMath.FromEulerAngles(new Vector3(x, y, z));
                }

                b.AnimationController.Position = position;
                b.AnimationController.Scale    = scale;
                b.AnimationController.Rotation = rotation;
            }

            if (Updated)
            {
                skeleton.Update();
            }
        }