Ejemplo n.º 1
0
        public ModelDefinition LoadArenaTownDefinition(string file)
        {
            string absolutePath = file;
            if (!Path.IsPathRooted(file))
            {
                absolutePath = Path.Combine(this.RootDirectory, file);
            }

            XDocument doc = XDocument.Load(absolutePath);
            XElement model = doc.Root;
            ModelDefinition obj = new ModelDefinition();
            this.LoadMapObjectModel(obj, model, file);
            string fileName = Path.GetFileName(file);
            obj.name = fileName.Substring(0, fileName.IndexOf("."));
            return obj;
        }
Ejemplo n.º 2
0
        public ModelDefinition LoadCreature(string file)
        {
            string absolutePath = file;
            if (!Path.IsPathRooted(file))
            {
                absolutePath = Path.Combine(this.RootDirectory, file);
            }

            XDocument doc = XDocument.Load(absolutePath);
            XElement root = doc.Element("Character");
            XElement model = root.Element("Model");
            XElement arenaAnimSet = root.Element("ArenaAnimSet");
            if (model != null && arenaAnimSet != null)
            {
                XAttribute modelHref = model.Attribute("href");
                XAttribute animSetHref = arenaAnimSet.Attribute("href");
                if (modelHref != null)
                {
                    FileLink modelLink = new FileLink(this.RootDirectory, file, modelHref.Value);
                    XElement modelElement = this.documentManager.GetLinkedElement(modelLink);
                    ModelDefinition def = new ModelDefinition();
                    this.LoadMapObjectModel(def, modelElement, modelLink.File);

                    if (animSetHref != null)
                    {
                        FileLink animLink = new FileLink(this.RootDirectory, file, animSetHref.Value);
                        XElement animSetElement = this.documentManager.GetLinkedElement(animLink);
                        this.LoadMapObjectAnimSet(def, animSetElement, animLink.File);
                    }
                    string fileName = Path.GetFileName(file);
                    def.name = fileName.Substring(0, fileName.IndexOf("."));
                    return def;
                }
            }
            return null;
        }
Ejemplo n.º 3
0
 void LoadTexture(ModelDefinition obj, string texturePath, XElement texture)
 {
     string loc = texture.Element("DestName").Attribute("href").Value;
     string path = Path.Combine(Path.GetDirectoryName(texturePath), loc);
     obj.Textures.Add(path);
 }
Ejemplo n.º 4
0
 void LoadSkeletalAnimation(ModelDefinition obj, XElement anim, string name)
 {
     string uid = anim.Element("uid").Value;
     obj.Animations[name] = uid;
 }
