JD2022-TU1/main/tools/framework/JD.Serialization/Animation/Animation.cs

248 lines
No EOL
6.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace JD.Serialization
{
public class PatchBank
{
public PatchBank(XmlNode node)
{
Name = node.Name;
Texture = new Path(node.SelectSingleNode("@value").Value);
}
public string Name { get; set; }
public Path Texture { get; set; }
}
public class Bone
{
public double AngleLocal { get; set; }
public Vec3d PosLocal { get; set; }
public double ScaleX { get; set; }
public double ScaleY { get; set; }
public double ZOrder { get; set; }
public string Name { get; set; }
public bool ParentCut { get; set; }
public string ParentUid { get; set; }
public string Uid { get; set; }
public Bone(XmlNode node)
{
PosLocal = new Vec3d();
Name = string.Empty;
ParentUid = string.Empty;
Uid = string.Empty;
Name = XMLHelper.getNodeValue("Name", node, Name);
ParentCut = XMLHelper.getNodeValue("ParentCut", node, ParentCut);
ParentUid = XMLHelper.getNodeValue("ParentUID", node, ParentUid);
Uid = XMLHelper.getNodeValue("UID", node, Uid);
AngleLocal = XMLHelper.getNodeValue("AngleLocal", node, AngleLocal);
PosLocal = XMLHelper.getNodeValue("PosLocal", node, PosLocal);
ScaleX = XMLHelper.getNodeValue("ScaleX", node, ScaleX);
ScaleY = XMLHelper.getNodeValue("ScaleY", node, ScaleY);
ZOrder = XMLHelper.getNodeValue("ZOrder", node, ZOrder);
}
}
public class PatchMapping
{
public string Texture { get; set; }
public string Patch { get; set; }
public PatchMapping(XmlNode node)
{
Texture = node.SelectSingleNode("Element[@index=\"1\"]").Attributes["value"].Value;
Patch = node.SelectSingleNode("Element[@index=\"2\"]").Attributes["value"].Value;
}
}
public class Frame
{
public Frame(XmlNode root)
{
Bones = new List<Bone>();
Events = new List<AnimMarkerEvent>();
PatchMappings = new List<PatchMapping>();
foreach (XmlNode node in root.SelectNodes("bones/*"))
{
Bones.Add(new Bone(node));
}
foreach (XmlNode node in root.SelectNodes("events/Element"))
{
uint type = XMLHelper.getNodeValue("Type", node, (uint)1);
switch (type)
{
case 1:
Events.Add(new AnimGameplayEvent(node));
break;
case 2:
Events.Add(new AnimAnimationEvent(node));
break;
case 3:
Events.Add(new AnimFXEvent(node));
break;
case 4:
Events.Add(new AnimPolylineEvent(node));
break;
}
}
foreach (XmlNode node in root.SelectNodes("fpl/Element"))
{
PatchMappings.Add(new PatchMapping(node));
}
}
public List<Bone> Bones { get; set; }
public List<AnimMarkerEvent> Events { get; set; }
public List<PatchMapping> PatchMappings { get; set; }
}
public class ANM
{
public ANM()
{
Frames = new List<Frame>();
PatchBanks = new List<PatchBank>();
}
public void Read(XmlDocument doc)
{
foreach (XmlNode node in doc.SelectNodes("root/PatchBankList/*"))
{
PatchBanks.Add(new PatchBank(node));
}
foreach (XmlNode node in doc.SelectNodes("root/PostureTab/Element"))
{
Frames.Add(new Frame(node));
}
}
public List<PatchBank> PatchBanks { get; set; }
public List<Frame> Frames { get; set; }
}
public class SubSkeleton
{
public class Selection
{
public Selection(XmlNode node)
{
BoneName = node.Name;
Selected = Convert.ToBoolean(node.Attributes["value"].Value);
}
public string BoneName { get; set; }
public bool Selected { get; set; }
}
public string Name { get; set; }
public List<Selection> SelectList { get; set; }
public SubSkeleton(XmlNode node)
{
Name = string.Empty;
SelectList = new List<Selection>();
Name = XMLHelper.getNodeValue("Name", node, Name);
foreach (XmlNode n in node.SelectNodes("SelectList/*"))
{
SelectList.Add(new Selection(n));
}
}
}
public class SkeletonFile
{
public List<Bone> BonesList { get; set; }
public uint MediaWidth { get; set; }
public string Name { get; set; }
public uint PolylineDate { get; set; }
public float Ratio { get; set; }
public List<SubSkeleton> SubSkeletons { get; set; }
public string Uid { get; set; }
public Vec3d ZoomOrigin { get; set; }
public Vec3d ZoomSize { get; set; }
public SkeletonFile()
{
BonesList = new List<Bone>();
Name = string.Empty;
SubSkeletons = new List<SubSkeleton>();
Uid = string.Empty;
ZoomOrigin = new Vec3d();
ZoomSize = new Vec3d();
}
public SkeletonFile(Path path)
: this()
{
Read(path);
}
public void Read(Path path)
{
XmlDocument doc = new XmlDocument();
doc.Load(path.getAbsolute());
Read(doc);
}
public void Read(XmlDocument doc)
{
foreach (XmlNode node in doc.SelectNodes("root/BonesListT/Element"))
{
BonesList.Add(new Bone(node));
}
foreach (XmlNode node in doc.SelectNodes("root/SubSqueleton/Element"))
{
SubSkeletons.Add(new SubSkeleton(node));
}
MediaWidth = XMLHelper.getNodeValue("MediaWidth", doc, MediaWidth);
Name = XMLHelper.getNodeValue("Name", doc, Name);
PolylineDate = XMLHelper.getNodeValue("PolylineDate", doc, PolylineDate);
Ratio = XMLHelper.getNodeValue("Ratio", doc, Ratio);
Uid = XMLHelper.getNodeValue("UID", doc, Uid);
ZoomOrigin = XMLHelper.getNodeValue("ZoomOrigin", doc, ZoomOrigin);
ZoomSize = XMLHelper.getNodeValue("ZoomSize", doc, ZoomSize);
}
public List<string> GetBoneNames()
{
return BonesList.Select(bone => bone.Name).ToList();
}
}
}