diff --git a/MshViewer/Header/Texture.h b/MshViewer/Header/Texture.h index ad193d1..cd56653 100644 --- a/MshViewer/Header/Texture.h +++ b/MshViewer/Header/Texture.h @@ -9,22 +9,13 @@ public: ~TextureTGA(); private: - std::vector vui8Pixels; - bool bCompressed; - std::uint32_t ui32IDLength; - bool bColorTabel; - std::uint32_t ui32PicType; - std::uint32_t ui32PaletteBegin; - std::uint32_t ui32PaletteLength; - std::uint32_t ui32PaletteBpP; + std::vector* vui8Pixels; + std::uint32_t ui32BpP; std::uint32_t ui32Width; std::uint32_t ui32Height; - std::uint32_t ui32Size; - std::uint32_t ui32BpP; - std::uint32_t ui32Attribut; public: - std::vector getData() const; + std::vector* getData() const; bool hasAlpha() const; std::uint32_t getWidth() const; std::uint32_t getHeight() const; diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index e1fee88..cb01b83 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -329,6 +329,21 @@ void Object::analyseGeomChunks(Modl * dataDestination, std::list& { for (std::list::iterator it = chunkList.begin(); it != chunkList.end(); it++) { + if (!strcmp("BBOX", (*it)->name)) + { + fsMesh.seekg((*it)->position); + std::uint32_t tempValue; + fsMesh.read(reinterpret_cast(&tempValue), sizeof(tempValue)); + + /* + float[4] 16 Quaternion Rotation in XYZW. + float[3] 12 Center of the BBox. + float[3] 12 Extents of the BBox(width / 2, height / 2, depth / 2). + float 4 Bounding sphere radius.*/ + + continue; + } + if (!strcmp("SEGM", (*it)->name)) { // get all subchunks diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index b2e221a..24a1174 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -455,7 +455,7 @@ void OpenGLController::loadMsh(const char * path) tempData->alpha = tempTex.hasAlpha(); tempData->width = tempTex.getWidth(); tempData->height = tempTex.getHeight(); - tempData->data = new std::vector(tempTex.getData()); + tempData->data = tempTex.getData(); } catch (std::invalid_argument e) { diff --git a/MshViewer/Source/Texture.cpp b/MshViewer/Source/Texture.cpp index 0ba4b84..9ed6ff3 100644 --- a/MshViewer/Source/Texture.cpp +++ b/MshViewer/Source/Texture.cpp @@ -13,35 +13,26 @@ TextureTGA::TextureTGA(const char * filePath) std::uint8_t ui8x18Header[19] = { 0 }; fsPicture.read(reinterpret_cast(&ui8x18Header), sizeof(ui8x18Header)-1); + //get variables + vui8Pixels = new std::vector; + bool bCompressed; + std::uint32_t ui32IDLength; + std::uint32_t ui32PicType; + std::uint32_t ui32PaletteLength; + std::uint32_t ui32Size; + // extract all information from header ui32IDLength = ui8x18Header[0]; - bColorTabel = ui8x18Header[1] == 1; ui32PicType = ui8x18Header[2]; - ui32PaletteBegin = ui8x18Header[4] * 0x100 + ui8x18Header[3]; ui32PaletteLength = ui8x18Header[6] * 0x100 + ui8x18Header[5]; - ui32PaletteBpP = ui8x18Header[7]; ui32Width = ui8x18Header[13] * 0x100 + ui8x18Header[12]; ui32Height = ui8x18Header[15] * 0x100 + ui8x18Header[14]; ui32BpP = ui8x18Header[16]; - ui32Attribut = ui8x18Header[17]; // calculate some more information ui32Size = ui32Width * ui32Height * ui32BpP/8; bCompressed = ui32PicType == 9 || ui32PicType == 10; - vui8Pixels.resize(ui32Size); - - /* consol output of the header - std::cout << "Header\n" - << "ID länge: " << ui32IDLength << std::endl - << "Farbtabelle: " << (int)bColorTabel << std::endl - << "Bildtype: " << ui32PicType << std::endl - << "Palletenbegin: " << ui32PaletteBegin << std::endl - << "Palletenlängen: " << ui32PaletteLength << std::endl - << "Bits pro Palleteneintrag: " << ui32PaletteBpP << std::endl - << "Breite: " << ui32Width << std::endl - << "Höhe: " << ui32Height << std::endl - << "Bit pro Pixel: " << ui32BpP << std::endl - << "Bild Attribute: " << ui32Attribut << std::endl;*/ + vui8Pixels->resize(ui32Size); // jump to the data block fsPicture.seekg(ui32IDLength + ui32PaletteLength, std::ios_base::cur); @@ -49,7 +40,7 @@ TextureTGA::TextureTGA(const char * filePath) // If not compressed 24 or 32 bit if (ui32PicType == 2 && (ui32BpP == 24 || ui32BpP == 32)) { - fsPicture.read(reinterpret_cast(vui8Pixels.data()), ui32Size); + fsPicture.read(reinterpret_cast(vui8Pixels->data()), ui32Size); } // else if compressed 24 or 32 bit else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed @@ -70,10 +61,10 @@ TextureTGA::TextureTGA(const char * filePath) for (int i = 0; i <= tempChunkHeader; i++) { - vui8Pixels[tempByteIndex++] = tempData[0]; - vui8Pixels[tempByteIndex++] = tempData[1]; - vui8Pixels[tempByteIndex++] = tempData[2]; - if(ui32BpP == 32) vui8Pixels[tempByteIndex++] = tempData[3]; + vui8Pixels->at(tempByteIndex++) = tempData[0]; + vui8Pixels->at(tempByteIndex++) = tempData[1]; + vui8Pixels->at(tempByteIndex++) = tempData[2]; + if(ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3]; } } else // data count @@ -85,10 +76,10 @@ TextureTGA::TextureTGA(const char * filePath) { fsPicture.read(reinterpret_cast(&tempData), ui32BpP/8); - vui8Pixels[tempByteIndex++] = tempData[0]; - vui8Pixels[tempByteIndex++] = tempData[1]; - vui8Pixels[tempByteIndex++] = tempData[2]; - if (ui32BpP == 32) vui8Pixels[tempByteIndex++] = tempData[3]; + vui8Pixels->at(tempByteIndex++) = tempData[0]; + vui8Pixels->at(tempByteIndex++) = tempData[1]; + vui8Pixels->at(tempByteIndex++) = tempData[2]; + if (ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3]; } } } while (tempByteIndex < ui32Size); @@ -105,10 +96,9 @@ TextureTGA::TextureTGA(const char * filePath) TextureTGA::~TextureTGA() { - vui8Pixels.clear(); } -std::vector TextureTGA::getData() const +std::vector* TextureTGA::getData() const { return vui8Pixels; }