diff --git a/radiantcore/model/picomodel/AseModelLoader.cpp b/radiantcore/model/picomodel/AseModelLoader.cpp index 26aa9c5580..266bc14bb8 100644 --- a/radiantcore/model/picomodel/AseModelLoader.cpp +++ b/radiantcore/model/picomodel/AseModelLoader.cpp @@ -5,6 +5,8 @@ #include "string/case_conv.h" #include "StaticModel.h" +#include "PicoModelLoader.h" + extern "C" { extern const picoModule_t picoModuleASE; @@ -55,7 +57,9 @@ IModelPtr AseModelLoader::loadModelFromPath(const std::string& path) return IModelPtr(); } - auto modelObj = std::make_shared(model, string::to_lower_copy(getExtension())); + auto surfaces = PicoModelLoader::CreateSurfaces(model, string::to_lower_copy(getExtension())); + + auto modelObj = std::make_shared(surfaces); // Set the filename modelObj->setFilename(os::getFilename(file->getName())); diff --git a/radiantcore/model/picomodel/PicoModelLoader.cpp b/radiantcore/model/picomodel/PicoModelLoader.cpp index dbcb1a2af3..08249d9e57 100644 --- a/radiantcore/model/picomodel/PicoModelLoader.cpp +++ b/radiantcore/model/picomodel/PicoModelLoader.cpp @@ -11,6 +11,7 @@ #include "idatastream.h" #include "string/case_conv.h" #include "StaticModel.h" +#include "StaticModelSurface.h" namespace model { @@ -60,7 +61,10 @@ IModelPtr PicoModelLoader::loadModelFromPath(const std::string& path) return IModelPtr(); } - auto modelObj = std::make_shared(model, fExt); + // Convert the pico model surfaces to StaticModelSurfaces + auto surfaces = CreateSurfaces(model, fExt); + + auto modelObj = std::make_shared(surfaces); // Set the filename modelObj->setFilename(os::getFilename(file->getName())); @@ -71,4 +75,42 @@ IModelPtr PicoModelLoader::loadModelFromPath(const std::string& path) return modelObj; } +std::vector PicoModelLoader::CreateSurfaces(picoModel_t* picoModel, const std::string& extension) +{ + // Convert the pico model surfaces to StaticModelSurfaces + std::vector surfaces; + + // Get the number of surfaces to create + int nSurf = PicoGetModelNumSurfaces(picoModel); + + // Create a StaticModelSurface for each surface in the structure + for (int n = 0; n < nSurf; ++n) + { + // Retrieve the surface, discarding it if it is null or non-triangulated (?) + picoSurface_t* surf = PicoGetModelSurface(picoModel, n); + + auto rSurf = CreateSurface(surf, extension); + + if (!rSurf) continue; + + surfaces.emplace_back(rSurf); + } + + return surfaces; +} + +StaticModelSurfacePtr PicoModelLoader::CreateSurface(picoSurface_t* picoSurface, const std::string& extension) +{ + if (picoSurface == 0 || PicoGetSurfaceType(picoSurface) != PICO_TRIANGLES) + { + return StaticModelSurfacePtr(); + } + + // Fix the normals of the surface (?) + PicoFixSurfaceNormals(picoSurface); + + // Create the StaticModelSurface object and add it to the vector + return std::make_shared(picoSurface, extension); +} + } // namespace model diff --git a/radiantcore/model/picomodel/PicoModelLoader.h b/radiantcore/model/picomodel/PicoModelLoader.h index 4aa14fe29c..81532ce072 100644 --- a/radiantcore/model/picomodel/PicoModelLoader.h +++ b/radiantcore/model/picomodel/PicoModelLoader.h @@ -1,8 +1,11 @@ #pragma once #include "ModelImporterBase.h" +#include "StaticModel.h" typedef struct picoModule_s picoModule_t; +typedef struct picoSurface_s picoSurface_t; +typedef struct picoModel_s picoModel_t; namespace model { @@ -18,6 +21,12 @@ class PicoModelLoader : // Load the given model from the path, VFS or absolute IModelPtr loadModelFromPath(const std::string& name) override; + +public: + static std::vector CreateSurfaces(picoModel_t* picoModel, const std::string& extension); + +private: + static StaticModelSurfacePtr CreateSurface(picoSurface_t* picoSurface, const std::string& extension); }; } // namespace model diff --git a/radiantcore/model/picomodel/StaticModel.cpp b/radiantcore/model/picomodel/StaticModel.cpp index dbbdf0dffd..2970b62903 100644 --- a/radiantcore/model/picomodel/StaticModel.cpp +++ b/radiantcore/model/picomodel/StaticModel.cpp @@ -15,36 +15,6 @@ namespace model { -StaticModel::StaticModel(picoModel_t* mod, const std::string& fExt) : - StaticModel(std::vector{}) -{ - // Get the number of surfaces to create - int nSurf = PicoGetModelNumSurfaces(mod); - - // Create a StaticModelSurface for each surface in the structure - for (int n = 0; n < nSurf; ++n) - { - // Retrieve the surface, discarding it if it is null or non-triangulated (?) - picoSurface_t* surf = PicoGetModelSurface(mod, n); - - if (surf == 0 || PicoGetSurfaceType(surf) != PICO_TRIANGLES) - { - continue; - } - - // Fix the normals of the surface (?) - PicoFixSurfaceNormals(surf); - - // Create the StaticModelSurface object and add it to the vector - auto rSurf = std::make_shared(surf, fExt); - - _surfVec.push_back(Surface(rSurf)); - - // Extend the model AABB to include the surface's AABB - _localAABB.includeAABB(rSurf->getAABB()); - } -} - StaticModel::StaticModel(const std::vector& surfaces) : _scaleTransformed(1, 1, 1), _scale(1, 1, 1), diff --git a/radiantcore/model/picomodel/StaticModel.h b/radiantcore/model/picomodel/StaticModel.h index 66d679cf32..6b5aa941c3 100644 --- a/radiantcore/model/picomodel/StaticModel.h +++ b/radiantcore/model/picomodel/StaticModel.h @@ -3,7 +3,6 @@ #include "iundo.h" #include "mapfile.h" #include "imodel.h" -#include "lib/picomodel.h" #include "math/AABB.h" #include "imodelsurface.h" @@ -39,7 +38,7 @@ class StaticModel : public IUndoable { private: - // greebo: RenderablePicoSurfaces are shared objects, the actual shaders + // greebo: StaticModelSurfaces are shared objects, the actual shaders // and the model skin handling are managed by the nodes/imodels referencing them struct Surface { @@ -62,7 +61,6 @@ class StaticModel : {} }; - // List of RenderablePicoSurfaces. typedef std::vector SurfaceList; // Vector of renderable surfaces for this model @@ -110,13 +108,6 @@ class StaticModel : public: - /** - * Constructor. Accepts a picoModel_t struct containing the raw model data - * loaded from picomodel, and a string filename extension to allow the - * correct handling of material paths (which differs between ASE and LWO) - */ - StaticModel(picoModel_t* mod, const std::string& fExt); - /** * Construct a StaticModel with the given set of surfaces. */