void ModelNode_Witcher::load(Model_Witcher::ParserContext &ctx) { ctx.mdb->skip(24); // Function pointers uint32 inheritColor = ctx.mdb->readUint32LE(); uint32 nodeNumber = ctx.mdb->readUint32LE(); _name = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); ctx.mdb->skip(8); // Parent pointers uint32 childrenOffset, childrenCount; Model::readArrayDef(*ctx.mdb, childrenOffset, childrenCount); std::vector<uint32> children; Model::readArray(*ctx.mdb, ctx.offModelData + childrenOffset, childrenCount, children); uint32 controllerKeyOffset, controllerKeyCount; Model::readArrayDef(*ctx.mdb, controllerKeyOffset, controllerKeyCount); uint32 controllerDataOffset, controllerDataCount; Model::readArrayDef(*ctx.mdb, controllerDataOffset, controllerDataCount); std::vector<float> controllerData; Model::readArray(*ctx.mdb, ctx.offModelData + controllerDataOffset, controllerDataCount, controllerData); readNodeControllers(ctx, ctx.offModelData + controllerKeyOffset, controllerKeyCount, controllerData); ctx.mdb->skip(4); // Unknown uint32 imposterGroup = ctx.mdb->readUint32LE(); uint32 fixedRot = ctx.mdb->readUint32LE(); int32 minLOD = ctx.mdb->readUint32LE(); int32 maxLOD = ctx.mdb->readUint32LE(); NodeType type = (NodeType) ctx.mdb->readUint32LE(); switch (type) { case kNodeTypeTrimesh: readMesh(ctx); break; case kNodeTypeTexturePaint: readTexturePaint(ctx); break; default: break; } // Only render the highest LOD (0), or if the node is not LODing (-1) if ((minLOD != -1) && (maxLOD != -1) && (minLOD > 0)) _render = false; for (std::vector<uint32>::const_iterator child = children.begin(); child != children.end(); ++child) { ModelNode_Witcher *childNode = new ModelNode_Witcher(*_model); ctx.nodes.push_back(childNode); childNode->setParent(this); ctx.mdb->seek(ctx.offModelData + *child); childNode->load(ctx); } }
void ModelNode_Witcher::load(Model_Witcher::ParserContext &ctx) { ctx.mdb->skip(24); uint32 inheritColor = ctx.mdb->readUint32LE(); uint32 nodeNumber = ctx.mdb->readUint32LE(); _name.readFixedASCII(*ctx.mdb, 64); ctx.mdb->skip(8); // Parent pointers uint32 childrenOffset, childrenCount; Model::readArrayDef(*ctx.mdb, childrenOffset, childrenCount); std::vector<uint32> children; Model::readArray(*ctx.mdb, ctx.offModelData + childrenOffset, childrenCount, children); uint32 controllerKeyOffset, controllerKeyCount; Model::readArrayDef(*ctx.mdb, controllerKeyOffset, controllerKeyCount); uint32 controllerDataOffset, controllerDataCount; Model::readArrayDef(*ctx.mdb, controllerDataOffset, controllerDataCount); std::vector<float> controllerData; Model::readArray(*ctx.mdb, ctx.offModelData + controllerDataOffset, controllerDataCount, controllerData); readNodeControllers(ctx, ctx.offModelData + controllerKeyOffset, controllerKeyCount, controllerData); ctx.mdb->skip(20); uint32 flags = ctx.mdb->readUint32LE(); if ((flags & 0xFFFC0000) != 0) throw Common::Exception("Unknown node flags %08X", flags); if (flags & kNodeFlagHasLight) { // TODO: Light } if (flags & kNodeFlagHasEmitter) { // TODO: Emitter } if (flags & kNodeFlagHasReference) { // TODO: Reference } if (flags & kNodeFlagHasMesh) { readMesh(ctx); } if (flags & kNodeFlagHasSkin) { // TODO: Skin } if (flags & kNodeFlagHasAnim) { // TODO: Anim } if (flags & kNodeFlagHasDangly) { // TODO: Dangly } if (flags & kNodeFlagHasAABB) { // TODO: AABB } for (std::vector<uint32>::const_iterator child = children.begin(); child != children.end(); ++child) { ModelNode_Witcher *childNode = new ModelNode_Witcher(*_model); ctx.nodes.push_back(childNode); childNode->setParent(this); ctx.mdb->seek(ctx.offModelData + *child); childNode->load(ctx); } }
void Model_Witcher::load(ParserContext &ctx) { if (ctx.mdb->readByte() != 0) { ctx.mdb->seek(0); Common::UString type = Common::readString(*ctx.mdb, Common::kEncodingASCII); if (type.beginsWith("binarycompositemodel")) throw Common::Exception("TODO: binarycompositemodel"); throw Common::Exception("Not a The Witcher MDB file"); } ctx.mdb->seek(4); ctx.fileVersion = ctx.mdb->readUint32LE() & 0x0FFFFFFF; if ((ctx.fileVersion != 136) && (ctx.fileVersion != 133)) throw Common::Exception("Unknown The Witcher MDB version %d", ctx.fileVersion); uint32 modelCount = ctx.mdb->readUint32LE(); if (modelCount != 1) throw Common::Exception("Unsupported model count %d in The Witcher MDB", modelCount); ctx.mdb->skip(4); ctx.modelDataSize = ctx.mdb->readUint32LE(); ctx.mdb->skip(4); ctx.offModelData = 32; if (ctx.fileVersion == 133) { ctx.offRawData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.rawDataSize = ctx.mdb->readUint32LE(); ctx.offTexData = ctx.offModelData; ctx.texDatasize = 0; } else { ctx.offRawData = ctx.offModelData; ctx.rawDataSize = 0; ctx.offTexData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.texDatasize = ctx.mdb->readUint32LE(); } ctx.mdb->skip(8); _name = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); uint32 offsetRootNode = ctx.mdb->readUint32LE(); ctx.mdb->skip(32); byte type = ctx.mdb->readByte(); ctx.mdb->skip(3); ctx.mdb->skip(48); float firstLOD = ctx.mdb->readIEEEFloatLE(); float lastLOD = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(16); Common::UString detailMap = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); ctx.mdb->skip(4); float modelScale = ctx.mdb->readIEEEFloatLE(); Common::UString superModel = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); ctx.mdb->skip(16); newState(ctx); ModelNode_Witcher *rootNode = new ModelNode_Witcher(*this); ctx.nodes.push_back(rootNode); ctx.mdb->seek(ctx.offModelData + offsetRootNode); rootNode->load(ctx); addState(ctx); }
void Model_Witcher::load(ParserContext &ctx) { if (ctx.mdb->readByte() != 0) { ctx.mdb->seek(0); Common::UString type; type.readASCII(*ctx.mdb); if (type.beginsWith("binarycompositemodel")) throw Common::Exception("TODO: binarycompositemodel"); throw Common::Exception("Not a The Witcher MDB file"); } ctx.mdb->seek(4); ctx.fileVersion = ctx.mdb->readUint16LE(); ctx.mdb->skip(10); ctx.modelDataSize = ctx.mdb->readUint32LE(); ctx.mdb->skip(4); ctx.offModelData = 32; if (ctx.fileVersion == 133) { ctx.offRawData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.rawDataSize = ctx.mdb->readUint32LE(); ctx.offTexData = ctx.offModelData; ctx.texDatasize = 0; } else { ctx.offRawData = ctx.offModelData; ctx.rawDataSize = 0; ctx.offTexData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.texDatasize = ctx.mdb->readUint32LE(); } ctx.mdb->skip(8); _name.readFixedASCII(*ctx.mdb, 64); uint32 offsetRootNode = ctx.mdb->readUint32LE(); ctx.mdb->skip(32); byte type = ctx.mdb->readByte(); ctx.mdb->skip(3); ctx.mdb->skip(48); float firstLOD = ctx.mdb->readIEEEFloatLE(); float lastLOD = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(16); Common::UString detailMap; detailMap.readFixedASCII(*ctx.mdb, 64); ctx.mdb->skip(4); float scale = ctx.mdb->readIEEEFloatLE(); Common::UString superModel; superModel.readFixedASCII(*ctx.mdb, 64); ctx.mdb->skip(16); newState(ctx); ModelNode_Witcher *rootNode = new ModelNode_Witcher(*this); ctx.nodes.push_back(rootNode); ctx.mdb->seek(ctx.offModelData + offsetRootNode); rootNode->load(ctx); addState(ctx); }