diff --git a/src/SWBF2/Level.cpp b/src/SWBF2/Level.cpp index 432b0b1..72d3972 100644 --- a/src/SWBF2/Level.cpp +++ b/src/SWBF2/Level.cpp @@ -18,10 +18,10 @@ namespace SWBF2 SWBF2::Native::UcfbChunk::ReadUcfbFile("data/_lvl_pc/cor/cor1.lvl"); - LoadMeshes(); + LoadLevelMeshes(); } - void Level::LoadMeshes() + void Level::LoadLevelMeshes() { for (auto const &[id, model] : Native::Level::m_models) { @@ -65,27 +65,29 @@ namespace SWBF2 meshInstance->set_mesh(arrMesh); - auto tex_id = 0; - for (const auto &texName : segment.m_textureNames) + if (!segment.m_textureNames.empty()) { - if (texName.empty()) - continue; + static godot::Ref emptyGodotRef; - auto &material = m_materialPool.getItem(texName); - if (material.is_null()) - { - godot::UtilityFunctions::printerr(__FILE__, ":", __LINE__, ": No material found for ", texName.c_str()); - continue; - } + const auto &mainTextureName = segment.m_textureNames[Native::ModelSegment::TEXTURE_DEFAULT]; + const auto &bumpTextureName = segment.m_textureNames[Native::ModelSegment::TEXTURE_NORMAL]; - godot::UtilityFunctions::print(__FILE__, ":", __LINE__, ": Found texture ", texName.c_str(), " for mesh ", id.c_str(), " with segment id ", segment_id); + auto &material = m_materialPool.getItem(mainTextureName); + if (material.is_valid()) + { + if (!bumpTextureName.empty() && Native::Level::m_tex.contains(bumpTextureName)) + { + auto &bumpTexture = Native::Level::m_tex[bumpTextureName].m_formats[0].m_faceLevels[0].m_gdTexture; - if (segment.m_material.m_flags & Native::Material::MATERIAL_TRANSPARENT) - material->set_transparency(godot::BaseMaterial3D::TRANSPARENCY_ALPHA); + material->set_feature(godot::BaseMaterial3D::FEATURE_NORMAL_MAPPING, true); + material->set_texture(godot::BaseMaterial3D::TEXTURE_NORMAL, bumpTexture); + } - meshInstance->set_surface_override_material(tex_id, material); + if (segment.m_material.m_flags & Native::Material::MATERIAL_TRANSPARENT) + material->set_transparency(godot::BaseMaterial3D::TRANSPARENCY_ALPHA); - tex_id++; + meshInstance->set_surface_override_material(0, material); + } } if (meshInstance->get_material_override().is_null()) diff --git a/src/SWBF2/Level.hpp b/src/SWBF2/Level.hpp index 15c9d77..26ba238 100644 --- a/src/SWBF2/Level.hpp +++ b/src/SWBF2/Level.hpp @@ -19,7 +19,7 @@ namespace SWBF2 virtual void _ready() override; - void LoadMeshes(); + void LoadLevelMeshes(); void _process(double delta_time) override; diff --git a/src/SWBF2/Native/Models/ModelSegment.hpp b/src/SWBF2/Native/Models/ModelSegment.hpp index 5c03d06..d79aef3 100644 --- a/src/SWBF2/Native/Models/ModelSegment.hpp +++ b/src/SWBF2/Native/Models/ModelSegment.hpp @@ -61,6 +61,14 @@ namespace SWBF2::Native class ModelSegment { public: + enum TextureType + { + TEXTURE_DEFAULT = 0, + TEXTURE_NORMAL, + TEXTURE_UNK3, + TEXTURE_UNK4 + }; + ModelSegmentInfo m_info; Material m_material;