OSDN Git Service

Assimp制御の改良
authorqw_fuku <fkhideaki@gmail.com>
Sun, 11 Sep 2016 11:33:56 +0000 (20:33 +0900)
committerqw_fuku <fkhideaki@gmail.com>
Sun, 11 Sep 2016 11:33:56 +0000 (20:33 +0900)
シーン本体との依存を軽減

Src/LibQtGeoViewerCore/Format/AssimpReader.cpp
Src/LibQtGeoViewerCore/Format/AssimpReader.h
Src/LibQtGeoViewerCore/Format/AssimpUtil.cpp
Src/LibQtGeoViewerCore/Format/AssimpUtil.h
Src/LibQtGeoViewerCore/Format/DaeLoader.cpp
Src/LibQtGeoViewerCore/Format/X/XFileLoader.cpp

index b50fd6d..fa349d7 100644 (file)
@@ -32,7 +32,7 @@ std::string AssimpReader::GetIndexedName(const std::string& base, int idx)
        return oss.str();
 }
 
-bool AssimpReader::LoadGeom(SceneMain& scene, const std::string& filename)
+geom::GeomObject* AssimpReader::LoadGeom(SceneMain& scene, const std::string& filename)
 {
        unsigned int ai_option =
                aiProcess_JoinIdenticalVertices;
@@ -40,14 +40,14 @@ bool AssimpReader::LoadGeom(SceneMain& scene, const std::string& filename)
        Assimp::Importer importer;
        const aiScene* ai_scene = importer.ReadFile(filename, ai_option);
        if (!ai_scene)
-               return false;
+               return NULL;
 
        //PlotASNode(ai_scene->mRootNode);
 
        std::string dirpath = lib_geo::Path::GetParentDirPath(filename);
        std::string title = FileUtil::GetFileTitle(filename);
 
-       GeomObject* geom = scene.CreateNewGeometry();
+       GeomObject* geom = new GeomObject();
        geom->m_Name = title;
 
        for (unsigned int i = 0; i < ai_scene->mNumMeshes; ++i)
@@ -55,8 +55,6 @@ bool AssimpReader::LoadGeom(SceneMain& scene, const std::string& filename)
                aiMesh* mesh_src = ai_scene->mMeshes[i];
                MeshBuf* mbuf = geom->CreateNewMeshBuf();
 
-               scene.RefreshObjectIndex();
-
                std::string name = mesh_src->mName.C_Str();
                if (name.empty())
                        name = GetIndexedName(title, i);
@@ -65,7 +63,7 @@ bool AssimpReader::LoadGeom(SceneMain& scene, const std::string& filename)
 
                ReadMeshShape(mesh_src, mbuf->m_Mesh);
 
-               AssimpUtil::CopyMaterials(mbuf, ai_scene, scene, dirpath);
+               AssimpUtil::CopyMaterials(mbuf, ai_scene, scene.m_TexConfig, dirpath);
 
                ResetBone(mbuf, mesh_src);
 
@@ -92,10 +90,7 @@ bool AssimpReader::LoadGeom(SceneMain& scene, const std::string& filename)
 
        //geom->m_Nodes.TraceNodeTree();
 
-       scene.UpdateTransform();
-       scene.ReportDoneEditGeometry();
-
-       return true;
+       return geom;
 }
 
 bool AssimpReader::LoadCamera(SceneMain& scene, const std::string& filename)
index cb0e197..d2e6299 100644 (file)
@@ -21,12 +21,20 @@ struct aiNodeAnim;
 struct aiAnimation;
 
 
+namespace geom
+{
+
+class GeomObject;
+
+}
+
+
 class AssimpReader
 {
 public:
        AssimpReader(geom::GeomFileFormat fmt_);
 
-       bool LoadGeom(SceneMain& scene, const std::string& filename);
+       geom::GeomObject* LoadGeom(SceneMain& scene, const std::string& filename);
        bool LoadCamera(SceneMain& scene, const std::string& filename);
 
 private:
index 5dce8b5..ecef47a 100644 (file)
@@ -97,7 +97,7 @@ std::string AssimpUtil::GetTextureNameFromFilePath(const std::string& filepath)
        return name_qs.toLocal8Bit().data();
 }
 
-void AssimpUtil::CopyMaterials(MeshBuf* mbuf, const aiScene* ai_scene, SceneMain& scene, const std::string& dirpath)
+void AssimpUtil::CopyMaterials(MeshBuf* mbuf, const aiScene* ai_scene, gl::TextureConfig& texConf, const std::string& dirpath)
 {
        if (!ai_scene->HasMaterials())
                return;
@@ -143,7 +143,7 @@ void AssimpUtil::CopyMaterials(MeshBuf* mbuf, const aiScene* ai_scene, SceneMain
                                filepath += ai_filepath->data;
                                const std::string name = GetTextureNameFromFilePath(filepath);
 
-                               mbuf->InitColorTexture(i, filepath, name, scene.m_TexConfig);
+                               mbuf->InitColorTexture(i, filepath, name, texConf);
                        }
                }
        }
index 54b6b1e..198a502 100644 (file)
@@ -15,7 +15,7 @@ public:
        static void CopyAIFaces(lib_geo::BaseMesh& mesh_dst, aiMesh* mesh);
        static lgr::color4f AIToColor(aiMaterialProperty* prop);
        static std::string GetTextureNameFromFilePath(const std::string& filepath);
-       static void CopyMaterials(MeshBuf* mbuf, const aiScene* ai_scene, SceneMain& scene, const std::string& dirpath);
+       static void CopyMaterials(MeshBuf* mbuf, const aiScene* ai_scene, gl::TextureConfig& texConf, const std::string& dirpath);
 
        static void CreateBoneTree(NodeMap& nodemap, SceneNode* bn);
        static int GetNumKeyOfFrame(const aiNodeAnim* ch);
index 57cd37a..b704812 100644 (file)
@@ -3,10 +3,21 @@
 
 #include "AssimpReader.h"
 
+#include <LibQtGeoViewerCore/SceneMain.h>
+
 
 
 bool DaeLoader::Load(SceneMain& scene, const std::string& filename)
 {
        AssimpReader reader(geom::GeomFileFormat::Collada);
-       return reader.LoadGeom(scene, filename);
+       geom::GeomObject* geom = reader.LoadGeom(scene, filename);
+       if (geom == NULL)
+               return false;
+
+       scene.m_Objects.push_back(geom);
+       scene.RefreshObjectIndex();
+       scene.UpdateTransform();
+       scene.ReportDoneEditGeometry();
+
+       return true;
 }
index 38ff046..9091aa5 100644 (file)
@@ -3,10 +3,21 @@
 
 #include "..\AssimpReader.h"
 
+#include <LibQtGeoViewerCore/SceneMain.h>
+
 
 
 bool XFileLoader::Load(SceneMain& scene, const std::string& filename)
 {
        AssimpReader reader(geom::GeomFileFormat::XFile);
-       return reader.LoadGeom(scene, filename);
+       geom::GeomObject* geom = reader.LoadGeom(scene, filename);
+       if (geom == NULL)
+               return false;
+
+       scene.m_Objects.push_back(geom);
+       scene.RefreshObjectIndex();
+       scene.UpdateTransform();
+       scene.ReportDoneEditGeometry();
+
+       return true;
 }