|
@@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
|
|
|
|
|
Copyright (c) 2006-2020, assimp team
|
|
Copyright (c) 2006-2020, assimp team
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
All rights reserved.
|
|
All rights reserved.
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
Redistribution and use of this software in source and binary forms,
|
|
@@ -83,39 +81,41 @@ aiColor4D AMFImporter::SPP_Material::GetColor(const float /*pX*/, const float /*
|
|
return tcol;
|
|
return tcol;
|
|
}
|
|
}
|
|
|
|
|
|
-void AMFImporter::PostprocessHelper_CreateMeshDataArray(const CAMFImporter_NodeElement_Mesh &pNodeElement, std::vector<aiVector3D> &pVertexCoordinateArray,
|
|
|
|
- std::vector<CAMFImporter_NodeElement_Color *> &pVertexColorArray) const {
|
|
|
|
- CAMFImporter_NodeElement_Vertices *vn = nullptr;
|
|
|
|
|
|
+void AMFImporter::PostprocessHelper_CreateMeshDataArray(const AMFMesh &pNodeElement, std::vector<aiVector3D> &pVertexCoordinateArray,
|
|
|
|
+ std::vector<AMFColor *> &pVertexColorArray) const {
|
|
|
|
+ AMFVertex *vn = nullptr;
|
|
size_t col_idx;
|
|
size_t col_idx;
|
|
|
|
|
|
// All data stored in "vertices", search for it.
|
|
// All data stored in "vertices", search for it.
|
|
- for (CAMFImporter_NodeElement *ne_child : pNodeElement.Child) {
|
|
|
|
- if (ne_child->Type == CAMFImporter_NodeElement::ENET_Vertices) vn = (CAMFImporter_NodeElement_Vertices *)ne_child;
|
|
|
|
|
|
+ for (AMFNodeElementBase *ne_child : pNodeElement.Child) {
|
|
|
|
+ if (ne_child->Type == AMFNodeElementBase::ENET_Vertices) {
|
|
|
|
+ vn = (AMFVertex *)ne_child;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// If "vertices" not found then no work for us.
|
|
// If "vertices" not found then no work for us.
|
|
- if (vn == nullptr) return;
|
|
|
|
|
|
+ if (vn == nullptr) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
pVertexCoordinateArray.reserve(vn->Child.size()); // all coordinates stored as child and we need to reserve space for future push_back's.
|
|
pVertexCoordinateArray.reserve(vn->Child.size()); // all coordinates stored as child and we need to reserve space for future push_back's.
|
|
pVertexColorArray.resize(vn->Child.size()); // colors count equal vertices count.
|
|
pVertexColorArray.resize(vn->Child.size()); // colors count equal vertices count.
|
|
col_idx = 0;
|
|
col_idx = 0;
|
|
// Inside vertices collect all data and place to arrays
|
|
// Inside vertices collect all data and place to arrays
|
|
- for (CAMFImporter_NodeElement *vn_child : vn->Child) {
|
|
|
|
|
|
+ for (AMFNodeElementBase *vn_child : vn->Child) {
|
|
// vertices, colors
|
|
// vertices, colors
|
|
- if (vn_child->Type == CAMFImporter_NodeElement::ENET_Vertex) {
|
|
|
|
|
|
+ if (vn_child->Type == AMFNodeElementBase::ENET_Vertex) {
|
|
// by default clear color for current vertex
|
|
// by default clear color for current vertex
|
|
pVertexColorArray[col_idx] = nullptr;
|
|
pVertexColorArray[col_idx] = nullptr;
|
|
|
|
|
|
- for (CAMFImporter_NodeElement *vtx : vn_child->Child) {
|
|
|
|
- if (vtx->Type == CAMFImporter_NodeElement::ENET_Coordinates) {
|
|
|
|
- pVertexCoordinateArray.push_back(((CAMFImporter_NodeElement_Coordinates *)vtx)->Coordinate);
|
|
|
|
-
|
|
|
|
|
|
+ for (AMFNodeElementBase *vtx : vn_child->Child) {
|
|
|
|
+ if (vtx->Type == AMFNodeElementBase::ENET_Coordinates) {
|
|
|
|
+ pVertexCoordinateArray.push_back(((AMFCoordinates *)vtx)->Coordinate);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- if (vtx->Type == CAMFImporter_NodeElement::ENET_Color) {
|
|
|
|
- pVertexColorArray[col_idx] = (CAMFImporter_NodeElement_Color *)vtx;
|
|
|
|
-
|
|
|
|
|
|
+ if (vtx->Type == AMFNodeElementBase::ENET_Color) {
|
|
|
|
+ pVertexColorArray[col_idx] = (AMFColor *)vtx;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
} // for(CAMFImporter_NodeElement* vtx: vn_child->Child)
|
|
} // for(CAMFImporter_NodeElement* vtx: vn_child->Child)
|
|
@@ -146,59 +146,77 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string &
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //
|
|
|
|
// Converted texture not found, create it.
|
|
// Converted texture not found, create it.
|
|
- //
|
|
|
|
- CAMFImporter_NodeElement_Texture *src_texture[4]{ nullptr };
|
|
|
|
- std::vector<CAMFImporter_NodeElement_Texture *> src_texture_4check;
|
|
|
|
|
|
+ AMFTexture *src_texture[4] {
|
|
|
|
+ nullptr
|
|
|
|
+ };
|
|
|
|
+ std::vector<AMFTexture *> src_texture_4check;
|
|
SPP_Texture converted_texture;
|
|
SPP_Texture converted_texture;
|
|
|
|
|
|
{ // find all specified source textures
|
|
{ // find all specified source textures
|
|
- CAMFImporter_NodeElement *t_tex;
|
|
|
|
-
|
|
|
|
|
|
+ AMFNodeElementBase *t_tex;
|
|
|
|
+
|
|
// R
|
|
// R
|
|
if (!pID_R.empty()) {
|
|
if (!pID_R.empty()) {
|
|
- if (!Find_NodeElement(pID_R, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_R);
|
|
|
|
|
|
+ pugi::xml_node *node = mXmlParser->findNode(pID_R);
|
|
|
|
+ if (nullptr == node) {
|
|
|
|
+ throw DeadlyImportError("Id not found " + pID_R + ".");
|
|
|
|
+ }
|
|
|
|
+ //if (!Find_NodeElement(pID_R, AMFNodeElementBase::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_R);
|
|
|
|
|
|
- src_texture[0] = (CAMFImporter_NodeElement_Texture *)t_tex;
|
|
|
|
- src_texture_4check.push_back((CAMFImporter_NodeElement_Texture *)t_tex);
|
|
|
|
|
|
+ src_texture[0] = (AMFTexture *)t_tex;
|
|
|
|
+ src_texture_4check.push_back((AMFTexture *)t_tex);
|
|
} else {
|
|
} else {
|
|
src_texture[0] = nullptr;
|
|
src_texture[0] = nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
// G
|
|
// G
|
|
if (!pID_G.empty()) {
|
|
if (!pID_G.empty()) {
|
|
- if (!Find_NodeElement(pID_G, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_G);
|
|
|
|
|
|
+ pugi::xml_node *node = mXmlParser->findNode(pID_G);
|
|
|
|
+ if (nullptr == node) {
|
|
|
|
+ throw DeadlyImportError("Id not found " + pID_G + ".");
|
|
|
|
+ }
|
|
|
|
|
|
- src_texture[1] = (CAMFImporter_NodeElement_Texture *)t_tex;
|
|
|
|
- src_texture_4check.push_back((CAMFImporter_NodeElement_Texture *)t_tex);
|
|
|
|
|
|
+ //if (!Find_NodeElement(pID_G, AMFNodeElementBase::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_G);
|
|
|
|
+
|
|
|
|
+ src_texture[1] = (AMFTexture *)t_tex;
|
|
|
|
+ src_texture_4check.push_back((AMFTexture *)t_tex);
|
|
} else {
|
|
} else {
|
|
src_texture[1] = nullptr;
|
|
src_texture[1] = nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
// B
|
|
// B
|
|
if (!pID_B.empty()) {
|
|
if (!pID_B.empty()) {
|
|
- if (!Find_NodeElement(pID_B, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_B);
|
|
|
|
|
|
+ //if (!Find_NodeElement(pID_B, AMFNodeElementBase::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_B);
|
|
|
|
+ pugi::xml_node *node = mXmlParser->findNode(pID_B);
|
|
|
|
+ if (nullptr == node) {
|
|
|
|
+ throw DeadlyImportError("Id not found " + pID_B + ".");
|
|
|
|
+ }
|
|
|
|
|
|
- src_texture[2] = (CAMFImporter_NodeElement_Texture *)t_tex;
|
|
|
|
- src_texture_4check.push_back((CAMFImporter_NodeElement_Texture *)t_tex);
|
|
|
|
|
|
+ src_texture[2] = (AMFTexture *)t_tex;
|
|
|
|
+ src_texture_4check.push_back((AMFTexture *)t_tex);
|
|
} else {
|
|
} else {
|
|
src_texture[2] = nullptr;
|
|
src_texture[2] = nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
// A
|
|
// A
|
|
if (!pID_A.empty()) {
|
|
if (!pID_A.empty()) {
|
|
- if (!Find_NodeElement(pID_A, CAMFImporter_NodeElement::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_A);
|
|
|
|
|
|
+ pugi::xml_node *node = mXmlParser->findNode(pID_A);
|
|
|
|
+ if (nullptr == node) {
|
|
|
|
+ throw DeadlyImportError("Id not found " + pID_A + ".");
|
|
|
|
+ }
|
|
|
|
|
|
- src_texture[3] = (CAMFImporter_NodeElement_Texture *)t_tex;
|
|
|
|
- src_texture_4check.push_back((CAMFImporter_NodeElement_Texture *)t_tex);
|
|
|
|
|
|
+ //if (!Find_NodeElement(pID_A, AMFNodeElementBase::ENET_Texture, &t_tex)) Throw_ID_NotFound(pID_A);
|
|
|
|
+
|
|
|
|
+ src_texture[3] = (AMFTexture *)t_tex;
|
|
|
|
+ src_texture_4check.push_back((AMFTexture *)t_tex);
|
|
} else {
|
|
} else {
|
|
src_texture[3] = nullptr;
|
|
src_texture[3] = nullptr;
|
|
}
|
|
}
|
|
} // END: find all specified source textures
|
|
} // END: find all specified source textures
|
|
|
|
|
|
// check that all textures has same size
|
|
// check that all textures has same size
|
|
- if (src_texture_4check.size() > 1) {
|
|
|
|
|
|
+ if (!src_texture_4check.empty() ) {
|
|
for (size_t i = 0, i_e = (src_texture_4check.size() - 1); i < i_e; i++) {
|
|
for (size_t i = 0, i_e = (src_texture_4check.size() - 1); i < i_e; i++) {
|
|
if ((src_texture_4check[i]->Width != src_texture_4check[i + 1]->Width) || (src_texture_4check[i]->Height != src_texture_4check[i + 1]->Height) ||
|
|
if ((src_texture_4check[i]->Width != src_texture_4check[i + 1]->Width) || (src_texture_4check[i]->Height != src_texture_4check[i + 1]->Height) ||
|
|
(src_texture_4check[i]->Depth != src_texture_4check[i + 1]->Depth)) {
|
|
(src_texture_4check[i]->Depth != src_texture_4check[i + 1]->Depth)) {
|
|
@@ -255,7 +273,7 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string &
|
|
auto CopyTextureData = [&](const std::string &pID, const size_t pOffset, const size_t pStep, const uint8_t pSrcTexNum) -> void {
|
|
auto CopyTextureData = [&](const std::string &pID, const size_t pOffset, const size_t pStep, const uint8_t pSrcTexNum) -> void {
|
|
if (!pID.empty()) {
|
|
if (!pID.empty()) {
|
|
for (size_t idx_target = pOffset, idx_src = 0; idx_target < tex_size; idx_target += pStep, idx_src++) {
|
|
for (size_t idx_target = pOffset, idx_src = 0; idx_target < tex_size; idx_target += pStep, idx_src++) {
|
|
- CAMFImporter_NodeElement_Texture *tex = src_texture[pSrcTexNum];
|
|
|
|
|
|
+ AMFTexture *tex = src_texture[pSrcTexNum];
|
|
ai_assert(tex);
|
|
ai_assert(tex);
|
|
converted_texture.Data[idx_target] = tex->Data.at(idx_src);
|
|
converted_texture.Data[idx_target] = tex->Data.at(idx_src);
|
|
}
|
|
}
|
|
@@ -276,7 +294,7 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string &
|
|
}
|
|
}
|
|
|
|
|
|
void AMFImporter::PostprocessHelper_SplitFacesByTextureID(std::list<SComplexFace> &pInputList, std::list<std::list<SComplexFace>> &pOutputList_Separated) {
|
|
void AMFImporter::PostprocessHelper_SplitFacesByTextureID(std::list<SComplexFace> &pInputList, std::list<std::list<SComplexFace>> &pOutputList_Separated) {
|
|
- auto texmap_is_equal = [](const CAMFImporter_NodeElement_TexMap *pTexMap1, const CAMFImporter_NodeElement_TexMap *pTexMap2) -> bool {
|
|
|
|
|
|
+ auto texmap_is_equal = [](const AMFTexMap *pTexMap1, const AMFTexMap *pTexMap2) -> bool {
|
|
if ((pTexMap1 == nullptr) && (pTexMap2 == nullptr)) return true;
|
|
if ((pTexMap1 == nullptr) && (pTexMap2 == nullptr)) return true;
|
|
if (pTexMap1 == nullptr) return false;
|
|
if (pTexMap1 == nullptr) return false;
|
|
if (pTexMap2 == nullptr) return false;
|
|
if (pTexMap2 == nullptr) return false;
|
|
@@ -313,56 +331,61 @@ void AMFImporter::PostprocessHelper_SplitFacesByTextureID(std::list<SComplexFace
|
|
} while (!pInputList.empty());
|
|
} while (!pInputList.empty());
|
|
}
|
|
}
|
|
|
|
|
|
-void AMFImporter::Postprocess_AddMetadata(const std::list<CAMFImporter_NodeElement_Metadata *> &metadataList, aiNode &sceneNode) const {
|
|
|
|
- if (!metadataList.empty()) {
|
|
|
|
- if (sceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
|
|
|
|
|
+void AMFImporter::Postprocess_AddMetadata(const std::list<AMFMetadata *> &metadataList, aiNode &sceneNode) const {
|
|
|
|
+ if (metadataList.empty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (sceneNode.mMetaData != nullptr) {
|
|
|
|
+ throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
|
|
|
+ }
|
|
|
|
|
|
- // copy collected metadata to output node.
|
|
|
|
- sceneNode.mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(metadataList.size()));
|
|
|
|
- size_t meta_idx(0);
|
|
|
|
|
|
+ // copy collected metadata to output node.
|
|
|
|
+ sceneNode.mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(metadataList.size()));
|
|
|
|
+ size_t meta_idx(0);
|
|
|
|
|
|
- for (const CAMFImporter_NodeElement_Metadata &metadata : metadataList) {
|
|
|
|
- sceneNode.mMetaData->Set(static_cast<unsigned int>(meta_idx++), metadata.Type, aiString(metadata.Value));
|
|
|
|
- }
|
|
|
|
- } // if(!metadataList.empty())
|
|
|
|
|
|
+ for (const AMFMetadata &metadata : metadataList) {
|
|
|
|
+ sceneNode.mMetaData->Set(static_cast<unsigned int>(meta_idx++), metadata.Type, aiString(metadata.Value));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-void AMFImporter::Postprocess_BuildNodeAndObject(const CAMFImporter_NodeElement_Object &pNodeElement, std::list<aiMesh *> &pMeshList, aiNode **pSceneNode) {
|
|
|
|
- CAMFImporter_NodeElement_Color *object_color = nullptr;
|
|
|
|
|
|
+void AMFImporter::Postprocess_BuildNodeAndObject(const AMFObject &pNodeElement, std::list<aiMesh *> &pMeshList, aiNode **pSceneNode) {
|
|
|
|
+ AMFColor *object_color = nullptr;
|
|
|
|
|
|
// create new aiNode and set name as <object> has.
|
|
// create new aiNode and set name as <object> has.
|
|
*pSceneNode = new aiNode;
|
|
*pSceneNode = new aiNode;
|
|
(*pSceneNode)->mName = pNodeElement.ID;
|
|
(*pSceneNode)->mName = pNodeElement.ID;
|
|
// read mesh and color
|
|
// read mesh and color
|
|
- for (const CAMFImporter_NodeElement *ne_child : pNodeElement.Child) {
|
|
|
|
|
|
+ for (const AMFNodeElementBase *ne_child : pNodeElement.Child) {
|
|
std::vector<aiVector3D> vertex_arr;
|
|
std::vector<aiVector3D> vertex_arr;
|
|
- std::vector<CAMFImporter_NodeElement_Color *> color_arr;
|
|
|
|
|
|
+ std::vector<AMFColor *> color_arr;
|
|
|
|
|
|
// color for object
|
|
// color for object
|
|
- if (ne_child->Type == CAMFImporter_NodeElement::ENET_Color) object_color = (CAMFImporter_NodeElement_Color *)ne_child;
|
|
|
|
|
|
+ if (ne_child->Type == AMFNodeElementBase::ENET_Color) {
|
|
|
|
+ object_color = (AMFColor *) ne_child;
|
|
|
|
+ }
|
|
|
|
|
|
- if (ne_child->Type == CAMFImporter_NodeElement::ENET_Mesh) {
|
|
|
|
|
|
+ if (ne_child->Type == AMFNodeElementBase::ENET_Mesh) {
|
|
// Create arrays from children of mesh: vertices.
|
|
// Create arrays from children of mesh: vertices.
|
|
- PostprocessHelper_CreateMeshDataArray(*((CAMFImporter_NodeElement_Mesh *)ne_child), vertex_arr, color_arr);
|
|
|
|
|
|
+ PostprocessHelper_CreateMeshDataArray(*((AMFMesh *)ne_child), vertex_arr, color_arr);
|
|
// Use this arrays as a source when creating every aiMesh
|
|
// Use this arrays as a source when creating every aiMesh
|
|
- Postprocess_BuildMeshSet(*((CAMFImporter_NodeElement_Mesh *)ne_child), vertex_arr, color_arr, object_color, pMeshList, **pSceneNode);
|
|
|
|
|
|
+ Postprocess_BuildMeshSet(*((AMFMesh *)ne_child), vertex_arr, color_arr, object_color, pMeshList, **pSceneNode);
|
|
}
|
|
}
|
|
} // for(const CAMFImporter_NodeElement* ne_child: pNodeElement)
|
|
} // for(const CAMFImporter_NodeElement* ne_child: pNodeElement)
|
|
}
|
|
}
|
|
|
|
|
|
-void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh &pNodeElement, const std::vector<aiVector3D> &pVertexCoordinateArray,
|
|
|
|
- const std::vector<CAMFImporter_NodeElement_Color *> &pVertexColorArray,
|
|
|
|
- const CAMFImporter_NodeElement_Color *pObjectColor, std::list<aiMesh *> &pMeshList, aiNode &pSceneNode) {
|
|
|
|
|
|
+void AMFImporter::Postprocess_BuildMeshSet(const AMFMesh &pNodeElement, const std::vector<aiVector3D> &pVertexCoordinateArray,
|
|
|
|
+ const std::vector<AMFColor *> &pVertexColorArray,
|
|
|
|
+ const AMFColor *pObjectColor, std::list<aiMesh *> &pMeshList, aiNode &pSceneNode) {
|
|
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 CAMFImporter_NodeElement *ne_child : pNodeElement.Child) {
|
|
|
|
- const CAMFImporter_NodeElement_Color *ne_volume_color = nullptr;
|
|
|
|
|
|
+ for (const AMFNodeElementBase *ne_child : pNodeElement.Child) {
|
|
|
|
+ const AMFColor *ne_volume_color = nullptr;
|
|
const SPP_Material *cur_mat = nullptr;
|
|
const SPP_Material *cur_mat = nullptr;
|
|
|
|
|
|
- if (ne_child->Type == CAMFImporter_NodeElement::ENET_Volume) {
|
|
|
|
|
|
+ if (ne_child->Type == AMFNodeElementBase::ENET_Volume) {
|
|
/******************* Get faces *******************/
|
|
/******************* Get faces *******************/
|
|
- const CAMFImporter_NodeElement_Volume *ne_volume = reinterpret_cast<const CAMFImporter_NodeElement_Volume *>(ne_child);
|
|
|
|
|
|
+ const AMFVolume *ne_volume = reinterpret_cast<const AMFVolume *>(ne_child);
|
|
|
|
|
|
std::list<SComplexFace> 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<std::list<SComplexFace>> 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.
|
|
@@ -373,13 +396,13 @@ void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh &
|
|
}
|
|
}
|
|
|
|
|
|
// 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 CAMFImporter_NodeElement *ne_volume_child : ne_volume->Child) {
|
|
|
|
|
|
+ for (const AMFNodeElementBase *ne_volume_child : ne_volume->Child) {
|
|
// color for volume
|
|
// color for volume
|
|
- if (ne_volume_child->Type == CAMFImporter_NodeElement::ENET_Color) {
|
|
|
|
- ne_volume_color = reinterpret_cast<const CAMFImporter_NodeElement_Color *>(ne_volume_child);
|
|
|
|
- } else if (ne_volume_child->Type == CAMFImporter_NodeElement::ENET_Triangle) // triangles, triangles colors
|
|
|
|
|
|
+ if (ne_volume_child->Type == AMFNodeElementBase::ENET_Color) {
|
|
|
|
+ ne_volume_color = reinterpret_cast<const AMFColor *>(ne_volume_child);
|
|
|
|
+ } else if (ne_volume_child->Type == AMFNodeElementBase::ENET_Triangle) // triangles, triangles colors
|
|
{
|
|
{
|
|
- const CAMFImporter_NodeElement_Triangle &tri_al = *reinterpret_cast<const CAMFImporter_NodeElement_Triangle *>(ne_volume_child);
|
|
|
|
|
|
+ const AMFTriangle &tri_al = *reinterpret_cast<const AMFTriangle *>(ne_volume_child);
|
|
|
|
|
|
SComplexFace complex_face;
|
|
SComplexFace complex_face;
|
|
|
|
|
|
@@ -388,11 +411,11 @@ void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh &
|
|
complex_face.TexMap = nullptr;
|
|
complex_face.TexMap = nullptr;
|
|
// 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 CAMFImporter_NodeElement *ne_triangle_child : tri_al.Child) {
|
|
|
|
- if (ne_triangle_child->Type == CAMFImporter_NodeElement::ENET_Color)
|
|
|
|
- complex_face.Color = reinterpret_cast<const CAMFImporter_NodeElement_Color *>(ne_triangle_child);
|
|
|
|
- else if (ne_triangle_child->Type == CAMFImporter_NodeElement::ENET_TexMap)
|
|
|
|
- complex_face.TexMap = reinterpret_cast<const CAMFImporter_NodeElement_TexMap *>(ne_triangle_child);
|
|
|
|
|
|
+ for (const AMFNodeElementBase *ne_triangle_child : tri_al.Child) {
|
|
|
|
+ if (ne_triangle_child->Type == AMFNodeElementBase::ENET_Color)
|
|
|
|
+ complex_face.Color = reinterpret_cast<const AMFColor *>(ne_triangle_child);
|
|
|
|
+ else if (ne_triangle_child->Type == AMFNodeElementBase::ENET_TexMap)
|
|
|
|
+ complex_face.TexMap = reinterpret_cast<const AMFTexMap *>(ne_triangle_child);
|
|
}
|
|
}
|
|
} // if(tri_al.Child.size())
|
|
} // if(tri_al.Child.size())
|
|
|
|
|
|
@@ -422,15 +445,18 @@ void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh &
|
|
if (face.Face.mIndices[idx_vert] > *pBiggerThan) {
|
|
if (face.Face.mIndices[idx_vert] > *pBiggerThan) {
|
|
rv = face.Face.mIndices[idx_vert];
|
|
rv = face.Face.mIndices[idx_vert];
|
|
found = true;
|
|
found = true;
|
|
-
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (found) break;
|
|
|
|
|
|
+ if (found) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if (!found) return *pBiggerThan;
|
|
|
|
|
|
+ if (!found) {
|
|
|
|
+ return *pBiggerThan;
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
rv = pFaceList.front().Face.mIndices[0];
|
|
rv = pFaceList.front().Face.mIndices[0];
|
|
} // if(pBiggerThan != nullptr) else
|
|
} // if(pBiggerThan != nullptr) else
|
|
@@ -505,9 +531,9 @@ void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh &
|
|
tmesh->mNumFaces = static_cast<unsigned int>(face_list_cur.size());
|
|
tmesh->mNumFaces = static_cast<unsigned int>(face_list_cur.size());
|
|
tmesh->mFaces = new aiFace[tmesh->mNumFaces];
|
|
tmesh->mFaces = new aiFace[tmesh->mNumFaces];
|
|
|
|
|
|
- // Create vertices list and optimize indices. Optimisation mean following.In AMF all volumes use one big list of vertices. And one volume
|
|
|
|
|
|
+ // Create vertices list and optimize indices. Optimization mean following.In AMF all volumes use one big list of vertices. And one volume
|
|
// can use only part of vertices list, for example: vertices list contain few thousands of vertices and volume use vertices 1, 3, 10.
|
|
// can use only part of vertices list, for example: vertices list contain few thousands of vertices and volume use vertices 1, 3, 10.
|
|
- // Do you need all this thousands of garbage? Of course no. So, optimisation step transformate sparse indices set to continuous.
|
|
|
|
|
|
+ // Do you need all this thousands of garbage? Of course no. So, optimization step transform sparse indices set to continuous.
|
|
size_t VertexCount_Max = tmesh->mNumFaces * 3; // 3 - triangles.
|
|
size_t VertexCount_Max = tmesh->mNumFaces * 3; // 3 - triangles.
|
|
std::vector<aiVector3D> vert_arr, texcoord_arr;
|
|
std::vector<aiVector3D> vert_arr, texcoord_arr;
|
|
std::vector<aiColor4D> col_arr;
|
|
std::vector<aiColor4D> col_arr;
|
|
@@ -566,7 +592,7 @@ void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh &
|
|
size_t idx_vert_new = vert_arr.size();
|
|
size_t idx_vert_new = vert_arr.size();
|
|
///TODO: clean unused vertices. "* 2": in certain cases - mesh full of triangle colors - vert_arr will contain duplicated vertices for
|
|
///TODO: clean unused vertices. "* 2": in certain cases - mesh full of triangle colors - vert_arr will contain duplicated vertices for
|
|
/// colored triangles and initial vertices (for colored vertices) which in real became unused. This part need more thinking about
|
|
/// colored triangles and initial vertices (for colored vertices) which in real became unused. This part need more thinking about
|
|
- /// optimisation.
|
|
|
|
|
|
+ /// optimization.
|
|
bool *idx_vert_used;
|
|
bool *idx_vert_used;
|
|
|
|
|
|
idx_vert_used = new bool[VertexCount_Max * 2];
|
|
idx_vert_used = new bool[VertexCount_Max * 2];
|
|
@@ -639,15 +665,15 @@ void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh &
|
|
} // if(mesh_idx.size() > 0)
|
|
} // if(mesh_idx.size() > 0)
|
|
}
|
|
}
|
|
|
|
|
|
-void AMFImporter::Postprocess_BuildMaterial(const CAMFImporter_NodeElement_Material &pMaterial) {
|
|
|
|
|
|
+void AMFImporter::Postprocess_BuildMaterial(const AMFMaterial &pMaterial) {
|
|
SPP_Material new_mat;
|
|
SPP_Material new_mat;
|
|
|
|
|
|
new_mat.ID = pMaterial.ID;
|
|
new_mat.ID = pMaterial.ID;
|
|
- for (const CAMFImporter_NodeElement *mat_child : pMaterial.Child) {
|
|
|
|
- if (mat_child->Type == CAMFImporter_NodeElement::ENET_Color) {
|
|
|
|
- new_mat.Color = (CAMFImporter_NodeElement_Color *)mat_child;
|
|
|
|
- } else if (mat_child->Type == CAMFImporter_NodeElement::ENET_Metadata) {
|
|
|
|
- new_mat.Metadata.push_back((CAMFImporter_NodeElement_Metadata *)mat_child);
|
|
|
|
|
|
+ for (const AMFNodeElementBase *mat_child : pMaterial.Child) {
|
|
|
|
+ if (mat_child->Type == AMFNodeElementBase::ENET_Color) {
|
|
|
|
+ new_mat.Color = (AMFColor*)mat_child;
|
|
|
|
+ } else if (mat_child->Type == AMFNodeElementBase::ENET_Metadata) {
|
|
|
|
+ new_mat.Metadata.push_back((AMFMetadata *)mat_child);
|
|
}
|
|
}
|
|
} // for(const CAMFImporter_NodeElement* mat_child; pMaterial.Child)
|
|
} // for(const CAMFImporter_NodeElement* mat_child; pMaterial.Child)
|
|
|
|
|
|
@@ -655,7 +681,7 @@ void AMFImporter::Postprocess_BuildMaterial(const CAMFImporter_NodeElement_Mater
|
|
mMaterial_Converted.push_back(new_mat);
|
|
mMaterial_Converted.push_back(new_mat);
|
|
}
|
|
}
|
|
|
|
|
|
-void AMFImporter::Postprocess_BuildConstellation(CAMFImporter_NodeElement_Constellation &pConstellation, std::list<aiNode *> &pNodeList) const {
|
|
|
|
|
|
+void AMFImporter::Postprocess_BuildConstellation(AMFConstellation &pConstellation, std::list<aiNode *> &pNodeList) const {
|
|
aiNode *con_node;
|
|
aiNode *con_node;
|
|
std::list<aiNode *> ch_node;
|
|
std::list<aiNode *> ch_node;
|
|
|
|
|
|
@@ -672,8 +698,8 @@ void AMFImporter::Postprocess_BuildConstellation(CAMFImporter_NodeElement_Conste
|
|
aiNode *t_node;
|
|
aiNode *t_node;
|
|
aiNode *found_node;
|
|
aiNode *found_node;
|
|
|
|
|
|
- if (ne->Type == CAMFImporter_NodeElement::ENET_Metadata) continue;
|
|
|
|
- if (ne->Type != CAMFImporter_NodeElement::ENET_Instance) throw DeadlyImportError("Only <instance> nodes can be in <constellation>.");
|
|
|
|
|
|
+ if (ne->Type == AMFNodeElementBase::ENET_Metadata) continue;
|
|
|
|
+ if (ne->Type != AMFNodeElementBase::ENET_Instance) throw DeadlyImportError("Only <instance> nodes can be in <constellation>.");
|
|
|
|
|
|
// create alias for conveniance
|
|
// create alias for conveniance
|
|
CAMFImporter_NodeElement_Instance &als = *((CAMFImporter_NodeElement_Instance *)ne);
|
|
CAMFImporter_NodeElement_Instance &als = *((CAMFImporter_NodeElement_Instance *)ne);
|
|
@@ -723,10 +749,10 @@ void AMFImporter::Postprocess_BuildScene(aiScene *pScene) {
|
|
pScene->mRootNode->mParent = nullptr;
|
|
pScene->mRootNode->mParent = nullptr;
|
|
pScene->mFlags |= AI_SCENE_FLAGS_ALLOW_SHARED;
|
|
pScene->mFlags |= AI_SCENE_FLAGS_ALLOW_SHARED;
|
|
// search for root(<amf>) element
|
|
// search for root(<amf>) element
|
|
- CAMFImporter_NodeElement *root_el = nullptr;
|
|
|
|
|
|
+ AMFNodeElementBase *root_el = nullptr;
|
|
|
|
|
|
- for (CAMFImporter_NodeElement *ne : mNodeElement_List) {
|
|
|
|
- if (ne->Type != CAMFImporter_NodeElement::ENET_Root) continue;
|
|
|
|
|
|
+ for (AMFNodeElementBase *ne : mNodeElement_List) {
|
|
|
|
+ if (ne->Type != AMFNodeElementBase::ENET_Root) continue;
|
|
|
|
|
|
root_el = ne;
|
|
root_el = ne;
|
|
|
|
|
|
@@ -742,15 +768,15 @@ void AMFImporter::Postprocess_BuildScene(aiScene *pScene) {
|
|
//
|
|
//
|
|
// 1. <material>
|
|
// 1. <material>
|
|
// 2. <texture> will be converted later when processing triangles list. \sa Postprocess_BuildMeshSet
|
|
// 2. <texture> will be converted later when processing triangles list. \sa Postprocess_BuildMeshSet
|
|
- for (const CAMFImporter_NodeElement *root_child : root_el->Child) {
|
|
|
|
- if (root_child->Type == CAMFImporter_NodeElement::ENET_Material) Postprocess_BuildMaterial(*((CAMFImporter_NodeElement_Material *)root_child));
|
|
|
|
|
|
+ for (const AMFNodeElementBase *root_child : root_el->Child) {
|
|
|
|
+ if (root_child->Type == AMFNodeElementBase::ENET_Material) Postprocess_BuildMaterial(*((CAMFImporter_NodeElement_Material *)root_child));
|
|
}
|
|
}
|
|
|
|
|
|
// After "appearance" nodes we must read <object> because it will be used in <constellation> -> <instance>.
|
|
// After "appearance" nodes we must read <object> because it will be used in <constellation> -> <instance>.
|
|
//
|
|
//
|
|
// 3. <object>
|
|
// 3. <object>
|
|
- for (const CAMFImporter_NodeElement *root_child : root_el->Child) {
|
|
|
|
- if (root_child->Type == CAMFImporter_NodeElement::ENET_Object) {
|
|
|
|
|
|
+ for (const AMFNodeElementBase *root_child : root_el->Child) {
|
|
|
|
+ if (root_child->Type == AMFNodeElementBase::ENET_Object) {
|
|
aiNode *tnode = nullptr;
|
|
aiNode *tnode = nullptr;
|
|
|
|
|
|
// for <object> mesh and node must be built: object ID assigned to aiNode name and will be used in future for <instance>
|
|
// for <object> mesh and node must be built: object ID assigned to aiNode name and will be used in future for <instance>
|
|
@@ -761,15 +787,15 @@ void AMFImporter::Postprocess_BuildScene(aiScene *pScene) {
|
|
|
|
|
|
// And finally read rest of nodes.
|
|
// And finally read rest of nodes.
|
|
//
|
|
//
|
|
- for (const CAMFImporter_NodeElement *root_child : root_el->Child) {
|
|
|
|
|
|
+ for (const AMFNodeElementBase *root_child : root_el->Child) {
|
|
// 4. <constellation>
|
|
// 4. <constellation>
|
|
- if (root_child->Type == CAMFImporter_NodeElement::ENET_Constellation) {
|
|
|
|
|
|
+ if (root_child->Type == AMFNodeElementBase::ENET_Constellation) {
|
|
// <object> and <constellation> at top of self abstraction use aiNode. So we can use only aiNode list for creating new aiNode's.
|
|
// <object> and <constellation> at top of self abstraction use aiNode. So we can use only aiNode list for creating new aiNode's.
|
|
- Postprocess_BuildConstellation(*((CAMFImporter_NodeElement_Constellation *)root_child), node_list);
|
|
|
|
|
|
+ Postprocess_BuildConstellation(*((AMFConstellation *)root_child), node_list);
|
|
}
|
|
}
|
|
|
|
|
|
// 5, <metadata>
|
|
// 5, <metadata>
|
|
- if (root_child->Type == CAMFImporter_NodeElement::ENET_Metadata) meta_list.push_back((CAMFImporter_NodeElement_Metadata *)root_child);
|
|
|
|
|
|
+ if (root_child->Type == AMFNodeElementBase::ENET_Metadata) meta_list.push_back((CAMFImporter_NodeElement_Metadata *)root_child);
|
|
} // for(const CAMFImporter_NodeElement* root_child: root_el->Child)
|
|
} // for(const CAMFImporter_NodeElement* root_child: root_el->Child)
|
|
|
|
|
|
// at now we can add collected metadata to root node
|
|
// at now we can add collected metadata to root node
|