From 1bdeffc7ed9d1826d681e2aed363951848dbeebb Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 24 May 2022 10:24:15 +0800 Subject: [PATCH] Convert b3d to GE spm --- src/graphics/b3d_mesh_loader.cpp | 40 ++++++++++++++++++++++++++---- src/graphics/sp/sp_mesh_buffer.cpp | 8 ++++++ src/graphics/sp/sp_mesh_buffer.hpp | 10 ++++++++ src/tracks/track.cpp | 7 +++++- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/graphics/b3d_mesh_loader.cpp b/src/graphics/b3d_mesh_loader.cpp index 3fbd26f97..4f0f3c906 100644 --- a/src/graphics/b3d_mesh_loader.cpp +++ b/src/graphics/b3d_mesh_loader.cpp @@ -5,6 +5,7 @@ #include "graphics/b3d_mesh_loader.hpp" #include "graphics/central_settings.hpp" #include "graphics/stk_tex_manager.hpp" +#include "graphics/material.hpp" #include "graphics/material_manager.hpp" #include "graphics/mesh_tools.hpp" #include "graphics/sp/sp_animation.hpp" @@ -18,6 +19,12 @@ #include +#ifndef SERVER_ONLY +#include +#include +#include +#endif + int B3DMeshLoader::m_straight_frame = 0; #undef _B3D_READER_DEBUG @@ -76,7 +83,8 @@ scene::IAnimatedMesh* B3DMeshLoader::createMesh(io::IReadFile* f) } #ifndef SERVER_ONLY - if (CVS->isGLSL()) + bool convert_spm = CVS->isGLSL() || GE::getVKDriver() != NULL; + if (convert_spm) { if (!AnimatedMesh) { @@ -86,8 +94,30 @@ scene::IAnimatedMesh* B3DMeshLoader::createMesh(io::IReadFile* f) SP::SPMesh* spm = toSPM(static_cast (AnimatedMesh->getMesh(m_straight_frame))); m_texture_string.clear(); - spm->setMinMax(min.toIrrVector(), max.toIrrVector()); - return spm; + if (CVS->isGLSL()) + { + spm->finalize(); + spm->setMinMax(min.toIrrVector(), max.toIrrVector()); + return spm; + } + GE::GESPM* ge_spm = new GE::GESPM(); + for (unsigned i = 0; i < spm->getMeshBufferCount(); i++) + { + SP::SPMeshBuffer* spbuf = spm->getSPMeshBuffer(i); + GE::GESPMBuffer* gebuf = new GE::GESPMBuffer(); + ge_spm->m_buffer.push_back(gebuf); + std::swap(gebuf->m_vertices, spbuf->getVerticesRef()); + std::swap(gebuf->m_indices, spbuf->getIndicesRef()); + Material* stk_material = spbuf->getSTKMaterial(0); + stk_material->setMaterialProperties(&gebuf->getMaterial(), gebuf); + gebuf->getMaterial().TextureLayer[0].Texture = + stk_material->getTexture(); + gebuf->recalculateBoundingBox(); + } + ge_spm->finalize(); + ge_spm->setMinMax(min.toIrrVector(), max.toIrrVector()); + spm->drop(); + return ge_spm; } #endif @@ -255,7 +285,6 @@ SP::SPMesh* B3DMeshLoader::toSPM(scene::CSkinnedMesh* mesh) } } - spm->finalize(); mesh->drop(); return spm; } @@ -1311,7 +1340,8 @@ void B3DMeshLoader::loadTextures(SB3dMaterial& material, scene::IMeshBuffer* mb) full_path = fs->getFileBasename(B3dTexture->TextureName); #ifndef SERVER_ONLY - if (CVS->isGLSL()) + bool convert_spm = CVS->isGLSL() || GE::getVKDriver() != NULL; + if (convert_spm) { auto& ret = m_texture_string[mb]; if (i == 0) diff --git a/src/graphics/sp/sp_mesh_buffer.cpp b/src/graphics/sp/sp_mesh_buffer.cpp index 8e2a73c0e..e05c33a9a 100644 --- a/src/graphics/sp/sp_mesh_buffer.cpp +++ b/src/graphics/sp/sp_mesh_buffer.cpp @@ -28,6 +28,9 @@ #include "utils/string_utils.hpp" #include +#ifndef SERVER_ONLY +#include +#endif namespace SP { @@ -471,6 +474,11 @@ void SPMeshBuffer::reloadTextureCompare() void SPMeshBuffer::setSTKMaterial(Material* m) { m_stk_material[0] = std::make_tuple(0u, getIndexCount(), m); +#ifndef SERVER_ONLY + // Used by b3d mesh loader, clean up later after SP is removed + if (GE::getVKDriver() != NULL) + return; +#endif const std::string shader_name = std::get<2>(m_stk_material[0])->getShaderName(); const std::string skinned_shader_name = diff --git a/src/graphics/sp/sp_mesh_buffer.hpp b/src/graphics/sp/sp_mesh_buffer.hpp index 1fbfbff7b..e0ae65d11 100644 --- a/src/graphics/sp/sp_mesh_buffer.hpp +++ b/src/graphics/sp/sp_mesh_buffer.hpp @@ -308,6 +308,11 @@ public: return m_vertices.data(); } // ------------------------------------------------------------------------ + std::vector& getVerticesRef() + { + return m_vertices; + } + // ------------------------------------------------------------------------ virtual u32 getVertexCount() const { return (unsigned)m_vertices.size(); @@ -318,6 +323,11 @@ public: return video::EIT_16BIT; } // ------------------------------------------------------------------------ + std::vector& getIndicesRef() + { + return m_indices; + } + // ------------------------------------------------------------------------ virtual const u16* getIndices() const { return m_indices.data(); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index f0fbcbcb4..2a9c9088c 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1245,13 +1245,18 @@ bool Track::loadMainTrack(const XMLNode &root) "Main track model '%s' in '%s' not found, aborting.\n", track_node->getName().c_str(), model_name.c_str()); } + scene::IAnimatedMesh* an_mesh = dynamic_cast(mesh); + bool ge_spm = false; + if (an_mesh && an_mesh->getMeshType() == scene::EAMT_SPM) + ge_spm = true; scene::ISceneNode* scene_node = NULL; scene::IMesh* tangent_mesh = NULL; #ifdef SERVER_ONLY if (false) #else - if (m_version < 7 && !CVS->isGLSL() && !GUIEngine::isNoGraphics()) + if (m_version < 7 && !CVS->isGLSL() && !GUIEngine::isNoGraphics() && + !ge_spm) #endif { // The mesh as returned does not have all mesh buffers with the same