Пример #1
0
        public void Save(TextureFormat texture, Stream outFormatData)
        {
            TIM2Texture tim2 = texture as TIM2Texture;

            if (tim2 == null)
            {
                throw new TextureFormatException("Not a valid TIM2Texture!");
            }

            BinaryWriter writer = new BinaryWriter(outFormatData);

            writer.Write("TIM2".ToCharArray());
            writer.Write((ushort)tim2.Version);
            writer.Write((ushort)tim2.TIM2SegmentsList.Count);

            for (int i = 0; i < 8; i++)
            {
                writer.Write((byte)0);
            }

            TIM2SegmentSerializer serializer = new TIM2SegmentSerializer(tim2.Swizzled);

            foreach (TIM2Segment segment in tim2.TIM2SegmentsList)
            {
                serializer.Save(segment, outFormatData);
            }
        }
Пример #2
0
        public void Export(TextureFormat texture, MetadataWriter metadata, string directory, string basename)
        {
            TIM2Texture tim2 = texture as TIM2Texture;

            if (tim2 == null)
            {
                throw new TextureFormatException("Not a valid TIM2Texture!");
            }

            metadata.BeginSection("TIM2");
            metadata.PutAttribute("Version", tim2.Version);
            metadata.PutAttribute("Basename", basename);
            metadata.PutAttribute("Swizzled", tim2.Swizzled);

            metadata.PutAttribute("Textures", tim2.TIM2SegmentsList.Count);
            int layer = 0;

            foreach (TIM2Segment segment in tim2.TIM2SegmentsList)
            {
                TextureFormatSerializer serializer = new TIM2SegmentSerializer();
                serializer.Export(segment, metadata, directory, basename + "_layer" + layer++);
            }

            metadata.EndSection();
        }
Пример #3
0
        public TextureFormat Import(MetadataReader metadata, string directory)
        {
            TIM2Texture tim2 = null;

            try
            {
                metadata.EnterSection("TIM2");

                int    version      = metadata.GetAttribute <int>("Version");
                string basename     = metadata.GetAttribute <string>("Basename");
                bool   swizzled     = metadata.GetAttribute <bool>("Swizzled");
                int    textureCount = metadata.GetAttribute <int>("Textures");

                List <TIM2Segment> imagesList = new List <TIM2Segment>();

                for (int i = 0; i < textureCount; i++)
                {
                    TIM2Segment segment = (TIM2Segment) new TIM2SegmentSerializer(swizzled).Import(metadata, directory);
                    imagesList.Add(segment);
                }

                metadata.ExitSection();
                tim2         = new TIM2Texture(imagesList);
                tim2.Version = version;
            }
            catch (FormatException e)
            {
                throw new TextureFormatException("Cannot parse value!\n" + e.Message, e);
            }
            catch (XmlException e)
            {
                throw new TextureFormatException("Not valid metadata!\n" + e.Message, e);
            }
            catch (TextureFormatException e)
            {
                throw new TextureFormatException(e.Message, e);
            }
            catch (Exception e)
            {
                throw new TextureFormatException("Error:\n" + e.Message, e);
            }

            return(tim2);
        }
Пример #4
0
        public TextureFormat Open(Stream formatData)
        {
            int version, textureCount;

            ReadHeader(formatData, out version, out textureCount);

            //construct images
            List <TIM2Segment> imagesList = new List <TIM2Segment>();

            for (int i = 0; i < textureCount; i++)
            {
                TextureFormatSerializer serializer = new TIM2SegmentSerializer();
                TIM2Segment             segment    = (TIM2Segment)serializer.Open(formatData);
                imagesList.Add(segment);
            }

            TIM2Texture tim = new TIM2Texture(imagesList);

            tim.Version = version;
            return(tim);
        }