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);
}
}