WorldModelGroup::WorldModelGroup( std::string path, int groupIndex ) : GroupIndex(groupIndex), MOBA(NULL), IsBad(false) { Data = new ChunkedData(path); if (!Data->Stream) { IsBad = true; return; } Chunk* mainChunk = Data->GetChunkByName("MOGP"); int32 firstSub = mainChunk->FindSubChunkOffset("MOPY"); if (firstSub == -1) return; Name = Utils::GetPlainName(path.c_str()); FILE* stream = mainChunk->GetStream(); fseek(stream, firstSub, SEEK_SET); SubData = new ChunkedData(stream, mainChunk->Length - firstSub); ReadHeader(); ReadMaterials(); ReadTriangles(); ReadVertices(); ReadNormals(); ReadLiquid(); ReadBatches(); }
bool M3DLoader::LoadM3d(const std::string& filename, std::vector<Vertex::PosNormalTexTan>& vertices, std::vector<USHORT>& indices, std::vector<MeshGeometry::Subset>& subsets, std::vector<M3dMaterial>& mats) { std::ifstream fin(filename); UINT numMaterials = 0; UINT numVertices = 0; UINT numTriangles = 0; UINT numBones = 0; UINT numAnimationClips = 0; std::string ignore; if( fin ) { fin >> ignore; // file header text fin >> ignore >> numMaterials; fin >> ignore >> numVertices; fin >> ignore >> numTriangles; fin >> ignore >> numBones; fin >> ignore >> numAnimationClips; ReadMaterials(fin, numMaterials, mats); ReadSubsetTable(fin, numMaterials, subsets); ReadVertices(fin, numVertices, vertices); ReadTriangles(fin, numTriangles, indices); return true; } return false; }
void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Assimp::IOSystem *pIOHandler) { // Open source file IOStream *f = pIOHandler->Open(pFile, "rb"); if (!f) { throw DeadlyImportError("Failed to open file " + pFile); } // Binary .mesh import if (EndsWith(pFile, ".mesh", false)) { /// @note MemoryStreamReader takes ownership of f. MemoryStreamReader reader(f); // Import mesh boost::scoped_ptr<Mesh> mesh(OgreBinarySerializer::ImportMesh(&reader)); // Import skeleton OgreBinarySerializer::ImportSkeleton(pIOHandler, mesh.get()); // Import mesh referenced materials ReadMaterials(pFile, pIOHandler, pScene, mesh.get()); // Convert to Assimp mesh->ConvertToAssimpScene(pScene); } // XML .mesh.xml import else { /// @note XmlReader does not take ownership of f, hence the scoped ptr. boost::scoped_ptr<IOStream> scopedFile(f); boost::scoped_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(scopedFile.get())); boost::scoped_ptr<XmlReader> reader(irr::io::createIrrXMLReader(xmlStream.get())); // Import mesh boost::scoped_ptr<MeshXml> mesh(OgreXmlSerializer::ImportMesh(reader.get())); // Import skeleton OgreXmlSerializer::ImportSkeleton(pIOHandler, mesh.get()); // Import mesh referenced materials ReadMaterials(pFile, pIOHandler, pScene, mesh.get()); // Convert to Assimp mesh->ConvertToAssimpScene(pScene); } }
bool ACAMTLoader::LoadFromFile( const CHAR* path, AMT_MODEL* outModel) { // open the file mpFile = fopen( path, "rb" ); if( !mpFile ) return false; ReadHeader(outModel); ReadVertices(outModel); ReadFaces(outModel); ReadMesh(outModel); ReadMaterials(outModel); ReadJoints(outModel); ReadAnimations(outModel); return CloseFile( true ); };
bool SkeletalModelLoader::LoadM3d(const std::string& filename, std::vector<SimpleVertex>& vertices, std::vector<unsigned int>& indices, std::vector<SkeletalModelSubSet>& subsets, std::vector<SkeletalModelMaterial>& mats, SkinnedMeshSkeleton & skinInfo) { std::ifstream md3File(filename); unsigned int nMaterials = 0, nVertices = 0, nTriangles = 0, nBones = 0, nAnimationClips = 0; std::string ignorStr = ""; if (md3File.good()) { // call the bellow loading functions md3File >> ignorStr; // ***************m3d-File-Header*************** md3File >> ignorStr >> nMaterials; md3File >> ignorStr >> nVertices; md3File >> ignorStr >> nTriangles; md3File >> ignorStr >> nBones; md3File >> ignorStr >> nAnimationClips; std::vector<DirectX::XMFLOAT4X4> boneOffsets; std::vector<int> boneIndexToParentIndex; std::map<std::string, AnimationClip> animationClips; ReadMaterials(md3File, nMaterials, mats); ReadSubsetTable(md3File, nMaterials, subsets); ReadSkinnedVertices(md3File, nVertices, vertices); // now check to see if the bones on each vertex are in an ok range std::vector<unsigned int> badVertexIndercies; std::vector<BYTE> badWeightIndexValueForVert; for (unsigned int i = 0; i < vertices.size(); i++) { for (unsigned int j = 0; j < 4; j++) { if (vertices[i].BoneIndices[j] >= nBones) { BYTE theValue = vertices[i].BoneIndices[j]; int badVertexIndex = i; badVertexIndercies.push_back(badVertexIndex); badWeightIndexValueForVert.push_back(theValue); } } } ReadTriangles(md3File, nTriangles, indices); ReadBoneOffsets(md3File, nBones, boneOffsets); ReadBoneHierarchy(md3File, nBones, boneIndexToParentIndex); ReadAnimationClips(md3File, nBones, nAnimationClips, animationClips); skinInfo.set(boneIndexToParentIndex, boneOffsets, animationClips); return true; }