mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Preliminary Geometry List dumping
This commit is contained in:
parent
477e9ff3d5
commit
0187573999
@ -3,14 +3,91 @@
|
||||
#include "../framework/rwbinarystream.h"
|
||||
|
||||
using RW::BSSectionHeader;
|
||||
using RW::BSFrameList;
|
||||
using RW::BSFrameListFrame;
|
||||
using RW::BSClump;
|
||||
|
||||
using namespace RW;
|
||||
|
||||
template<class T> T readStructure(char* data, size_t& dataI)
|
||||
{
|
||||
size_t orgoff = dataI; dataI += sizeof(T);
|
||||
return *reinterpret_cast<T*>(data+orgoff);
|
||||
}
|
||||
|
||||
BSSectionHeader readHeader(char* data, size_t& dataI)
|
||||
{
|
||||
return readStructure<BSSectionHeader>(data, dataI);
|
||||
}
|
||||
|
||||
void dumpModelFile(char* data, size_t& dataI)
|
||||
{
|
||||
auto header = readHeader(data, dataI);
|
||||
|
||||
std::cout << "ID = " << std::hex << (unsigned long)header.id << " (IsClump = " << (header.id == RW::SID_Clump) << ")" << std::endl;
|
||||
std::cout << "Size = " << std::dec << (unsigned long)header.size << " bytes" << std::endl;
|
||||
std::cout << "Version ID = " << std::hex << (unsigned long)header.versionid << std::endl;
|
||||
|
||||
readHeader(data, dataI);
|
||||
|
||||
auto clump = readStructure<BSClump>(data, dataI);
|
||||
std::cout << " Clump Data" << std::endl;
|
||||
std::cout << " Atomics = " << std::dec << (unsigned long)clump.numatomics << std::endl;
|
||||
|
||||
auto frameheader = readHeader(data, dataI);
|
||||
std::cout << "ID = " << std::hex << (unsigned long)frameheader.id << " (IsFrameList = " << (frameheader.id == RW::SID_FrameList) << ")" << std::endl;
|
||||
|
||||
readHeader(data, dataI);
|
||||
|
||||
BSFrameList frames = readStructure<BSFrameList>(data, dataI);
|
||||
std::cout << " Frame List Data" << std::endl;
|
||||
std::cout << " Frames = " << std::dec << (unsigned long)frames.numframes << std::endl;
|
||||
|
||||
for(size_t i = 0; i < frames.numframes; ++i)
|
||||
{
|
||||
BSFrameListFrame frame = readStructure<BSFrameListFrame>(data, dataI);
|
||||
std::cout << " Frame Data" << std::endl;
|
||||
std::cout << " Index = " << std::dec << (unsigned long)frame.index << std::endl;
|
||||
std::cout << " Position = " << frame.postiion.x << " " << frame.postiion.y << " " << frame.postiion.z << std::endl;
|
||||
std::cout << " Rotation = " << std::endl;
|
||||
std::cout << " " << frame.rotation.a.x << " " << frame.rotation.a.y << " " << frame.rotation.a.z << std::endl;
|
||||
std::cout << " " << frame.rotation.b.x << " " << frame.rotation.b.y << " " << frame.rotation.b.z << std::endl;
|
||||
std::cout << " " << frame.rotation.c.x << " " << frame.rotation.c.y << " " << frame.rotation.c.z << std::endl;
|
||||
}
|
||||
|
||||
// Skip over the Frame extentions we can't parse.
|
||||
auto nextHeader = readHeader(data, dataI);
|
||||
while(nextHeader.id == RW::SID_Extension)
|
||||
{
|
||||
dataI += nextHeader.size;
|
||||
nextHeader = readHeader(data, dataI);
|
||||
}
|
||||
|
||||
readHeader(data, dataI); // Structure Header..
|
||||
|
||||
auto geomlist = readStructure<BSGeometryList>(data, dataI);
|
||||
std::cout << " Geometry List Data" << std::endl;
|
||||
std::cout << std::hex << dataI << std::endl;
|
||||
std::cout << " Geometries = " << std::dec << geomlist.numgeometry << std::endl;
|
||||
for(size_t i = 0; i < geomlist.numgeometry; ++i)
|
||||
{
|
||||
auto geomHeader = readHeader(data, dataI);
|
||||
size_t basedata = dataI;
|
||||
readHeader(data, dataI);
|
||||
auto geom = readStructure<BSGeometry>(data, dataI);
|
||||
std::cout << " Geometry Data" << std::endl;
|
||||
std::cout << " Flags = " << std::hex << static_cast<unsigned long>(geom.flags) << std::endl;
|
||||
std::cout << " UV Sets = " << std::dec << static_cast<unsigned long>(geom.numuvs) << std::endl;
|
||||
std::cout << " Flags = " << std::hex << static_cast<unsigned long>(geom.geomflags) << std::endl;
|
||||
std::cout << " Triangles = " << std::dec << static_cast<unsigned long>(geom.numtris) << std::endl;
|
||||
std::cout << " Verticies = " << static_cast<unsigned long>(geom.numverts) << std::endl;
|
||||
std::cout << " Frames = " << static_cast<unsigned long>(geom.numframes) << std::endl;
|
||||
|
||||
// Jump to the start of the next geometry
|
||||
dataI = basedata + geomHeader.size;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
for(int i = 1; i < argc; ++i)
|
||||
@ -28,20 +105,7 @@ int main(int argc, char** argv)
|
||||
dfile.read(data, length);
|
||||
size_t dataI = 0;
|
||||
|
||||
BSSectionHeader first = readStructure<BSSectionHeader>(data, dataI);
|
||||
|
||||
std::cout << "ID = " << std::hex << (unsigned long)first.id << " (IsClump = " << (first.id == RW::SID_Clump) << ")" << std::endl;
|
||||
std::cout << "Size = " << std::dec << (unsigned long)first.size << " bytes" << std::endl;
|
||||
std::cout << "Version ID = " << std::hex << (unsigned long)first.versionid << std::endl;
|
||||
|
||||
if(first.id == RW::SID_Clump)
|
||||
{
|
||||
BSClump clump = readStructure<BSClump>(data, dataI);
|
||||
std::cout << " Clump Data" << std::endl;
|
||||
std::cout << " Atomics = " << std::dec << (unsigned long)clump.numatomics << std::endl;
|
||||
std::cout << " Lights = " << std::dec << (unsigned long)clump.numlights << std::endl;
|
||||
std::cout << " Cameras = " << std::dec << (unsigned long)clump.numcameras << std::endl;
|
||||
}
|
||||
dumpModelFile(data, dataI);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
@ -15,9 +15,31 @@ namespace RW
|
||||
SID_String = 0x0002,
|
||||
SID_Extension = 0x0003,
|
||||
|
||||
SID_Texture = 0x0006,
|
||||
SID_Material = 0x0007,
|
||||
SID_MaterialList = 0x0008,
|
||||
|
||||
SID_FrameList = 0x000E,
|
||||
SID_Geometry = 0x000F,
|
||||
SID_Clump = 0x0010
|
||||
};
|
||||
|
||||
/**
|
||||
* Vector data
|
||||
*/
|
||||
struct BSTVector3
|
||||
{
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
/**
|
||||
* Rotation Matrix
|
||||
*/
|
||||
struct BSTMatrix
|
||||
{
|
||||
BSTVector3 a, b, c;
|
||||
};
|
||||
|
||||
struct BSSectionHeader
|
||||
{
|
||||
uint32_t id;
|
||||
@ -25,11 +47,47 @@ namespace RW
|
||||
uint32_t versionid;
|
||||
};
|
||||
|
||||
struct BSExtension
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct BSFrameList
|
||||
{
|
||||
uint32_t numframes;
|
||||
};
|
||||
|
||||
struct BSFrameListFrame //??????
|
||||
{
|
||||
BSTMatrix rotation;
|
||||
BSTVector3 postiion;
|
||||
uint32_t index;
|
||||
uint32_t matrixflags; // UNUSED BY ANYTHING.
|
||||
};
|
||||
|
||||
struct BSClump
|
||||
{
|
||||
uint32_t numatomics;
|
||||
uint32_t numlights;
|
||||
uint32_t numcameras;
|
||||
};
|
||||
|
||||
struct BSStruct
|
||||
{
|
||||
uint32_t id; // = 0x0001
|
||||
};
|
||||
|
||||
struct BSGeometryList
|
||||
{
|
||||
uint32_t numgeometry;
|
||||
};
|
||||
|
||||
struct BSGeometry
|
||||
{
|
||||
uint16_t flags;
|
||||
uint8_t numuvs;
|
||||
uint8_t geomflags;
|
||||
uint32_t numtris;
|
||||
uint32_t numverts;
|
||||
uint32_t numframes;
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user