Merge branch 'import_amf' into import_x3d

pull/1014/head
Alexandr Arutjunov 2016-09-30 00:30:26 +03:00
commit db54eb98e3
4 changed files with 47 additions and 57 deletions

View File

@ -12,11 +12,8 @@
#include "fast_atof.h" #include "fast_atof.h"
#include "DefaultIOSystem.h" #include "DefaultIOSystem.h"
// Header files, Boost.
#include <boost/format.hpp>
#include <boost/scoped_ptr.hpp>
// Header files, stdlib. // Header files, stdlib.
#include <memory>
#include <string> #include <string>
namespace Assimp namespace Assimp
@ -121,12 +118,12 @@ void AMFImporter::Throw_CloseNotFound(const std::string& pNode)
void AMFImporter::Throw_IncorrectAttr(const std::string& pAttrName) void AMFImporter::Throw_IncorrectAttr(const std::string& pAttrName)
{ {
throw DeadlyImportError(boost::str(boost::format("Node <%s> has incorrect attribute \"%s\".") % mReader->getNodeName() % pAttrName)); throw DeadlyImportError("Node <" + std::string(mReader->getNodeName()) + "> has incorrect attribute \"" + pAttrName + "\".");
} }
void AMFImporter::Throw_IncorrectAttrValue(const std::string& pAttrName) void AMFImporter::Throw_IncorrectAttrValue(const std::string& pAttrName)
{ {
throw DeadlyImportError(boost::str(boost::format("Attribute \"%s\" in node <%s> has incorrect value.") % pAttrName % mReader->getNodeName())); throw DeadlyImportError("Attribute \"" + pAttrName + "\" in node <" + std::string(mReader->getNodeName()) + "> has incorrect value.");
} }
void AMFImporter::Throw_MoreThanOnceDefined(const std::string& pNodeType, const std::string& pDescription) void AMFImporter::Throw_MoreThanOnceDefined(const std::string& pNodeType, const std::string& pDescription)
@ -136,7 +133,7 @@ void AMFImporter::Throw_MoreThanOnceDefined(const std::string& pNodeType, const
void AMFImporter::Throw_ID_NotFound(const std::string& pID) const void AMFImporter::Throw_ID_NotFound(const std::string& pID) const
{ {
throw DeadlyImportError(boost::str(boost::format("Not found node with name \"%s\".") % pID)); throw DeadlyImportError("Not found node with name \"" + pID + "\".");
} }
/*********************************************************************************************************************************************/ /*********************************************************************************************************************************************/
@ -185,13 +182,13 @@ size_t sk_idx;
casu_cres: casu_cres:
if(!found) throw DeadlyImportError(boost::str(boost::format("Unknown node \"%s\" in %s.") % nn % pParentNodeName)); if(!found) throw DeadlyImportError("Unknown node \"" + nn + "\" in " + pParentNodeName + ".");
if(!close_found) Throw_CloseNotFound(nn); if(!close_found) Throw_CloseNotFound(nn);
if(!skipped_before[sk_idx]) if(!skipped_before[sk_idx])
{ {
skipped_before[sk_idx] = true; skipped_before[sk_idx] = true;
LogWarning(boost::str(boost::format("Skipping node \"%s\" in %s.") % nn % pParentNodeName)); LogWarning("Skipping node \"" + nn + "\" in " + pParentNodeName + ".");
} }
} }
@ -365,13 +362,13 @@ uint8_t arr4[4], arr3[3];
void AMFImporter::ParseFile(const std::string& pFile, IOSystem* pIOHandler) void AMFImporter::ParseFile(const std::string& pFile, IOSystem* pIOHandler)
{ {
irr::io::IrrXMLReader* OldReader = mReader;// store current XMLreader. irr::io::IrrXMLReader* OldReader = mReader;// store current XMLreader.
boost::scoped_ptr<IOStream> file(pIOHandler->Open(pFile, "rb")); std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
// Check whether we can read from the file // Check whether we can read from the file
if(file.get() == NULL) throw DeadlyImportError("Failed to open AMF file " + pFile + "."); if(file.get() == NULL) throw DeadlyImportError("Failed to open AMF file " + pFile + ".");
// generate a XML reader for it // generate a XML reader for it
boost::scoped_ptr<CIrrXML_IOStreamReader> mIOWrapper(new CIrrXML_IOStreamReader(file.get())); std::unique_ptr<CIrrXML_IOStreamReader> mIOWrapper(new CIrrXML_IOStreamReader(file.get()));
mReader = irr::io::createIrrXMLReader(mIOWrapper.get()); mReader = irr::io::createIrrXMLReader(mIOWrapper.get());
if(!mReader) throw DeadlyImportError("Failed to create XML reader for file" + pFile + "."); if(!mReader) throw DeadlyImportError("Failed to create XML reader for file" + pFile + ".");
// //

View File

@ -9,6 +9,7 @@
// Header files, stdlib. // Header files, stdlib.
#include <list> #include <list>
#include <string> #include <string>
#include <vector>
// Header files, Assimp. // Header files, Assimp.
#include "assimp/types.h" #include "assimp/types.h"

View File

@ -100,9 +100,6 @@ size_t col_idx;
size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string& pID_R, const std::string& pID_G, const std::string& pID_B, size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string& pID_R, const std::string& pID_G, const std::string& pID_B,
const std::string& pID_A) const std::string& pID_A)
{ {
using CNE_Texture = CAMFImporter_NodeElement_Texture;
using CNE = CAMFImporter_NodeElement;
size_t TextureConverted_Index; size_t TextureConverted_Index;
std::string TextureConverted_ID; std::string TextureConverted_ID;
@ -125,20 +122,20 @@ std::string TextureConverted_ID;
// //
// Converted texture not found, create it. // Converted texture not found, create it.
// //
CNE_Texture* src_texture[4]{nullptr}; CAMFImporter_NodeElement_Texture* src_texture[4]{nullptr};
std::vector<CNE_Texture*> src_texture_4check; std::vector<CAMFImporter_NodeElement_Texture*> src_texture_4check;
SPP_Texture converted_texture; SPP_Texture converted_texture;
{// find all specified source textures {// find all specified source textures
CNE* t_tex; CAMFImporter_NodeElement* t_tex;
// R // R
if(!pID_R.empty()) if(!pID_R.empty())
{ {
if(!Find_NodeElement(pID_R, CNE::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_R); if(!Find_NodeElement(pID_R, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_R);
src_texture[0] = (CNE_Texture*)t_tex; src_texture[0] = (CAMFImporter_NodeElement_Texture*)t_tex;
src_texture_4check.push_back((CNE_Texture*)t_tex); src_texture_4check.push_back((CAMFImporter_NodeElement_Texture*)t_tex);
} }
else else
{ {
@ -148,10 +145,10 @@ std::string TextureConverted_ID;
// G // G
if(!pID_G.empty()) if(!pID_G.empty())
{ {
if(!Find_NodeElement(pID_G, CNE::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_G); if(!Find_NodeElement(pID_G, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_G);
src_texture[1] = (CNE_Texture*)t_tex; src_texture[1] = (CAMFImporter_NodeElement_Texture*)t_tex;
src_texture_4check.push_back((CNE_Texture*)t_tex); src_texture_4check.push_back((CAMFImporter_NodeElement_Texture*)t_tex);
} }
else else
{ {
@ -161,10 +158,10 @@ std::string TextureConverted_ID;
// B // B
if(!pID_B.empty()) if(!pID_B.empty())
{ {
if(!Find_NodeElement(pID_B, CNE::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_B); if(!Find_NodeElement(pID_B, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_B);
src_texture[2] = (CNE_Texture*)t_tex; src_texture[2] = (CAMFImporter_NodeElement_Texture*)t_tex;
src_texture_4check.push_back((CNE_Texture*)t_tex); src_texture_4check.push_back((CAMFImporter_NodeElement_Texture*)t_tex);
} }
else else
{ {
@ -174,10 +171,10 @@ std::string TextureConverted_ID;
// A // A
if(!pID_A.empty()) if(!pID_A.empty())
{ {
if(!Find_NodeElement(pID_A, CNE::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_A); if(!Find_NodeElement(pID_A, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_A);
src_texture[3] = (CNE_Texture*)t_tex; src_texture[3] = (CAMFImporter_NodeElement_Texture*)t_tex;
src_texture_4check.push_back((CNE_Texture*)t_tex); src_texture_4check.push_back((CAMFImporter_NodeElement_Texture*)t_tex);
} }
else else
{ {
@ -348,26 +345,21 @@ void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh&
const std::vector<CAMFImporter_NodeElement_Color*>& pVertexColorArray, const std::vector<CAMFImporter_NodeElement_Color*>& pVertexColorArray,
const CAMFImporter_NodeElement_Color* pObjectColor, std::list<aiMesh*>& pMeshList, aiNode& pSceneNode) const CAMFImporter_NodeElement_Color* pObjectColor, std::list<aiMesh*>& pMeshList, aiNode& pSceneNode)
{ {
using CNE = CAMFImporter_NodeElement;
using CNE_Color = CAMFImporter_NodeElement_Color;
using CNE_TexMap = CAMFImporter_NodeElement_TexMap;
using ComplexFaceList = std::list<SComplexFace>;
std::list<unsigned int> mesh_idx; std::list<unsigned int> mesh_idx;
// all data stored in "volume", search for it. // all data stored in "volume", search for it.
for(const CNE* ne_child: pNodeElement.Child) for(const CAMFImporter_NodeElement* ne_child: pNodeElement.Child)
{ {
const CNE_Color* ne_volume_color = nullptr; const CAMFImporter_NodeElement_Color* ne_volume_color = nullptr;
const SPP_Material* cur_mat = nullptr; const SPP_Material* cur_mat = nullptr;
if(ne_child->Type == CNE::ENET_Volume) if(ne_child->Type == CAMFImporter_NodeElement::ENET_Volume)
{ {
/******************* Get faces *******************/ /******************* Get faces *******************/
const CAMFImporter_NodeElement_Volume* ne_volume = reinterpret_cast<const CAMFImporter_NodeElement_Volume*>(ne_child); const CAMFImporter_NodeElement_Volume* ne_volume = reinterpret_cast<const CAMFImporter_NodeElement_Volume*>(ne_child);
ComplexFaceList complex_faces_list;// List of the faces of the volume. std::list<SComplexFace> complex_faces_list;// List of the faces of the volume.
std::list<ComplexFaceList> complex_faces_toplist;// List of the face list for every mesh. std::list<std::list<SComplexFace> > complex_faces_toplist;// List of the face list for every mesh.
// check if volume use material // check if volume use material
if(!ne_volume->MaterialID.empty()) if(!ne_volume->MaterialID.empty())
@ -376,14 +368,14 @@ std::list<unsigned int> mesh_idx;
} }
// inside "volume" collect all data and place to arrays or create new objects // inside "volume" collect all data and place to arrays or create new objects
for(const CNE* ne_volume_child: ne_volume->Child) for(const CAMFImporter_NodeElement* ne_volume_child: ne_volume->Child)
{ {
// color for volume // color for volume
if(ne_volume_child->Type == CNE::ENET_Color) if(ne_volume_child->Type == CAMFImporter_NodeElement::ENET_Color)
{ {
ne_volume_color = reinterpret_cast<const CNE_Color*>(ne_volume_child); ne_volume_color = reinterpret_cast<const CAMFImporter_NodeElement_Color*>(ne_volume_child);
} }
else if(ne_volume_child->Type == CNE::ENET_Triangle)// triangles, triangles colors else if(ne_volume_child->Type == CAMFImporter_NodeElement::ENET_Triangle)// triangles, triangles colors
{ {
const CAMFImporter_NodeElement_Triangle& tri_al = *reinterpret_cast<const CAMFImporter_NodeElement_Triangle*>(ne_volume_child); const CAMFImporter_NodeElement_Triangle& tri_al = *reinterpret_cast<const CAMFImporter_NodeElement_Triangle*>(ne_volume_child);
@ -395,12 +387,12 @@ std::list<unsigned int> mesh_idx;
// get data from triangle children: color, texture coordinates. // get data from triangle children: color, texture coordinates.
if(tri_al.Child.size()) if(tri_al.Child.size())
{ {
for(const CNE* ne_triangle_child: tri_al.Child) for(const CAMFImporter_NodeElement* ne_triangle_child: tri_al.Child)
{ {
if(ne_triangle_child->Type == CNE::ENET_Color) if(ne_triangle_child->Type == CAMFImporter_NodeElement::ENET_Color)
complex_face.Color = reinterpret_cast<const CNE_Color*>(ne_triangle_child); complex_face.Color = reinterpret_cast<const CAMFImporter_NodeElement_Color*>(ne_triangle_child);
else if(ne_triangle_child->Type == CNE::ENET_TexMap) else if(ne_triangle_child->Type == CAMFImporter_NodeElement::ENET_TexMap)
complex_face.TexMap = reinterpret_cast<const CNE_TexMap*>(ne_triangle_child); complex_face.TexMap = reinterpret_cast<const CAMFImporter_NodeElement_TexMap*>(ne_triangle_child);
} }
}// if(tri_al.Child.size()) }// if(tri_al.Child.size())
@ -412,15 +404,15 @@ std::list<unsigned int> mesh_idx;
complex_face.Face.mIndices[2] = tri_al.V[2]; complex_face.Face.mIndices[2] = tri_al.V[2];
complex_faces_list.push_back(complex_face); complex_faces_list.push_back(complex_face);
} }
}// for(const CNE* ne_volume_child: ne_volume->Child) }// for(const CAMFImporter_NodeElement* ne_volume_child: ne_volume->Child)
/**** Split faces list: one list per mesh ****/ /**** Split faces list: one list per mesh ****/
PostprocessHelper_SplitFacesByTextureID(complex_faces_list, complex_faces_toplist); PostprocessHelper_SplitFacesByTextureID(complex_faces_list, complex_faces_toplist);
/***** Create mesh for every faces list ******/ /***** Create mesh for every faces list ******/
for(ComplexFaceList& face_list_cur: complex_faces_toplist) for(std::list<SComplexFace>& face_list_cur: complex_faces_toplist)
{ {
auto VertexIndex_GetMinimal = [](const ComplexFaceList& pFaceList, const size_t* pBiggerThan) -> size_t auto VertexIndex_GetMinimal = [](const std::list<SComplexFace>& pFaceList, const size_t* pBiggerThan) -> size_t
{ {
size_t rv; size_t rv;
@ -470,9 +462,9 @@ std::list<unsigned int> mesh_idx;
}// for(const SComplexFace& face: pFaceList) }// for(const SComplexFace& face: pFaceList)
return rv; return rv;
};// auto VertexIndex_GetMinimal = [](const ComplexFaceList& pFaceList, const size_t* pBiggerThan) -> size_t };// auto VertexIndex_GetMinimal = [](const std::list<SComplexFace>& pFaceList, const size_t* pBiggerThan) -> size_t
auto VertexIndex_Replace = [](ComplexFaceList& pFaceList, const size_t pIdx_From, const size_t pIdx_To) -> void auto VertexIndex_Replace = [](std::list<SComplexFace>& pFaceList, const size_t pIdx_From, const size_t pIdx_To) -> void
{ {
for(const SComplexFace& face: pFaceList) for(const SComplexFace& face: pFaceList)
{ {
@ -481,7 +473,7 @@ std::list<unsigned int> mesh_idx;
if(face.Face.mIndices[vi] == pIdx_From) face.Face.mIndices[vi] = pIdx_To; if(face.Face.mIndices[vi] == pIdx_From) face.Face.mIndices[vi] = pIdx_To;
} }
} }
};// auto VertexIndex_Replace = [](ComplexFaceList& pFaceList, const size_t pIdx_From, const size_t pIdx_To) -> void };// auto VertexIndex_Replace = [](std::list<SComplexFace>& pFaceList, const size_t pIdx_From, const size_t pIdx_To) -> void
auto Vertex_CalculateColor = [&](const size_t pIdx) -> aiColor4D auto Vertex_CalculateColor = [&](const size_t pIdx) -> aiColor4D
{ {
@ -661,9 +653,9 @@ std::list<unsigned int> mesh_idx;
// store new aiMesh // store new aiMesh
mesh_idx.push_back(pMeshList.size()); mesh_idx.push_back(pMeshList.size());
pMeshList.push_back(tmesh); pMeshList.push_back(tmesh);
}// for(const ComplexFaceList& face_list_cur: complex_faces_toplist) }// for(const std::list<SComplexFace>& face_list_cur: complex_faces_toplist)
}// if(ne_child->Type == CAMFImporter_NodeElement::ENET_Volume) }// if(ne_child->Type == CAMFImporter_NodeElement::ENET_Volume)
}// for(const CNE* ne_child: pNodeElement.Child) }// for(const CAMFImporter_NodeElement* ne_child: pNodeElement.Child)
// if meshes was created then assign new indices with current aiNode // if meshes was created then assign new indices with current aiNode
if(mesh_idx.size() > 0) if(mesh_idx.size() > 0)

View File

@ -1,4 +1,4 @@
# Open Asset Import Library (assimp) # Open Asset Import Library (assimp)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# #
# Copyright (c) 2006-2016, assimp team # Copyright (c) 2006-2016, assimp team