From 063297b5b67ce2e285f94ce1201b3037c30498fd Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Thu, 30 May 2024 20:06:45 +0200 Subject: [PATCH] load mtxf ADT chunk, no saving/usage yet. credit Adspartan --- src/noggit/MapHeaders.h | 14 +++++++++- src/noggit/MapTile.cpp | 51 ++++++++++++++++++------------------- src/noggit/MapTile.h | 1 + src/noggit/TextureManager.h | 1 + src/noggit/texture_set.cpp | 10 +++++++- 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/noggit/MapHeaders.h b/src/noggit/MapHeaders.h index 43386995..f8512e84 100755 --- a/src/noggit/MapHeaders.h +++ b/src/noggit/MapHeaders.h @@ -74,7 +74,7 @@ struct MHDR /*020h*/ uint32_t modf; //WMO Positioning Information /*024h*/ uint32_t mfbo; // tbc, wotlk; only when flags&1 /*028h*/ uint32_t mh2o; // wotlk - /*02Ch*/ uint32_t mtfx; // wotlk + /*02Ch*/ uint32_t mtxf; // wotlk /*030h*/ uint32_t pad4; /*034h*/ uint32_t pad5; /*038h*/ uint32_t pad6; @@ -300,3 +300,15 @@ struct MPHD uint32_t something; uint32_t unused[6]; }; + +struct mtxf_entry +{ + uint32_t use_cubemap : 1; // do_not_load_specular_or_height_texture_but_use_cubemap + /* + uint32_t : 3; + uint32_t texture_scale : 4; // MOP+ Texture scale here is not an actual "scale". + // Default value is 0 (no extra scaling applied). The values are computed as 1 << SMTextureFlags.texture_scale. + uint32_t : 24; + */ + uint32_t unused : 31; +}; \ No newline at end of file diff --git a/src/noggit/MapTile.cpp b/src/noggit/MapTile.cpp index 9a445b23..73676990 100755 --- a/src/noggit/MapTile.cpp +++ b/src/noggit/MapTile.cpp @@ -125,6 +125,8 @@ void MapTile::finishLoading() std::vector mModelFilenames; std::vector mWMOFilenames; + // std::map _mtxf_entries; + uint32_t fourcc; uint32_t size; @@ -302,34 +304,30 @@ void MapTile::finishLoading() } } - // - MTFX ---------------------------------------------- - /* - //! \todo Implement this or just use Terrain Cube maps? - Log << "MTFX offs: " << Header.mtfx << std::endl; - if(Header.mtfx != 0){ - Log << "Try to load MTFX" << std::endl; - theFile.seek( Header.mtfx + 0x14 ); - - theFile.read( &fourcc, 4 ); - theFile.read( &size, 4 ); - - assert( fourcc == 'MTFX' ); - - + // - MTXF ---------------------------------------------- + if (Header.mtxf != 0) { - char* lCurPos = reinterpret_cast( theFile.getPointer() ); - char* lEnd = lCurPos + size; - int tCount = 0; - while( lCurPos < lEnd ) { - int temp = 0; - theFile.read(&temp, 4); - Log << "Adding to " << mTextureFilenames[tCount].first << " texture effect: " << temp << std::endl; - mTextureFilenames[tCount++].second = temp; - lCurPos += 4; - } - } + theFile.seek(Header.mtxf + 0x14); - }*/ + theFile.read(&fourcc, 4); + theFile.read(&size, 4); + + assert(fourcc == 'MTXF'); + + int count = size / 0x4; + + std::vector mtxf_data(count); + + theFile.read(mtxf_data.data(), size); + + for (int i = 0; i < count; ++i) + { + // _mtxf_entries[mTextureFilenames[i]] = mtxf_data[i]; + // only save those with flags set + if (mtxf_data[i].use_cubemap) + _mtxf_entries[mTextureFilenames[i]] = mtxf_data[i]; + } + } // - Done. --------------------------------------------- @@ -374,6 +372,7 @@ void MapTile::finishLoading() } // can be cleared after texture sets are loaded in chunks. mTextureFilenames.clear(); + _mtxf_entries.clear(); theFile.close(); diff --git a/src/noggit/MapTile.h b/src/noggit/MapTile.h index 210488af..39f661cf 100755 --- a/src/noggit/MapTile.h +++ b/src/noggit/MapTile.h @@ -199,6 +199,7 @@ private: std::vector mTextureFilenames; // std::vector mModelFilenames; // std::vector mWMOFilenames; + std::map _mtxf_entries; std::vector uids; tsl::robin_map> object_instances; // only includes M2 and WMO. perhaps a medium common ancestor then? diff --git a/src/noggit/TextureManager.h b/src/noggit/TextureManager.h index 4b7b8030..7693f656 100755 --- a/src/noggit/TextureManager.h +++ b/src/noggit/TextureManager.h @@ -128,6 +128,7 @@ struct scoped_blp_texture_reference bool operator== (scoped_blp_texture_reference const& other) const; + bool use_cubemap = false; private: struct Deleter { diff --git a/src/noggit/texture_set.cpp b/src/noggit/texture_set.cpp index 1170ab4e..02d12e96 100755 --- a/src/noggit/texture_set.cpp +++ b/src/noggit/texture_set.cpp @@ -34,7 +34,15 @@ TextureSet::TextureSet (MapChunk* chunk, BlizzardArchive::ClientFile* f, size_t { f->read (&tmp_entry_mcly[i], sizeof(ENTRY_MCLY)); // f->read (&_layers_info[i], sizeof(ENTRY_MCLY)); - textures.emplace_back (tile->mTextureFilenames[tmp_entry_mcly[i].textureID], _context); + std::string const& texturefilename = tile->mTextureFilenames[tmp_entry_mcly[i].textureID]; + textures.emplace_back (texturefilename, _context); + + if (tile->_mtxf_entries.contains(texturefilename)) + { + if (tile->_mtxf_entries[texturefilename].use_cubemap) + textures.back().use_cubemap = true; + } + _layers_info[i].effectID = tmp_entry_mcly[i].effectID; _layers_info[i].flags = tmp_entry_mcly[i].flags; }