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;
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)
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);
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);
//geom->m_Nodes.TraceNodeTree();
- scene.UpdateTransform();
- scene.ReportDoneEditGeometry();
-
- return true;
+ return geom;
}
bool AssimpReader::LoadCamera(SceneMain& scene, const std::string& filename)
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:
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;
filepath += ai_filepath->data;
const std::string name = GetTextureNameFromFilePath(filepath);
- mbuf->InitColorTexture(i, filepath, name, scene.m_TexConfig);
+ mbuf->InitColorTexture(i, filepath, name, texConf);
}
}
}
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);
#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;
}
#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;
}