Пример #1
0
        public override void load(MediaLoader ml, FileSystem fs, string path)
        {
            MeshDef mesh = MeshFile.Load(fs, path);

            mesh.compile(ml);
            this.mesh = mesh.Compiled;
        }
Пример #2
0
        public static Actor Load(FileSystem fs, string p)
        {
            XmlElement xactor = Xml.Open(Xml.FromStream(fs.open(p)), "actor");
            XmlElement xmesh  = xactor["mesh"];

            List <AnimationInformation> animinfo = ParseAnimationInfo(xmesh);
            List <string> bonesToIgnore          = ParseIgnoreBone(xmesh);

            Dictionary <string, string> texmap    = ParseSetTexture(xmesh);
            Dictionary <string, string> overrides = ParseOverrides(xmesh);

            fs.setOverrides(overrides);

            string meshpath = Xml.GetAttributeString(xmesh, "file");
            float  scale    = Xml.GetAttribute <float>(xmesh, "scale", math1.ParseFloat, 1.0f);

            MeshDef   def;
            Animation animation;

            string ext = Path.GetExtension(meshpath);

            if (ext == ".txt")
            {
                SimpleEngine.load.MilkshapeAscii.Load(fs, meshpath, out def, out animation, 1);
            }
            else if (ext == ".ms3d")
            {
                SimpleEngine.load.MilkshapeBinary.Load(fs, meshpath, out def, out animation);
            }
            else if (animinfo.Count == 0)
            {
                animation = null;
                def       = MeshFile.Load(fs, meshpath);
            }
            else
            {
                throw new Exception("Unhandled format " + ext + " for " + meshpath);
            }

            foreach (string ignoreThisBone in bonesToIgnore)
            {
                for (int i = 0; i < def.bones.Count; ++i)
                {
                    if (ignoreThisBone == def.bones[i].name)
                    {
                        def.bones.RemoveAt(i);
                        animation.bones.RemoveAt(i);
                    }
                }
            }

            foreach (MeshDef.MaterialDef mat in def.Materials)
            {
                string matname = mat.name.ToLower();
                if (texmap.ContainsKey(matname))
                {
                    mat.texture = texmap[matname];
                    texmap.Remove(matname);
                }
            }

            if (texmap.Count != 0)
            {
                throw new Exception("Some materials was not mapped");
            }

            def.scale(scale);
            if (animation != null)
            {
                animation.scale(scale);
            }

            def.translateFiles(overrides);

            Actor actor = new Actor(def.mapBones());

            if (animation != null)
            {
                foreach (AnimationInformation ai in animinfo)
                {
                    Animation an = animation.subanim(ai);
                    actor.add(ai.name, an);
                }
            }

            fs.clearOverrides(overrides);
            return(actor);
        }