public void ModifyD3DTX(DDS_Master dds) //ISSUE HERE WITH DXT5 AND MIP MAPS WITH UPSCALED TEXTURES { mWidth = dds.header.dwWidth; //this is correct mHeight = dds.header.dwHeight; //this is correct mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC); //this is correct mDepth = dds.header.dwDepth; mNumMipLevels = dds.header.dwMipMapCount; List <byte[]> ddsData = dds.textureData; ddsData.Reverse(); mPixelData.Clear(); //this is correct mPixelData = ddsData; //this is correct StreamHeader newStreamHeader = new StreamHeader() { mRegionCount = (int)dds.header.dwMipMapCount, //this is correct mAuxDataCount = mStreamHeader.mAuxDataCount, //this is correct mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct }; mStreamHeader = newStreamHeader; //this is correct List <RegionStreamHeader> regionStreamHeader = new List <RegionStreamHeader>(); //this is correct uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight); bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header); for (int i = 0; i < mStreamHeader.mRegionCount; i++) { RegionStreamHeader region = new RegionStreamHeader() { mDataSize = (uint)mPixelData[i].Length, mFaceIndex = 0, //NOTE: for cubemap textures this will need to change mMipCount = 1, //NOTE: for cubemap textures this will need to change mMipIndex = (mStreamHeader.mRegionCount - 1) - i, mPitch = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[mStreamHeader.mRegionCount - i, 0], blockSizeDouble), //this is correct mSlicePitch = mPixelData[i].Length, //this is correct }; regionStreamHeader.Add(region); } regionStreamHeader.Reverse(); mRegionHeaders = regionStreamHeader.ToArray(); UpdateArrayCapacities(); PrintConsole(); }
public void ModifyD3DTX(DDS_Master dds) { mWidth = dds.header.dwWidth; mHeight = dds.header.dwHeight; mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC); mDepth = dds.header.dwDepth; mNumMipLevels = dds.header.dwMipMapCount; List <byte[]> ddsData = new List <byte[]>(dds.textureData); //this is correct ddsData.Reverse(); //this is correct mPixelData.Clear(); //this is correct mPixelData = ddsData; //this is correct StreamHeader newStreamHeader = new StreamHeader() { mRegionCount = (int)dds.header.dwMipMapCount, mAuxDataCount = mStreamHeader.mAuxDataCount, mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct }; mStreamHeader = newStreamHeader; RegionStreamHeader[] regionStreamHeader = new RegionStreamHeader[mStreamHeader.mRegionCount]; uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight); bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header); for (int i = 0; i < regionStreamHeader.Length; i++) { regionStreamHeader[i] = new RegionStreamHeader() { mDataSize = (uint)mPixelData[i].Length, mFaceIndex = 0, //NOTE: for cubemap textures this will need to change mMipCount = 1, //NOTE: for cubemap textures this will need to change mMipIndex = (regionStreamHeader.Length - 1) - i, //mMipIndex = (regionStreamHeader.Length - 1) - i, mPitch = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[regionStreamHeader.Length - i, 0], blockSizeDouble), //this is correct mSlicePitch = mPixelData[i].Length, //this is correct }; } mRegionHeaders = regionStreamHeader; UpdateArrayCapacities(); //PrintConsole(); }
/// <summary> /// Deserializes a D3DTX Object from a byte array. /// </summary> /// <param name="data"></param> /// <param name="bytePointerPosition"></param> public D3DTX_V7(BinaryReader reader, bool showConsole = false) { mVersion = reader.ReadInt32(); //mVersion [4 bytes] mSamplerState_BlockSize = reader.ReadInt32(); //mSamplerState Block Size [4 bytes] mSamplerState = new T3SamplerStateBlock() //mSamplerState [4 bytes] { mData = reader.ReadUInt32() }; mPlatform_BlockSize = reader.ReadInt32(); //mPlatform Block Size [4 bytes] mPlatform = EnumPlatformType.GetPlatformType(reader.ReadInt32()); //mPlatform [4 bytes] mName_BlockSize = reader.ReadInt32(); //mName Block Size [4 bytes] //mName block size (size + string len) mName = ByteFunctions.ReadString(reader); //mName [x bytes] mImportName_BlockSize = reader.ReadInt32(); //mImportName Block Size [4 bytes] //mImportName block size (size + string len) mImportName = ByteFunctions.ReadString(reader); //mImportName [x bytes] (this is always 0) mImportScale = reader.ReadSingle(); //mImportScale [4 bytes] mToolProps = new ToolProps() //mToolProps [1 byte] { mbHasProps = reader.ReadBoolean() }; mNumMipLevels = reader.ReadUInt32(); //mNumMipLevels [4 bytes] mWidth = reader.ReadUInt32(); //mWidth [4 bytes] mHeight = reader.ReadUInt32(); //mHeight [4 bytes] mSurfaceFormat = T3TextureBase_Functions.GetSurfaceFormat(reader.ReadInt32()); //mSurfaceFormat [4 bytes] mTextureLayout = T3TextureBase_Functions.GetTextureLayout(reader.ReadInt32()); //mTextureLayout [4 bytes] mSurfaceGamma = T3TextureBase_Functions.GetSurfaceGamma(reader.ReadInt32()); //mSurfaceGamma [4 bytes] mSurfaceMultisample = T3TextureBase_Functions.GetSurfaceMultisample(reader.ReadInt32()); //mSurfaceMultisample [4 bytes] mResourceUsage = T3TextureBase_Functions.GetResourceUsage(reader.ReadInt32()); //mResourceUsage [4 bytes] mType = T3Texture_Functions.GetTextureType(reader.ReadInt32()); //mType [4 bytes] mSwizzleSize = reader.ReadInt32(); //mSwizzleSize [4 bytes] mSwizzle = new RenderSwizzleParams() //mSwizzle [4 bytes] { mSwizzle1 = (char)reader.ReadByte(), mSwizzle2 = (char)reader.ReadByte(), mSwizzle3 = (char)reader.ReadByte(), mSwizzle4 = (char)reader.ReadByte() }; mNormalMapFormat = reader.ReadInt32(); //mNormalMapFormat [4 bytes] mHDRLightmapScale = reader.ReadSingle(); //mHDRLightmapScale [4 bytes] mToonGradientCutoff = reader.ReadSingle(); //mToonGradientCutoff [4 bytes] mAlphaMode = T3Texture_Functions.GetAlphaMode(reader.ReadInt32()); //mAlphaMode [4 bytes] mColorMode = T3Texture_Functions.GetColorMode(reader.ReadInt32()); //mColorMode [4 bytes] mUVOffset = new Vector2() //mUVOffset [8 bytes] { x = reader.ReadSingle(), //[4 bytes] y = reader.ReadSingle() //[4 bytes] }; mUVScale = new Vector2() //mUVScale [8 bytes] { x = reader.ReadSingle(), //[4 bytes] y = reader.ReadSingle() //[4 bytes] }; //--------------------------mArrayFrameNames-------------------------- mArrayFrameNames_ArrayCapacity = reader.ReadUInt32(); //mArrayFrameNames DCArray Capacity [4 bytes] mArrayFrameNames_ArrayLength = reader.ReadInt32(); //mArrayFrameNames DCArray Length [4 bytes] //ADD 1 BECAUSE COUNTING STARTS AT 0 mArrayFrameNames = new List <Symbol>(); for (int i = 0; i < mArrayFrameNames_ArrayLength; i++) { Symbol newSymbol = new Symbol() { mCrc64 = reader.ReadUInt64() }; mArrayFrameNames.Add(newSymbol); } //--------------------------mToonRegions-------------------------- mToonRegions_ArrayCapacity = reader.ReadUInt32(); //mToonRegions DCArray Capacity [4 bytes] mToonRegions_ArrayLength = reader.ReadInt32(); //mToonRegions DCArray Length [4 bytes] mToonRegions = new T3ToonGradientRegion[mToonRegions_ArrayLength]; for (int i = 0; i < mToonRegions_ArrayLength; i++) { mToonRegions[i] = new T3ToonGradientRegion() { mColor = new Color() { r = reader.ReadSingle(), //[4 bytes] g = reader.ReadSingle(), //[4 bytes] b = reader.ReadSingle(), //[4 bytes] a = reader.ReadSingle() //[4 bytes] }, mSize = reader.ReadSingle() //[4 bytes] }; } //--------------------------StreamHeader-------------------------- mStreamHeader = new StreamHeader() { mRegionCount = reader.ReadInt32(), //[4 bytes] mAuxDataCount = reader.ReadInt32(), //[4 bytes] mTotalDataSize = reader.ReadInt32() //[4 bytes] }; //--------------------------mRegionHeaders-------------------------- mRegionHeaders = new RegionStreamHeader[mStreamHeader.mRegionCount]; for (int i = 0; i < mStreamHeader.mRegionCount; i++) { mRegionHeaders[i] = new RegionStreamHeader() { mFaceIndex = reader.ReadInt32(), //[4 bytes] mMipIndex = reader.ReadInt32(), //[4 bytes] mMipCount = reader.ReadInt32(), //[4 bytes] mDataSize = reader.ReadUInt32(), //[4 bytes] mPitch = reader.ReadInt32(), //[4 bytes] mSlicePitch = reader.ReadInt32() //[4 bytes] }; } //-----------------------------------------D3DTX HEADER END----------------------------------------- //--------------------------STORING D3DTX IMAGE DATA-------------------------- mPixelData = new List <byte[]>(); for (int i = 0; i < mStreamHeader.mRegionCount; i++) { int dataSize = (int)mRegionHeaders[i].mDataSize; byte[] imageData = reader.ReadBytes(dataSize); mPixelData.Add(imageData); } if (showConsole) { PrintConsole(); } }
/// <summary> /// Deserializes a D3DTX Object from a byte array. /// </summary> /// <param name="data"></param> /// <param name="bytePointerPosition"></param> public D3DTX_V5(BinaryReader reader, bool showConsole = false) { mVersion = reader.ReadInt32(); //mVersion [4 bytes] mSamplerState_BlockSize = reader.ReadInt32(); //mSamplerState Block Size [4 bytes] mSamplerState = new T3SamplerStateBlock() //mSamplerState [4 bytes] { mData = reader.ReadUInt32() }; mPlatform_BlockSize = reader.ReadInt32(); //mPlatform Block Size [4 bytes] mPlatform = EnumPlatformType.GetPlatformType(reader.ReadInt32()); //mPlatform [4 bytes] mName_BlockSize = reader.ReadInt32(); //mName Block Size [4 bytes] //mName block size (size + string len) mName = ByteFunctions.ReadString(reader); //mName [x bytes] mImportName_BlockSize = reader.ReadInt32(); //mImportName Block Size [4 bytes] //mImportName block size (size + string len) mImportName = ByteFunctions.ReadString(reader); //mImportName [x bytes] (this is always 0) mImportScale = reader.ReadSingle(); //mImportScale [4 bytes] Unknown0 = reader.ReadInt32(); //Unknown 0 [4 bytes] always zero (tool props byte structure size?) mToolProps = new ToolProps() //mToolProps [1 byte] { mbHasProps = reader.ReadBoolean() }; mNumMipLevels = reader.ReadUInt32(); //mNumMipLevels [4 bytes] mWidth = reader.ReadUInt32(); //mWidth [4 bytes] mHeight = reader.ReadUInt32(); //mHeight [4 bytes] mSurfaceFormat = T3TextureBase_Functions.GetSurfaceFormat(reader.ReadInt32()); //mSurfaceFormat [4 bytes] mResourceUsage = T3TextureBase_Functions.GetResourceUsage(reader.ReadInt32()); //mResourceUsage [4 bytes] Unknown1 = reader.ReadInt32(); //Unknown 1 [4 bytes] Unknown2 = reader.ReadInt32(); //Unknown 2 [4 bytes] Unknown3 = reader.ReadInt32(); //Unknown 3 [4 bytes] Unknown4 = reader.ReadInt32(); //Unknown 4 [4 bytes] mSpecularGlossExponent = reader.ReadSingle(); //mSpecularGlossExponent [4 bytes] mHDRLightmapScale = reader.ReadSingle(); //mHDRLightmapScale [4 bytes] mToonGradientCutoff = reader.ReadSingle(); //mToonGradientCutoff [4 bytes] mAlphaMode = T3Texture_Functions.GetAlphaMode(reader.ReadInt32()); //mAlphaMode [4 bytes] mColorMode = T3Texture_Functions.GetColorMode(reader.ReadInt32()); //mColorMode [4 bytes] mUVOffset = new Vector2() //mUVOffset [8 bytes] { x = reader.ReadSingle(), //[4 bytes] y = reader.ReadSingle() //[4 bytes] }; mUVScale = new Vector2() //mUVScale [8 bytes] { x = reader.ReadSingle(), //[4 bytes] y = reader.ReadSingle() //[4 bytes] }; //--------------------------mToonRegions-------------------------- mToonRegions_ArrayCapacity = reader.ReadUInt32(); //mToonRegions DCArray Capacity [4 bytes] mToonRegions_ArrayLength = reader.ReadInt32(); //mToonRegions DCArray Length [4 bytes] mToonRegions = new T3ToonGradientRegion[mToonRegions_ArrayLength]; for (int i = 0; i < mToonRegions_ArrayLength; i++) { mToonRegions[i] = new T3ToonGradientRegion() { mColor = new Color() { r = reader.ReadSingle(), //[4 bytes] g = reader.ReadSingle(), //[4 bytes] b = reader.ReadSingle(), //[4 bytes] a = reader.ReadSingle() //[4 bytes] }, mSize = reader.ReadSingle() //[4 bytes] }; } //--------------------------StreamHeader-------------------------- mStreamHeader = new StreamHeader() { mRegionCount = reader.ReadInt32(), //[4 bytes] mAuxDataCount = reader.ReadInt32(), //[4 bytes] mTotalDataSize = reader.ReadInt32() //[4 bytes] }; //--------------------------mRegionHeaders-------------------------- mRegionHeaders = new RegionStreamHeader[mStreamHeader.mRegionCount]; for (int i = 0; i < mStreamHeader.mRegionCount; i++) { mRegionHeaders[i] = new RegionStreamHeader() { mFaceIndex = reader.ReadInt32(), //[4 bytes] mMipIndex = reader.ReadInt32(), //[4 bytes] mMipCount = reader.ReadInt32(), //[4 bytes] mDataSize = reader.ReadUInt32(), //[4 bytes] mPitch = reader.ReadInt32(), //[4 bytes] }; } //-----------------------------------------D3DTX HEADER END----------------------------------------- //--------------------------STORING D3DTX IMAGE DATA-------------------------- mPixelData = new List <byte[]>(); for (int i = 0; i < mStreamHeader.mRegionCount; i++) { int dataSize = (int)mRegionHeaders[i].mDataSize; byte[] imageData = reader.ReadBytes(dataSize); mPixelData.Add(imageData); } if (showConsole) { PrintConsole(); } }