2020-03-21 06:34:12 +00:00
|
|
|
/*
|
2016-10-03 17:24:14 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2016-10-03 17:24:14 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2016-09-28 14:49:15 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_AMF_IMPORTER
|
|
|
|
|
|
|
|
#include "AMFImporter.hpp"
|
2020-06-27 13:57:06 +00:00
|
|
|
#include <assimp/ParsingUtils.h>
|
|
|
|
|
|
|
|
namespace Assimp {
|
2016-09-28 14:49:15 +00:00
|
|
|
|
|
|
|
// <mesh>
|
|
|
|
// </mesh>
|
|
|
|
// A 3D mesh hull.
|
|
|
|
// Multi elements - Yes.
|
|
|
|
// Parent element - <object>.
|
2020-06-27 13:57:06 +00:00
|
|
|
void AMFImporter::ParseNode_Mesh(XmlNode &node) {
|
|
|
|
AMFNodeElementBase *ne = nullptr;
|
|
|
|
|
|
|
|
// Check for child nodes
|
|
|
|
if (0 != ASSIMP_stricmp(node.name(), "mesh")) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-12 12:40:19 +00:00
|
|
|
// create new mesh object.
|
|
|
|
ne = new AMFMesh(mNodeElement_Cur);
|
2020-06-27 13:57:06 +00:00
|
|
|
bool found_verts = false, found_volumes = false;
|
2020-09-09 22:05:53 +00:00
|
|
|
if (!node.empty()) {
|
|
|
|
ParseHelper_Node_Enter(ne);
|
|
|
|
pugi::xml_node vertNode = node.child("vertices");
|
|
|
|
if (!vertNode.empty()) {
|
|
|
|
ParseNode_Vertices(vertNode);
|
|
|
|
found_verts = true;
|
|
|
|
}
|
2020-06-27 13:57:06 +00:00
|
|
|
|
2020-09-09 22:05:53 +00:00
|
|
|
pugi::xml_node volumeNode = node.child("volume");
|
|
|
|
if (!volumeNode.empty()) {
|
|
|
|
ParseNode_Volume(volumeNode);
|
|
|
|
found_volumes = true;
|
|
|
|
}
|
|
|
|
ParseHelper_Node_Exit();
|
2021-09-07 13:04:08 +00:00
|
|
|
}
|
2020-06-27 13:57:06 +00:00
|
|
|
|
|
|
|
if (!found_verts && !found_volumes) {
|
|
|
|
mNodeElement_Cur->Child.push_back(ne);
|
|
|
|
} // if(!mReader->isEmptyElement()) else
|
|
|
|
|
|
|
|
// and to node element list because its a new object in graph.
|
|
|
|
mNodeElement_List.push_back(ne);
|
2016-09-28 14:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// <vertices>
|
|
|
|
// </vertices>
|
|
|
|
// The list of vertices to be used in defining triangles.
|
|
|
|
// Multi elements - No.
|
|
|
|
// Parent element - <mesh>.
|
2020-06-27 13:57:06 +00:00
|
|
|
void AMFImporter::ParseNode_Vertices(XmlNode &node) {
|
|
|
|
AMFNodeElementBase *ne = nullptr;
|
|
|
|
|
|
|
|
// create new mesh object.
|
|
|
|
ne = new AMFVertices(mNodeElement_Cur);
|
|
|
|
// Check for child nodes
|
2021-04-03 08:25:03 +00:00
|
|
|
if (node.empty()) {
|
2020-06-27 13:57:06 +00:00
|
|
|
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
2021-04-03 08:25:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ParseHelper_Node_Enter(ne);
|
|
|
|
for (XmlNode ¤tNode : node.children()) {
|
|
|
|
const std::string ¤tName = currentNode.name();
|
|
|
|
if (currentName == "vertex") {
|
|
|
|
ParseNode_Vertex(currentNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ParseHelper_Node_Exit();
|
2020-06-27 13:57:06 +00:00
|
|
|
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
2016-09-28 14:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// <vertex>
|
|
|
|
// </vertex>
|
|
|
|
// A vertex to be referenced in triangles.
|
|
|
|
// Multi elements - Yes.
|
|
|
|
// Parent element - <vertices>.
|
2020-06-27 13:57:06 +00:00
|
|
|
void AMFImporter::ParseNode_Vertex(XmlNode &node) {
|
|
|
|
AMFNodeElementBase *ne = nullptr;
|
|
|
|
|
|
|
|
// create new mesh object.
|
|
|
|
ne = new AMFVertex(mNodeElement_Cur);
|
2020-07-10 20:25:38 +00:00
|
|
|
|
|
|
|
// Check for child nodes
|
2020-06-27 13:57:06 +00:00
|
|
|
pugi::xml_node colorNode = node.child("color");
|
|
|
|
bool col_read = false;
|
|
|
|
bool coord_read = false;
|
2020-09-09 22:05:53 +00:00
|
|
|
if (!node.empty()) {
|
|
|
|
ParseHelper_Node_Enter(ne);
|
|
|
|
if (!colorNode.empty()) {
|
|
|
|
ParseNode_Color(colorNode);
|
|
|
|
col_read = true;
|
|
|
|
}
|
|
|
|
pugi::xml_node coordNode = node.child("coordinates");
|
|
|
|
if (!coordNode.empty()) {
|
|
|
|
ParseNode_Coordinates(coordNode);
|
|
|
|
coord_read = true;
|
|
|
|
}
|
|
|
|
ParseHelper_Node_Exit();
|
2020-06-27 13:57:06 +00:00
|
|
|
}
|
2020-09-09 22:05:53 +00:00
|
|
|
|
2020-09-04 05:33:10 +00:00
|
|
|
if (!coord_read && !col_read) {
|
2020-06-27 13:57:06 +00:00
|
|
|
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
|
|
|
}
|
|
|
|
|
|
|
|
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
2016-09-28 14:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// <coordinates>
|
|
|
|
// </coordinates>
|
|
|
|
// Specifies the 3D location of this vertex.
|
|
|
|
// Multi elements - No.
|
|
|
|
// Parent element - <vertex>.
|
|
|
|
//
|
|
|
|
// Children elements:
|
|
|
|
// <x>, <y>, <z>
|
|
|
|
// Multi elements - No.
|
|
|
|
// X, Y, or Z coordinate, respectively, of a vertex position in space.
|
2020-06-27 13:57:06 +00:00
|
|
|
void AMFImporter::ParseNode_Coordinates(XmlNode &node) {
|
|
|
|
AMFNodeElementBase *ne = nullptr;
|
2020-09-09 22:05:53 +00:00
|
|
|
if (!node.empty()) {
|
2021-04-03 08:25:03 +00:00
|
|
|
ne = new AMFCoordinates(mNodeElement_Cur);
|
2020-09-09 22:05:53 +00:00
|
|
|
ParseHelper_Node_Enter(ne);
|
|
|
|
for (XmlNode ¤tNode : node.children()) {
|
2021-04-03 08:25:03 +00:00
|
|
|
// create new color object.
|
|
|
|
AMFCoordinates &als = *((AMFCoordinates *)ne); // alias for convenience
|
|
|
|
const std::string ¤tName = ai_tolower(currentNode.name());
|
|
|
|
if (currentName == "x") {
|
2020-09-09 22:05:53 +00:00
|
|
|
XmlParser::getValueAsFloat(currentNode, als.Coordinate.x);
|
2021-04-03 08:25:03 +00:00
|
|
|
} else if (currentName == "y") {
|
2020-09-09 22:05:53 +00:00
|
|
|
XmlParser::getValueAsFloat(currentNode, als.Coordinate.y);
|
2021-04-03 08:25:03 +00:00
|
|
|
} else if (currentName == "z") {
|
2020-09-09 22:05:53 +00:00
|
|
|
XmlParser::getValueAsFloat(currentNode, als.Coordinate.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ParseHelper_Node_Exit();
|
2021-04-03 08:25:03 +00:00
|
|
|
|
2020-09-09 22:05:53 +00:00
|
|
|
} else {
|
2021-04-03 08:25:03 +00:00
|
|
|
mNodeElement_Cur->Child.push_back(new AMFCoordinates(mNodeElement_Cur));
|
2020-09-09 22:05:53 +00:00
|
|
|
}
|
2020-06-27 13:57:06 +00:00
|
|
|
|
|
|
|
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
2016-09-28 14:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// <volume
|
|
|
|
// materialid="" - Which material to use.
|
2021-02-14 02:28:14 +00:00
|
|
|
// type="" - What this volume describes can be "region" or "support". If none specified, "object" is assumed. If support, then the geometric
|
2016-09-28 14:49:15 +00:00
|
|
|
// requirements 1-8 listed in section 5 do not need to be maintained.
|
|
|
|
// >
|
|
|
|
// </volume>
|
|
|
|
// Defines a volume from the established vertex list.
|
|
|
|
// Multi elements - Yes.
|
|
|
|
// Parent element - <mesh>.
|
2020-06-27 13:57:06 +00:00
|
|
|
void AMFImporter::ParseNode_Volume(XmlNode &node) {
|
|
|
|
std::string materialid;
|
|
|
|
std::string type;
|
|
|
|
AMFNodeElementBase *ne = new AMFVolume(mNodeElement_Cur);
|
|
|
|
|
|
|
|
// Read attributes for node <color>.
|
|
|
|
// and assign read data
|
2021-09-07 13:04:08 +00:00
|
|
|
|
2020-06-27 13:57:06 +00:00
|
|
|
((AMFVolume *)ne)->MaterialID = node.attribute("materialid").as_string();
|
2021-09-07 13:04:08 +00:00
|
|
|
|
2020-06-27 13:57:06 +00:00
|
|
|
((AMFVolume *)ne)->Type = type;
|
|
|
|
// Check for child nodes
|
2020-07-04 07:04:06 +00:00
|
|
|
bool col_read = false;
|
2020-09-09 22:05:53 +00:00
|
|
|
if (!node.empty()) {
|
|
|
|
ParseHelper_Node_Enter(ne);
|
2021-04-03 08:25:03 +00:00
|
|
|
for (auto ¤tNode : node.children()) {
|
2020-09-09 22:05:53 +00:00
|
|
|
const std::string currentName = currentNode.name();
|
|
|
|
if (currentName == "color") {
|
|
|
|
if (col_read) Throw_MoreThanOnceDefined(currentName, "color", "Only one color can be defined for <volume>.");
|
|
|
|
ParseNode_Color(currentNode);
|
|
|
|
col_read = true;
|
|
|
|
} else if (currentName == "triangle") {
|
|
|
|
ParseNode_Triangle(currentNode);
|
|
|
|
} else if (currentName == "metadata") {
|
|
|
|
ParseNode_Metadata(currentNode);
|
|
|
|
} else if (currentName == "volume") {
|
|
|
|
ParseNode_Metadata(currentNode);
|
|
|
|
}
|
2020-07-04 07:04:06 +00:00
|
|
|
}
|
2020-09-09 22:05:53 +00:00
|
|
|
ParseHelper_Node_Exit();
|
|
|
|
} else {
|
|
|
|
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
2020-07-04 07:04:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-27 13:57:06 +00:00
|
|
|
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
2016-09-28 14:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// <triangle>
|
|
|
|
// </triangle>
|
|
|
|
// Defines a 3D triangle from three vertices, according to the right-hand rule (counter-clockwise when looking from the outside).
|
|
|
|
// Multi elements - Yes.
|
|
|
|
// Parent element - <volume>.
|
|
|
|
//
|
|
|
|
// Children elements:
|
|
|
|
// <v1>, <v2>, <v3>
|
|
|
|
// Multi elements - No.
|
|
|
|
// Index of the desired vertices in a triangle or edge.
|
2020-07-04 07:04:06 +00:00
|
|
|
void AMFImporter::ParseNode_Triangle(XmlNode &node) {
|
|
|
|
AMFNodeElementBase *ne = new AMFTriangle(mNodeElement_Cur);
|
2020-06-27 13:57:06 +00:00
|
|
|
|
2020-07-10 20:25:38 +00:00
|
|
|
// create new triangle object.
|
2020-07-04 07:04:06 +00:00
|
|
|
|
|
|
|
AMFTriangle &als = *((AMFTriangle *)ne); // alias for convenience
|
|
|
|
|
2020-09-27 19:01:48 +00:00
|
|
|
bool col_read = false;
|
2020-09-09 22:05:53 +00:00
|
|
|
if (!node.empty()) {
|
|
|
|
ParseHelper_Node_Enter(ne);
|
2021-04-03 08:25:03 +00:00
|
|
|
std::string v;
|
|
|
|
for (auto ¤tNode : node.children()) {
|
2020-09-09 22:05:53 +00:00
|
|
|
const std::string currentName = currentNode.name();
|
|
|
|
if (currentName == "color") {
|
|
|
|
if (col_read) Throw_MoreThanOnceDefined(currentName, "color", "Only one color can be defined for <triangle>.");
|
|
|
|
ParseNode_Color(currentNode);
|
|
|
|
col_read = true;
|
|
|
|
} else if (currentName == "texmap") {
|
|
|
|
ParseNode_TexMap(currentNode);
|
|
|
|
} else if (currentName == "map") {
|
|
|
|
ParseNode_TexMap(currentNode, true);
|
|
|
|
} else if (currentName == "v1") {
|
2021-04-03 08:25:03 +00:00
|
|
|
XmlParser::getValueAsString(currentNode, v);
|
|
|
|
als.V[0] = std::atoi(v.c_str());
|
2020-09-09 22:05:53 +00:00
|
|
|
} else if (currentName == "v2") {
|
2021-04-03 08:25:03 +00:00
|
|
|
XmlParser::getValueAsString(currentNode, v);
|
|
|
|
als.V[1] = std::atoi(v.c_str());
|
2020-09-09 22:05:53 +00:00
|
|
|
} else if (currentName == "v3") {
|
2021-04-03 08:25:03 +00:00
|
|
|
XmlParser::getValueAsString(currentNode, v);
|
|
|
|
als.V[2] = std::atoi(v.c_str());
|
2020-09-09 22:05:53 +00:00
|
|
|
}
|
2020-07-04 07:04:06 +00:00
|
|
|
}
|
2020-09-09 22:05:53 +00:00
|
|
|
ParseHelper_Node_Exit();
|
|
|
|
} else {
|
|
|
|
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
2020-07-04 07:04:06 +00:00
|
|
|
}
|
2020-09-09 22:05:53 +00:00
|
|
|
|
2020-06-27 13:57:06 +00:00
|
|
|
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
2016-09-28 14:49:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-27 13:57:06 +00:00
|
|
|
} // namespace Assimp
|
2016-09-28 14:49:15 +00:00
|
|
|
|
|
|
|
#endif // !ASSIMP_BUILD_NO_AMF_IMPORTER
|