[8344] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER |
---|
| 16 | |
---|
| 17 | #include "md3_data.h" |
---|
| 18 | |
---|
[8357] | 19 | #include "md3_bone_frame.h" |
---|
[8371] | 20 | #include "md3_tag.h" |
---|
[8372] | 21 | #include "md3_mesh.h" |
---|
[8344] | 22 | |
---|
[8418] | 23 | #include "material.h" |
---|
[8357] | 24 | |
---|
[8490] | 25 | #include "debug.h" |
---|
[8418] | 26 | |
---|
[8351] | 27 | namespace md3 |
---|
| 28 | { |
---|
[8344] | 29 | |
---|
| 30 | /******************************************************************************** |
---|
| 31 | * MD3Data * |
---|
| 32 | ********************************************************************************/ |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | \brief simple constructor |
---|
| 36 | */ |
---|
| 37 | MD3Data::MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale) |
---|
| 38 | { |
---|
[8724] | 39 | this->filename = modelFileName; |
---|
[8344] | 40 | |
---|
[8724] | 41 | this->parentTagIndex = -1; |
---|
| 42 | this->parent = NULL; |
---|
[8344] | 43 | |
---|
[8724] | 44 | this->animationState.currentFrame = 0; |
---|
| 45 | this->animationState.nextFrame = 1; |
---|
| 46 | this->animationState.interpolationFraction = 0.0f; |
---|
[8344] | 47 | |
---|
[8724] | 48 | this->animation = NULL; |
---|
| 49 | this->bInterpolate = false; |
---|
| 50 | this->upperBound = 0; |
---|
| 51 | |
---|
[8344] | 52 | this->loadModel(modelFileName); |
---|
[8354] | 53 | // this->loadSkin(skinFileName); |
---|
[8724] | 54 | this->init(); |
---|
[8344] | 55 | } |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | \brief simple destructor |
---|
| 60 | |
---|
| 61 | this will clean out all the necessary data for a specific md2model |
---|
| 62 | */ |
---|
| 63 | MD3Data::~MD3Data() |
---|
| 64 | { |
---|
| 65 | delete this->header; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
[8724] | 69 | /** |
---|
| 70 | * init data |
---|
| 71 | */ |
---|
| 72 | void MD3Data::init() |
---|
| 73 | { |
---|
| 74 | // create the temporary data to work with (interpolation data) |
---|
| 75 | this->tmpBoneFrame = new MD3BoneFrame(); |
---|
[8344] | 76 | |
---|
[8724] | 77 | this->tmpMesh = new sVec3D*[this->header->meshNum]; |
---|
| 78 | for( int i = 0; i < this->header->meshNum; i++) |
---|
| 79 | this->tmpMesh[i] = new sVec3D[this->meshes[i]->header->vertexNum]; |
---|
| 80 | |
---|
| 81 | this->tmpNormal = new MD3Normal*[this->header->meshNum]; |
---|
| 82 | for( int i = 0; i < this->header->meshNum; i++) |
---|
| 83 | this->tmpNormal[i] = new MD3Normal[this->meshes[i]->header->vertexNum]; |
---|
| 84 | |
---|
| 85 | // there are at most 4 different models and submodels |
---|
| 86 | this->tmpMatrix = new float*[4]; |
---|
| 87 | for( int i = 0; i < 4; i++) |
---|
| 88 | this->tmpMatrix[i] = new float[16]; |
---|
| 89 | |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
[8344] | 93 | /** |
---|
[8724] | 94 | * link a model at the specified tag position to this model. if the position is already |
---|
| 95 | * occupied, the old submodel will be replaced |
---|
| 96 | * |
---|
| 97 | * @param tagIndex: tag to link the submodel to |
---|
| 98 | * @param child: the submodel that should be linked to this model |
---|
| 99 | */ |
---|
| 100 | void MD3Data::addLinkedModel(int tagIndex, MD3Data* child) |
---|
| 101 | { |
---|
| 102 | this->sortedMap[tagIndex] = child; |
---|
| 103 | child->parentTagIndex = tagIndex; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | /** |
---|
| 109 | * Return the index of the tag with the given name for this model. |
---|
| 110 | * |
---|
| 111 | * This will return -1 if their is no such tag. |
---|
| 112 | */ |
---|
| 113 | int MD3Data::getTagIndexByName(std::string tagName) |
---|
| 114 | { |
---|
| 115 | int res = -1; |
---|
| 116 | |
---|
| 117 | if( this->header->boneFrameNum > 0) { |
---|
| 118 | MD3Tag** tags = this->boneFrames[0]->tags; |
---|
| 119 | for( int i = 0; i < this->header->tagNum; i++) |
---|
| 120 | if( tags[i]->name.find(tagName) == std::string::npos) |
---|
| 121 | return i; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | return res; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | /** |
---|
[8344] | 130 | \brief this will load the whole model data (vertices, opengl command list, ...) |
---|
| 131 | * @param fileName: the name of the model file |
---|
| 132 | \return true if success |
---|
| 133 | */ |
---|
| 134 | bool MD3Data::loadModel(const std::string& fileName) |
---|
| 135 | { |
---|
| 136 | FILE *pFile; //file stream |
---|
[8353] | 137 | // char* buffer; //buffer for frame data |
---|
[8354] | 138 | int fileOffset = 0; // file data offset |
---|
[8346] | 139 | |
---|
| 140 | |
---|
[8344] | 141 | //! @todo this chek should include deleting a loaded model (eventually) |
---|
| 142 | if (fileName.empty()) |
---|
| 143 | return false; |
---|
| 144 | |
---|
[8354] | 145 | PRINTF(0)("opening file: %s\n", fileName.c_str()); |
---|
[8344] | 146 | pFile = fopen(fileName.c_str(), "rb"); |
---|
| 147 | if( unlikely(!pFile)) |
---|
| 148 | { |
---|
[8347] | 149 | PRINTF(1)("Couldn't open the MD3 File for loading. Exiting.\n"); |
---|
[8344] | 150 | return false; |
---|
| 151 | } |
---|
[8357] | 152 | fileOffset += this->readHeader(pFile, fileOffset); |
---|
[8344] | 153 | /* check for the header version: make sure its a md2 file :) */ |
---|
[8354] | 154 | if( unlikely(this->header->version != MD3_VERSION) && unlikely(this->header->ident != MD3_IDENT)) |
---|
[8344] | 155 | { |
---|
| 156 | PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); |
---|
| 157 | return false; |
---|
| 158 | } |
---|
| 159 | |
---|
[8353] | 160 | |
---|
[8354] | 161 | // check if the filesize is correct |
---|
| 162 | if( this->header->fileSize > this->header->tagStart && |
---|
| 163 | this->header->fileSize >= this->header->meshStart) |
---|
| 164 | { |
---|
| 165 | bool bBoneFrames, bTags, bMeshes; |
---|
| 166 | bBoneFrames = ( this->header->boneFrameNum == 0); |
---|
| 167 | bTags = ( this->header->tagNum == 0); |
---|
| 168 | bMeshes = ( this->header->meshNum == 0); |
---|
| 169 | |
---|
| 170 | // read different parts of the model in correct order |
---|
| 171 | while( !(bBoneFrames && bTags && bMeshes)) |
---|
| 172 | { |
---|
[8426] | 173 | printf("while, fileOffset = %i\n", fileOffset); |
---|
[8354] | 174 | if( fileOffset == this->header->boneFrameStart && !bBoneFrames) |
---|
[8355] | 175 | { |
---|
| 176 | fileOffset += this->readBoneFrames(pFile, fileOffset); |
---|
| 177 | bBoneFrames = true; |
---|
| 178 | } |
---|
[8354] | 179 | else if( fileOffset == this->header->tagStart && !bTags) |
---|
[8355] | 180 | { |
---|
| 181 | fileOffset += this->readTags(pFile, fileOffset); |
---|
| 182 | bTags = true; |
---|
| 183 | } |
---|
[8354] | 184 | else if( fileOffset == this->header->meshStart && !bMeshes) |
---|
[8355] | 185 | { |
---|
| 186 | fileOffset += this->readMeshes(pFile, fileOffset); |
---|
| 187 | bMeshes = true; |
---|
| 188 | } |
---|
[8354] | 189 | } |
---|
| 190 | |
---|
| 191 | } |
---|
| 192 | |
---|
[8344] | 193 | fclose(pFile); |
---|
[8347] | 194 | |
---|
| 195 | return true; |
---|
[8344] | 196 | } |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | /** |
---|
| 200 | \brief loads the skin/material stuff |
---|
| 201 | * @param fileName: name of the skin file |
---|
| 202 | \return true if success |
---|
| 203 | */ |
---|
| 204 | bool MD3Data::loadSkin(const std::string& fileName) |
---|
| 205 | { |
---|
[8357] | 206 | // if( fileName.empty()) |
---|
| 207 | // { |
---|
| 208 | // this->skinFileName = ""; |
---|
| 209 | // return false; |
---|
| 210 | // } |
---|
| 211 | // |
---|
| 212 | // this->skinFileName = fileName; |
---|
| 213 | // |
---|
| 214 | // this->material.setName("md2ModelMaterial"); |
---|
| 215 | // this->material.setDiffuseMap(fileName); |
---|
| 216 | // this->material.setIllum(3); |
---|
| 217 | // this->material.setAmbient(1.0, 1.0, 1.0); |
---|
[8344] | 218 | |
---|
[8347] | 219 | return true; |
---|
[8344] | 220 | } |
---|
[8346] | 221 | |
---|
| 222 | |
---|
| 223 | /** |
---|
| 224 | * read heaader |
---|
| 225 | */ |
---|
[8355] | 226 | int MD3Data::readHeader(FILE* pFile, int fileOffset) |
---|
| 227 | { |
---|
[8426] | 228 | PRINTF(0)("Reading Header\n"); |
---|
| 229 | |
---|
[8357] | 230 | this->header = new MD3Header; |
---|
| 231 | fread(this->header, 1, sizeof(MD3Header), pFile); |
---|
| 232 | |
---|
| 233 | //header debug: |
---|
| 234 | PRINTF(0)("MD3 Header debug section======================================\n"); |
---|
| 235 | printf("ident: %i\n", this->header->ident); |
---|
| 236 | printf("version: %i\n", this->header->version); |
---|
| 237 | printf("filename: %s\n", this->header->filename); |
---|
| 238 | printf("boneFrameNum: %i\n", this->header->boneFrameNum); |
---|
| 239 | printf("tag number: %i\n", this->header->tagNum); |
---|
| 240 | printf("mesh number: %i\n", this->header->meshNum); |
---|
| 241 | printf("max tex num: %i\n", this->header->maxTexNum); |
---|
| 242 | printf("bone frame start: %i\n", this->header->boneFrameStart); |
---|
| 243 | printf("tag start: %i\n", this->header->tagStart); |
---|
| 244 | printf("mesh start: %i\n", this->header->meshStart); |
---|
| 245 | printf("fileSize: %i\n", this->header->fileSize); |
---|
| 246 | |
---|
| 247 | return sizeof(MD3Header); |
---|
[8355] | 248 | } |
---|
[8346] | 249 | |
---|
| 250 | |
---|
| 251 | /** |
---|
| 252 | * read bone frames |
---|
| 253 | */ |
---|
[8355] | 254 | int MD3Data::readBoneFrames(FILE* pFile, int fileOffset) |
---|
| 255 | { |
---|
[8426] | 256 | PRINTF(0)("Reading Bone Frames\n"); |
---|
| 257 | |
---|
[8357] | 258 | this->boneFrames = new MD3BoneFrame*[this->header->boneFrameNum]; |
---|
| 259 | |
---|
| 260 | for( int i = 0; i < this->header->boneFrameNum; i++) |
---|
[8358] | 261 | { |
---|
[8357] | 262 | this->boneFrames[i] = new MD3BoneFrame(i); |
---|
| 263 | |
---|
[8358] | 264 | MD3BoneFrameData* md = new MD3BoneFrameData; |
---|
| 265 | fread(md, 1, sizeof(MD3BoneFrameData), pFile); |
---|
[8372] | 266 | this->boneFrames[i]->data = md; |
---|
[8358] | 267 | } |
---|
| 268 | |
---|
| 269 | return this->header->boneFrameNum * sizeof(MD3BoneFrameData); |
---|
[8355] | 270 | } |
---|
[8346] | 271 | |
---|
| 272 | |
---|
| 273 | /** |
---|
| 274 | * read the tags |
---|
| 275 | */ |
---|
[8355] | 276 | int MD3Data::readTags(FILE* pFile, int fileOffset) |
---|
| 277 | { |
---|
[8426] | 278 | PRINTF(0)("Reading Tags\n"); |
---|
[8359] | 279 | |
---|
| 280 | for( int i = 0; i < this->header->boneFrameNum; i++) |
---|
| 281 | { |
---|
[8371] | 282 | this->boneFrames[i]->tags = new MD3Tag*[this->header->tagNum]; |
---|
| 283 | |
---|
[8359] | 284 | for( int j = 0; j < this->header->tagNum; j++) |
---|
| 285 | { |
---|
[8371] | 286 | this->boneFrames[i]->tags[j] = new MD3Tag(); |
---|
| 287 | MD3TagData* md = new MD3TagData; |
---|
| 288 | fread(md, 1, sizeof(MD3TagData), pFile); |
---|
[8372] | 289 | this->boneFrames[i]->tags[j]->data = md; |
---|
[8724] | 290 | |
---|
| 291 | this->boneFrames[i]->tags[j]->name = std::string(this->boneFrames[i]->tags[j]->data->name); |
---|
| 292 | this->boneFrames[i]->tags[j]->position = Vector( this->boneFrames[i]->tags[j]->data->position[0], |
---|
| 293 | this->boneFrames[i]->tags[j]->data->position[1], |
---|
| 294 | this->boneFrames[i]->tags[j]->data->position[2]); |
---|
| 295 | for( int k = 0; k < 3; k++) |
---|
| 296 | for( int l = 0; l < 3; l++) |
---|
| 297 | this->boneFrames[i]->tags[j]->matrix[k][l] = this->boneFrames[i]->tags[j]->data->matrix[k][l]; |
---|
| 298 | |
---|
| 299 | //PRINTF(0)("Tag name: %s\n", this->boneFrames[i]->tags[j]->name.c_str()); |
---|
[8359] | 300 | } |
---|
| 301 | } |
---|
| 302 | |
---|
[8371] | 303 | return this->header->boneFrameNum * this->header->tagNum * sizeof(MD3TagData); |
---|
[8355] | 304 | } |
---|
[8346] | 305 | |
---|
| 306 | |
---|
| 307 | /** |
---|
| 308 | * read meshes |
---|
| 309 | */ |
---|
[8355] | 310 | int MD3Data::readMeshes(FILE* pFile, int fileOffset) |
---|
| 311 | { |
---|
[8426] | 312 | PRINTF(0)("Reading Mesh Data\n"); |
---|
[8375] | 313 | |
---|
[8432] | 314 | fileOffset = 0; |
---|
[8426] | 315 | |
---|
[8372] | 316 | this->meshes = new MD3Mesh*[this->header->meshNum]; |
---|
| 317 | |
---|
| 318 | for( int i = 0; i < this->header->meshNum; i++) |
---|
| 319 | { |
---|
| 320 | this->meshes[i] = new MD3Mesh(); |
---|
| 321 | |
---|
[8432] | 322 | int localFileOffset = 0; |
---|
[8375] | 323 | bool bTriangles, bTexVecs, bVertices, bTextures; //!< the parts that have been read so far |
---|
[8374] | 324 | |
---|
| 325 | //start reading mesh data |
---|
[8375] | 326 | MD3MeshHeader* md = new MD3MeshHeader; |
---|
| 327 | fread(md, 1, sizeof(MD3MeshHeader), pFile); |
---|
| 328 | this->meshes[i]->header = md; |
---|
| 329 | localFileOffset += sizeof(MD3MeshHeader); |
---|
[8374] | 330 | |
---|
[8426] | 331 | PRINTF(0)("MD3 Mesh Header debug section\n"); |
---|
| 332 | printf("ident: %i\n", md->id); |
---|
| 333 | printf("filename: %s\n", md->name); |
---|
| 334 | printf("meshFrameNum: %i\n", md->meshFrameNum); |
---|
| 335 | printf("textureNum: %i\n", md->textureNum); |
---|
| 336 | printf("vertexNum: %i \n", md->vertexNum); |
---|
| 337 | printf("triangleNum: %i\n", md->triangleNum); |
---|
| 338 | printf("triangleStart: %i\n", md->triangleStart); |
---|
| 339 | printf("textureStart: %i\n", md->textureStart); |
---|
| 340 | printf("texVecStart: %i\n", md->texVecStart); |
---|
| 341 | printf("vertexStart: %i\n", md->vertexStart); |
---|
| 342 | printf("fileSize: %i\n", md->meshSize); |
---|
| 343 | |
---|
[8432] | 344 | if( unlikely(this->meshes[i]->header->id != MD3_IDENT)) |
---|
| 345 | { |
---|
| 346 | PRINTF(1)("Wrong MD3 mesh file tag, file %s could be corrupt\n", this->filename.c_str()); |
---|
| 347 | return false; |
---|
| 348 | } |
---|
| 349 | |
---|
[8375] | 350 | // check which parts to be loaded |
---|
| 351 | bTriangles = ( this->meshes[i]->header->triangleNum == 0); |
---|
| 352 | bTexVecs = ( this->meshes[i]->header->vertexNum == 0); |
---|
| 353 | bVertices = ( this->meshes[i]->header->meshFrameNum == 0); |
---|
| 354 | bTextures = ( this->meshes[i]->header->textureNum == 0); |
---|
| 355 | |
---|
| 356 | // now read the data block whise |
---|
| 357 | while( !(bTriangles && bTexVecs && bVertices && bTextures)) |
---|
| 358 | { |
---|
[8426] | 359 | PRINTF(0)("while2: localOffset = %i\n", localFileOffset); |
---|
[8375] | 360 | if( localFileOffset == this->meshes[i]->header->triangleStart && !bTriangles) |
---|
| 361 | { |
---|
[8382] | 362 | localFileOffset += this->readMeshTriangles(pFile, localFileOffset, i); |
---|
[8375] | 363 | bTriangles = true; |
---|
| 364 | } |
---|
| 365 | else if( localFileOffset == this->meshes[i]->header->textureStart && !bTextures) |
---|
| 366 | { |
---|
[8428] | 367 | localFileOffset += this->readMeshTextures(pFile, localFileOffset, i); |
---|
[8375] | 368 | bTextures = true; |
---|
| 369 | } |
---|
| 370 | else if( localFileOffset == this->meshes[i]->header->texVecStart && !bTexVecs) |
---|
| 371 | { |
---|
[8382] | 372 | localFileOffset += this->readMeshTexVecs(pFile, localFileOffset, i); |
---|
[8375] | 373 | bTexVecs = true; |
---|
| 374 | } |
---|
[8428] | 375 | else if( localFileOffset == this->meshes[i]->header->vertexStart && !bVertices) |
---|
[8375] | 376 | { |
---|
[8382] | 377 | localFileOffset += this->readMeshVertices(pFile, localFileOffset, i); |
---|
[8375] | 378 | bVertices = true; |
---|
| 379 | } |
---|
| 380 | } |
---|
[8432] | 381 | fileOffset += localFileOffset; |
---|
| 382 | PRINTF(0)("finished reading mesh %i, got %i of %i byes\n", i, localFileOffset, md->meshSize); |
---|
[8372] | 383 | } |
---|
[8432] | 384 | return fileOffset; |
---|
[8355] | 385 | } |
---|
[8351] | 386 | |
---|
[8382] | 387 | |
---|
| 388 | |
---|
[8418] | 389 | /** |
---|
| 390 | * reading in the mesh triangles |
---|
| 391 | */ |
---|
[8382] | 392 | int MD3Data::readMeshTriangles(FILE* pFile, int fileOffset, int mesh) |
---|
| 393 | { |
---|
[8426] | 394 | PRINTF(0)("Reading Mesh Triangles\n"); |
---|
[8416] | 395 | // create the memomry to save the triangles |
---|
[8418] | 396 | this->meshes[mesh]->triangles = new MD3Triangle[this->meshes[mesh]->header->triangleNum]; |
---|
[8433] | 397 | fread(this->meshes[mesh]->triangles, 1, sizeof(MD3Triangle) * this->meshes[mesh]->header->triangleNum, pFile); |
---|
[8416] | 398 | |
---|
[8724] | 399 | // for( int i = 0; i < this->meshes[mesh]->header->triangleNum; i++) { |
---|
| 400 | // PRINTF(0)("Triangle read: %i, %i, %i\n", this->meshes[mesh]->triangles[i].vertexOffset[0], this->meshes[mesh]->triangles[i].vertexOffset[1] |
---|
| 401 | // , this->meshes[mesh]->triangles[i].vertexOffset[2]); |
---|
| 402 | // } |
---|
| 403 | |
---|
[8416] | 404 | return this->meshes[mesh]->header->triangleNum * sizeof(MD3Triangle); |
---|
[8353] | 405 | } |
---|
| 406 | |
---|
[8418] | 407 | |
---|
| 408 | /** |
---|
| 409 | * reading in the mesh textures |
---|
| 410 | */ |
---|
[8382] | 411 | int MD3Data::readMeshTextures(FILE* pFile, int fileOffset, int mesh) |
---|
[8416] | 412 | { |
---|
[8426] | 413 | PRINTF(0)("Reading Mesh Textures\n"); |
---|
| 414 | |
---|
[8418] | 415 | // create the textures |
---|
| 416 | this->meshes[mesh]->material = new Material[this->meshes[mesh]->header->textureNum]; |
---|
| 417 | |
---|
| 418 | MD3Texture* tex = new MD3Texture[this->meshes[mesh]->header->textureNum]; |
---|
[8433] | 419 | fread(tex, 1, sizeof(MD3Texture) * this->meshes[mesh]->header->textureNum, pFile); |
---|
[8418] | 420 | |
---|
| 421 | for( int i = 0; i < this->meshes[mesh]->header->textureNum; i++) { |
---|
| 422 | PRINTF(0)(" texture file: %s\n", tex[i].fileName); |
---|
[8724] | 423 | #warning texture stuff hard coded. make this again |
---|
| 424 | std::string path("/home/boenzlip/tmp/q3/Downloads/MOH/q3mdl-alien3/"); |
---|
| 425 | std::string path1(tex[i].fileName); |
---|
| 426 | std::string fullPath( path + path1); |
---|
| 427 | this->meshes[mesh]->material[i].setDiffuseMap(/*tex[i].fileName*/ /*fullPath.c_str()*/ "maps/creatures/gork/gorkup.tga"); |
---|
[8418] | 428 | this->meshes[mesh]->material[i].setAmbient(1, 1, 1); |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | return this->meshes[mesh]->header->textureNum * sizeof(MD3Texture); |
---|
[8416] | 432 | } |
---|
[8382] | 433 | |
---|
[8418] | 434 | |
---|
| 435 | /** |
---|
| 436 | * reading in the mesh tex vecs |
---|
| 437 | */ |
---|
[8382] | 438 | int MD3Data::readMeshTexVecs(FILE* pFile, int fileOffset, int mesh) |
---|
[8416] | 439 | { |
---|
[8426] | 440 | PRINTF(0)("Reading Mesh TexVecs\n"); |
---|
[8428] | 441 | |
---|
[8420] | 442 | this->meshes[mesh]->texVecs = new MD3TexVecs[this->meshes[mesh]->header->vertexNum]; |
---|
[8433] | 443 | fread(this->meshes[mesh]->texVecs, 1, sizeof(MD3TexVecs) * this->meshes[mesh]->header->vertexNum, pFile); |
---|
[8420] | 444 | |
---|
[8724] | 445 | // for( int i = 0; i < this->meshes[mesh]->header->vertexNum; i++) { |
---|
| 446 | // PRINTF(0)("TexVec read: %f, %f\n", this->meshes[mesh]->texVecs[i].textureCoord[0], this->meshes[mesh]->texVecs[i].textureCoord[0]); |
---|
| 447 | // } |
---|
| 448 | |
---|
[8420] | 449 | return this->meshes[mesh]->header->vertexNum * sizeof(MD3TexVecs); |
---|
[8416] | 450 | } |
---|
[8382] | 451 | |
---|
[8418] | 452 | |
---|
| 453 | /** |
---|
| 454 | * reading in the mesh vertices |
---|
| 455 | */ |
---|
[8382] | 456 | int MD3Data::readMeshVertices(FILE* pFile, int fileOffset, int mesh) |
---|
[8416] | 457 | { |
---|
[8426] | 458 | PRINTF(0)("Reading Mesh Vertices\n"); |
---|
| 459 | |
---|
[8423] | 460 | // reserver memory for the vertex informations |
---|
[8724] | 461 | this->meshes[mesh]->meshFrames = new sVec3D*[this->meshes[mesh]->header->meshFrameNum]; // * this->meshes[mesh]->header->vertexNum |
---|
| 462 | this->meshes[mesh]->normals = new MD3Normal*[this->meshes[mesh]->header->meshFrameNum]; |
---|
[8423] | 463 | |
---|
[8724] | 464 | for( int i = 0; i < this->meshes[mesh]->header->meshFrameNum; i++) |
---|
[8436] | 465 | { |
---|
[8724] | 466 | this->meshes[mesh]->meshFrames[i] = new sVec3D[this->meshes[mesh]->header->vertexNum]; |
---|
| 467 | this->meshes[mesh]->normals[i] = new MD3Normal[this->meshes[mesh]->header->vertexNum]; |
---|
[8423] | 468 | |
---|
[8724] | 469 | for( int j = 0; j < this->meshes[mesh]->header->vertexNum; j++) |
---|
| 470 | { |
---|
| 471 | // read out the compressed data |
---|
| 472 | MD3VertexCompressed* vc = new MD3VertexCompressed; |
---|
| 473 | fread(vc, 1, sizeof(MD3VertexCompressed), pFile); |
---|
[8423] | 474 | |
---|
[8724] | 475 | this->meshes[mesh]->meshFrames[i][j][0] = (float)vc->vector[0] / 64.0f; |
---|
| 476 | this->meshes[mesh]->meshFrames[i][j][1] = (float)vc->vector[1] / 64.0f; |
---|
| 477 | this->meshes[mesh]->meshFrames[i][j][2] = (float)vc->vector[2] / 64.0f; |
---|
[8439] | 478 | |
---|
[8724] | 479 | this->meshes[mesh]->normals[i][j].vertexNormal[0] = (int)vc->vertexNormal[0]; |
---|
| 480 | this->meshes[mesh]->normals[i][j].vertexNormal[1] = (int)vc->vertexNormal[1]; |
---|
| 481 | |
---|
| 482 | // PRINTF(0)("nr: %i, meshframes: %f, %f, %f, normal: %f, %f\n", i, this->meshes[mesh]->meshFrames[i][0], this->meshes[mesh]->meshFrames[i][1], |
---|
| 483 | // this->meshes[mesh]->meshFrames[i][2], this->meshes[mesh]->normals[i].vertexNormal[0], this->meshes[mesh]->normals[i].vertexNormal[1]); |
---|
| 484 | |
---|
| 485 | delete vc; |
---|
| 486 | } |
---|
[8423] | 487 | } |
---|
| 488 | |
---|
| 489 | return this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum * sizeof(MD3VertexCompressed); |
---|
[8416] | 490 | } |
---|
[8382] | 491 | |
---|
[8724] | 492 | |
---|
| 493 | |
---|
[8382] | 494 | } |
---|
| 495 | |
---|
| 496 | |
---|
| 497 | |
---|
| 498 | |
---|
| 499 | |
---|
| 500 | |
---|
| 501 | |
---|