Exemplo n.º 1
0
        private void LoadData(Texture texture)
        {
            foreach (var set in sorted.Values)
            {
                foreach (var list in set)
                {
                    foreach (Texture.Image image in list.Value)
                    {
                        if (!File.Exists(image.filename))
                        {
                            mgr.Error("Image file: " + image.filename + " does not exist");
                            continue;
                        }
                        List <ImageData> result = new List <ImageData>();
                        mgr.Message("Reading texture: " + image.filename);
                        string err = "";
                        if (image.level == 0)
                        {
                            err = mgr.imageMgr.Load(image.filename, image.format, result, texture.numMips);
                        }
                        else
                        {
                            err = mgr.imageMgr.Load(image.filename, image.format, result, 0);
                        }
                        if (err.Length > 0)
                        {
                            mgr.Error("Image error: " + err);
                        }

                        foreach (ImageData idata in result)
                        {
                            Texture.Image image2 = list.Value.FirstOrDefault((i) => i.type == image.type && i.level == idata.m_MipLevel);
                            if (image2 == image)
                            {
                                image.data   = idata;
                                image.format = idata.format;
                            }
                            else if (image2 == null)
                            {
                                image2          = new Texture.Image();
                                image2.filename = image.filename;
                                image2.level    = idata.m_MipLevel;
                                image2.type     = image.type;
                                image2.data     = idata;
                                image2.format   = idata.format;
                                texture.images.Add(image2);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void Process(string filename)
        {
            string  name = Path.GetFileNameWithoutExtension(filename);
            Texture text = mgr.GetData <Texture>(name, GetterType.Create);

            if (text == null)
            {
                return;
            }

            Texture.Image image = new Texture.Image();
            image.filename = filename;
            text.images.Add(image);
        }
Exemplo n.º 3
0
        protected override void Process(string tname)
        {
            string   name   = mgr.name + "." + tname;
            XElement xImage = parent.GetFromLib(null, tname, "image");

            if (xImage == null)
            {
                mgr.Error("cannot find image " + tname);
                return;
            }
            xImage = xImage.Element(parent.ns + "init_from");
            if (xImage == null)
            {
                mgr.Error("cannot find image init_from " + tname);
                return;
            }

            Texture text = mgr.GetData <Texture>(name, GetterType.Create);

            if (text == null)
            {
                return;
            }

            Texture.Image image = new Texture.Image();
            if (xImage.Value.StartsWith("file:///"))
            {
                image.filename = xImage.Value.Substring(8);
            }
            else
            {
                image.filename = xImage.Value;
            }
            image.filename = image.filename.Replace("%20", " ");
            text.images.Add(image);
        }
Exemplo n.º 4
0
        protected override void Process(XElement item)
        {
            string name = (string)item.Attribute("name");

            if (name == null)
            {
                name = mgr.name;
            }
            else
            {
                name = mgr.name + "." + name;
            }
            Texture text = mgr.GetData <Texture>(name, GetterType.Create);

            if (text == null)
            {
                return;
            }

            string min = (string)item.Attribute("min");
            string mag = (string)item.Attribute("mag");
            string mip = (string)item.Attribute("mip");
            string s   = (string)item.Attribute("s");
            string t   = (string)item.Attribute("t");

            if (min != null || mag != null || mip != null)
            {
                text.filter = 0;
                switch (min)
                {
                case "nearest": text.filter |= Texture.Filter.MIN_NEAREST; break;

                case "none": text.filter |= Texture.Filter.MIN_NONE; break;

                default: text.filter |= Texture.Filter.MIN_LINEAR; break;
                }
                switch (mag)
                {
                case "nearest": text.filter |= Texture.Filter.MAG_NEAREST; break;

                case "none": text.filter |= Texture.Filter.MAG_NONE; break;

                default: text.filter |= Texture.Filter.MAG_LINEAR; break;
                }
                switch (mip)
                {
                case "linear": text.filter |= Texture.Filter.MIP_LINEAR; break;

                case "none": text.filter |= Texture.Filter.MIP_NONE; break;

                default: text.filter |= Texture.Filter.MIP_NEAREST; break;
                }
            }
            switch (s)
            {
            case "clamp": text.s = Texture.Wrap.CLAMP; break;

            case "mirrored": text.s = Texture.Wrap.MIRRORED; break;

            case "mirroronce": text.s = Texture.Wrap.MIRROR_ONCE; break;

            case "border": text.s = Texture.Wrap.BORDER; break;

            case "repeat": text.s = Texture.Wrap.REPEAT; break;
            }
            switch (t)
            {
            case "clamp": text.t = Texture.Wrap.CLAMP; break;

            case "mirrored": text.t = Texture.Wrap.MIRRORED; break;

            case "mirroronce": text.t = Texture.Wrap.MIRROR_ONCE; break;

            case "border": text.t = Texture.Wrap.BORDER; break;

            case "repeat": text.t = Texture.Wrap.REPEAT; break;
            }
            if (item.Attribute("nummips") != null)
            {
                text.numMips = (int)item.Attribute("nummips");
            }

            if (text.images.Count > 0)
            {
                if (item.Attribute("type") != null)
                {
                    text.images[0].type = (string)item.Attribute("type");
                }
            }

            foreach (XElement child in item.Elements("format"))
            {
                text.formatChoices.Add(LoadFormat(child));
            }

            foreach (XElement xImage in item.Elements("image"))
            {
                Texture.Image image = new Texture.Image();
                image.filename = mgr.MakeAbsolute((string)xImage.Attribute("filename"), parent.filename);
                text.images.Add(image);

                if (xImage.Attribute("type") != null)
                {
                    image.type = (string)item.Attribute("type");
                }
                if (xImage.Attribute("level") != null)
                {
                    image.level = (int)item.Attribute("level");
                }
                image.format = LoadFormat(xImage.Element("format"));
            }
        }