From 873421e9b2b699eb77f3a9b6d7ed88f3f29fb64d Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Sun, 30 Jun 2013 05:25:06 +0100 Subject: [PATCH] Material and Texture decoding --- datadump/main.cpp | 44 ++++++++++++++++++++++++++++++++++++++ framework/rwbinarystream.h | 22 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/datadump/main.cpp b/datadump/main.cpp index 3dcc6026..031540b6 100644 --- a/datadump/main.cpp +++ b/datadump/main.cpp @@ -146,6 +146,50 @@ void dumpModelFile(char* data, size_t& dataI) } } + auto materialListHeader = readHeader(data, dataI); + readHeader(data, dataI); // Ignore the structure header.. + + auto materialList = readStructure(data, dataI); + std::cout << " Material List Data" << std::endl; + std::cout << " Materials = " << materialList.nummaterials << std::endl; + + // Skip over the per-material byte values that I don't know what do. + dataI += sizeof(uint32_t) * materialList.nummaterials; + + for(size_t m = 0; m < materialList.nummaterials; ++m) + { + auto materialHeader = readHeader(data, dataI); + size_t secbase = dataI; + readHeader(data, dataI); + + auto material = readStructure(data, dataI); + std::cout << " Material Data" << std::endl; + std::cout << " Textures = " << std::dec << material.numtextures << std::endl; + std::cout << " Color = 0x" << std::hex << material.color << std::endl; + + for(size_t t = 0; t < material.numtextures; ++t) + { + auto textureHeader = readHeader(data, dataI); + size_t texsecbase = dataI; + readHeader(data, dataI); + + auto texture = readStructure(data, dataI); + + auto nameHeader = readHeader(data, dataI); + std::string textureName(data+dataI, nameHeader.size); + dataI += nameHeader.size; + auto alphaHeader = readHeader(data, dataI); + std::string alphaName(data+dataI, alphaHeader.size); + + std::cout << " Texture Data" << std::endl; + std::cout << " Name = " << textureName << std::endl; + std::cout << " Alpha = " << alphaName << std::endl; + + dataI = texsecbase + textureHeader.size; + } + + dataI = secbase + materialHeader.size; + } // Jump to the start of the next geometry dataI = basedata + geomHeader.size; diff --git a/framework/rwbinarystream.h b/framework/rwbinarystream.h index 13a54d39..3be8e6a9 100644 --- a/framework/rwbinarystream.h +++ b/framework/rwbinarystream.h @@ -137,6 +137,28 @@ namespace RW uint32_t positions; uint32_t normals; }; + + struct BSMaterialList + { + uint32_t nummaterials; + }; + + struct BSMaterial + { + uint32_t unknown; + BSColor color; + uint32_t alsounknown; + uint32_t numtextures; + float ambient; + float specular; + float diffuse; + }; + + struct BSTexture + { + uint16_t filterflags; + uint16_t unknown; + }; }; #endif \ No newline at end of file