From: qw_fuku Date: Sun, 11 Sep 2016 12:19:58 +0000 (+0900) Subject: 形状データインポート処理の整理 X-Git-Url: http://git.osdn.net/view?p=qtgeoviewer%2FQtGeoViewer.git;a=commitdiff_plain;h=7bae39a6381a33c24e8cc66cf5703cdbded4f275 形状データインポート処理の整理 --- diff --git a/Src/LibQtGeoViewerCore/Format/DaeLoader.cpp b/Src/LibQtGeoViewerCore/Format/DaeLoader.cpp index eb8f170..2347c2a 100644 --- a/Src/LibQtGeoViewerCore/Format/DaeLoader.cpp +++ b/Src/LibQtGeoViewerCore/Format/DaeLoader.cpp @@ -7,10 +7,15 @@ -bool DaeLoader::Load(SceneMain& scene, const std::string& filename) +GeomObject* DaeLoader::LoadGeom(SceneMain& scene, const std::string& filename) { AssimpReader reader(geom::GeomFileFormat::Collada); - geom::GeomObject* geom = reader.LoadGeom(scene, filename); + return reader.LoadGeom(scene, filename); +} + +bool DaeLoader::Load(SceneMain& scene, const std::string& filename) +{ + GeomObject* geom = LoadGeom(scene, filename); if (geom == NULL) return false; diff --git a/Src/LibQtGeoViewerCore/Format/DaeLoader.h b/Src/LibQtGeoViewerCore/Format/DaeLoader.h index c4b08bd..193b71a 100644 --- a/Src/LibQtGeoViewerCore/Format/DaeLoader.h +++ b/Src/LibQtGeoViewerCore/Format/DaeLoader.h @@ -3,8 +3,18 @@ #include "GeomFileReader.h" + +namespace geom +{ + +class GeomObject; + +} + + class DaeLoader : public GeomFileReader { public: bool Load(SceneMain& scene, const std::string& filename); + virtual geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename); }; diff --git a/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.cpp b/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.cpp index 58f98be..89ac28a 100644 --- a/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.cpp +++ b/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.cpp @@ -9,13 +9,13 @@ -bool MqoLoader::Load(SceneMain& scene, const std::string& filename) +GeomObject* MqoLoader::LoadGeom(SceneMain& scene, const std::string& filename) { lib_geo::MqoObject mqo_obj; lib_geo::MqoLoader loader; loader.Load( mqo_obj , filename ); - GeomObject* geom = scene.CreateNewGeometry(); + GeomObject* geom = new GeomObject(); MeshBuf* mbuf = geom->CreateNewMeshBuf(); mqo_obj.ConvertToBaseMesh(mbuf->m_Mesh); @@ -37,6 +37,17 @@ bool MqoLoader::Load(SceneMain& scene, const std::string& filename) geom->m_FilePath = filename; geom->InitializeBufferCommon(); + return geom; +} + +bool MqoLoader::Load(SceneMain& scene, const std::string& filename) +{ + GeomObject* geom = LoadGeom(scene, filename); + if (geom == NULL) + return false; + + scene.m_Objects.push_back(geom); + scene.RefreshObjectIndex(); scene.UpdateTransform(); scene.ReportDoneEditGeometry(); diff --git a/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.h b/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.h index 2eb1b01..75887e7 100644 --- a/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.h +++ b/Src/LibQtGeoViewerCore/Format/Mqo/MqoLoader.h @@ -3,8 +3,18 @@ #include "..\GeomFileReader.h" + +namespace geom +{ + +class GeomObject; + +} + + class MqoLoader : public GeomFileReader { public: bool Load(SceneMain& scene, const std::string& filename); + virtual geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename); }; diff --git a/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.cpp b/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.cpp index 0e58bb1..c68ff94 100644 --- a/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.cpp +++ b/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.cpp @@ -13,13 +13,13 @@ -bool ObjLoader::Load(SceneMain& scene, const std::string& filename) +GeomObject* ObjLoader::LoadGeom(SceneMain& scene, const std::string& filename) { lib_geo::ObjMesh obj_mesh; if (!obj_mesh.Load(filename)) - return false; + return NULL; - GeomObject* geom = NULL; + GeomObject* geom = new GeomObject(); ObjSplitMode splitMode = ObjSplitMode::None; if (scene.m_IOConfig.ObjSplit) @@ -27,8 +27,6 @@ bool ObjLoader::Load(SceneMain& scene, const std::string& filename) if (splitMode == ObjSplitMode::None) { - geom = scene.CreateNewGeometry(); - MeshBuf* mbuf = geom->CreateNewMeshBuf(); obj_mesh.ConvertToBaseMesh(mbuf->m_Mesh); @@ -46,9 +44,7 @@ bool ObjLoader::Load(SceneMain& scene, const std::string& filename) std::vector mesh_ary; obj_mesh.ConvertToBaseMeshSeparated(splitMode, mesh_ary); if (mesh_ary.empty()) - return true; - - geom = scene.CreateNewGeometry(); + return geom; for (size_t i = 0; i < mesh_ary.size(); ++i) { @@ -80,6 +76,17 @@ bool ObjLoader::Load(SceneMain& scene, const std::string& filename) geom->InitializeBufferCommon(); + return geom; +} + +bool ObjLoader::Load(SceneMain& scene, const std::string& filename) +{ + GeomObject* geom = LoadGeom(scene, filename); + if (geom == NULL) + return false; + + scene.m_Objects.push_back(geom); + scene.RefreshObjectIndex(); scene.UpdateTransform(); scene.ReportDoneEditGeometry(); diff --git a/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.h b/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.h index 6b6de42..82aadc4 100644 --- a/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.h +++ b/Src/LibQtGeoViewerCore/Format/Obj/ObjLoader.h @@ -18,6 +18,7 @@ class ObjLoader : public GeomFileReader { public: bool Load(SceneMain& scene, const std::string& filename); + virtual geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename); private: void InitTextureFromObjMeshBuf(SceneMain& scene, geom::MeshBuf& mbuf, const lib_geo::ObjMesh& obj_mesh); diff --git a/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.cpp b/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.cpp index 60e842b..bc95878 100644 --- a/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.cpp +++ b/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.cpp @@ -9,13 +9,13 @@ -bool PlyLoader::Load(SceneMain& scene, const std::string& filename) +GeomObject* PlyLoader::LoadGeom(SceneMain& scene, const std::string& filename) { lib_geo::ply::PlyMesh ply_mesh; if (!ply_mesh.Load(filename)) - return false; + return NULL; - GeomObject* geom = scene.CreateNewGeometry(); + GeomObject* geom = new GeomObject(); MeshBuf* mbuf = geom->CreateNewMeshBuf(); lib_geo::BaseMesh& mesh_dst = mbuf->m_Mesh; @@ -30,6 +30,17 @@ bool PlyLoader::Load(SceneMain& scene, const std::string& filename) geom->m_FilePath = filename; geom->InitializeBufferCommon(); + return geom; +} + +bool PlyLoader::Load(SceneMain& scene, const std::string& filename) +{ + GeomObject* geom = LoadGeom(scene, filename); + if (geom == NULL) + return false; + + scene.m_Objects.push_back(geom); + scene.RefreshObjectIndex(); scene.UpdateTransform(); scene.ReportDoneEditGeometry(); diff --git a/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.h b/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.h index 6fd204e..d5fc3bd 100644 --- a/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.h +++ b/Src/LibQtGeoViewerCore/Format/Ply/Plyloader.h @@ -3,8 +3,18 @@ #include "..\GeomFileReader.h" + +namespace geom +{ + +class GeomObject; + +} + + class PlyLoader : public GeomFileReader { public: bool Load(SceneMain& scene, const std::string& filename); + virtual geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename); }; diff --git a/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.cpp b/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.cpp index 7945395..3a98ea8 100644 --- a/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.cpp +++ b/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.cpp @@ -14,13 +14,13 @@ -bool PmdLoader::Load(SceneMain& scene, const std::string& filename) +GeomObject* PmdLoader::LoadGeom(SceneMain& scene, const std::string& filename) { meshio::pmd::IO pm; if (!pm.read(filename.c_str())) - return false; + return NULL; - GeomObject* geom = scene.CreateNewGeometry(); + GeomObject* geom = new GeomObject(); MeshBuf* mbuf = geom->CreateNewMeshBuf(); lib_geo::BaseMesh& m = mbuf->m_Mesh; @@ -116,6 +116,17 @@ bool PmdLoader::Load(SceneMain& scene, const std::string& filename) geom->m_FilePath = filename; geom->InitializeBufferCommon(); + return geom; +} + +bool PmdLoader::Load(SceneMain& scene, const std::string& filename) +{ + GeomObject* geom = LoadGeom(scene, filename); + if (geom == NULL) + return false; + + scene.m_Objects.push_back(geom); + scene.RefreshObjectIndex(); scene.UpdateTransform(); scene.ReportDoneEditGeometry(); diff --git a/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.h b/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.h index 1d5593d..670e9ed 100644 --- a/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.h +++ b/Src/LibQtGeoViewerCore/Format/Pmd/PmdLoader.h @@ -3,8 +3,18 @@ #include "..\GeomFileReader.h" + +namespace geom +{ + +class GeomObject; + +} + + class PmdLoader : public GeomFileReader { public: bool Load(SceneMain& scene, const std::string& filename); + virtual geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename); }; diff --git a/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.cpp b/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.cpp index b2049a6..c4eb97e 100644 --- a/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.cpp +++ b/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.cpp @@ -9,9 +9,9 @@ -bool StlLoader::Load(SceneMain& scene, const std::string& filename) +GeomObject* StlLoader::LoadGeom(SceneMain& scene, const std::string& filename) { - GeomObject* geom = scene.CreateNewGeometry(); + GeomObject* geom = new GeomObject(); MeshBuf* mbuf = geom->CreateNewMeshBuf(); lib_geo::BaseMesh& mesh_dst = mbuf->m_Mesh; @@ -32,6 +32,17 @@ bool StlLoader::Load(SceneMain& scene, const std::string& filename) geom->m_FilePath = filename; geom->InitializeBufferCommon(); + return geom; +} + +bool StlLoader::Load(SceneMain& scene, const std::string& filename) +{ + GeomObject* geom = LoadGeom(scene, filename); + if (geom == NULL) + return false; + + scene.m_Objects.push_back(geom); + scene.RefreshObjectIndex(); scene.UpdateTransform(); scene.ReportDoneEditGeometry(); diff --git a/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.h b/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.h index f00e641..e4450dd 100644 --- a/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.h +++ b/Src/LibQtGeoViewerCore/Format/Stl/StlLoader.h @@ -3,8 +3,18 @@ #include "..\GeomFileReader.h" + +namespace geom +{ + +class GeomObject; + +} + + class StlLoader : public GeomFileReader { public: bool Load(SceneMain& scene, const std::string& filename); + virtual geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename); }; diff --git a/Src/LibQtGeoViewerCore/Format/X/XFileLoader.cpp b/Src/LibQtGeoViewerCore/Format/X/XFileLoader.cpp index 6920c51..11bcab5 100644 --- a/Src/LibQtGeoViewerCore/Format/X/XFileLoader.cpp +++ b/Src/LibQtGeoViewerCore/Format/X/XFileLoader.cpp @@ -7,10 +7,15 @@ +GeomObject* XFileLoader::LoadGeom(SceneMain& scene, const std::string& filename) +{ + AssimpReader reader(geom::GeomFileFormat::Collada); + return reader.LoadGeom(scene, filename); +} + bool XFileLoader::Load(SceneMain& scene, const std::string& filename) { - AssimpReader reader(geom::GeomFileFormat::XFile); - geom::GeomObject* geom = reader.LoadGeom(scene, filename); + GeomObject* geom = LoadGeom(scene, filename); if (geom == NULL) return false; diff --git a/Src/LibQtGeoViewerCore/Format/X/XFileLoader.h b/Src/LibQtGeoViewerCore/Format/X/XFileLoader.h index b057af6..e577324 100644 --- a/Src/LibQtGeoViewerCore/Format/X/XFileLoader.h +++ b/Src/LibQtGeoViewerCore/Format/X/XFileLoader.h @@ -3,8 +3,18 @@ #include "..\GeomFileReader.h" + +namespace geom +{ + +class GeomObject; + +} + + class XFileLoader : public GeomFileReader { public: bool Load(SceneMain& scene, const std::string& filename); + virtual geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename); };