vrshoot
diff libs/assimp/HMPLoader.cpp @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/HMPLoader.cpp Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,509 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2012, assimp team 1.10 + 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the following 1.15 +conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 + copyright notice, this list of conditions and the 1.19 + following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 + copyright notice, this list of conditions and the 1.23 + following disclaimer in the documentation and/or other 1.24 + materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 + contributors may be used to endorse or promote products 1.28 + derived from this software without specific prior 1.29 + written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 +--------------------------------------------------------------------------- 1.43 +*/ 1.44 + 1.45 +/** @file Implementation of the MDL importer class */ 1.46 + 1.47 +#include "AssimpPCH.h" 1.48 +#ifndef ASSIMP_BUILD_NO_HMP_IMPORTER 1.49 + 1.50 +// internal headers 1.51 +#include "HMPLoader.h" 1.52 +#include "MD2FileData.h" 1.53 + 1.54 +using namespace Assimp; 1.55 + 1.56 +static const aiImporterDesc desc = { 1.57 + "3D GameStudio Heightmap (HMP) Importer", 1.58 + "", 1.59 + "", 1.60 + "", 1.61 + aiImporterFlags_SupportBinaryFlavour, 1.62 + 0, 1.63 + 0, 1.64 + 0, 1.65 + 0, 1.66 + "hmp" 1.67 +}; 1.68 + 1.69 +// ------------------------------------------------------------------------------------------------ 1.70 +// Constructor to be privately used by Importer 1.71 +HMPImporter::HMPImporter() 1.72 +{ 1.73 + // nothing to do here 1.74 +} 1.75 + 1.76 +// ------------------------------------------------------------------------------------------------ 1.77 +// Destructor, private as well 1.78 +HMPImporter::~HMPImporter() 1.79 +{ 1.80 + // nothing to do here 1.81 +} 1.82 + 1.83 +// ------------------------------------------------------------------------------------------------ 1.84 +// Returns whether the class can handle the format of the given file. 1.85 +bool HMPImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool cs) const 1.86 +{ 1.87 + const std::string extension = GetExtension(pFile); 1.88 + if (extension == "hmp" ) 1.89 + return true; 1.90 + 1.91 + // if check for extension is not enough, check for the magic tokens 1.92 + if (!extension.length() || cs) { 1.93 + uint32_t tokens[3]; 1.94 + tokens[0] = AI_HMP_MAGIC_NUMBER_LE_4; 1.95 + tokens[1] = AI_HMP_MAGIC_NUMBER_LE_5; 1.96 + tokens[2] = AI_HMP_MAGIC_NUMBER_LE_7; 1.97 + return CheckMagicToken(pIOHandler,pFile,tokens,3,0); 1.98 + } 1.99 + return false; 1.100 +} 1.101 + 1.102 +// ------------------------------------------------------------------------------------------------ 1.103 +// Get list of all file extensions that are handled by this loader 1.104 +const aiImporterDesc* HMPImporter::GetInfo () const 1.105 +{ 1.106 + return &desc; 1.107 +} 1.108 + 1.109 +// ------------------------------------------------------------------------------------------------ 1.110 +// Imports the given file into the given scene structure. 1.111 +void HMPImporter::InternReadFile( const std::string& pFile, 1.112 + aiScene* _pScene, IOSystem* _pIOHandler) 1.113 +{ 1.114 + pScene = _pScene; 1.115 + pIOHandler = _pIOHandler; 1.116 + boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile)); 1.117 + 1.118 + // Check whether we can read from the file 1.119 + if( file.get() == NULL) 1.120 + throw DeadlyImportError( "Failed to open HMP file " + pFile + "."); 1.121 + 1.122 + // Check whether the HMP file is large enough to contain 1.123 + // at least the file header 1.124 + const size_t fileSize = file->FileSize(); 1.125 + if( fileSize < 50) 1.126 + throw DeadlyImportError( "HMP File is too small."); 1.127 + 1.128 + // Allocate storage and copy the contents of the file to a memory buffer 1.129 + std::vector<uint8_t> buffer(fileSize); 1.130 + mBuffer = &buffer[0]; 1.131 + file->Read( (void*)mBuffer, 1, fileSize); 1.132 + iFileSize = (unsigned int)fileSize; 1.133 + 1.134 + // Determine the file subtype and call the appropriate member function 1.135 + const uint32_t iMagic = *((uint32_t*)this->mBuffer); 1.136 + 1.137 + // HMP4 format 1.138 + if (AI_HMP_MAGIC_NUMBER_LE_4 == iMagic || 1.139 + AI_HMP_MAGIC_NUMBER_BE_4 == iMagic) 1.140 + { 1.141 + DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A4, magic word is HMP4"); 1.142 + InternReadFile_HMP4(); 1.143 + } 1.144 + // HMP5 format 1.145 + else if (AI_HMP_MAGIC_NUMBER_LE_5 == iMagic || 1.146 + AI_HMP_MAGIC_NUMBER_BE_5 == iMagic) 1.147 + { 1.148 + DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A5, magic word is HMP5"); 1.149 + InternReadFile_HMP5(); 1.150 + } 1.151 + // HMP7 format 1.152 + else if (AI_HMP_MAGIC_NUMBER_LE_7 == iMagic || 1.153 + AI_HMP_MAGIC_NUMBER_BE_7 == iMagic) 1.154 + { 1.155 + DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A7, magic word is HMP7"); 1.156 + InternReadFile_HMP7(); 1.157 + } 1.158 + else 1.159 + { 1.160 + // Print the magic word to the logger 1.161 + char szBuffer[5]; 1.162 + szBuffer[0] = ((char*)&iMagic)[0]; 1.163 + szBuffer[1] = ((char*)&iMagic)[1]; 1.164 + szBuffer[2] = ((char*)&iMagic)[2]; 1.165 + szBuffer[3] = ((char*)&iMagic)[3]; 1.166 + szBuffer[4] = '\0'; 1.167 + 1.168 + // We're definitely unable to load this file 1.169 + throw DeadlyImportError( "Unknown HMP subformat " + pFile + 1.170 + ". Magic word (" + szBuffer + ") is not known"); 1.171 + } 1.172 + 1.173 + // Set the AI_SCENE_FLAGS_TERRAIN bit 1.174 + pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN; 1.175 + 1.176 + // File buffer destructs automatically now 1.177 +} 1.178 + 1.179 +// ------------------------------------------------------------------------------------------------ 1.180 +void HMPImporter::ValidateHeader_HMP457( ) 1.181 +{ 1.182 + const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer; 1.183 + 1.184 + if (120 > iFileSize) 1.185 + { 1.186 + throw DeadlyImportError("HMP file is too small (header size is " 1.187 + "120 bytes, this file is smaller)"); 1.188 + } 1.189 + 1.190 + if (!pcHeader->ftrisize_x || !pcHeader->ftrisize_y) 1.191 + throw DeadlyImportError("Size of triangles in either x or y direction is zero"); 1.192 + 1.193 + if(pcHeader->fnumverts_x < 1.0f || (pcHeader->numverts/pcHeader->fnumverts_x) < 1.0f) 1.194 + throw DeadlyImportError("Number of triangles in either x or y direction is zero"); 1.195 + 1.196 + if(!pcHeader->numframes) 1.197 + throw DeadlyImportError("There are no frames. At least one should be there"); 1.198 + 1.199 +} 1.200 + 1.201 +// ------------------------------------------------------------------------------------------------ 1.202 +void HMPImporter::InternReadFile_HMP4( ) 1.203 +{ 1.204 + throw DeadlyImportError("HMP4 is currently not supported"); 1.205 +} 1.206 + 1.207 +// ------------------------------------------------------------------------------------------------ 1.208 +void HMPImporter::InternReadFile_HMP5( ) 1.209 +{ 1.210 + // read the file header and skip everything to byte 84 1.211 + const HMP::Header_HMP5* pcHeader = (const HMP::Header_HMP5*)mBuffer; 1.212 + const unsigned char* szCurrent = (const unsigned char*)(mBuffer+84); 1.213 + ValidateHeader_HMP457(); 1.214 + 1.215 + // generate an output mesh 1.216 + pScene->mNumMeshes = 1; 1.217 + pScene->mMeshes = new aiMesh*[1]; 1.218 + aiMesh* pcMesh = pScene->mMeshes[0] = new aiMesh(); 1.219 + 1.220 + pcMesh->mMaterialIndex = 0; 1.221 + pcMesh->mVertices = new aiVector3D[pcHeader->numverts]; 1.222 + pcMesh->mNormals = new aiVector3D[pcHeader->numverts]; 1.223 + 1.224 + const unsigned int height = (unsigned int)(pcHeader->numverts / pcHeader->fnumverts_x); 1.225 + const unsigned int width = (unsigned int)pcHeader->fnumverts_x; 1.226 + 1.227 + // generate/load a material for the terrain 1.228 + CreateMaterial(szCurrent,&szCurrent); 1.229 + 1.230 + // goto offset 120, I don't know why ... 1.231 + // (fixme) is this the frame header? I assume yes since it starts with 2. 1.232 + szCurrent += 36; 1.233 + SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width); 1.234 + 1.235 + // now load all vertices from the file 1.236 + aiVector3D* pcVertOut = pcMesh->mVertices; 1.237 + aiVector3D* pcNorOut = pcMesh->mNormals; 1.238 + const HMP::Vertex_HMP5* src = (const HMP::Vertex_HMP5*) szCurrent; 1.239 + for (unsigned int y = 0; y < height;++y) 1.240 + { 1.241 + for (unsigned int x = 0; x < width;++x) 1.242 + { 1.243 + pcVertOut->x = x * pcHeader->ftrisize_x; 1.244 + pcVertOut->y = y * pcHeader->ftrisize_y; 1.245 + pcVertOut->z = (((float)src->z / 0xffff)-0.5f) * pcHeader->ftrisize_x * 8.0f; 1.246 + MD2::LookupNormalIndex(src->normals162index, *pcNorOut ); 1.247 + ++pcVertOut;++pcNorOut;++src; 1.248 + } 1.249 + } 1.250 + 1.251 + // generate texture coordinates if necessary 1.252 + if (pcHeader->numskins) 1.253 + GenerateTextureCoords(width,height); 1.254 + 1.255 + // now build a list of faces 1.256 + CreateOutputFaceList(width,height); 1.257 + 1.258 + // there is no nodegraph in HMP files. Simply assign the one mesh 1.259 + // (no, not the one ring) to the root node 1.260 + pScene->mRootNode = new aiNode(); 1.261 + pScene->mRootNode->mName.Set("terrain_root"); 1.262 + pScene->mRootNode->mNumMeshes = 1; 1.263 + pScene->mRootNode->mMeshes = new unsigned int[1]; 1.264 + pScene->mRootNode->mMeshes[0] = 0; 1.265 +} 1.266 + 1.267 +// ------------------------------------------------------------------------------------------------ 1.268 +void HMPImporter::InternReadFile_HMP7( ) 1.269 +{ 1.270 + // read the file header and skip everything to byte 84 1.271 + const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer; 1.272 + const unsigned char* szCurrent = (const unsigned char*)(mBuffer+84); 1.273 + ValidateHeader_HMP457(); 1.274 + 1.275 + // generate an output mesh 1.276 + pScene->mNumMeshes = 1; 1.277 + pScene->mMeshes = new aiMesh*[1]; 1.278 + aiMesh* pcMesh = pScene->mMeshes[0] = new aiMesh(); 1.279 + 1.280 + pcMesh->mMaterialIndex = 0; 1.281 + pcMesh->mVertices = new aiVector3D[pcHeader->numverts]; 1.282 + pcMesh->mNormals = new aiVector3D[pcHeader->numverts]; 1.283 + 1.284 + const unsigned int height = (unsigned int)(pcHeader->numverts / pcHeader->fnumverts_x); 1.285 + const unsigned int width = (unsigned int)pcHeader->fnumverts_x; 1.286 + 1.287 + // generate/load a material for the terrain 1.288 + CreateMaterial(szCurrent,&szCurrent); 1.289 + 1.290 + // goto offset 120, I don't know why ... 1.291 + // (fixme) is this the frame header? I assume yes since it starts with 2. 1.292 + szCurrent += 36; 1.293 + 1.294 + SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width); 1.295 + 1.296 + // now load all vertices from the file 1.297 + aiVector3D* pcVertOut = pcMesh->mVertices; 1.298 + aiVector3D* pcNorOut = pcMesh->mNormals; 1.299 + const HMP::Vertex_HMP7* src = (const HMP::Vertex_HMP7*) szCurrent; 1.300 + for (unsigned int y = 0; y < height;++y) 1.301 + { 1.302 + for (unsigned int x = 0; x < width;++x) 1.303 + { 1.304 + pcVertOut->x = x * pcHeader->ftrisize_x; 1.305 + pcVertOut->y = y * pcHeader->ftrisize_y; 1.306 + 1.307 + // FIXME: What exctly is the correct scaling factor to use? 1.308 + // possibly pcHeader->scale_origin[2] in combination with a 1.309 + // signed interpretation of src->z? 1.310 + pcVertOut->z = (((float)src->z / 0xffff)-0.5f) * pcHeader->ftrisize_x * 8.0f; 1.311 + 1.312 + pcNorOut->x = ((float)src->normal_x / 0x80 ); // * pcHeader->scale_origin[0]; 1.313 + pcNorOut->y = ((float)src->normal_y / 0x80 ); // * pcHeader->scale_origin[1]; 1.314 + pcNorOut->z = 1.0f; 1.315 + pcNorOut->Normalize(); 1.316 + 1.317 + ++pcVertOut;++pcNorOut;++src; 1.318 + } 1.319 + } 1.320 + 1.321 + // generate texture coordinates if necessary 1.322 + if (pcHeader->numskins)GenerateTextureCoords(width,height); 1.323 + 1.324 + // now build a list of faces 1.325 + CreateOutputFaceList(width,height); 1.326 + 1.327 + // there is no nodegraph in HMP files. Simply assign the one mesh 1.328 + // (no, not the One Ring) to the root node 1.329 + pScene->mRootNode = new aiNode(); 1.330 + pScene->mRootNode->mName.Set("terrain_root"); 1.331 + pScene->mRootNode->mNumMeshes = 1; 1.332 + pScene->mRootNode->mMeshes = new unsigned int[1]; 1.333 + pScene->mRootNode->mMeshes[0] = 0; 1.334 +} 1.335 + 1.336 +// ------------------------------------------------------------------------------------------------ 1.337 +void HMPImporter::CreateMaterial(const unsigned char* szCurrent, 1.338 + const unsigned char** szCurrentOut) 1.339 +{ 1.340 + aiMesh* const pcMesh = pScene->mMeshes[0]; 1.341 + const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer; 1.342 + 1.343 + // we don't need to generate texture coordinates if 1.344 + // we have no textures in the file ... 1.345 + if (pcHeader->numskins) 1.346 + { 1.347 + pcMesh->mTextureCoords[0] = new aiVector3D[pcHeader->numverts]; 1.348 + pcMesh->mNumUVComponents[0] = 2; 1.349 + 1.350 + // now read the first skin and skip all others 1.351 + ReadFirstSkin(pcHeader->numskins,szCurrent,&szCurrent); 1.352 + } 1.353 + else 1.354 + { 1.355 + // generate a default material 1.356 + const int iMode = (int)aiShadingMode_Gouraud; 1.357 + aiMaterial* pcHelper = new aiMaterial(); 1.358 + pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL); 1.359 + 1.360 + aiColor3D clr; 1.361 + clr.b = clr.g = clr.r = 0.6f; 1.362 + pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE); 1.363 + pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR); 1.364 + 1.365 + clr.b = clr.g = clr.r = 0.05f; 1.366 + pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT); 1.367 + 1.368 + aiString szName; 1.369 + szName.Set(AI_DEFAULT_MATERIAL_NAME); 1.370 + pcHelper->AddProperty(&szName,AI_MATKEY_NAME); 1.371 + 1.372 + // add the material to the scene 1.373 + pScene->mNumMaterials = 1; 1.374 + pScene->mMaterials = new aiMaterial*[1]; 1.375 + pScene->mMaterials[0] = pcHelper; 1.376 + } 1.377 + *szCurrentOut = szCurrent; 1.378 +} 1.379 + 1.380 +// ------------------------------------------------------------------------------------------------ 1.381 +void HMPImporter::CreateOutputFaceList(unsigned int width,unsigned int height) 1.382 +{ 1.383 + aiMesh* const pcMesh = this->pScene->mMeshes[0]; 1.384 + 1.385 + // Allocate enough storage 1.386 + pcMesh->mNumFaces = (width-1) * (height-1); 1.387 + pcMesh->mFaces = new aiFace[pcMesh->mNumFaces]; 1.388 + 1.389 + pcMesh->mNumVertices = pcMesh->mNumFaces*4; 1.390 + aiVector3D* pcVertices = new aiVector3D[pcMesh->mNumVertices]; 1.391 + aiVector3D* pcNormals = new aiVector3D[pcMesh->mNumVertices]; 1.392 + 1.393 + aiFace* pcFaceOut(pcMesh->mFaces); 1.394 + aiVector3D* pcVertOut = pcVertices; 1.395 + aiVector3D* pcNorOut = pcNormals; 1.396 + 1.397 + aiVector3D* pcUVs = pcMesh->mTextureCoords[0] ? new aiVector3D[pcMesh->mNumVertices] : NULL; 1.398 + aiVector3D* pcUVOut(pcUVs); 1.399 + 1.400 + // Build the terrain square 1.401 + unsigned int iCurrent = 0; 1.402 + for (unsigned int y = 0; y < height-1;++y) { 1.403 + for (unsigned int x = 0; x < width-1;++x,++pcFaceOut) { 1.404 + pcFaceOut->mNumIndices = 4; 1.405 + pcFaceOut->mIndices = new unsigned int[4]; 1.406 + 1.407 + *pcVertOut++ = pcMesh->mVertices[y*width+x]; 1.408 + *pcVertOut++ = pcMesh->mVertices[(y+1)*width+x]; 1.409 + *pcVertOut++ = pcMesh->mVertices[(y+1)*width+x+1]; 1.410 + *pcVertOut++ = pcMesh->mVertices[y*width+x+1]; 1.411 + 1.412 + 1.413 + *pcNorOut++ = pcMesh->mNormals[y*width+x]; 1.414 + *pcNorOut++ = pcMesh->mNormals[(y+1)*width+x]; 1.415 + *pcNorOut++ = pcMesh->mNormals[(y+1)*width+x+1]; 1.416 + *pcNorOut++ = pcMesh->mNormals[y*width+x+1]; 1.417 + 1.418 + if (pcMesh->mTextureCoords[0]) 1.419 + { 1.420 + *pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x]; 1.421 + *pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x]; 1.422 + *pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x+1]; 1.423 + *pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x+1]; 1.424 + } 1.425 + 1.426 + for (unsigned int i = 0; i < 4;++i) 1.427 + pcFaceOut->mIndices[i] = iCurrent++; 1.428 + } 1.429 + } 1.430 + delete[] pcMesh->mVertices; 1.431 + pcMesh->mVertices = pcVertices; 1.432 + 1.433 + delete[] pcMesh->mNormals; 1.434 + pcMesh->mNormals = pcNormals; 1.435 + 1.436 + if (pcMesh->mTextureCoords[0]) 1.437 + { 1.438 + delete[] pcMesh->mTextureCoords[0]; 1.439 + pcMesh->mTextureCoords[0] = pcUVs; 1.440 + } 1.441 +} 1.442 + 1.443 +// ------------------------------------------------------------------------------------------------ 1.444 +void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szCursor, 1.445 + const unsigned char** szCursorOut) 1.446 +{ 1.447 + ai_assert(0 != iNumSkins && NULL != szCursor); 1.448 + 1.449 + // read the type of the skin ... 1.450 + // sometimes we need to skip 12 bytes here, I don't know why ... 1.451 + uint32_t iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t); 1.452 + if (0 == iType) 1.453 + { 1.454 + szCursor += sizeof(uint32_t) * 2; 1.455 + iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t); 1.456 + if (!iType) 1.457 + throw DeadlyImportError("Unable to read HMP7 skin chunk"); 1.458 + 1.459 + } 1.460 + // read width and height 1.461 + uint32_t iWidth = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t); 1.462 + uint32_t iHeight = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t); 1.463 + 1.464 + // allocate an output material 1.465 + aiMaterial* pcMat = new aiMaterial(); 1.466 + 1.467 + // read the skin, this works exactly as for MDL7 1.468 + ParseSkinLump_3DGS_MDL7(szCursor,&szCursor, 1.469 + pcMat,iType,iWidth,iHeight); 1.470 + 1.471 + // now we need to skip any other skins ... 1.472 + for (unsigned int i = 1; i< iNumSkins;++i) 1.473 + { 1.474 + iType = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t); 1.475 + iWidth = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t); 1.476 + iHeight = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t); 1.477 + 1.478 + SkipSkinLump_3DGS_MDL7(szCursor,&szCursor,iType,iWidth,iHeight); 1.479 + SizeCheck(szCursor); 1.480 + } 1.481 + 1.482 + // setup the material ... 1.483 + pScene->mNumMaterials = 1; 1.484 + pScene->mMaterials = new aiMaterial*[1]; 1.485 + pScene->mMaterials[0] = pcMat; 1.486 + 1.487 + *szCursorOut = szCursor; 1.488 +} 1.489 + 1.490 +// ------------------------------------------------------------------------------------------------ 1.491 +// Generate proepr texture coords 1.492 +void HMPImporter::GenerateTextureCoords( 1.493 + const unsigned int width, const unsigned int height) 1.494 +{ 1.495 + ai_assert(NULL != pScene->mMeshes && NULL != pScene->mMeshes[0] && 1.496 + NULL != pScene->mMeshes[0]->mTextureCoords[0]); 1.497 + 1.498 + aiVector3D* uv = pScene->mMeshes[0]->mTextureCoords[0]; 1.499 + 1.500 + const float fY = (1.0f / height) + (1.0f / height) / (height-1); 1.501 + const float fX = (1.0f / width) + (1.0f / width) / (width-1); 1.502 + 1.503 + for (unsigned int y = 0; y < height;++y) { 1.504 + for (unsigned int x = 0; x < width;++x,++uv) { 1.505 + uv->y = fY*y; 1.506 + uv->x = fX*x; 1.507 + uv->z = 0.0f; 1.508 + } 1.509 + } 1.510 +} 1.511 + 1.512 +#endif // !! ASSIMP_BUILD_NO_HMP_IMPORTER