1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Geometry dumping

This commit is contained in:
Daniel Evans 2013-06-30 03:46:22 +01:00
parent 0187573999
commit 5eca76e220
2 changed files with 116 additions and 4 deletions

View File

@ -55,11 +55,21 @@ void dumpModelFile(char* data, size_t& dataI)
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;
for(size_t i = 0; i < 2; ++i) {
auto firstHeader = readHeader(data, dataI);
if(firstHeader.id == RW::SID_NodeName)
{
std::cout << " Name = " << std::string(data+dataI, firstHeader.size) << std::endl;
}
else if(firstHeader.id == RW::SID_HAnimPLG)
{
std::cout << " Bone Information Present" << std::endl;
}
dataI += firstHeader.size;
}
nextHeader = readHeader(data, dataI);
}
@ -67,7 +77,6 @@ void dumpModelFile(char* data, size_t& dataI)
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)
{
@ -83,6 +92,61 @@ void dumpModelFile(char* data, size_t& dataI)
std::cout << " Verticies = " << static_cast<unsigned long>(geom.numverts) << std::endl;
std::cout << " Frames = " << static_cast<unsigned long>(geom.numframes) << std::endl;
if(geomHeader.versionid < 0x1003FFFF)
{
std::cout << " Some extra colour info" << std::endl;
auto colors = readStructure<BSGeometryColor>(data, dataI);
}
if(geom.flags & BSGeometry::VertexColors)
{
std::cout << " Vertex Colours Present" << std::endl;
for(size_t v = 0; v < geom.numverts; ++v)
{
std::cout << " " << v << ": " << static_cast<unsigned long>(readStructure<BSColor>(data, dataI)) << std::endl;
}
}
if(geom.flags & BSGeometry::TexCoords1 || geom.flags & BSGeometry::TexCoords2)
{
std::cout << " UV Coords Present" << std::endl;
for(size_t v = 0; v < geom.numverts; ++v)
{
auto coords = readStructure<BSGeometryUV>(data, dataI);
std::cout << " " << v << ": U" << coords.u << " V" << coords.v << std::endl;
}
}
for(int j = 0; j < geom.numtris; ++j)
{
auto tri = readStructure<BSGeometryTriangle>(data, dataI);
std::cout << " Triangle " << std::dec
<< static_cast<unsigned long>(tri.first) << " "
<< static_cast<unsigned long>(tri.second) << " "
<< static_cast<unsigned long>(tri.third) << " "
<< "A: " << static_cast<unsigned long>(tri.attrib) << std::endl;
}
auto bounds = readStructure<BSGeometryBounds>(data,dataI);
std::cout << " Bounding Radius = " << bounds.radius << std::endl;
for(size_t v = 0; v < geom.numverts; ++v)
{
auto p = readStructure<BSTVector3>(data, dataI);
std::cout << " v " << p.x << " " << p.y << " " << p.z << std::endl;
}
if(geom.flags & BSGeometry::StoreNormals)
{
std::cout << " Vertex Normals present" << std::endl;
for(size_t v = 0; v < geom.numverts; ++v)
{
auto p = readStructure<BSTVector3>(data, dataI);
std::cout << " n " << p.x << " " << p.y << " " << p.z << std::endl;
}
}
// Jump to the start of the next geometry
dataI = basedata + geomHeader.size;
}

View File

@ -21,7 +21,13 @@ namespace RW
SID_FrameList = 0x000E,
SID_Geometry = 0x000F,
SID_Clump = 0x0010
SID_Clump = 0x0010,
SID_GeometryList = 0x001A,
SID_HAnimPLG = 0x011E,
SID_NodeName = 0x0253F2FE
};
/**
@ -88,6 +94,48 @@ namespace RW
uint32_t numtris;
uint32_t numverts;
uint32_t numframes;
enum {
IsTriangleStrip = 0x1,
VertexTranslation = 0x2,
TexCoords1 = 0x4,
VertexColors = 0x8,
StoreNormals = 0x16,
DynamicVertexLighting = 0x32,
ModuleMaterialColor = 0x64,
TexCoords2 = 0x128
};
};
typedef uint32_t BSColor;
struct BSGeometryColor
{
BSColor ambient;
BSColor diffuse;
BSColor specular;
};
struct BSGeometryUV
{
float u;
float v;
};
struct BSGeometryTriangle
{
uint16_t first;
uint16_t second;
uint16_t attrib; // Who designed this nonsense.
uint16_t third;
};
struct BSGeometryBounds
{
BSTVector3 center;
float radius;
uint32_t positions;
uint32_t normals;
};
};