std::list<video::Texture*> ImageLoaderWAD::loadTextureList(const io::stringc &Filename) { /* Reset the loader */ reset(); /* Information message */ io::Log::message("Load WAD texture list: \"" + Filename + "\""); /* Open a new file */ File_ = FileSys_.openFile(Filename, io::FILE_READ); /* Check if the file has been opened successful */ if (!File_) return TextureList_; /* Read the header */ readHeader(); /* Read the texture information */ readTextureInfo(); /* Read the textures */ readTextures(); /* Close the file */ FileSys_.closeFile(File_); /* Return the entity */ return TextureList_; }
// Read in the scene data, and load the necessary resources scene_data* loadScene(const std::string& fileName) { scene_data* scene = new scene_data; boost::property_tree::ptree pt; boost::property_tree::read_json(fileName, pt); readGeometry(scene, pt.get_child("geometry")); readTextures(scene, pt.get_child("textures")); readMaterials(scene, pt.get_child("materials")); readObjects(scene, pt.get_child("objects")); readLighting(scene, pt.get_child("lighting")); readDynamicLights(scene, pt.get_child("dynamic_lighting")); return scene; }
AHalfLifeDecoder::AHalfLifeDecoder(const char *fname) : AMeshDecoder(fname) { init(); openFile(fname); readHeader(); if(numbones) readBones(); if(numbonecontrollers) readBoneControllers(); if(numhitboxes) readHitBoxes(); if(numseq) readSeqs(); if(numseqgroups) readSeqGroups(); if(numtextures) readTextures(); if(numskinref*numskinfamilies) readSkins(); if(numbodyparts) readBodyParts(); if(numattachments) readAttachments(); if(soundtable) readSounds(); if(soundgroups) readSoundGroups(); if(numtransitions) readTransitions(); }
void AMD3Decoder::readMeshes() { DEBUG_OUT<<"AMD3Decoder::readMeshes()...\n"; if(!fd) return; //if(errorFlag) return; DEBUG_OUT<<"There are "<<nmeshes<<" meshes.\n"; if(!nmeshes) return; fseek(fd,meshesOffset,SEEK_SET); for(unsigned int i=0;i<nmeshes;i++) { lastMesh=i; DEBUG_OUT<<"mesh "<<i<<": \n"; // NOTE: Only read first mesh, since we lose track of the offset to the next mesh header if(!i) { /*if(!errorFlag)*/ readMeshHeader(); /*if(!errorFlag)*/ readVertices(); /*if(!errorFlag)*/ readTriangles(); /*if(!errorFlag)*/ readTextures(); /*if(!errorFlag)*/ readTextCoords(); } } }
void ModelNode_Witcher::readMesh(Model_Witcher::ParserContext &ctx) { ctx.mdb->skip(4); // Function pointer ctx.mdb->skip(4); // Unknown uint32 offMeshArrays = ctx.mdb->readUint32LE(); ctx.mdb->skip(4); // Unknown float boundingMin[3], boundingMax[3]; boundingMin[0] = ctx.mdb->readIEEEFloatLE(); boundingMin[1] = ctx.mdb->readIEEEFloatLE(); boundingMin[2] = ctx.mdb->readIEEEFloatLE(); boundingMax[0] = ctx.mdb->readIEEEFloatLE(); boundingMax[1] = ctx.mdb->readIEEEFloatLE(); boundingMax[2] = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(28); // Unknown float volFogScale = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(16); // Unknown _diffuse[0] = ctx.mdb->readIEEEFloatLE(); _diffuse[1] = ctx.mdb->readIEEEFloatLE(); _diffuse[2] = ctx.mdb->readIEEEFloatLE(); _ambient[0] = ctx.mdb->readIEEEFloatLE(); _ambient[1] = ctx.mdb->readIEEEFloatLE(); _ambient[2] = ctx.mdb->readIEEEFloatLE(); float textureTransRot[3]; textureTransRot[0] = ctx.mdb->readIEEEFloatLE(); textureTransRot[1] = ctx.mdb->readIEEEFloatLE(); textureTransRot[2] = ctx.mdb->readIEEEFloatLE(); _shininess = ctx.mdb->readIEEEFloatLE(); _shadow = ctx.mdb->readUint32LE() == 1; _beaming = ctx.mdb->readUint32LE() == 1; _render = ctx.mdb->readUint32LE() == 1; _hasTransparencyHint = true; _transparencyHint = ctx.mdb->readUint32LE() == 1; ctx.mdb->skip(4); // Unknown Common::UString texture[4]; for (int t = 0; t < 4; t++) { texture[t] = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); if (texture[t] == "NULL") texture[t].clear(); } bool tileFade = ctx.mdb->readUint32LE() == 1; bool controlFade = ctx.mdb->readByte() == 1; bool lightMapped = ctx.mdb->readByte() == 1; bool rotateTexture = ctx.mdb->readByte() == 1; ctx.mdb->skip(1); // Unknown float transparencyShift = ctx.mdb->readIEEEFloatLE(); uint32 defaultRenderList = ctx.mdb->readUint32LE(); uint32 preserveVColors = ctx.mdb->readUint32LE(); uint32 fourCC = ctx.mdb->readUint32BE(); ctx.mdb->skip(4); // Unknown float depthOffset = ctx.mdb->readIEEEFloatLE(); float coronaCenterMult = ctx.mdb->readIEEEFloatLE(); float fadeStartDistance = ctx.mdb->readIEEEFloatLE(); bool distFromScreenCenterFace = ctx.mdb->readByte() == 1; ctx.mdb->skip(3); // Unknown float enlargeStartDistance = ctx.mdb->readIEEEFloatLE(); bool affectedByWind = ctx.mdb->readByte() == 1; ctx.mdb->skip(3); // Unknown float dampFactor = ctx.mdb->readIEEEFloatLE(); uint32 blendGroup = ctx.mdb->readUint32LE(); bool dayNightLightMaps = ctx.mdb->readByte() == 1; Common::UString dayNightTransition = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 200); bool ignoreHitCheck = ctx.mdb->readByte() == 1; bool needsReflection = ctx.mdb->readByte() == 1; ctx.mdb->skip(1); // Unknown float reflectionPlaneNormal[3]; reflectionPlaneNormal[0] = ctx.mdb->readIEEEFloatLE(); reflectionPlaneNormal[1] = ctx.mdb->readIEEEFloatLE(); reflectionPlaneNormal[2] = ctx.mdb->readIEEEFloatLE(); float reflectionPlaneDistance = ctx.mdb->readIEEEFloatLE(); bool fadeOnCameraCollision = ctx.mdb->readByte() == 1; bool noSelfShadow = ctx.mdb->readByte() == 1; bool isReflected = ctx.mdb->readByte() == 1; bool onlyReflected = ctx.mdb->readByte() == 1; Common::UString lightMapName = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); bool canDecal = ctx.mdb->readByte() == 1; bool multiBillBoard = ctx.mdb->readByte() == 1; bool ignoreLODReflection = ctx.mdb->readByte() == 1; ctx.mdb->skip(1); // Unknown float detailMapScape = ctx.mdb->readIEEEFloatLE(); ctx.offTextureInfo = ctx.mdb->readUint32LE(); uint32 endPos = ctx.mdb->seek(ctx.offRawData + offMeshArrays); ctx.mdb->skip(4); uint32 vertexOffset, vertexCount; Model::readArrayDef(*ctx.mdb, vertexOffset, vertexCount); uint32 normalsOffset, normalsCount; Model::readArrayDef(*ctx.mdb, normalsOffset, normalsCount); uint32 tangentsOffset, tangentsCount; Model::readArrayDef(*ctx.mdb, tangentsOffset, tangentsCount); uint32 biNormalsOffset, biNormalsCount; Model::readArrayDef(*ctx.mdb, biNormalsOffset, biNormalsCount); uint32 tVertsOffset[4], tVertsCount[4]; for (uint t = 0; t < 4; t++) Model::readArrayDef(*ctx.mdb, tVertsOffset[t], tVertsCount[t]); uint32 unknownOffset, unknownCount; Model::readArrayDef(*ctx.mdb, unknownOffset, unknownCount); uint32 facesOffset, facesCount; Model::readArrayDef(*ctx.mdb, facesOffset, facesCount); if (ctx.fileVersion == 133) ctx.offTexData = ctx.mdb->readUint32LE(); if ((vertexCount == 0) || (facesCount == 0)) { ctx.mdb->seek(endPos); return; } std::vector<Common::UString> textures; readTextures(ctx, textures); evaluateTextures(4, textures, texture, tVertsCount, dayNightLightMaps, lightMapName); loadTextures(textures); size_t texCount = textures.size(); // Read vertices VertexDecl vertexDecl; vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT)); vertexDecl.push_back(VertexAttrib(VNORMAL , 3, GL_FLOAT)); for (uint t = 0; t < texCount; t++) vertexDecl.push_back(VertexAttrib(VTCOORD + t, 2, GL_FLOAT)); _vertexBuffer.setVertexDeclLinear(vertexCount, vertexDecl); // Read vertex position ctx.mdb->seek(ctx.offRawData + vertexOffset); float *v = reinterpret_cast<float *>(_vertexBuffer.getData(0)); for (uint32 i = 0; i < vertexCount; i++) { *v++ = ctx.mdb->readIEEEFloatLE(); *v++ = ctx.mdb->readIEEEFloatLE(); *v++ = ctx.mdb->readIEEEFloatLE(); } // Read vertex normals assert(normalsCount == vertexCount); ctx.mdb->seek(ctx.offRawData + normalsOffset); v = reinterpret_cast<float *>(_vertexBuffer.getData(1)); for (uint32 i = 0; i < normalsCount; i++) { *v++ = ctx.mdb->readIEEEFloatLE(); *v++ = ctx.mdb->readIEEEFloatLE(); *v++ = ctx.mdb->readIEEEFloatLE(); } // Read texture coordinates for (uint t = 0; t < texCount; t++) { ctx.mdb->seek(ctx.offRawData + tVertsOffset[t]); v = reinterpret_cast<float *>(_vertexBuffer.getData(2 + t)); for (uint32 i = 0; i < tVertsCount[t]; i++) { if (i < tVertsCount[t]) { *v++ = ctx.mdb->readIEEEFloatLE(); *v++ = ctx.mdb->readIEEEFloatLE(); } else { *v++ = 0.0f; *v++ = 0.0f; } } } // Read faces _indexBuffer.setSize(facesCount * 3, sizeof(uint32), GL_UNSIGNED_INT); ctx.mdb->seek(ctx.offRawData + facesOffset); uint32 *f = reinterpret_cast<uint32 *>(_indexBuffer.getData()); for (uint32 i = 0; i < facesCount; i++) { ctx.mdb->skip(4 * 4 + 4); if (ctx.fileVersion == 133) ctx.mdb->skip(3 * 4); // Vertex indices *f++ = ctx.mdb->readUint32LE(); *f++ = ctx.mdb->readUint32LE(); *f++ = ctx.mdb->readUint32LE(); if (ctx.fileVersion == 133) ctx.mdb->skip(4); } createBound(); ctx.mdb->seek(endPos); }
void ModelNode_Witcher::readMesh(Model_Witcher::ParserContext &ctx) { ctx.mdb->skip(8); uint32 offMeshArrays = ctx.mdb->readUint32LE(); ctx.mdb->skip(76); _ambient [0] = ctx.mdb->readIEEEFloatLE(); _ambient [1] = ctx.mdb->readIEEEFloatLE(); _ambient [2] = ctx.mdb->readIEEEFloatLE(); _diffuse [0] = ctx.mdb->readIEEEFloatLE(); _diffuse [1] = ctx.mdb->readIEEEFloatLE(); _diffuse [2] = ctx.mdb->readIEEEFloatLE(); _specular[0] = ctx.mdb->readIEEEFloatLE(); _specular[1] = ctx.mdb->readIEEEFloatLE(); _specular[2] = ctx.mdb->readIEEEFloatLE(); _shininess = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(20); Common::UString texture[4]; texture[0].readFixedASCII(*ctx.mdb, 64); texture[1].readFixedASCII(*ctx.mdb, 64); texture[2].readFixedASCII(*ctx.mdb, 64); texture[3].readFixedASCII(*ctx.mdb, 64); ctx.mdb->skip(20); uint32 fourCC = ctx.mdb->readUint32BE(); ctx.mdb->skip(8); float coronaCenterX = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(8); float enlargeStartDistance = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(308); ctx.offTextureInfo = ctx.mdb->readUint32LE(); ctx.mdb->skip(4); uint32 endPos = ctx.mdb->seekTo(ctx.offRawData + offMeshArrays); ctx.mdb->skip(4); uint32 verticesOffset, verticesCount; Model::readArrayDef(*ctx.mdb, verticesOffset, verticesCount); uint32 normalsOffset, normalsCount; Model::readArrayDef(*ctx.mdb, normalsOffset, normalsCount); uint32 tangentsOffset, tangentsCount; Model::readArrayDef(*ctx.mdb, tangentsOffset, tangentsCount); uint32 biNormalsOffset, biNormalsCount; Model::readArrayDef(*ctx.mdb, biNormalsOffset, biNormalsCount); uint32 tVerts0Offset, tVerts0Count; Model::readArrayDef(*ctx.mdb, tVerts0Offset, tVerts0Count); uint32 tVerts1Offset, tVerts1Count; Model::readArrayDef(*ctx.mdb, tVerts1Offset, tVerts1Count); uint32 tVerts2Offset, tVerts2Count; Model::readArrayDef(*ctx.mdb, tVerts2Offset, tVerts2Count); uint32 tVerts3Offset, tVerts3Count; Model::readArrayDef(*ctx.mdb, tVerts3Offset, tVerts3Count); uint32 unknownOffset, unknownCount; Model::readArrayDef(*ctx.mdb, unknownOffset, unknownCount); uint32 facesOffset, facesCount; Model::readArrayDef(*ctx.mdb, facesOffset, facesCount); if (ctx.fileVersion == 133) ctx.offTexData = ctx.mdb->readUint32LE(); if ((verticesCount == 0) || (facesCount == 0)) { ctx.mdb->seekTo(endPos); return; } _render = true; std::vector<Common::UString> textures; readTextures(ctx, texture[0], textures); loadTextures(textures); uint32 textureCount = textures.size(); if (!createFaces(facesCount)) { ctx.mdb->seekTo(endPos); return; } // Read vertex coordinates ctx.mdb->seekTo(ctx.offRawData + verticesOffset); std::vector<float> vX, vY, vZ; vX.resize(verticesCount); vY.resize(verticesCount); vZ.resize(verticesCount); for (uint32 i = 0; i < verticesCount; i++) { vX[i] = ctx.mdb->readIEEEFloatLE(); vY[i] = ctx.mdb->readIEEEFloatLE(); vZ[i] = ctx.mdb->readIEEEFloatLE(); } // Read texture coordinates ctx.mdb->seekTo(ctx.offRawData + tVerts0Offset); std::vector<float> tX, tY; tX.resize(tVerts0Count); tY.resize(tVerts0Count); for (uint32 i = 0; i < tVerts0Count; i++) { tX[i] = ctx.mdb->readIEEEFloatLE(); tY[i] = ctx.mdb->readIEEEFloatLE(); } // Read faces ctx.mdb->seekTo(ctx.offRawData + facesOffset); for (uint32 i = 0; i < facesCount; i++) { ctx.mdb->skip(4 * 4 + 4); if (ctx.fileVersion == 133) ctx.mdb->skip(3 * 4); // Vertex indices const uint32 v1 = ctx.mdb->readUint32LE(); const uint32 v2 = ctx.mdb->readUint32LE(); const uint32 v3 = ctx.mdb->readUint32LE(); // Vertex coordinates _vX[3 * i + 0] = v1 < vX.size() ? vX[v1] : 0.0; _vY[3 * i + 0] = v1 < vY.size() ? vY[v1] : 0.0; _vZ[3 * i + 0] = v1 < vZ.size() ? vZ[v1] : 0.0; _boundBox.add(_vX[3 * i + 0], _vY[3 * i + 0], _vZ[3 * i + 0]); _vX[3 * i + 1] = v2 < vX.size() ? vX[v2] : 0.0; _vY[3 * i + 1] = v2 < vY.size() ? vY[v2] : 0.0; _vZ[3 * i + 1] = v2 < vZ.size() ? vZ[v2] : 0.0; _boundBox.add(_vX[3 * i + 1], _vY[3 * i + 1], _vZ[3 * i + 1]); _vX[3 * i + 2] = v3 < vX.size() ? vX[v3] : 0.0; _vY[3 * i + 2] = v3 < vY.size() ? vY[v3] : 0.0; _vZ[3 * i + 2] = v3 < vZ.size() ? vZ[v3] : 0.0; _boundBox.add(_vX[3 * i + 2], _vY[3 * i + 2], _vZ[3 * i + 2]); const float tX1 = v1 < tX.size() ? tX[v1] : 0.0; const float tY1 = v1 < tY.size() ? tY[v1] : 0.0; const float tX2 = v2 < tX.size() ? tX[v2] : 0.0; const float tY2 = v2 < tY.size() ? tY[v2] : 0.0; const float tX3 = v3 < tX.size() ? tX[v3] : 0.0; const float tY3 = v3 < tY.size() ? tY[v3] : 0.0; for (uint32 t = 0; t < textureCount; t++) { _tX[3 * textureCount * i + 3 * t + 0] = tX1; _tY[3 * textureCount * i + 3 * t + 0] = tY1; _tX[3 * textureCount * i + 3 * t + 1] = tX2; _tY[3 * textureCount * i + 3 * t + 1] = tY2; _tX[3 * textureCount * i + 3 * t + 2] = tX3; _tY[3 * textureCount * i + 3 * t + 2] = tY3; } if (ctx.fileVersion == 133) ctx.mdb->skip(4); } createCenter(); ctx.mdb->seekTo(endPos); }