[*] Style and doc changes.

pull/1011/head
Alexandr Arutjunov 2016-09-29 18:04:31 +03:00
parent d63bff707e
commit e4cb388153
4 changed files with 98 additions and 112 deletions

View File

@ -39,14 +39,14 @@ const aiImporterDesc AMFImporter::Description = {
void AMFImporter::Clear() void AMFImporter::Clear()
{ {
mNodeElement_Cur = NULL; mNodeElement_Cur = nullptr;
mUnit.clear(); mUnit.clear();
mMaterial_Converted.clear(); mMaterial_Converted.clear();
mTexture_Converted.clear(); mTexture_Converted.clear();
// Delete all elements // Delete all elements
if(mNodeElement_List.size()) if(mNodeElement_List.size())
{ {
for(std::list<CAMFImporter_NodeElement*>::iterator it = mNodeElement_List.begin(); it != mNodeElement_List.end(); it++) delete *it; for(CAMFImporter_NodeElement* ne: mNodeElement_List) { delete ne; }
mNodeElement_List.clear(); mNodeElement_List.clear();
} }
@ -54,7 +54,7 @@ void AMFImporter::Clear()
AMFImporter::~AMFImporter() AMFImporter::~AMFImporter()
{ {
if(mReader != NULL) delete mReader; if(mReader != nullptr) delete mReader;
// Clear() is accounting if data already is deleted. So, just check again if all data is deleted. // Clear() is accounting if data already is deleted. So, just check again if all data is deleted.
Clear(); Clear();
} }
@ -65,15 +65,15 @@ AMFImporter::~AMFImporter()
bool AMFImporter::Find_NodeElement(const std::string& pID, const CAMFImporter_NodeElement::EType pType, CAMFImporter_NodeElement** pNodeElement) const bool AMFImporter::Find_NodeElement(const std::string& pID, const CAMFImporter_NodeElement::EType pType, CAMFImporter_NodeElement** pNodeElement) const
{ {
for(std::list<CAMFImporter_NodeElement*>::const_iterator it = mNodeElement_List.begin(); it != mNodeElement_List.end(); it++) for(CAMFImporter_NodeElement* ne: mNodeElement_List)
{ {
if(((*it)->ID == pID) && ((*it)->Type == pType)) if((ne->ID == pID) && (ne->Type == pType))
{ {
if(pNodeElement != NULL) *pNodeElement = *it; if(pNodeElement != nullptr) *pNodeElement = ne;
return true; return true;
} }
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = mNodeElement_List.begin(); it != mNodeElement_List.end(); it++) }// for(CAMFImporter_NodeElement* ne: mNodeElement_List)
return false; return false;
} }
@ -82,30 +82,30 @@ bool AMFImporter::Find_ConvertedNode(const std::string& pID, std::list<aiNode*>&
{ {
aiString node_name(pID.c_str()); aiString node_name(pID.c_str());
for(std::list<aiNode*>::const_iterator it = pNodeList.begin(); it != pNodeList.end(); it++) for(aiNode* node: pNodeList)
{ {
if((*it)->mName == node_name) if(node->mName == node_name)
{ {
if(pNode != NULL) *pNode = *it; if(pNode != nullptr) *pNode = node;
return true; return true;
} }
}// for(std::list<aiNode*>::const_iterator it = pNodeList.begin(); it != pNodeList.end(); it++) }// for(aiNode* node: pNodeList)
return false; return false;
} }
bool AMFImporter::Find_ConvertedMaterial(const std::string& pID, const SPP_Material** pConvertedMaterial) const bool AMFImporter::Find_ConvertedMaterial(const std::string& pID, const SPP_Material** pConvertedMaterial) const
{ {
for(std::list<SPP_Material>::const_iterator it = mMaterial_Converted.begin(); it != mMaterial_Converted.end(); it++) for(const SPP_Material& mat: mMaterial_Converted)
{ {
if((*it).ID == pID) if(mat.ID == pID)
{ {
if(pConvertedMaterial != NULL) *pConvertedMaterial = (SPP_Material*)&(*it); if(pConvertedMaterial != nullptr) *pConvertedMaterial = &mat;
return true; return true;
} }
}// for(std::list<SPP_Material>::const_iterator it = mMaterial_Converted.begin(); it != mMaterial_Converted.end(); it++) }// for(const SPP_Material& mat: mMaterial_Converted)
return false; return false;
} }
@ -277,7 +277,7 @@ void AMFImporter::ParseHelper_Node_Enter(CAMFImporter_NodeElement* pNode)
void AMFImporter::ParseHelper_Node_Exit() void AMFImporter::ParseHelper_Node_Exit()
{ {
// check if we can walk up. // check if we can walk up.
if(mNodeElement_Cur != NULL) mNodeElement_Cur = mNodeElement_Cur->Parent; if(mNodeElement_Cur != nullptr) mNodeElement_Cur = mNodeElement_Cur->Parent;
} }
void AMFImporter::ParseHelper_FixTruncatedFloatString(const char* pInStr, std::string& pOutString) void AMFImporter::ParseHelper_FixTruncatedFloatString(const char* pInStr, std::string& pOutString)
@ -412,7 +412,7 @@ CAMFImporter_NodeElement* ne;
} }
// create root node element. // create root node element.
ne = new CAMFImporter_NodeElement_Root(NULL); ne = new CAMFImporter_NodeElement_Root(nullptr);
mNodeElement_Cur = ne;// set first "current" element mNodeElement_Cur = ne;// set first "current" element
// and assign attribute's values // and assign attribute's values
((CAMFImporter_NodeElement_Root*)ne)->Unit = unit; ((CAMFImporter_NodeElement_Root*)ne)->Unit = unit;

View File

@ -27,26 +27,13 @@ namespace Assimp
/// ///
/// Implementing features. /// Implementing features.
/// ///
/// Triangles/faces colors and texture mapping.
/// In both cases used same method. At begin - Assimp declare that
/// "A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex colors per vertex. NULL if not present. Each array is mNumVertices in size if present."
/// and
/// "A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per vertex. NULL if not present. The array is mNumVertices in size.".
/// As you seen arrays must has mNumVertices in size. But Assimp can not check size of that arrays. So, we can create create arrays with any size.
/// That is used. For colors importer create two arrays mColors: one for vertices colors and one for faces colors.
/// For texture mapping used one more feature: Assimp can not store texture ID for every face. In this case importer also create two arrays mTextureCoords:
/// one for texture coordinates of faces and one for texture IDs of faces.
///
/// Using \ref achFormatHint in \ref aiTexture importer set information about texture properties. For now used:
/// Texture format description used in achFormatHint array:
/// Byte 0
/// Bit 0 - texture fill mode:
/// value 0 - clamp
/// value 1 - repeat
///
///
/// Limitations. /// Limitations.
/// ///
/// 1. When for texture mapping used set of source textures (r, g, b, a) not only one then attribute "tiled" for all set will be true if it true in any of
/// source textures.
/// Example. Triangle use for texture mapping three textures. Two of them has "tiled" set to false and one - set to true. In scene all three textures
/// will be tiled.
///
/// Unsupported features: /// Unsupported features:
/// 1. Node <composite>, formulas in <composite> and <color>. For implementing this feature can be used expression parser "muParser" like in project /// 1. Node <composite>, formulas in <composite> and <color>. For implementing this feature can be used expression parser "muParser" like in project
/// "amf_tools". /// "amf_tools".
@ -54,11 +41,7 @@ namespace Assimp
/// 3. Curved geometry: <edge>, <normal> and children nodes of them. /// 3. Curved geometry: <edge>, <normal> and children nodes of them.
/// 4. Attributes: "unit" and "version" in <amf> read but do nothing. /// 4. Attributes: "unit" and "version" in <amf> read but do nothing.
/// 5. <metadata> stored only for root node <amf>. /// 5. <metadata> stored only for root node <amf>.
/// 6. When for texture mappinf used set of source textures (r, g, b, a) not only one then attribute "tiled" for all set will be true if it true in any of /// 6. Color averaging of vertices for which <triangle>'s set different colors.
/// source textures.
/// Example. Triangle use for texture mapping three textures. Two of them has "tiled" set to false and one - set to true. In scene all three textures
/// will be tiled.
/// 7. Color averaging of vertices for which <triangle>'s set different colors.
/// ///
/// Supported nodes: /// Supported nodes:
/// General: /// General:
@ -197,16 +180,17 @@ private:
/// \return true - if the material is found, else - false. /// \return true - if the material is found, else - false.
bool Find_ConvertedMaterial(const std::string& pID, const SPP_Material** pConvertedMaterial) const; bool Find_ConvertedMaterial(const std::string& pID, const SPP_Material** pConvertedMaterial) const;
/// \fn bool Find_ConvertedTexture(const std::string& pID_R, const std::string& pID_G, const std::string& pID_B, const std::string& pID_A, uint32_t* pConvertedTextureIndex = NULL) const /// \fn bool Find_ConvertedTexture(const std::string& pID_R, const std::string& pID_G, const std::string& pID_B, const std::string& pID_A, uint32_t* pConvertedTextureIndex = nullptr) const
/// Find texture in list of converted textures. Use at postprocessing step, /// Find texture in list of converted textures. Use at postprocessing step,
/// \param [in] pID_R - ID of source "red" texture. /// \param [in] pID_R - ID of source "red" texture.
/// \param [in] pID_G - ID of source "green" texture. /// \param [in] pID_G - ID of source "green" texture.
/// \param [in] pID_B - ID of source "blue" texture. /// \param [in] pID_B - ID of source "blue" texture.
/// \param [in] pID_A - ID of source "alpha" texture. Use empty string to find RGB-texture. /// \param [in] pID_A - ID of source "alpha" texture. Use empty string to find RGB-texture.
/// \param [out] pConvertedTextureIndex - pointer where index in list of found texture will be written. If equivalent to NULL then nothing will be written. /// \param [out] pConvertedTextureIndex - pointer where index in list of found texture will be written. If equivalent to nullptr then nothing will be
/// written.
/// \return true - if the texture is found, else - false. /// \return true - if the texture is found, else - false.
bool Find_ConvertedTexture(const std::string& pID_R, const std::string& pID_G, const std::string& pID_B, const std::string& pID_A, bool Find_ConvertedTexture(const std::string& pID_R, const std::string& pID_G, const std::string& pID_B, const std::string& pID_A,
uint32_t* pConvertedTextureIndex = NULL) const; uint32_t* pConvertedTextureIndex = nullptr) const;
/***********************************************/ /***********************************************/
/********* Functions: postprocess set **********/ /********* Functions: postprocess set **********/
@ -217,7 +201,7 @@ private:
/// \param [in] pNodeElement - reference to node element which kept <object> data. /// \param [in] pNodeElement - reference to node element which kept <object> data.
/// \param [in] pVertexCoordinateArray - reference to vertices coordinates kept in <vertices>. /// \param [in] pVertexCoordinateArray - reference to vertices coordinates kept in <vertices>.
/// \param [in] pVertexColorArray - reference to vertices colors for all <vertex's. If color for vertex is not set then corresponding member of array /// \param [in] pVertexColorArray - reference to vertices colors for all <vertex's. If color for vertex is not set then corresponding member of array
/// contain NULL. /// contain nullptr.
void PostprocessHelper_CreateMeshDataArray(const CAMFImporter_NodeElement_Mesh& pNodeElement, std::vector<aiVector3D>& pVertexCoordinateArray, void PostprocessHelper_CreateMeshDataArray(const CAMFImporter_NodeElement_Mesh& pNodeElement, std::vector<aiVector3D>& pVertexCoordinateArray,
std::vector<CAMFImporter_NodeElement_Color*>& pVertexColorArray) const; std::vector<CAMFImporter_NodeElement_Color*>& pVertexColorArray) const;
@ -258,8 +242,8 @@ private:
/// \param [in] pNodeElement - reference to node element which kept <mesh> data. /// \param [in] pNodeElement - reference to node element which kept <mesh> data.
/// \param [in] pVertexCoordinateArray - reference to vertices coordinates for all <volume>'s. /// \param [in] pVertexCoordinateArray - reference to vertices coordinates for all <volume>'s.
/// \param [in] pVertexColorArray - reference to vertices colors for all <volume>'s. If color for vertex is not set then corresponding member of array /// \param [in] pVertexColorArray - reference to vertices colors for all <volume>'s. If color for vertex is not set then corresponding member of array
/// contain NULL. /// contain nullptr.
/// \param [in] pObjectColor - pointer to colors for <object>. If color is not set then argument contain NULL. /// \param [in] pObjectColor - pointer to colors for <object>. If color is not set then argument contain nullptr.
/// \param [in] pMaterialList - reference to a list with defined materials. /// \param [in] pMaterialList - reference to a list with defined materials.
/// \param [out] pMeshList - reference to a list with all aiMesh of the scene. /// \param [out] pMeshList - reference to a list with all aiMesh of the scene.
/// \param [out] pSceneNode - reference to aiNode which will own new aiMesh's. /// \param [out] pSceneNode - reference to aiNode which will own new aiMesh's.
@ -503,7 +487,7 @@ public:
/// \fn AMFImporter() /// \fn AMFImporter()
/// Default constructor. /// Default constructor.
AMFImporter() AMFImporter()
: mNodeElement_Cur(NULL), mReader(NULL) : mNodeElement_Cur(nullptr), mReader(nullptr)
{} {}
/// \fn ~AMFImporter() /// \fn ~AMFImporter()

View File

@ -63,7 +63,7 @@ public:
public: public:
std::string ID;///< ID of element. std::string ID;///< ID of element.
CAMFImporter_NodeElement* Parent;///< Parrent element. If NULL then this node is root. CAMFImporter_NodeElement* Parent;///< Parrent element. If nullptr then this node is root.
std::list<CAMFImporter_NodeElement*> Child;///< Child elements. std::list<CAMFImporter_NodeElement*> Child;///< Child elements.
/***********************************************/ /***********************************************/

View File

@ -51,49 +51,50 @@ aiColor4D tcol;
void AMFImporter::PostprocessHelper_CreateMeshDataArray(const CAMFImporter_NodeElement_Mesh& pNodeElement, std::vector<aiVector3D>& pVertexCoordinateArray, void AMFImporter::PostprocessHelper_CreateMeshDataArray(const CAMFImporter_NodeElement_Mesh& pNodeElement, std::vector<aiVector3D>& pVertexCoordinateArray,
std::vector<CAMFImporter_NodeElement_Color*>& pVertexColorArray) const std::vector<CAMFImporter_NodeElement_Color*>& pVertexColorArray) const
{ {
CAMFImporter_NodeElement_Vertices* vn = NULL; CAMFImporter_NodeElement_Vertices* 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(std::list<CAMFImporter_NodeElement*>::const_iterator it = pNodeElement.Child.begin(); it != pNodeElement.Child.end(); it++) for(CAMFImporter_NodeElement* ne_child: pNodeElement.Child)
{ {
if((*it)->Type == CAMFImporter_NodeElement::ENET_Vertices) vn = (CAMFImporter_NodeElement_Vertices*)(*it); if(ne_child->Type == CAMFImporter_NodeElement::ENET_Vertices) vn = (CAMFImporter_NodeElement_Vertices*)ne_child;
} }
// If "vertices" not found then no work for us. // If "vertices" not found then no work for us.
if(vn == NULL) 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(std::list<CAMFImporter_NodeElement*>::const_iterator it = vn->Child.begin(); it != vn->Child.end(); it++) for(CAMFImporter_NodeElement* vn_child: vn->Child)
{ {
// vertices, colors // vertices, colors
if((*it)->Type == CAMFImporter_NodeElement::ENET_Vertex) if(vn_child->Type == CAMFImporter_NodeElement::ENET_Vertex)
{ {
// by default clear color for current vertex // by default clear color for current vertex
pVertexColorArray[col_idx] = NULL; pVertexColorArray[col_idx] = nullptr;
for(std::list<CAMFImporter_NodeElement*>::const_iterator vtx_it = (*it)->Child.begin(); vtx_it != (*it)->Child.end(); vtx_it++) for(CAMFImporter_NodeElement* vtx: vn_child->Child)
{ {
if((*vtx_it)->Type == CAMFImporter_NodeElement::ENET_Coordinates) if(vtx->Type == CAMFImporter_NodeElement::ENET_Coordinates)
{ {
pVertexCoordinateArray.push_back(((CAMFImporter_NodeElement_Coordinates*)(*vtx_it))->Coordinate); pVertexCoordinateArray.push_back(((CAMFImporter_NodeElement_Coordinates*)vtx)->Coordinate);
continue; continue;
}// if((*vtx_it)->Type == CAMFImporter_NodeElement::ENET_Coordinates) }
if((*vtx_it)->Type == CAMFImporter_NodeElement::ENET_Color) if(vtx->Type == CAMFImporter_NodeElement::ENET_Color)
{ {
pVertexColorArray[col_idx] = (CAMFImporter_NodeElement_Color*)(*vtx_it); pVertexColorArray[col_idx] = (CAMFImporter_NodeElement_Color*)vtx;
continue; continue;
}// if((*vtx_it)->Type == CAMFImporter_NodeElement::ENET_Coordinates) }
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator vtx_it = (*it)->Child.begin(); vtx_it != (*it)->Child.end(); vtx_it++) }// for(CAMFImporter_NodeElement* vtx: vn_child->Child)
col_idx++; col_idx++;
}// if((*it)->Type == CAMFImporter_NodeElement::ENET_Vertex) }// if(vn_child->Type == CAMFImporter_NodeElement::ENET_Vertex)
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = pNodeElement.Child.begin(); it != pNodeElement.Child.end(); it++) }// for(CAMFImporter_NodeElement* vn_child: vn->Child)
} }
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,
@ -300,7 +301,7 @@ void AMFImporter::Postprocess_AddMetadata(const std::list<CAMFImporter_NodeEleme
{ {
if(pMetadataList.size() > 0) if(pMetadataList.size() > 0)
{ {
if(pSceneNode.mMetaData != NULL) throw DeadlyImportError("Postprocess. MetaData member in node are not NULL. Something went wrong."); if(pSceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
// copy collected metadata to output node. // copy collected metadata to output node.
pSceneNode.mMetaData = new aiMetadata(); pSceneNode.mMetaData = new aiMetadata();
@ -310,37 +311,37 @@ void AMFImporter::Postprocess_AddMetadata(const std::list<CAMFImporter_NodeEleme
size_t meta_idx = 0; size_t meta_idx = 0;
for(std::list<CAMFImporter_NodeElement_Metadata*>::const_iterator it = pMetadataList.begin(); it != pMetadataList.end(); it++) for(const CAMFImporter_NodeElement_Metadata& metadata: pMetadataList)
{ {
pSceneNode.mMetaData->Set(meta_idx++, (*it)->Type, (*it)->Value.c_str()); pSceneNode.mMetaData->Set(meta_idx++, metadata.Type, metadata.Value.c_str());
} }
}// if(pMetadataList.size() > 0) }// if(pMetadataList.size() > 0)
} }
void AMFImporter::Postprocess_BuildNodeAndObject(const CAMFImporter_NodeElement_Object& pNodeElement, std::list<aiMesh*>& pMeshList, aiNode** pSceneNode) void AMFImporter::Postprocess_BuildNodeAndObject(const CAMFImporter_NodeElement_Object& pNodeElement, std::list<aiMesh*>& pMeshList, aiNode** pSceneNode)
{ {
CAMFImporter_NodeElement_Color* object_color = NULL; CAMFImporter_NodeElement_Color* 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(std::list<CAMFImporter_NodeElement*>::const_iterator it = pNodeElement.Child.begin(); it != pNodeElement.Child.end(); it++) for(const CAMFImporter_NodeElement* ne_child: pNodeElement.Child)
{ {
std::vector<aiVector3D> vertex_arr; std::vector<aiVector3D> vertex_arr;
std::vector<CAMFImporter_NodeElement_Color*> color_arr; std::vector<CAMFImporter_NodeElement_Color*> color_arr;
// color for object // color for object
if((*it)->Type == CAMFImporter_NodeElement::ENET_Color) object_color = (CAMFImporter_NodeElement_Color*)(*it); if(ne_child->Type == CAMFImporter_NodeElement::ENET_Color) object_color = (CAMFImporter_NodeElement_Color*)ne_child;
if((*it)->Type == CAMFImporter_NodeElement::ENET_Mesh) if(ne_child->Type == CAMFImporter_NodeElement::ENET_Mesh)
{ {
// Create arrays from children of mesh: vertices. // Create arrays from children of mesh: vertices.
PostprocessHelper_CreateMeshDataArray(*((CAMFImporter_NodeElement_Mesh*)*it), vertex_arr, color_arr); PostprocessHelper_CreateMeshDataArray(*((CAMFImporter_NodeElement_Mesh*)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*)*it), vertex_arr, color_arr, object_color, pMeshList, **pSceneNode); Postprocess_BuildMeshSet(*((CAMFImporter_NodeElement_Mesh*)ne_child), vertex_arr, color_arr, object_color, pMeshList, **pSceneNode);
}// if((*it)->Type == CAMFImporter_NodeElement::ENET_Mesh) }
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = pNodeElement.Child.begin(); it != pNodeElement.Child.end(); it++) }// for(const CAMFImporter_NodeElement* ne_child: pNodeElement)
} }
void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh& pNodeElement, const std::vector<aiVector3D>& pVertexCoordinateArray, void AMFImporter::Postprocess_BuildMeshSet(const CAMFImporter_NodeElement_Mesh& pNodeElement, const std::vector<aiVector3D>& pVertexCoordinateArray,
@ -521,7 +522,7 @@ std::list<unsigned int> mesh_idx;
else// set default color. else// set default color.
{ {
return {0, 0, 0, 0}; return {0, 0, 0, 0};
}// if((vi < pVertexColorArray.size()) && (pVertexColorArray[vi] != NULL)) else }// if((vi < pVertexColorArray.size()) && (pVertexColorArray[vi] != nullptr)) else
};// auto Vertex_CalculateColor = [&](const size_t pIdx) -> aiColor4D };// auto Vertex_CalculateColor = [&](const size_t pIdx) -> aiColor4D
@ -680,17 +681,17 @@ void AMFImporter::Postprocess_BuildMaterial(const CAMFImporter_NodeElement_Mater
SPP_Material new_mat; SPP_Material new_mat;
new_mat.ID = pMaterial.ID; new_mat.ID = pMaterial.ID;
for(std::list<CAMFImporter_NodeElement*>::const_iterator it = pMaterial.Child.begin(); it != pMaterial.Child.end(); it++) for(const CAMFImporter_NodeElement* mat_child: pMaterial.Child)
{ {
if((*it)->Type == CAMFImporter_NodeElement::ENET_Color) if(mat_child->Type == CAMFImporter_NodeElement::ENET_Color)
{ {
new_mat.Color = (CAMFImporter_NodeElement_Color*)(*it); new_mat.Color = (CAMFImporter_NodeElement_Color*)mat_child;
} }
else if((*it)->Type == CAMFImporter_NodeElement::ENET_Metadata) else if(mat_child->Type == CAMFImporter_NodeElement::ENET_Metadata)
{ {
new_mat.Metadata.push_back((CAMFImporter_NodeElement_Metadata*)(*it)); new_mat.Metadata.push_back((CAMFImporter_NodeElement_Metadata*)mat_child);
} }
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = pMaterial.Child.begin(); it != pMaterial.Child.end(); it++) }// for(const CAMFImporter_NodeElement* mat_child; pMaterial.Child)
// place converted material to special list // place converted material to special list
mMaterial_Converted.push_back(new_mat); mMaterial_Converted.push_back(new_mat);
@ -709,17 +710,17 @@ std::list<aiNode*> ch_node;
con_node = new aiNode; con_node = new aiNode;
con_node->mName = pConstellation.ID; con_node->mName = pConstellation.ID;
// Walk thru children and search for instances of another objects, constellations. // Walk thru children and search for instances of another objects, constellations.
for(std::list<CAMFImporter_NodeElement*>::const_iterator it = pConstellation.Child.begin(); it != pConstellation.Child.end(); it++) for(const CAMFImporter_NodeElement* ne: pConstellation.Child)
{ {
aiMatrix4x4 tmat; aiMatrix4x4 tmat;
aiNode* t_node; aiNode* t_node;
aiNode* found_node; aiNode* found_node;
if((*it)->Type == CAMFImporter_NodeElement::ENET_Metadata) continue; if(ne->Type == CAMFImporter_NodeElement::ENET_Metadata) continue;
if((*it)->Type != CAMFImporter_NodeElement::ENET_Instance) throw DeadlyImportError("Only <instance> nodes can be in <constellation>."); if(ne->Type != CAMFImporter_NodeElement::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*)(*it)); CAMFImporter_NodeElement_Instance& als = *((CAMFImporter_NodeElement_Instance*)ne);
// find referenced object // find referenced object
if(!Find_ConvertedNode(als.ObjectID, pNodeList, &found_node)) Throw_ID_NotFound(als.ObjectID); if(!Find_ConvertedNode(als.ObjectID, pNodeList, &found_node)) Throw_ID_NotFound(als.ObjectID);
@ -737,7 +738,7 @@ std::list<aiNode*> ch_node;
SceneCombiner::Copy(&t_node->mChildren[0], found_node); SceneCombiner::Copy(&t_node->mChildren[0], found_node);
t_node->mChildren[0]->mParent = t_node; t_node->mChildren[0]->mParent = t_node;
ch_node.push_back(t_node); ch_node.push_back(t_node);
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = mNodeElement_List.begin(); it != mNodeElement_List.end(); it++) }// for(const CAMFImporter_NodeElement* ne: pConstellation.Child)
// copy found aiNode's as children // copy found aiNode's as children
if(ch_node.size() == 0) throw DeadlyImportError("<constellation> must have at least one <instance>."); if(ch_node.size() == 0) throw DeadlyImportError("<constellation> must have at least one <instance>.");
@ -746,7 +747,7 @@ std::list<aiNode*> ch_node;
con_node->mNumChildren = ch_node.size(); con_node->mNumChildren = ch_node.size();
con_node->mChildren = new aiNode*[con_node->mNumChildren]; con_node->mChildren = new aiNode*[con_node->mNumChildren];
for(std::list<aiNode*>::const_iterator it = ch_node.begin(); it != ch_node.end(); it++) con_node->mChildren[ch_idx++] = *it; for(aiNode* node: ch_node) con_node->mChildren[ch_idx++] = node;
// and place "root" of <constellation> node to node list // and place "root" of <constellation> node to node list
pNodeList.push_back(con_node); pNodeList.push_back(con_node);
@ -763,21 +764,22 @@ std::list<CAMFImporter_NodeElement_Metadata*> meta_list;
// For building aiScene we are must to do few steps: // For building aiScene we are must to do few steps:
// at first creating root node for aiScene. // at first creating root node for aiScene.
pScene->mRootNode = new aiNode; pScene->mRootNode = new aiNode;
pScene->mRootNode->mParent = NULL; 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 = NULL; CAMFImporter_NodeElement* root_el = nullptr;
for(std::list<CAMFImporter_NodeElement*>::const_iterator it = mNodeElement_List.begin(); it != mNodeElement_List.end(); it++)
{
if((*it)->Type != CAMFImporter_NodeElement::ENET_Root) continue;
root_el = *it; for(CAMFImporter_NodeElement* ne: mNodeElement_List)
{
if(ne->Type != CAMFImporter_NodeElement::ENET_Root) continue;
root_el = ne;
break; break;
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = mNodeElement_List.begin(); it != mNodeElement_List.end(); it++) }// for(const CAMFImporter_NodeElement* ne: mNodeElement_List)
// Check if root element are found. // Check if root element are found.
if(root_el == NULL) throw DeadlyImportError("Root(<amf>) element not found."); if(root_el == nullptr) throw DeadlyImportError("Root(<amf>) element not found.");
// after that walk thru children of root and collect data. Five types of nodes can be placed at top level - in <amf>: <object>, <material>, <texture>, // after that walk thru children of root and collect data. Five types of nodes can be placed at top level - in <amf>: <object>, <material>, <texture>,
// <constellation> and <metadata>. But at first we must read <material> and <texture> because they will be used in <object>. <metadata> can be read // <constellation> and <metadata>. But at first we must read <material> and <texture> because they will be used in <object>. <metadata> can be read
@ -785,41 +787,41 @@ std::list<CAMFImporter_NodeElement_Metadata*> meta_list;
// //
// 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(std::list<CAMFImporter_NodeElement*>::const_iterator it = root_el->Child.begin(), it_end = root_el->Child.end(); it != it_end; it++) for(const CAMFImporter_NodeElement* root_child: root_el->Child)
{ {
if((*it)->Type == CAMFImporter_NodeElement::ENET_Material) Postprocess_BuildMaterial(*((CAMFImporter_NodeElement_Material*)*it)); if(root_child->Type == CAMFImporter_NodeElement::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(std::list<CAMFImporter_NodeElement*>::const_iterator it = root_el->Child.begin(), it_end = root_el->Child.end(); it != it_end; it++) for(const CAMFImporter_NodeElement* root_child: root_el->Child)
{ {
if((*it)->Type == CAMFImporter_NodeElement::ENET_Object) if(root_child->Type == CAMFImporter_NodeElement::ENET_Object)
{ {
aiNode* tnode = NULL; 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>
Postprocess_BuildNodeAndObject(*((CAMFImporter_NodeElement_Object*)*it), mesh_list, &tnode); Postprocess_BuildNodeAndObject(*((CAMFImporter_NodeElement_Object*)root_child), mesh_list, &tnode);
if(tnode != NULL) node_list.push_back(tnode); if(tnode != nullptr) node_list.push_back(tnode);
}// if(it->Type == CAMFImporter_NodeElement::ENET_Object) }
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = root_el->Child.begin(), it_end = root_el->Child.end(); it != it_end; it++) }// for(const CAMFImporter_NodeElement* root_child: root_el->Child)
// And finally read rest of nodes. // And finally read rest of nodes.
// //
for(std::list<CAMFImporter_NodeElement*>::const_iterator it = root_el->Child.begin(), it_end = root_el->Child.end(); it != it_end; it++) for(const CAMFImporter_NodeElement* root_child: root_el->Child)
{ {
// 4. <constellation> // 4. <constellation>
if((*it)->Type == CAMFImporter_NodeElement::ENET_Constellation) if(root_child->Type == CAMFImporter_NodeElement::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*)*it), node_list); Postprocess_BuildConstellation(*((CAMFImporter_NodeElement_Constellation*)root_child), node_list);
} }
// 5, <metadata> // 5, <metadata>
if((*it)->Type == CAMFImporter_NodeElement::ENET_Metadata) meta_list.push_back((CAMFImporter_NodeElement_Metadata*)*it); if(root_child->Type == CAMFImporter_NodeElement::ENET_Metadata) meta_list.push_back((CAMFImporter_NodeElement_Metadata*)root_child);
}// for(std::list<CAMFImporter_NodeElement*>::const_iterator it = root_el->Child.begin(), it_end = root_el->Child.end(); it != it_end; it++) }// 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
Postprocess_AddMetadata(meta_list, *pScene->mRootNode); Postprocess_AddMetadata(meta_list, *pScene->mRootNode);
@ -843,7 +845,7 @@ nl_clean_loop:
next_it++; next_it++;
for(; next_it != node_list.end(); next_it++) for(; next_it != node_list.end(); next_it++)
{ {
if((*next_it)->FindNode((*nl_it)->mName) != NULL) if((*next_it)->FindNode((*nl_it)->mName) != nullptr)
{ {
// if current top node(nl_it) found in another top node then erase it from node_list and restart search loop. // if current top node(nl_it) found in another top node then erase it from node_list and restart search loop.
node_list.erase(nl_it); node_list.erase(nl_it);