Beispiel #1
0
        public static void WriteJPSkeletonBoneAnimData(XmlWriter writer, JPSkeletalAnim anim)
        {
            foreach (var bone in anim.Bones)
            {
                writer.WriteStartElement("BoneAnim");
                writer.WriteAttributeString("Name", bone.Name);
                writer.WriteAttributeString("Hash", bone.Hash.ToString());
                writer.WriteAttributeString("RotType", bone.RotType.ToString());
                writer.WriteAttributeString("UseSegmentScaleCompensate", bone.UseSegmentScaleCompensate.ToString());

                // Animation tracks
                writer.WriteStartElement("AnimationTracks");
                WriteAnimTrack(writer, bone.XSCA);
                WriteAnimTrack(writer, bone.YSCA);
                WriteAnimTrack(writer, bone.ZSCA);

                WriteAnimTrack(writer, bone.XROT);
                WriteAnimTrack(writer, bone.YROT);
                WriteAnimTrack(writer, bone.ZROT);
                WriteAnimTrack(writer, bone.WROT);

                WriteAnimTrack(writer, bone.XPOS);
                WriteAnimTrack(writer, bone.YPOS);
                WriteAnimTrack(writer, bone.ZPOS);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
        }
Beispiel #2
0
        private static void WriteSkeletalAnimation(XmlWriter writer, SkeletalAnim anim)
        {
            JPSkeletalAnim jPSkeletalAnim = new JPSkeletalAnim();

            jPSkeletalAnim.LoadAnimData(anim);

            writer.WriteStartElement("Anim");

            writer.WriteAttributeString("Name", anim.Name);
            writer.WriteAttributeString("IsBaked", anim.Baked.ToString());
            writer.WriteAttributeString("IsLooping", anim.Loop.ToString());
            writer.WriteAttributeString("ScalingType", anim.FlagsScale.ToString());
            writer.WriteAttributeString("RotationType", anim.FlagsRotate.ToString());
            writer.WriteAttributeString("FrameCount", anim.FrameCount.ToString());
            writer.WriteAttributeString("BoneAnimationCount", anim.BoneAnims.Count.ToString());
            writer.WriteAttributeString("BakedSize", anim.BakedSize.ToString());
            writer.WriteAttributeString("UserDataCount", anim.UserData.Count.ToString());       // TODO Is this printing IK data??
            string bindIndices = "";

            for (int i = 0; i < anim.BindIndices.Length; i++)
            {
                short index = (short)anim.BindIndices[i];
                bindIndices += index.ToString() + ",";
            }
            bindIndices = bindIndices.Trim(',');
            writer.WriteAttributeString("BindIndices", bindIndices);

            writer.WriteStartElement("BoneAnims");

            // Check for non hermite curves
            for (int i = 0; i < anim.BoneAnims.Count; i++)
            {
                for (int j = 0; j < anim.BoneAnims[i].Curves.Count; j++)
                {
                    Program.AssertAndLog(Program.ErrorType.eNonHermiteAnimCurve, anim.BoneAnims[i].Curves[j].CurveType == AnimCurveType.Cubic, $"{anim.BoneAnims[i].Curves[j].CurveType} is a non hermite curve");
                }
            }

            WriteJPSkeletonBoneAnimData(writer, jPSkeletalAnim);

            writer.WriteEndElement();

            writer.WriteStartElement("UserDatas");
            for (int i = 0; i < anim.UserData.Count; i++)
            {
                writer.WriteStartElement("UserData");
                writer.WriteAttributeString("Name", anim.UserData[i].Name.ToString());
                writer.WriteAttributeString("Type", anim.UserData[i].Type.ToString());
                string values = "";
                switch (anim.UserData[i].Type)
                {
                case UserDataType.Int32:
                    foreach (int value in anim.UserData[i].GetValueInt32Array())
                    {
                        values += value.ToString() + ',';
                    }
                    values = values.Trim(',');
                    writer.WriteAttributeString("Values", values);
                    break;

                case UserDataType.Single:
                    foreach (float value in anim.UserData[i].GetValueSingleArray())
                    {
                        values += value.ToString() + ',';
                    }
                    values = values.Trim(',');
                    writer.WriteAttributeString("Values", values);
                    break;

                case UserDataType.String:
                    foreach (string value in anim.UserData[i].GetValueStringArray())
                    {
                        values += value.ToString() + ',';
                    }
                    values = values.Trim(',');
                    writer.WriteAttributeString("Values", values);
                    break;

                case UserDataType.WString:
                    foreach (string value in anim.UserData[i].GetValueStringArray())
                    {
                        values += value.ToString() + ',';
                    }
                    values = values.Trim(',');
                    writer.WriteAttributeString("Values", values);
                    break;

                case UserDataType.Byte:
                    foreach (byte value in anim.UserData[i].GetValueByteArray())
                    {
                        values += value.ToString() + ',';
                    }
                    values = values.Trim(',');
                    writer.WriteAttributeString("Values", values);
                    break;

                default:
                    break;
                }
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            // anim.BindSkeleton just know this exists

            writer.WriteEndElement();
        }