Exemplo n.º 1
0
            private void ExportTexture(xxTexture texture, xxParser parser)
            {
                string texName = EncodeName(texture.Name);

                // image
                XmlElement image = doc.CreateElement("image", uri);
                image.SetAttribute("id", texName + "-image");
                image.SetAttribute("name", texName);
                libraries[(int)LibraryIdx.Images].AppendChild(image);

                XmlElement imageInit = doc.CreateElement("init_from", uri);
                imageInit.InnerText = "file://" + texture.Name;
                image.AppendChild(imageInit);
            }
Exemplo n.º 2
0
        protected xxTexture ParseTexture()
        {
            xxTexture tex = new xxTexture();
            tex.Name = reader.ReadName();
            tex.Unknown1 = reader.ReadBytes(4);
            tex.Width = reader.ReadInt32();
            tex.Height = reader.ReadInt32();
            tex.Depth = reader.ReadInt32();
            tex.MipLevels = reader.ReadInt32();
            tex.Format = reader.ReadInt32();
            tex.ResourceType = reader.ReadInt32();
            tex.ImageFileFormat = reader.ReadInt32();
            tex.Checksum = reader.ReadByte();

            int imgDataLen = reader.ReadInt32();
            tex.ImageData = reader.ReadBytes(imgDataLen);
            return tex;
        }
Exemplo n.º 3
0
        public void MergeTexture(xxTexture tex)
        {
            var newTex = tex.Clone();

            bool found = false;
            for (int i = 0; i < Parser.TextureList.Count; i++)
            {
                var oldTex = Parser.TextureList[i];
                if (oldTex.Name == newTex.Name)
                {
                    Parser.TextureList.RemoveAt(i);
                    Parser.TextureList.Insert(i, newTex);
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Parser.TextureList.Add(newTex);
            }
        }
Exemplo n.º 4
0
        public static xxTexture CreateTexture(ImportedTexture texture)
        {
            var imgInfo = ImageInformation.FromMemory(texture.Data);

            xxTexture xxTex = new xxTexture();
            xxTex.Width = imgInfo.Width;
            xxTex.Height = imgInfo.Height;
            xxTex.Depth = imgInfo.Depth;
            xxTex.Format = (int)imgInfo.Format;
            xxTex.ImageFileFormat = (int)imgInfo.ImageFileFormat;
            xxTex.MipLevels = imgInfo.MipLevels;
            xxTex.Name = texture.Name;
            xxTex.ResourceType = (int)imgInfo.ResourceType;

            byte checksum = 0;
            for (int i = 0; i < texture.Data.Length; i += 32)
            {
                checksum += texture.Data[i];
            }
            xxTex.Checksum = checksum;

            if (imgInfo.ImageFileFormat == ImageFileFormat.Bmp)
            {
                xxTex.ImageData = (byte[])texture.Data.Clone();
                xxTex.ImageData[0] = 0;
                xxTex.ImageData[1] = 0;
            }
            else if(imgInfo.ImageFileFormat == ImageFileFormat.Tga)
            {
                byte[] tgaHeader = new byte[18];
                Array.Copy(texture.Data, tgaHeader, tgaHeader.Length);
                int imgdataLen = tgaHeader[16] / 8 * BitConverter.ToInt16(tgaHeader, 12) * BitConverter.ToInt16(tgaHeader, 14);
                if (imgdataLen > texture.Data.Length - (tgaHeader.Length + tgaHeader[0]))
                    imgdataLen = texture.Data.Length - (tgaHeader.Length + tgaHeader[0]);
                xxTex.ImageData = new byte[tgaHeader.Length + imgdataLen];
                Array.Copy(texture.Data, xxTex.ImageData, tgaHeader.Length);
                Array.Copy(texture.Data, tgaHeader.Length + tgaHeader[0], xxTex.ImageData, tgaHeader.Length, imgdataLen);
                xxTex.ImageData[0] = 0;
            }
            else
            {
                xxTex.ImageData = (byte[])texture.Data.Clone();
            }

            return xxTex;
        }