Sfoglia il codice sorgente

Merge branch 'import_x3d' into export_x3d

Alexandr Arutjunov 9 anni fa
parent
commit
dc7654f796

+ 1 - 0
code/CMakeLists.txt

@@ -617,6 +617,7 @@ ADD_ASSIMP_IMPORTER(X3D
   X3DImporter_Geometry3D.cpp
   X3DImporter_Group.cpp
   X3DImporter_Light.cpp
+  X3DImporter_Macro.hpp
   X3DImporter_Metadata.cpp
   X3DImporter_Networking.cpp
   X3DImporter_Node.hpp

+ 49 - 28
code/X3DImporter.cpp

@@ -23,7 +23,7 @@ namespace Assimp
 /// Conastant which hold importer description
 const aiImporterDesc X3DImporter::Description = {
 	"Extensible 3D(X3D) Importer",
-	"nevorek",
+	"smalcom",
 	"",
 	"See documentation in source code. Chapter: Limitations.",
 	aiImporterFlags_SupportTextFlavour | aiImporterFlags_LimitedSupport | aiImporterFlags_Experimental,
@@ -1371,10 +1371,28 @@ bool close_found = false;// flag: true if close tag of node are found.
 
 void X3DImporter::ParseNode_Scene()
 {
+auto GroupCounter_Increase = [](size_t& pCounter, const char* pGroupName) -> void
+{
+	pCounter++;
+	if(pCounter == 0) throw DeadlyImportError("Group counter overflow. Too much groups with type: " + std::string(pGroupName) + ".");
+};
+
+auto GroupCounter_Decrease = [&](size_t& pCounter, const char* pGroupName) -> void
+{
+	if(pCounter == 0) Throw_TagCountIncorrect(pGroupName);
+
+	pCounter--;
+};
+
+const char* GroupName_Group = "Group";
+const char* GroupName_StaticGroup = "StaticGroup";
+const char* GroupName_Transform = "Transform";
+const char* GroupName_Switch = "Switch";
+
 bool close_found = false;
-ssize_t group_cnt = 0;
-ssize_t transform_cnt = 0;
-ssize_t sw_cnt = 0;
+size_t counter_group = 0;
+size_t counter_transform = 0;
+size_t counter_switch = 0;
 
 	// while create static node? Because objects name used deeper in "USE" attribute can be equal to some meta in <head> node.
 	ParseHelper_Group_Begin(true);
@@ -1386,30 +1404,33 @@ ssize_t sw_cnt = 0;
 			{
 				ParseNode_Shape_Shape();
 			}
-			else if(XML_CheckNode_NameEqual("Group"))
+			else if(XML_CheckNode_NameEqual(GroupName_Group))
 			{
-				group_cnt++;
+				GroupCounter_Increase(counter_group, GroupName_Group);
 				ParseNode_Grouping_Group();
-				if(mReader->isEmptyElement()) group_cnt--;// if node is empty then decrease group counter at this place.
+				// if node is empty then decrease group counter at this place.
+				if(mReader->isEmptyElement()) GroupCounter_Decrease(counter_group, GroupName_Group);
 			}
-			else if(XML_CheckNode_NameEqual("StaticGroup"))
+			else if(XML_CheckNode_NameEqual(GroupName_StaticGroup))
 			{
-				group_cnt++;
+				GroupCounter_Increase(counter_group, GroupName_StaticGroup);
 				ParseNode_Grouping_StaticGroup();
-				if(mReader->isEmptyElement()) group_cnt--;// if node is empty then decrease group counter at this place.
-
+				// if node is empty then decrease group counter at this place.
+				if(mReader->isEmptyElement()) GroupCounter_Decrease(counter_group, GroupName_StaticGroup);
 			}
-			else if(XML_CheckNode_NameEqual("Transform"))
+			else if(XML_CheckNode_NameEqual(GroupName_Transform))
 			{
-				transform_cnt++;
+				GroupCounter_Increase(counter_transform, GroupName_Transform);
 				ParseNode_Grouping_Transform();
-				if(mReader->isEmptyElement()) transform_cnt--;// if node is empty then decrease group counter at this place.
+				// if node is empty then decrease group counter at this place.
+				if(mReader->isEmptyElement()) GroupCounter_Decrease(counter_transform, GroupName_Transform);
 			}
-			else if(XML_CheckNode_NameEqual("Switch"))
+			else if(XML_CheckNode_NameEqual(GroupName_Switch))
 			{
-				sw_cnt++;
+				GroupCounter_Increase(counter_switch, GroupName_Switch);
 				ParseNode_Grouping_Switch();
-				if(mReader->isEmptyElement()) sw_cnt--;// if node is empty then decrease group counter at this place.
+				// if node is empty then decrease group counter at this place.
+				if(mReader->isEmptyElement()) GroupCounter_Decrease(counter_switch, GroupName_Switch);
 			}
 			else if(XML_CheckNode_NameEqual("DirectionalLight"))
 			{
@@ -1440,24 +1461,24 @@ ssize_t sw_cnt = 0;
 
 				break;
 			}
-			else if(XML_CheckNode_NameEqual("Group"))
+			else if(XML_CheckNode_NameEqual(GroupName_Group))
 			{
-				group_cnt--;
+				GroupCounter_Decrease(counter_group, GroupName_Group);
 				ParseNode_Grouping_GroupEnd();
 			}
-			else if(XML_CheckNode_NameEqual("StaticGroup"))
+			else if(XML_CheckNode_NameEqual(GroupName_StaticGroup))
 			{
-				group_cnt--;
+				GroupCounter_Decrease(counter_group, GroupName_StaticGroup);
 				ParseNode_Grouping_StaticGroupEnd();
 			}
-			else if(XML_CheckNode_NameEqual("Transform"))
+			else if(XML_CheckNode_NameEqual(GroupName_Transform))
 			{
-				transform_cnt--;
+				GroupCounter_Decrease(counter_transform, GroupName_Transform);
 				ParseNode_Grouping_TransformEnd();
 			}
-			else if(XML_CheckNode_NameEqual("Switch"))
+			else if(XML_CheckNode_NameEqual(GroupName_Switch))
 			{
-				sw_cnt--;
+				GroupCounter_Decrease(counter_switch, GroupName_Switch);
 				ParseNode_Grouping_SwitchEnd();
 			}
 		}// if(mReader->getNodeType() == irr::io::EXN_ELEMENT) else
@@ -1465,9 +1486,9 @@ ssize_t sw_cnt = 0;
 
 	ParseHelper_Node_Exit();
 
-	if(group_cnt) Throw_TagCountIncorrect("Group");
-	if(transform_cnt) Throw_TagCountIncorrect("Transform");
-	if(sw_cnt) Throw_TagCountIncorrect("Switch");
+	if(counter_group) Throw_TagCountIncorrect("Group");
+	if(counter_transform) Throw_TagCountIncorrect("Transform");
+	if(counter_switch) Throw_TagCountIncorrect("Switch");
 	if(!close_found) Throw_CloseNotFound("Scene");
 
 }

+ 2 - 2
code/X3DImporter_Light.cpp

@@ -174,9 +174,9 @@ void X3DImporter::ParseNode_Lighting_SpotLight()
 std::string def, use;
 float ambientIntensity = 0;
 aiVector3D attenuation(1, 0, 0);
-float beamWidth = 0.7854;
+float beamWidth = 0.7854f;
 aiColor3D color(1, 1, 1);
-float cutOffAngle = 1.570796;
+float cutOffAngle = 1.570796f;
 aiVector3D direction(0, 0, -1);
 bool global = true;
 float intensity = 1;

+ 1 - 1
code/X3DImporter_Macro.hpp

@@ -1,7 +1,7 @@
 /// \file X3DImporter_Macro.hpp
 /// \brief Useful macrodefines.
 /// \date 2015-2016
-/// \author nevorek@gmail.com
+/// \author smal.root@gmail.com
 
 #ifndef X3DIMPORTER_MACRO_HPP_INCLUDED
 #define X3DIMPORTER_MACRO_HPP_INCLUDED

+ 1 - 1
code/X3DImporter_Postprocess.cpp

@@ -167,7 +167,7 @@ void X3DImporter::Postprocess_BuildMaterial(const CX3DImporter_NodeElement& pNod
 			tvalf = 1;
 			taimat.AddProperty(&tvalf, 1, AI_MATKEY_SHININESS_STRENGTH);
 			taimat.AddProperty(&tnemat.Shininess, 1, AI_MATKEY_SHININESS);
-			tvalf = 1.0 - tnemat.Transparency;
+			tvalf = 1.0f - tnemat.Transparency;
 			taimat.AddProperty(&tvalf, 1, AI_MATKEY_OPACITY);
 		}// if((*el_it)->Type == CX3DImporter_NodeElement::ENET_Material)
 		else if((*el_it)->Type == CX3DImporter_NodeElement::ENET_ImageTexture)

+ 3 - 3
code/X3DImporter_Shape.cpp

@@ -159,10 +159,10 @@ CX3DImporter_NodeElement* ne;
 void X3DImporter::ParseNode_Shape_Material()
 {
 std::string use, def;
-float ambientIntensity = 0.2;
-float shininess = 0.2;
+float ambientIntensity = 0.2f;
+float shininess = 0.2f;
 float transparency = 0;
-aiColor3D diffuseColor(0.8, 0.8, 0.8);
+aiColor3D diffuseColor(0.8f, 0.8f, 0.8f);
 aiColor3D emissiveColor(0, 0, 0);
 aiColor3D specularColor(0, 0, 0);
 CX3DImporter_NodeElement* ne;