Ejemplo n.º 5
0
        void LoadModelDefinition(ModelDefinition model, XElement root, string path)
        {
            XElement mod = root.Element("Model");
            XAttribute modHref = mod.Attribute("href");
            if (modHref != null)
            {
                FileLink modelLink = new FileLink(this.RootDirectory, path, modHref.Value);
                this.LoadMapObjectModel(model, this.documentManager.GetLinkedElement(modelLink), modelLink.File);

                XElement animSet = root.Element("AnimSet");
                if (animSet != null)
                {
                    XAttribute animSetHref = animSet.Attribute("href");
                    if (animSetHref != null)
                    {
                        FileLink animSetLink = new FileLink(this.RootDirectory, path, animSetHref.Value);
                        this.LoadMapObjectAnimSet(model, this.documentManager.GetLinkedElement(animSetLink), animSetLink.File);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        void LoadMapObjectModel(ModelDefinition obj, XElement model, string path)
        {
            XElement materials = model.Element("Materials");
            foreach(XElement item in materials.Elements())
            {
                XAttribute itemHrefAttrib = item.Attribute("href");
                if (itemHrefAttrib != null)
                {
                    string m = itemHrefAttrib.Value;
                    XElement material;
                    string textureFile = path;
                    if (!m.Contains("inline"))
                    {
                        FileLink materialLink = new FileLink(this.RootDirectory, path, m);
                        material = this.documentManager.GetLinkedElement(materialLink);
                        textureFile = materialLink.File;
                    }
                    else
                    {
                        material = item.Element("Material");
                    }
                    XElement textureElement = material.Element("Texture");
                    XAttribute textureHrefAttribute = textureElement.Attribute("href");
                    if (textureHrefAttribute != null)
                    {
                        string textureHref = textureHrefAttribute.Value;
                        FileLink textureLink = new FileLink(this.RootDirectory, textureFile, textureHref);
                        XElement textureLinkedElement = this.documentManager.GetLinkedElement(textureLink);
                        if (textureLinkedElement != null)
                        {
                            this.LoadTexture(obj, textureLink.File, textureLinkedElement);
                        }
                    }
                }
            }
            XElement geom = model.Element("Geometry");
            XAttribute geomHrefAttrib = geom.Attribute("href");
            if (geomHrefAttrib == null) return;
            string geomHref = geomHrefAttrib.Value;
            XElement geomInner;
            if(geomHref.Contains("inline"))
            {
                geomInner = geom.Element("Geometry");
            }
            else
            {
                FileLink geomLink = new FileLink(this.RootDirectory, path, geomHref);
                geomInner = this.documentManager.GetLinkedElement(geomLink);
            }

            string guid = geomInner.Element("uid").Value;
            obj.geometryFile = guid;

            XElement skeleton = model.Element("Skeleton");
            XAttribute skelHrefAttr = skeleton.Attribute("href");
            if(skelHrefAttr != null)
            {
                string skelHref = skelHrefAttr.Value;
                XElement skelInner;
                if(skelHref.Contains("inline"))
                {
                    skelInner = skeleton.Element("Skeleton");
                }
                else
                {
                    FileLink skelLink = new FileLink(this.RootDirectory, path, skelHref);
                    skelInner = this.documentManager.GetLinkedElement(skelLink);
                }

                string suid = skelInner.Element("uid").Value;
                obj.skeletonFile = suid;
            }
        }
Ejemplo n.º 7
0
 void LoadMapObjectAnimSet(ModelDefinition obj, XElement animSet, string path)
 {
     foreach(XElement item in animSet.Element("animations").Elements())
     {
         string name = item.Element("Kind").Value;
         XElement anim = item.Element("Anim");
         if (anim != null)
         {
             XAttribute href = anim.Attribute("href");
             if (href != null)
             {
                 FileLink link = new FileLink(this.RootDirectory, path, href.Value);
                 this.LoadSkeletalAnimation(obj, this.documentManager.GetLinkedElement(link), name);
             }
         }
     }
 }
Ejemplo n.º 8
0
        static void ConvertCreature(ModelDefinition model, string targetDirectory)
        {
            string binFolder = Path.Combine(baseFolder, "bin");
            string modelsFolder = Path.Combine(binFolder, "Geometries");
            string skeletonFolder = Path.Combine(binFolder, "Skeletons");
            string animationsFolder = Path.Combine(binFolder, "animations");

            bool hasGeometry = model.geometryFile != null;

            if (!hasGeometry)
            {
                return;
            }
            bool hasSkeleton = model.skeletonFile != null;
            bool hasAnimations = hasSkeleton && model.Animations.Count(kvp => File.Exists(Path.Combine(animationsFolder, kvp.Value))) > 0;

            string creatureDirectory = Path.Combine(targetDirectory, model.name);
            string meshName = hasSkeleton && hasAnimations ? "geometry.skinnedmesh" : "geometry.staticmesh";
            string meshSMDName = meshName + ".smd";
            string meshSMDBinName = meshSMDName + ".bin";
            string meshFileName = Path.Combine(creatureDirectory, meshName);

            if (Directory.Exists(creatureDirectory))
            {
                foreach (string file in Directory.GetFiles(creatureDirectory, "*.*", SearchOption.AllDirectories))
                {
                    File.SetAttributes(file, FileAttributes.Normal);
                }
                Directory.Delete(creatureDirectory, true);
            }
            while (Directory.Exists(creatureDirectory))
            {
                System.Threading.Thread.Sleep(16);
            }
            Directory.CreateDirectory(creatureDirectory);

            File.Copy(Path.Combine(modelsFolder, model.geometryFile), Path.Combine(creatureDirectory, meshFileName));
            if (hasSkeleton)
            {
                File.Copy(Path.Combine(skeletonFolder, model.skeletonFile), Path.Combine(creatureDirectory, "skeleton.gr2"));
            }

            List<string> animations = new List<string>();
            if (hasAnimations)
            {
                foreach (KeyValuePair<string, string> animation in model.Animations)
                {
                    string targetFile = Path.Combine(creatureDirectory, animation.Key + ".gr2");
                    string source = Path.Combine(animationsFolder, animation.Value);
                    if (!File.Exists(source))
                    {
                        continue;
                    }
                    File.Copy(source, targetFile);

                    animations.Add(targetFile);
                }
            }

            List<string> textures = new List<string>();
            foreach (string texture in model.Textures)
            {
                string targetFile = Path.Combine(creatureDirectory, Path.GetFileName(texture));
                if (!File.Exists(targetFile))
                {
                    File.Copy(texture, targetFile);
                }
                textures.Add(targetFile);
            }
            ArchangelDriver driver = new ArchangelDriver();
            if (hasSkeleton)
            {
                driver.ConvertModelWithSkeleton(model.name, "Foo", creatureDirectory, meshName, "skeleton.gr2", textures);
            }
            else
            {
                driver.ConvertModel(model.name, "Foo", creatureDirectory, meshName, textures);
            }

            if (hasSkeleton && hasAnimations)
            {
                ConvertSkinnedSMDFile(Path.Combine(creatureDirectory, meshSMDName), Path.Combine(creatureDirectory, meshSMDBinName));
            }
            else
            {
                ConvertStaticSMDFile(Path.Combine(creatureDirectory, meshSMDName), Path.Combine(creatureDirectory, meshSMDBinName));
            }

            if (hasSkeleton)
            {
                ConvertGr2File(Path.Combine(creatureDirectory, "skeleton.gr2"), Path.Combine(creatureDirectory, "skeleton"), "skeleton");
            }

            if (hasAnimations)
            {
                string animationDirectory = Path.Combine(creatureDirectory, "animations");
                Directory.CreateDirectory(animationDirectory);

                foreach (string animation in animations)
                {
                    ConvertGr2File(animation, Path.Combine(animationDirectory, Path.GetFileNameWithoutExtension(animation)), "animation");
                }
            }
        }