// <Material name="character_anim:eyeBallM" meta_data="diffuse=%20upBodyC.jpg%20"/>
        /// <summary>
        ///
        /// </summary>
        /// <param name="xElement"></param>
        /// <returns></returns>
        public static EZMMaterial Parse(XElement xElement)
        {
            EZMMaterial result = null;

            if (xElement.Name == "Material")
            {
                result = new EZMMaterial();
                {
                    var name = xElement.Attribute("name");
                    if (name != null)
                    {
                        result.Name = name.Value;
                    }
                }
                {
                    var meta_data = xElement.Attribute("meta_data");
                    if (meta_data != null)
                    {
                        string   value = meta_data.Value;
                        string[] parts = value.Split(materialSeparator, StringSplitOptions.RemoveEmptyEntries);
                        if (parts.Length > 0)
                        {
                            result.MetaData = parts[0];
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        private static AiMaterial Parse(EZMMaterial ezmMaterial)
        {
            var aiMaterial = new AiMaterial();

            aiMaterial.Name     = ezmMaterial.Name;
            aiMaterial.MetaData = ezmMaterial.MetaData;
            aiMaterial.Tag      = ezmMaterial.Tag;

            return(aiMaterial);
        }
        // <MeshSystem asset_name="dude.fbx" asset_info="null" mesh_system_version="1" mesh_system_asset_version="0">
        /// <summary>
        ///
        /// </summary>
        /// <param name="xElement"></param>
        /// <returns></returns>
        public static EZMMeshSystem Parse(System.Xml.Linq.XElement xElement)
        {
            EZMMeshSystem result = null;

            if (xElement.Name == "MeshSystem")
            {
                result = new EZMMeshSystem();
                {
                    var attr = xElement.Attribute("asset_name");
                    if (attr != null)
                    {
                        result.AssetName = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("asset_info");
                    if (attr != null)
                    {
                        result.AssetInfo = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("mesh_system_version");
                    if (attr != null)
                    {
                        result.Version = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("mesh_system_asset_version");
                    if (attr != null)
                    {
                        result.AssetVersion = attr.Value;
                    }
                }
                {
                    var skeletionRoot = xElement.Element("Skeletons");
                    if (skeletionRoot != null)
                    {
                        var xSkeletons = skeletionRoot.Elements("Skeleton");
                        var skeletons  = new EZMSkeleton[xSkeletons.Count()];
                        int index      = 0;
                        foreach (var xSkeleton in xSkeletons)
                        {
                            skeletons[index++] = EZMSkeleton.Parse(xSkeleton);
                        }
                        result.Skeletons = skeletons;
                    }
                }
                {
                    var animationRoot = xElement.Element("Animations");
                    if (animationRoot != null)
                    {
                        var xAnimations = animationRoot.Elements("Animation");
                        var animations  = new EZMAnimation[xAnimations.Count()];
                        int index       = 0;
                        foreach (var xAnimation in xAnimations)
                        {
                            var animation = EZMAnimation.Parse(xAnimation);
                            foreach (var animTrack in animation.AnimTracks)
                            {
                                string name = animTrack.BoneName;
                                if (name != null)
                                {
                                    foreach (var skeleton in result.Skeletons)
                                    {
                                        EZMBone bone = null;
                                        if (skeleton.nameBoneDict.TryGetValue(name, out bone))
                                        {
                                            if (animTrack.Bone != null)
                                            {
                                                throw new Exception("More than 1 bone for the animTrack!");
                                            }

                                            animTrack.Bone = bone;
                                            //break;
                                        }
                                    }
                                }
                            }
                            animations[index++] = animation;
                        }
                        result.Animations = animations;
                    }
                }

                var nameMaterialDict = new Dictionary <string, EZMMaterial>();
                {
                    var materialsRoot = xElement.Element("Materials");
                    if (materialsRoot != null)
                    {
                        var xMaterials = materialsRoot.Elements("Material");
                        var materials  = new EZMMaterial[xMaterials.Count()];
                        int index      = 0;
                        foreach (var xMaterial in xMaterials)
                        {
                            var material = EZMMaterial.Parse(xMaterial);
                            nameMaterialDict.Add(material.Name, material);
                            materials[index++] = material;
                        }
                        result.Materials = materials;
                    }
                }
                {
                    var meshesRoot = xElement.Element("Meshes");
                    if (meshesRoot != null)
                    {
                        var xMeshes = meshesRoot.Elements("Mesh");
                        var meshes  = new EZMMesh[xMeshes.Count()];
                        int index   = 0;
                        foreach (var xMesh in xMeshes)
                        {
                            EZMMesh mesh = EZMMesh.Parse(xMesh);
                            foreach (var meshSection in mesh.MeshSections)
                            {
                                string      name     = meshSection.MaterialName;
                                EZMMaterial material = null;
                                if (nameMaterialDict.TryGetValue(name, out material))
                                {
                                    meshSection.Material = material;
                                }
                            }
                            EZMSkeleton[] skeletons = result.Skeletons;
                            if (skeletons.Length > 0)
                            {
                                if (string.IsNullOrEmpty(mesh.SkeletonName) ||
                                    mesh.SkeletonName == "null")
                                {
                                    mesh.Skeleton = skeletons[0];
                                }
                                else
                                {
                                    foreach (var skeleton in skeletons)
                                    {
                                        if (mesh.SkeletonName == skeleton.Name)
                                        {
                                            mesh.Skeleton = skeleton;
                                            break;
                                        }
                                    }
                                }
                            }
                            meshes[index++] = mesh;
                        }
                        result.Meshes = meshes;
                    }
                }
            }

            return(result);
        }