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(); }
/************* * DESCRIPTION: read a RAW-file * INPUT: rc context * filename name of RAW-file * link link structure * pos object position * ox,oy,oz object orientation * actor pointer to actor * surf surface to replace object surface with * version version number * OUTPUT: returns error string (NULL if ok) *************/ extern "C" char* SAVEDS objRead(rsiCONTEXT *rc, char *filename, OBJLINK *link, const VECTOR *pos, const VECTOR *ox, const VECTOR *oy, const VECTOR *oz, const VECTOR *scale, ACTOR *actor, SURFACE *surf, ULONG *version, float (*SetProgress)(rsiCONTEXT*, float)) { char *errstr; HANDLER_DATA data; data.link = link; data.mainactor = actor; data.rc = rc; data.root = NULL; data.transmatrix.IdentityMatrix(); data.transmatrix.SetSOTMatrix(scale, ox, oy, oz, pos); if (!OpenRAW(&data, filename)) { objCleanup(&data); return errors[ERR_OPEN]; } errstr = ReadTriangles(&data, surf); objCleanup(&data); return errstr; }
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; }
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; }