Пример #1
0
        public static AvatarSkeletonInfo ParseXml(XmlNode root)
        {
            if (root.NodeType != XmlNodeType.Element)
            {
                throw new Exception("Invalid root node.");
            }

            XmlElement rootElement = (XmlElement)root;

            AvatarSkeletonInfo avatarSkeletonInfo = new AvatarSkeletonInfo();

            avatarSkeletonInfo.NumBones = ParseInt(rootElement.GetAttribute("num_bones"), "Couldn't find number of bones.", "Couldn't parse number of bones");
            int.TryParse(rootElement.GetAttribute("num_collision_volumes"), out var i);
            avatarSkeletonInfo.NumCollisionVolumes = i;

            foreach (XmlNode childNode in rootElement.ChildNodes)
            {
                if (childNode.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                AvatarBoneInfo boneInfo = AvatarBoneInfo.ParseXml(childNode);
                avatarSkeletonInfo.BoneInfoList.Add(boneInfo);
            }

            return(avatarSkeletonInfo);
        }
Пример #2
0
        public static AvatarBoneInfo ParseXml(XmlNode root)
        {
            if (root.NodeType != XmlNodeType.Element)
            {
                throw new Exception($"Invalid root node. ({root.NodeType})");
            }

            AvatarBoneInfo info = new AvatarBoneInfo();

            XmlElement rootElement = (XmlElement)root;

            switch (root.Name)
            {
            case "bone":
                info.IsJoint = true;
                info.Name    = rootElement.GetAttribute("name");
                if (string.IsNullOrEmpty(info.Name))
                {
                    throw new Exception("Bone without name.");
                }

                info.Aliases = rootElement.GetAttribute("aliases");     //Aliases are not required.
                break;

            case "collision_volume":
                info.IsJoint = false;
                info.Name    = rootElement.GetAttribute("name");
                if (string.IsNullOrEmpty(info.Name))
                {
                    info.Name = "Collision Volume";
                }
                break;

            default:
                throw new Exception($"Invalid root node. ({root.Name})");
            }

            info.Pos   = ParseVector3(rootElement.GetAttribute("pos"), "Bone without position. ({info.Name})", "Couldn't parse position. ({info.Name})");
            info.Rot   = ParseVector3(rootElement.GetAttribute("rot"), "Bone without rotation. ({info.Name})", "Couldn't parse rotation. ({info.Name})");
            info.Scale = ParseVector3(rootElement.GetAttribute("scale"), "Bone without scale. ({info.Name})", "Couldn't parse scale. ({info.Name})");

            info.End = ParseVector3(rootElement.GetAttribute("end"), "Bone without end. ({info.Name})", "Couldn't parse end. ({info.Name})", true);

            info.Support = rootElement.GetAttribute("support");
            if (string.IsNullOrEmpty(info.Support))
            {
                Logger.LogWarning("AvatarBoneInfo.ParseXml", $"Bone without support. ({info.Name})");
            }

            if (info.IsJoint)
            {
                info.Pivot = ParseVector3(rootElement.GetAttribute("pivot"), "Bone without pivot. ({info.Name})", "Couldn't parse pivot. ({info.Name})");
            }

            // Parse children:
            foreach (XmlNode childNode in rootElement.ChildNodes)
            {
                AvatarBoneInfo childInfo = AvatarBoneInfo.ParseXml(childNode);
                info.Children.Add(childInfo);
            }

            return(info);
        }