FindNodes() публичный Метод

public FindNodes ( string nodeName, string attributeName = null, string attributeValue = null ) : List
nodeName string
attributeName string
attributeValue string
Результат List
Пример #1
0
 public void Write(PssgNode node)
 {
     node.attributes["height"].data = MiscUtil.Conversion.EndianBitConverter.Big.GetBytes(header.height);
     node.attributes["width"].data = MiscUtil.Conversion.EndianBitConverter.Big.GetBytes(header.width);
     if (node.attributes.ContainsKey("numberMipMapLevels") == true)
     {
         if ((int)header.mipMapCount - 1 >= 0)
         {
             node.attributes["numberMipMapLevels"].data = MiscUtil.Conversion.EndianBitConverter.Big.GetBytes(header.mipMapCount - 1);
         }
         else
         {
             node.attributes["numberMipMapLevels"].data = MiscUtil.Conversion.EndianBitConverter.Big.GetBytes(0);
         }
     }
     if (header.ddspf.rGBBitCount == 32)
     {
         node.attributes["texelFormat"].data = "ui8x4";
     }
     else if (header.ddspf.rGBBitCount == 8)
     {
         node.attributes["texelFormat"].data = "u8";
     }
     else
     {
         node.attributes["texelFormat"].data = Encoding.UTF8.GetString(BitConverter.GetBytes(header.ddspf.fourCC)).ToLower();
     }
     List<PssgNode> textureImageBlocks = node.FindNodes("TEXTUREIMAGEBLOCK");
     if (bdata2 != null && bdata2.Count > 0)
     {
         for (int i = 0; i < textureImageBlocks.Count; i++)
         {
             switch (textureImageBlocks[i].attributes["typename"].ToString())
             {
                 case "Raw":
                     if (bdata2.ContainsKey(0) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data = bdata2[0];
                         textureImageBlocks[i].attributes["size"].data = EndianBitConverter.Big.GetBytes(bdata2[0].Length);
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawNegativeX":
                     if (bdata2.ContainsKey(1) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data = bdata2[1];
                         textureImageBlocks[i].attributes["size"].data = EndianBitConverter.Big.GetBytes(bdata2[1].Length);
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawPositiveY":
                     if (bdata2.ContainsKey(2) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data = bdata2[2];
                         textureImageBlocks[i].attributes["size"].data = EndianBitConverter.Big.GetBytes(bdata2[2].Length);
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawNegativeY":
                     if (bdata2.ContainsKey(3) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data = bdata2[3];
                         textureImageBlocks[i].attributes["size"].data = EndianBitConverter.Big.GetBytes(bdata2[3].Length);
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawPositiveZ":
                     if (bdata2.ContainsKey(4) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data = bdata2[4];
                         textureImageBlocks[i].attributes["size"].data = EndianBitConverter.Big.GetBytes(bdata2[4].Length);
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
                 case "RawNegativeZ":
                     if (bdata2.ContainsKey(5) == true)
                     {
                         textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data = bdata2[5];
                         textureImageBlocks[i].attributes["size"].data = EndianBitConverter.Big.GetBytes(bdata2[5].Length);
                     }
                     else
                     {
                         throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
                     }
                     break;
             }
         }
     }
     else
     {
         if ((uint)node.attributes["imageBlockCount"].Value > 1)
         {
             throw new Exception("Loading cubemap failed because not all blocks were found. (Write)");
         }
         textureImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data = bdata;
         textureImageBlocks[0].attributes["size"].data = EndianBitConverter.Big.GetBytes(bdata.Length);
     }
 }
Пример #2
0
 public Dds(PssgNode node, bool cubePreview)
 {
     magic = 0x20534444;
     header.size = 124;
     header.flags |= DDS_HEADER.Flags.DDSD_CAPS | DDS_HEADER.Flags.DDSD_HEIGHT | DDS_HEADER.Flags.DDSD_WIDTH | DDS_HEADER.Flags.DDSD_PIXELFORMAT;
     header.height = (uint)(node.attributes["height"].Value);
     header.width = (uint)(node.attributes["width"].Value);
     switch ((string)node.attributes["texelFormat"].Value)
     {
         case "dxt1":
             header.flags |= DDS_HEADER.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = (uint)(Math.Max(1, (((uint)node.attributes["width"].Value) + 3) / 4) * 8);
             header.ddspf.flags |= DDS_PIXELFORMAT.Flags.DDPF_FOURCC;
             header.ddspf.fourCC = BitConverter.ToUInt32(Encoding.UTF8.GetBytes(((string)node.attributes["texelFormat"].Value).ToUpper()), 0);
             break;
         case "dxt2":
         case "dxt3":
         case "dxt4":
         case "dxt5":
             header.flags |= DDS_HEADER.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = (uint)(Math.Max(1, (((uint)node.attributes["width"].Value) + 3) / 4) * 16);
             header.ddspf.flags |= DDS_PIXELFORMAT.Flags.DDPF_FOURCC;
             header.ddspf.fourCC = BitConverter.ToUInt32(Encoding.UTF8.GetBytes(((string)node.attributes["texelFormat"].Value).ToUpper()), 0);
             break;
         case "ui8x4":
             header.flags |= DDS_HEADER.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = (uint)(Math.Max(1, (((uint)node.attributes["width"].Value) + 3) / 4) * 16); // is this right?
             header.ddspf.flags |= DDS_PIXELFORMAT.Flags.DDPF_ALPHAPIXELS | DDS_PIXELFORMAT.Flags.DDPF_RGB;
             header.ddspf.fourCC = 0;
             header.ddspf.rGBBitCount = 32;
             header.ddspf.rBitMask = 0xFF0000;
             header.ddspf.gBitMask = 0xFF00;
             header.ddspf.bBitMask = 0xFF;
             header.ddspf.aBitMask = 0xFF000000;
             break;
         case "u8":
             header.flags |= DDS_HEADER.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = (uint)(Math.Max(1, (((uint)node.attributes["width"].Value) + 3) / 4) * 16); // is this right?
             // Interchanging the commented values will both work, not sure which is better
             header.ddspf.flags |= DDS_PIXELFORMAT.Flags.DDPF_LUMINANCE;
             //header.ddspf.flags |= DDS_PIXELFORMAT.Flags.DDPF_ALPHA;
             header.ddspf.fourCC = 0;
             header.ddspf.rGBBitCount = 8;
             header.ddspf.rBitMask = 0xFF;
             //header.ddspf.aBitMask = 0xFF;
             break;
     }
     if (node.attributes.ContainsKey("automipmap") == true && node.attributes.ContainsKey("numberMipMapLevels") == true)
     {
         if ((uint)node.attributes["automipmap"].Value == 0 && (uint)node.attributes["numberMipMapLevels"].Value > 0)
         {
             header.flags |= DDS_HEADER.Flags.DDSD_MIPMAPCOUNT;
             header.mipMapCount = (uint)((uint)node.attributes["numberMipMapLevels"].Value + 1);
             header.caps |= DDS_HEADER.Caps.DDSCAPS_MIPMAP | DDS_HEADER.Caps.DDSCAPS_COMPLEX;
         }
     }
     header.reserved1 = new uint[11];
     header.ddspf.size = 32;
     header.caps |= DDS_HEADER.Caps.DDSCAPS_TEXTURE;
     List<PssgNode> textureImageBlocks = node.FindNodes("TEXTUREIMAGEBLOCK");
     if ((uint)node.attributes["imageBlockCount"].Value > 1)
     {
         bdata2 = new Dictionary<int, byte[]>();
         for (int i = 0; i < textureImageBlocks.Count; i++)
         {
             switch (textureImageBlocks[i].attributes["typename"].ToString())
             {
                 case "Raw":
                     header.caps2 |= DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEX;
                     bdata2.Add(0, textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data);
                     break;
                 case "RawNegativeX":
                     header.caps2 |= DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEX;
                     bdata2.Add(1, textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data);
                     break;
                 case "RawPositiveY":
                     header.caps2 |= DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEY;
                     bdata2.Add(2, textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data);
                     break;
                 case "RawNegativeY":
                     header.caps2 |= DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEY;
                     bdata2.Add(3, textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data);
                     break;
                 case "RawPositiveZ":
                     header.caps2 |= DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEZ;
                     bdata2.Add(4, textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data);
                     break;
                 case "RawNegativeZ":
                     header.caps2 |= DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEZ;
                     bdata2.Add(5, textureImageBlocks[i].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data);
                     break;
             }
         }
         if (cubePreview == true)
         {
             header.caps2 = 0;
         }
         else if (bdata2.Count == (uint)node.attributes["imageBlockCount"].Value)
         {
             header.caps2 |= DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP;
             header.flags = header.flags ^ DDS_HEADER.Flags.DDSD_LINEARSIZE;
             header.pitchOrLinearSize = 0;
             header.caps |= DDS_HEADER.Caps.DDSCAPS_COMPLEX;
         }
         else
         {
             throw new Exception("Loading cubemap failed because not all blocks were found. (Read)");
         }
     }
     else
     {
         bdata = textureImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].data;
     }
 }