#include "renderware.h" #include using namespace std; namespace rw { void Geometry::readXboxNativeData(ifstream &dff) { HeaderInfo header; READ_HEADER(CHUNK_STRUCT); uint32 platform = readUInt32(dff); if (platform != 0x05) { cerr << "error: native data not in xbox format\n"; return; } uint32 vertexPosition = dff.tellg(); vertexPosition += readUInt32(dff); /* Header */ dff.seekg(2, ios::cur); uint32 splitCount = readUInt16(dff); splits.resize(splitCount); /* from here the index blocks are 0x10 byte aligned */ uint32 pos1 = dff.tellg(); dff.seekg(4, ios::cur); uint32 vertexCount = readUInt32(dff); uint32 vertexSize = readUInt32(dff); dff.seekg(16, ios::cur); /* Splits */ for (uint32 i = 0; i < splitCount; i++) { dff.seekg(8, ios::cur); splits[i].indices.resize(readUInt32(dff)); dff.seekg(12, ios::cur); } /* Indices */ for (uint32 i = 0; i < splitCount; i++) { /* skip padding */ uint32 pos2 = dff.tellg(); if ((pos2 - pos1) % 0x10 != 0) dff.seekg(0x10 - (pos2 - pos1) % 0x10, ios::cur); for (uint32 j = 0; j < splits[i].indices.size(); j++) splits[i].indices[j] = readUInt16(dff); } /* Vertices */ dff.seekg(vertexPosition, ios::beg); if (vertexSize != 0x18 || vertexSize != 0x1C) cout << "unknown vertexSize: " << hex << vertexSize << endl; /* TODO: multiple uv sets and vertex colors */ for (uint32 i = 0; i < vertexCount; i++) { vertices.push_back(readFloat32(dff)); vertices.push_back(readFloat32(dff)); vertices.push_back(readFloat32(dff)); if (flags & FLAGS_NORMALS) { uint32 compNormal = readUInt32(dff); int32 normal[3]; normal[0] = compNormal & 0x7FF; normal[1] = (compNormal & 0x3FF800) >> 11; normal[2] = (compNormal & 0xFFC00000) >> 22; if (normal[0] & 0x400) normal[0] -= 0x800; if (normal[1] & 0x400) normal[1] -= 0x800; if (normal[2] & 0x200) normal[2] -= 0x400; normals.push_back((float) normal[0] / 0x3FF); normals.push_back((float) normal[1] / 0x3FF); normals.push_back((float) normal[2] / 0x1FF); } if (flags & FLAGS_PRELIT) { uint8 color[4]; dff.read(reinterpret_cast (color), 4*sizeof(uint8)); vertexColors.push_back(color[2]); vertexColors.push_back(color[1]); vertexColors.push_back(color[0]); vertexColors.push_back(color[3]); } if (flags & FLAGS_TEXTURED) { texCoords1.push_back(readFloat32(dff)); texCoords1.push_back(readFloat32(dff)); } } } }