Merge branch 'master' into pugi_xml
This commit is contained in:
@@ -1,701 +0,0 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/// \file AMFImporter.cpp
|
||||
/// \brief AMF-format files importer for Assimp: main algorithm implementation.
|
||||
/// \date 2016
|
||||
/// \author smal.root@gmail.com
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_AMF_IMPORTER
|
||||
|
||||
// Header files, Assimp.
|
||||
#include "AMFImporter.hpp"
|
||||
#include "AMFImporter_Macro.hpp"
|
||||
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
/// \var aiImporterDesc AMFImporter::Description
|
||||
/// Constant which hold importer description
|
||||
const aiImporterDesc AMFImporter::Description = {
|
||||
"Additive manufacturing file format(AMF) Importer",
|
||||
"smalcom",
|
||||
"",
|
||||
"See documentation in source code. Chapter: Limitations.",
|
||||
aiImporterFlags_SupportTextFlavour | aiImporterFlags_LimitedSupport | aiImporterFlags_Experimental,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"amf"
|
||||
};
|
||||
|
||||
void AMFImporter::Clear() {
|
||||
mNodeElement_Cur = nullptr;
|
||||
mUnit.clear();
|
||||
mMaterial_Converted.clear();
|
||||
mTexture_Converted.clear();
|
||||
// Delete all elements
|
||||
if (!mNodeElement_List.empty()) {
|
||||
for (AMFNodeElementBase *ne : mNodeElement_List) {
|
||||
delete ne;
|
||||
}
|
||||
|
||||
mNodeElement_List.clear();
|
||||
}
|
||||
}
|
||||
|
||||
AMFImporter::~AMFImporter() {
|
||||
if (mXmlParser != nullptr) {
|
||||
delete mXmlParser;
|
||||
mXmlParser = nullptr;
|
||||
}
|
||||
|
||||
// Clear() is accounting if data already is deleted. So, just check again if all data is deleted.
|
||||
Clear();
|
||||
}
|
||||
|
||||
void AMFImporter::ParseHelper_Decode_Base64(const std::string &pInputBase64, std::vector<uint8_t> &pOutputData) const {
|
||||
// With help from
|
||||
// René Nyffenegger http://www.adp-gmbh.ch/cpp/common/base64.html
|
||||
const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
uint8_t tidx = 0;
|
||||
uint8_t arr4[4], arr3[3];
|
||||
|
||||
// check input data
|
||||
if (pInputBase64.size() % 4) throw DeadlyImportError("Base64-encoded data must have size multiply of four.");
|
||||
// prepare output place
|
||||
pOutputData.clear();
|
||||
pOutputData.reserve(pInputBase64.size() / 4 * 3);
|
||||
|
||||
for (size_t in_len = pInputBase64.size(), in_idx = 0; (in_len > 0) && (pInputBase64[in_idx] != '='); in_len--) {
|
||||
if (ParseHelper_Decode_Base64_IsBase64(pInputBase64[in_idx])) {
|
||||
arr4[tidx++] = pInputBase64[in_idx++];
|
||||
if (tidx == 4) {
|
||||
for (tidx = 0; tidx < 4; tidx++)
|
||||
arr4[tidx] = (uint8_t)base64_chars.find(arr4[tidx]);
|
||||
|
||||
arr3[0] = (arr4[0] << 2) + ((arr4[1] & 0x30) >> 4);
|
||||
arr3[1] = ((arr4[1] & 0x0F) << 4) + ((arr4[2] & 0x3C) >> 2);
|
||||
arr3[2] = ((arr4[2] & 0x03) << 6) + arr4[3];
|
||||
for (tidx = 0; tidx < 3; tidx++)
|
||||
pOutputData.push_back(arr3[tidx]);
|
||||
|
||||
tidx = 0;
|
||||
} // if(tidx == 4)
|
||||
} // if(ParseHelper_Decode_Base64_IsBase64(pInputBase64[in_idx]))
|
||||
else {
|
||||
in_idx++;
|
||||
} // if(ParseHelper_Decode_Base64_IsBase64(pInputBase64[in_idx])) else
|
||||
}
|
||||
|
||||
if (tidx) {
|
||||
for (uint8_t i = tidx; i < 4; i++)
|
||||
arr4[i] = 0;
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
arr4[i] = (uint8_t)(base64_chars.find(arr4[i]));
|
||||
|
||||
arr3[0] = (arr4[0] << 2) + ((arr4[1] & 0x30) >> 4);
|
||||
arr3[1] = ((arr4[1] & 0x0F) << 4) + ((arr4[2] & 0x3C) >> 2);
|
||||
arr3[2] = ((arr4[2] & 0x03) << 6) + arr4[3];
|
||||
for (uint8_t i = 0; i < (tidx - 1); i++)
|
||||
pOutputData.push_back(arr3[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void AMFImporter::ParseFile(const std::string &pFile, IOSystem *pIOHandler) {
|
||||
std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
|
||||
|
||||
// Check whether we can read from the file
|
||||
if (file.get() == nullptr) {
|
||||
throw DeadlyImportError("Failed to open AMF file " + pFile + ".");
|
||||
}
|
||||
|
||||
mXmlParser = new XmlParser;
|
||||
XmlNode *root = mXmlParser->parse(file.get());
|
||||
if (nullptr == root) {
|
||||
throw DeadlyImportError("Failed to create XML reader for file" + pFile + ".");
|
||||
}
|
||||
|
||||
// start reading
|
||||
// search for root tag <amf>
|
||||
|
||||
if (!root->find_child("amf")) {
|
||||
throw DeadlyImportError("Root node \"amf\" not found.");
|
||||
}
|
||||
|
||||
ParseNode_Root(*root);
|
||||
|
||||
delete mXmlParser;
|
||||
mXmlParser = nullptr;
|
||||
}
|
||||
|
||||
// <amf
|
||||
// unit="" - The units to be used. May be "inch", "millimeter", "meter", "feet", or "micron".
|
||||
// version="" - Version of file format.
|
||||
// >
|
||||
// </amf>
|
||||
// Root XML element.
|
||||
// Multi elements - No.
|
||||
void AMFImporter::ParseNode_Root(XmlNode &root) {
|
||||
std::string unit, version;
|
||||
AMFNodeElementBase *ne(nullptr);
|
||||
|
||||
// Read attributes for node <amf>.
|
||||
for (pugi::xml_attribute_iterator ait = root.attributes_begin(); ait != root.attributes_end(); ++ait) {
|
||||
if (ait->name() == "unit") {
|
||||
unit = ait->as_string();
|
||||
} else if (ait->name() == "version") {
|
||||
version = ait->as_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Check attributes
|
||||
if (!mUnit.empty()) {
|
||||
if ((mUnit != "inch") && (mUnit != "millimeter") && (mUnit != "meter") && (mUnit != "feet") && (mUnit != "micron")) {
|
||||
throw DeadlyImportError("Root node does not contain any units.");
|
||||
}
|
||||
}
|
||||
|
||||
// create root node element.
|
||||
ne = new AMFRoot(nullptr);
|
||||
|
||||
// set first "current" element
|
||||
mNodeElement_Cur = ne;
|
||||
|
||||
// and assign attributes values
|
||||
((AMFRoot *)ne)->Unit = unit;
|
||||
((AMFRoot *)ne)->Version = version;
|
||||
|
||||
// Check for child nodes
|
||||
for (pugi::xml_node child : node->children()) {
|
||||
if (child.name() == "object") {
|
||||
ParseNode_Object(child);
|
||||
} else if (child.name() == "material") {
|
||||
ParseNode_Material(child);
|
||||
} else if (child.name() == "texture") {
|
||||
ParseNode_Texture(child);
|
||||
} else if (child.name() == "constellation") {
|
||||
ParseNode_Constellation(child);
|
||||
} else if (child.name() == "metadata") {
|
||||
ParseNode_Metadata(child);
|
||||
}
|
||||
}
|
||||
mNodeElement_List.push_back(ne); // add to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <constellation
|
||||
// id="" - The Object ID of the new constellation being defined.
|
||||
// >
|
||||
// </constellation>
|
||||
// A collection of objects or constellations with specific relative locations.
|
||||
// Multi elements - Yes.
|
||||
// Parent element - <amf>.
|
||||
void AMFImporter::ParseNode_Constellation(XmlNode &root) {
|
||||
std::string id = root.attribute("id").as_string();
|
||||
|
||||
// create and if needed - define new grouping object.
|
||||
AMFNodeElementBase *ne = new AMFConstellation(mNodeElement_Cur);
|
||||
|
||||
AMFConstellation &als = *((AMFConstellation *)ne); // alias for convenience
|
||||
|
||||
for (pugi::xml_node &child : root.children()) {
|
||||
if (child.name() == "instance") {
|
||||
ParseNode_Instance(child);
|
||||
} else if (child.name() == "metadata") {
|
||||
ParseNode_Metadata(child);
|
||||
}
|
||||
}
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <instance
|
||||
// objectid="" - The Object ID of the new constellation being defined.
|
||||
// >
|
||||
// </instance>
|
||||
// A collection of objects or constellations with specific relative locations.
|
||||
// Multi elements - Yes.
|
||||
// Parent element - <amf>.
|
||||
void AMFImporter::ParseNode_Instance(XmlNode &root) {
|
||||
std::string objectid = root.attribute("objectid").as_string();
|
||||
|
||||
// used object id must be defined, check that.
|
||||
if (objectid.empty()) {
|
||||
throw DeadlyImportError("\"objectid\" in <instance> must be defined.");
|
||||
}
|
||||
// create and define new grouping object.
|
||||
AMFNodeElementBase *ne = new AMFInstance(mNodeElement_Cur);
|
||||
|
||||
AMFInstance &als = *((AMFInstance *)ne); // alias for convenience
|
||||
|
||||
als.ObjectID = objectid;
|
||||
// Check for child nodes
|
||||
if (!mXmlParser->isEmptyElement()) {
|
||||
bool read_flag[6] = { false, false, false, false, false, false };
|
||||
|
||||
als.Delta.Set(0, 0, 0);
|
||||
als.Rotation.Set(0, 0, 0);
|
||||
ParseHelper_Node_Enter(ne);
|
||||
MACRO_NODECHECK_LOOPBEGIN("instance");
|
||||
MACRO_NODECHECK_READCOMP_F("deltax", read_flag[0], als.Delta.x);
|
||||
MACRO_NODECHECK_READCOMP_F("deltay", read_flag[1], als.Delta.y);
|
||||
MACRO_NODECHECK_READCOMP_F("deltaz", read_flag[2], als.Delta.z);
|
||||
MACRO_NODECHECK_READCOMP_F("rx", read_flag[3], als.Rotation.x);
|
||||
MACRO_NODECHECK_READCOMP_F("ry", read_flag[4], als.Rotation.y);
|
||||
MACRO_NODECHECK_READCOMP_F("rz", read_flag[5], als.Rotation.z);
|
||||
MACRO_NODECHECK_LOOPEND("instance");
|
||||
ParseHelper_Node_Exit();
|
||||
// also convert degrees to radians.
|
||||
als.Rotation.x = AI_MATH_PI_F * als.Rotation.x / 180.0f;
|
||||
als.Rotation.y = AI_MATH_PI_F * als.Rotation.y / 180.0f;
|
||||
als.Rotation.z = AI_MATH_PI_F * als.Rotation.z / 180.0f;
|
||||
} // if(!mReader->isEmptyElement())
|
||||
else {
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
} // if(!mReader->isEmptyElement()) else
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <object
|
||||
// id="" - A unique ObjectID for the new object being defined.
|
||||
// >
|
||||
// </object>
|
||||
// An object definition.
|
||||
// Multi elements - Yes.
|
||||
// Parent element - <amf>.
|
||||
void AMFImporter::ParseNode_Object(XmlNode &node) {
|
||||
|
||||
std::string id;
|
||||
for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) {
|
||||
if (ait->name() == "id") {
|
||||
id = ait->as_string();
|
||||
}
|
||||
}
|
||||
// Read attributes for node <object>.
|
||||
|
||||
// create and if needed - define new geometry object.
|
||||
AMFNodeElementBase *ne = new AMFObject(mNodeElement_Cur);
|
||||
|
||||
AMFObject &als = *((AMFObject *)ne); // alias for convenience
|
||||
|
||||
if (!id.empty()) {
|
||||
als.ID = id;
|
||||
}
|
||||
|
||||
// Check for child nodes
|
||||
for (pugi::xml_node_iterator it = node.children().begin(); it != node.children->end(); ++it) {
|
||||
bool col_read = false;
|
||||
if (it->name() == "mesh") {
|
||||
ParseNode_Mesh(*it);
|
||||
} else if (it->name() == "metadata") {
|
||||
ParseNode_Metadata(*it);
|
||||
} else if (it->name() == "color") {
|
||||
ParseNode_Color(*it);
|
||||
}
|
||||
}
|
||||
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
}
|
||||
|
||||
// <metadata
|
||||
// type="" - The type of the attribute.
|
||||
// >
|
||||
// </metadata>
|
||||
// Specify additional information about an entity.
|
||||
// Multi elements - Yes.
|
||||
// Parent element - <amf>, <object>, <volume>, <material>, <vertex>.
|
||||
//
|
||||
// Reserved types are:
|
||||
// "Name" - The alphanumeric label of the entity, to be used by the interpreter if interacting with the user.
|
||||
// "Description" - A description of the content of the entity
|
||||
// "URL" - A link to an external resource relating to the entity
|
||||
// "Author" - Specifies the name(s) of the author(s) of the entity
|
||||
// "Company" - Specifying the company generating the entity
|
||||
// "CAD" - specifies the name of the originating CAD software and version
|
||||
// "Revision" - specifies the revision of the entity
|
||||
// "Tolerance" - specifies the desired manufacturing tolerance of the entity in entity's unit system
|
||||
// "Volume" - specifies the total volume of the entity, in the entity's unit system, to be used for verification (object and volume only)
|
||||
void AMFImporter::ParseNode_Metadata() {
|
||||
std::string type, value;
|
||||
AMFNodeElementBase *ne(nullptr);
|
||||
|
||||
// read attribute
|
||||
MACRO_ATTRREAD_LOOPBEG;
|
||||
MACRO_ATTRREAD_CHECK_RET("type", type, mXmlParser->getAttributeValue);
|
||||
MACRO_ATTRREAD_LOOPEND;
|
||||
// and value of node.
|
||||
value = mXmlParser->getNodeData();
|
||||
// Create node element and assign read data.
|
||||
ne = new AMFMetadata(mNodeElement_Cur);
|
||||
((AMFMetadata *)ne)->Type = type;
|
||||
((AMFMetadata *)ne)->Value = value;
|
||||
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.
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************************************/
|
||||
/******************************************************** Functions: BaseImporter set ********************************************************/
|
||||
/*********************************************************************************************************************************************/
|
||||
|
||||
bool AMFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool pCheckSig) const {
|
||||
const std::string extension = GetExtension(pFile);
|
||||
|
||||
if (extension == "amf") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!extension.length() || pCheckSig) {
|
||||
const char *tokens[] = { "<amf" };
|
||||
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AMFImporter::GetExtensionList(std::set<std::string> &extensionList) {
|
||||
extensionList.insert("amf");
|
||||
}
|
||||
|
||||
const aiImporterDesc *AMFImporter::GetInfo() const {
|
||||
return &Description;
|
||||
}
|
||||
|
||||
void AMFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||
Clear();
|
||||
|
||||
ParseFile(pFile, pIOHandler);
|
||||
|
||||
Postprocess_BuildScene(pScene);
|
||||
}
|
||||
|
||||
void AMFImporter::ParseNode_Mesh(XmlNode &node) {
|
||||
AMFNodeElementBase *ne;
|
||||
|
||||
if (node.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (pugi::xml_node &child : node.children()) {
|
||||
if (child.name() == "vertices") {
|
||||
ParseNode_Vertices(child);
|
||||
}
|
||||
}
|
||||
// create new mesh object.
|
||||
ne = new AMFMesh(mNodeElement_Cur);
|
||||
// Check for child nodes
|
||||
if (!mXmlParser->isEmptyElement()) {
|
||||
bool vert_read = false;
|
||||
|
||||
ParseHelper_Node_Enter(ne);
|
||||
MACRO_NODECHECK_LOOPBEGIN("mesh");
|
||||
if (XML_CheckNode_NameEqual("vertices")) {
|
||||
// Check if data already defined.
|
||||
if (vert_read) Throw_MoreThanOnceDefined("vertices", "Only one vertices set can be defined for <mesh>.");
|
||||
// read data and set flag about it
|
||||
vert_read = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (XML_CheckNode_NameEqual("volume")) {
|
||||
ParseNode_Volume();
|
||||
continue;
|
||||
}
|
||||
MACRO_NODECHECK_LOOPEND("mesh");
|
||||
ParseHelper_Node_Exit();
|
||||
} // if(!mReader->isEmptyElement())
|
||||
else {
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
} // if(!mReader->isEmptyElement()) else
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <vertices>
|
||||
// </vertices>
|
||||
// The list of vertices to be used in defining triangles.
|
||||
// Multi elements - No.
|
||||
// Parent element - <mesh>.
|
||||
void AMFImporter::ParseNode_Vertices(XmlNode &node) {
|
||||
AMFNodeElementBase *ne = new AMFVertices(mNodeElement_Cur);
|
||||
|
||||
for (pugi::xml_node &child : node.children()) {
|
||||
if (child.name() == "vertices") {
|
||||
ParseNode_Vertex(child);
|
||||
}
|
||||
}
|
||||
// Check for child nodes
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <vertex>
|
||||
// </vertex>
|
||||
// A vertex to be referenced in triangles.
|
||||
// Multi elements - Yes.
|
||||
// Parent element - <vertices>.
|
||||
void AMFImporter::ParseNode_Vertex() {
|
||||
AMFNodeElementBase *ne;
|
||||
|
||||
// create new mesh object.
|
||||
ne = new AMFVertex(mNodeElement_Cur);
|
||||
// Check for child nodes
|
||||
if (!mXmlParser->isEmptyElement()) {
|
||||
bool col_read = false;
|
||||
bool coord_read = false;
|
||||
|
||||
ParseHelper_Node_Enter(ne);
|
||||
MACRO_NODECHECK_LOOPBEGIN("vertex");
|
||||
if (XML_CheckNode_NameEqual("color")) {
|
||||
// Check if data already defined.
|
||||
if (col_read) Throw_MoreThanOnceDefined("color", "Only one color can be defined for <vertex>.");
|
||||
// read data and set flag about it
|
||||
ParseNode_Color();
|
||||
col_read = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (XML_CheckNode_NameEqual("coordinates")) {
|
||||
// Check if data already defined.
|
||||
if (coord_read) Throw_MoreThanOnceDefined("coordinates", "Only one coordinates set can be defined for <vertex>.");
|
||||
// read data and set flag about it
|
||||
ParseNode_Coordinates();
|
||||
coord_read = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (XML_CheckNode_NameEqual("metadata")) {
|
||||
ParseNode_Metadata();
|
||||
continue;
|
||||
}
|
||||
MACRO_NODECHECK_LOOPEND("vertex");
|
||||
ParseHelper_Node_Exit();
|
||||
} // if(!mReader->isEmptyElement())
|
||||
else {
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
} // if(!mReader->isEmptyElement()) else
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <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.
|
||||
void AMFImporter::ParseNode_Coordinates() {
|
||||
AMFNodeElementBase *ne;
|
||||
|
||||
// create new color object.
|
||||
ne = new AMFCoordinates(mNodeElement_Cur);
|
||||
|
||||
AMFCoordinates &als = *((AMFCoordinates *)ne); // alias for convenience
|
||||
|
||||
// Check for child nodes
|
||||
if (!mXmlParser->isEmptyElement()) {
|
||||
bool read_flag[3] = { false, false, false };
|
||||
|
||||
ParseHelper_Node_Enter(ne);
|
||||
MACRO_NODECHECK_LOOPBEGIN("coordinates");
|
||||
MACRO_NODECHECK_READCOMP_F("x", read_flag[0], als.Coordinate.x);
|
||||
MACRO_NODECHECK_READCOMP_F("y", read_flag[1], als.Coordinate.y);
|
||||
MACRO_NODECHECK_READCOMP_F("z", read_flag[2], als.Coordinate.z);
|
||||
MACRO_NODECHECK_LOOPEND("coordinates");
|
||||
ParseHelper_Node_Exit();
|
||||
// check that all components was defined
|
||||
if ((read_flag[0] && read_flag[1] && read_flag[2]) == 0) throw DeadlyImportError("Not all coordinate's components are defined.");
|
||||
|
||||
} // if(!mReader->isEmptyElement())
|
||||
else {
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
} // if(!mReader->isEmptyElement()) else
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <volume
|
||||
// materialid="" - Which material to use.
|
||||
// type="" - What this volume describes can be “region” or “support”. If none specified, “object” is assumed. If support, then the geometric
|
||||
// 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>.
|
||||
void AMFImporter::ParseNode_Volume() {
|
||||
std::string materialid;
|
||||
std::string type;
|
||||
AMFNodeElementBase *ne;
|
||||
|
||||
// Read attributes for node <color>.
|
||||
MACRO_ATTRREAD_LOOPBEG;
|
||||
MACRO_ATTRREAD_CHECK_RET("materialid", materialid, mXmlParser->getAttributeValue);
|
||||
MACRO_ATTRREAD_CHECK_RET("type", type, mXmlParser->getAttributeValue);
|
||||
MACRO_ATTRREAD_LOOPEND;
|
||||
|
||||
// create new object.
|
||||
ne = new AMFVolume(mNodeElement_Cur);
|
||||
// and assign read data
|
||||
((AMFVolume *)ne)->MaterialID = materialid;
|
||||
((AMFVolume *)ne)->Type = type;
|
||||
// Check for child nodes
|
||||
if (!mXmlParser->isEmptyElement()) {
|
||||
bool col_read = false;
|
||||
|
||||
ParseHelper_Node_Enter(ne);
|
||||
MACRO_NODECHECK_LOOPBEGIN("volume");
|
||||
if (XML_CheckNode_NameEqual("color")) {
|
||||
// Check if data already defined.
|
||||
if (col_read) Throw_MoreThanOnceDefined("color", "Only one color can be defined for <volume>.");
|
||||
// read data and set flag about it
|
||||
ParseNode_Color();
|
||||
col_read = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (XML_CheckNode_NameEqual("triangle")) {
|
||||
ParseNode_Triangle();
|
||||
continue;
|
||||
}
|
||||
if (XML_CheckNode_NameEqual("metadata")) {
|
||||
ParseNode_Metadata();
|
||||
continue;
|
||||
}
|
||||
MACRO_NODECHECK_LOOPEND("volume");
|
||||
ParseHelper_Node_Exit();
|
||||
} // if(!mReader->isEmptyElement())
|
||||
else {
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
} // if(!mReader->isEmptyElement()) else
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <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.
|
||||
void AMFImporter::ParseNode_Triangle() {
|
||||
AMFNodeElementBase *ne;
|
||||
|
||||
// create new color object.
|
||||
ne = new AMFTriangle(mNodeElement_Cur);
|
||||
|
||||
AMFTriangle &als = *((AMFTriangle *)ne); // alias for convenience
|
||||
|
||||
// Check for child nodes
|
||||
if (!mXmlParser->isEmptyElement()) {
|
||||
bool col_read = false, tex_read = false;
|
||||
bool read_flag[3] = { false, false, false };
|
||||
|
||||
ParseHelper_Node_Enter(ne);
|
||||
MACRO_NODECHECK_LOOPBEGIN("triangle");
|
||||
if (XML_CheckNode_NameEqual("color")) {
|
||||
// Check if data already defined.
|
||||
if (col_read) Throw_MoreThanOnceDefined("color", "Only one color can be defined for <triangle>.");
|
||||
// read data and set flag about it
|
||||
ParseNode_Color();
|
||||
col_read = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (XML_CheckNode_NameEqual("texmap")) // new name of node: "texmap".
|
||||
{
|
||||
// Check if data already defined.
|
||||
if (tex_read) Throw_MoreThanOnceDefined("texmap", "Only one texture coordinate can be defined for <triangle>.");
|
||||
// read data and set flag about it
|
||||
ParseNode_TexMap();
|
||||
tex_read = true;
|
||||
|
||||
continue;
|
||||
} else if (XML_CheckNode_NameEqual("map")) // old name of node: "map".
|
||||
{
|
||||
// Check if data already defined.
|
||||
if (tex_read) Throw_MoreThanOnceDefined("map", "Only one texture coordinate can be defined for <triangle>.");
|
||||
// read data and set flag about it
|
||||
ParseNode_TexMap(true);
|
||||
tex_read = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// MACRO_NODECHECK_READCOMP_U32("v1", read_flag[0], als.V[0]);
|
||||
// MACRO_NODECHECK_READCOMP_U32("v2", read_flag[1], als.V[1]);
|
||||
// MACRO_NODECHECK_READCOMP_U32("v3", read_flag[2], als.V[2]);
|
||||
// MACRO_NODECHECK_LOOPEND("triangle");
|
||||
ParseHelper_Node_Exit();
|
||||
// check that all components was defined
|
||||
if ((read_flag[0] && read_flag[1] && read_flag[2]) == 0) throw DeadlyImportError("Not all vertices of the triangle are defined.");
|
||||
|
||||
} // if(!mReader->isEmptyElement())
|
||||
else {
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
} // if(!mReader->isEmptyElement()) else
|
||||
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // !ASSIMP_BUILD_NO_AMF_IMPORTER
|
||||
@@ -1,302 +0,0 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/// \file AMFImporter.hpp
|
||||
/// \brief AMF-format files importer for Assimp.
|
||||
/// \date 2016
|
||||
/// \author smal.root@gmail.com
|
||||
// Thanks to acorn89 for support.
|
||||
|
||||
#pragma once
|
||||
#ifndef INCLUDED_AI_AMF_IMPORTER_H
|
||||
#define INCLUDED_AI_AMF_IMPORTER_H
|
||||
|
||||
#include "AMFImporter_Node.hpp"
|
||||
|
||||
// Header files, Assimp.
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include "assimp/types.h"
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include <assimp/XmlParser.h>
|
||||
|
||||
// Header files, stdlib.
|
||||
#include <set>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
/// \class AMFImporter
|
||||
/// Class that holding scene graph which include: geometry, metadata, materials etc.
|
||||
///
|
||||
/// Implementing features.
|
||||
///
|
||||
/// 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:
|
||||
/// 1. Node <composite>, formulas in <composite> and <color>. For implementing this feature can be used expression parser "muParser" like in project
|
||||
/// "amf_tools".
|
||||
/// 2. Attribute "profile" in node <color>.
|
||||
/// 3. Curved geometry: <edge>, <normal> and children nodes of them.
|
||||
/// 4. Attributes: "unit" and "version" in <amf> read but do nothing.
|
||||
/// 5. <metadata> stored only for root node <amf>.
|
||||
/// 6. Color averaging of vertices for which <triangle>'s set different colors.
|
||||
///
|
||||
/// Supported nodes:
|
||||
/// General:
|
||||
/// <amf>; <constellation>; <instance> and children <deltax>, <deltay>, <deltaz>, <rx>, <ry>, <rz>; <metadata>;
|
||||
///
|
||||
/// Geometry:
|
||||
/// <object>; <mesh>; <vertices>; <vertex>; <coordinates> and children <x>, <y>, <z>; <volume>; <triangle> and children <v1>, <v2>, <v3>;
|
||||
///
|
||||
/// Material:
|
||||
/// <color> and children <r>, <g>, <b>, <a>; <texture>; <material>;
|
||||
/// two variants of texture coordinates:
|
||||
/// new - <texmap> and children <utex1>, <utex2>, <utex3>, <vtex1>, <vtex2>, <vtex3>
|
||||
/// old - <map> and children <u1>, <u2>, <u3>, <v1>, <v2>, <v3>
|
||||
///
|
||||
class AMFImporter : public BaseImporter {
|
||||
private:
|
||||
struct SPP_Material;// forward declaration
|
||||
|
||||
/// \struct SPP_Composite
|
||||
/// Data type for post-processing step. More suitable container for part of material's composition.
|
||||
struct SPP_Composite {
|
||||
SPP_Material* Material;///< Pointer to material - part of composition.
|
||||
std::string Formula;///< Formula for calculating ratio of \ref Material.
|
||||
};
|
||||
|
||||
/// \struct SPP_Material
|
||||
/// Data type for post-processing step. More suitable container for material.
|
||||
struct SPP_Material {
|
||||
std::string ID;///< Material ID.
|
||||
std::list<AMFMetadata*> Metadata;///< Metadata of material.
|
||||
AMFColor* Color;///< Color of material.
|
||||
std::list<SPP_Composite> Composition;///< List of child materials if current material is composition of few another.
|
||||
|
||||
/// Return color calculated for specified coordinate.
|
||||
/// \param [in] pX - "x" coordinate.
|
||||
/// \param [in] pY - "y" coordinate.
|
||||
/// \param [in] pZ - "z" coordinate.
|
||||
/// \return calculated color.
|
||||
aiColor4D GetColor(const float pX, const float pY, const float pZ) const;
|
||||
};
|
||||
|
||||
/// Data type for post-processing step. More suitable container for texture.
|
||||
struct SPP_Texture {
|
||||
std::string ID;
|
||||
size_t Width, Height, Depth;
|
||||
bool Tiled;
|
||||
char FormatHint[9];// 8 for string + 1 for terminator.
|
||||
uint8_t *Data;
|
||||
};
|
||||
|
||||
/// Data type for post-processing step. Contain face data.
|
||||
struct SComplexFace {
|
||||
aiFace Face;///< Face vertices.
|
||||
const AMFColor* Color;///< Face color. Equal to nullptr if color is not set for the face.
|
||||
const AMFTexMap* TexMap;///< Face texture mapping data. Equal to nullptr if texture mapping is not set for the face.
|
||||
};
|
||||
|
||||
/// Clear all temporary data.
|
||||
void Clear();
|
||||
|
||||
/// Get data stored in <vertices> and place it to arrays.
|
||||
/// \param [in] pNodeElement - reference to node element which kept <object> data.
|
||||
/// \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
|
||||
/// contain nullptr.
|
||||
void PostprocessHelper_CreateMeshDataArray(const AMFMesh& pNodeElement, std::vector<aiVector3D>& pVertexCoordinateArray,
|
||||
std::vector<AMFColor*>& pVertexColorArray) const;
|
||||
|
||||
/// Return converted texture ID which related to specified source textures ID's. If converted texture does not exist then it will be created and ID on new
|
||||
/// converted texture will be returned. Conversion: set of textures from \ref CAMFImporter_NodeElement_Texture to one \ref SPP_Texture and place it
|
||||
/// to converted textures list.
|
||||
/// Any of source ID's can be absent(empty string) or even one ID only specified. But at least one ID must be specified.
|
||||
/// \param [in] pID_R - ID of source "red" texture.
|
||||
/// \param [in] pID_G - ID of source "green" texture.
|
||||
/// \param [in] pID_B - ID of source "blue" texture.
|
||||
/// \param [in] pID_A - ID of source "alpha" texture.
|
||||
/// \return index of the texture in array of the converted textures.
|
||||
size_t PostprocessHelper_GetTextureID_Or_Create(const std::string& pID_R, const std::string& pID_G, const std::string& pID_B, const std::string& pID_A);
|
||||
|
||||
/// Separate input list by texture IDs. This step is needed because aiMesh can contain mesh which is use only one texture (or set: diffuse, bump etc).
|
||||
/// \param [in] pInputList - input list with faces. Some of them can contain color or texture mapping, or both of them, or nothing. Will be cleared after
|
||||
/// processing.
|
||||
/// \param [out] pOutputList_Separated - output list of the faces lists. Separated faces list by used texture IDs. Will be cleared before processing.
|
||||
void PostprocessHelper_SplitFacesByTextureID(std::list<SComplexFace>& pInputList, std::list<std::list<SComplexFace> >& pOutputList_Separated);
|
||||
|
||||
/// Check if child elements of node element is metadata and add it to scene node.
|
||||
/// \param [in] pMetadataList - reference to list with collected metadata.
|
||||
/// \param [out] pSceneNode - scene node in which metadata will be added.
|
||||
void Postprocess_AddMetadata(const std::list<AMFMetadata*>& pMetadataList, aiNode& pSceneNode) const;
|
||||
|
||||
/// To create aiMesh and aiNode for it from <object>.
|
||||
/// \param [in] pNodeElement - reference to node element which kept <object> data.
|
||||
/// \param [out] pMeshList - reference to a list with all aiMesh of the scene.
|
||||
/// \param [out] pSceneNode - pointer to place where new aiNode will be created.
|
||||
void Postprocess_BuildNodeAndObject(const AMFObject& pNodeElement, std::list<aiMesh*>& pMeshList, aiNode** pSceneNode);
|
||||
|
||||
/// Create mesh for every <volume> in <mesh>.
|
||||
/// \param [in] pNodeElement - reference to node element which kept <mesh> data.
|
||||
/// \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
|
||||
/// contain nullptr.
|
||||
/// \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 [out] pMeshList - reference to a list with all aiMesh of the scene.
|
||||
/// \param [out] pSceneNode - reference to aiNode which will own new aiMesh's.
|
||||
void Postprocess_BuildMeshSet(const AMFMesh& pNodeElement, const std::vector<aiVector3D>& pVertexCoordinateArray,
|
||||
const std::vector<AMFColor*>& pVertexColorArray, const AMFColor* pObjectColor,
|
||||
std::list<aiMesh*>& pMeshList, aiNode& pSceneNode);
|
||||
|
||||
/// Convert material from \ref CAMFImporter_NodeElement_Material to \ref SPP_Material.
|
||||
/// \param [in] pMaterial - source CAMFImporter_NodeElement_Material.
|
||||
void Postprocess_BuildMaterial(const AMFMaterial& pMaterial);
|
||||
|
||||
/// Create and add to aiNode's list new part of scene graph defined by <constellation>.
|
||||
/// \param [in] pConstellation - reference to <constellation> node.
|
||||
/// \param [out] pNodeList - reference to aiNode's list.
|
||||
void Postprocess_BuildConstellation(AMFConstellation& pConstellation, std::list<aiNode*>& pNodeList) const;
|
||||
|
||||
/// Build Assimp scene graph in aiScene from collected data.
|
||||
/// \param [out] pScene - pointer to aiScene where tree will be built.
|
||||
void Postprocess_BuildScene(aiScene* pScene);
|
||||
|
||||
/// Decode Base64-encoded data.
|
||||
/// \param [in] pInputBase64 - reference to input Base64-encoded string.
|
||||
/// \param [out] pOutputData - reference to output array for decoded data.
|
||||
void ParseHelper_Decode_Base64(const std::string& pInputBase64, std::vector<uint8_t>& pOutputData) const;
|
||||
|
||||
/// Parse <AMF> node of the file.
|
||||
void ParseNode_Root(XmlNode &root);
|
||||
|
||||
/// Parse <constellation> node of the file.
|
||||
void ParseNode_Constellation(XmlNode &node);
|
||||
|
||||
/// Parse <instance> node of the file.
|
||||
void ParseNode_Instance(XmlNode &node);
|
||||
|
||||
/// Parse <material> node of the file.
|
||||
void ParseNode_Material(XmlNode &node);
|
||||
|
||||
/// Parse <metadata> node.
|
||||
void ParseNode_Metadata(XmlNode &node);
|
||||
|
||||
/// Parse <object> node of the file.
|
||||
void ParseNode_Object(XmlNode &node);
|
||||
|
||||
/// Parse <texture> node of the file.
|
||||
void ParseNode_Texture(XmlNode &node);
|
||||
|
||||
/// Parse <coordinates> node of the file.
|
||||
void ParseNode_Coordinates(XmlNode &node);
|
||||
|
||||
/// Parse <edge> node of the file.
|
||||
void ParseNode_Edge(XmlNode &node);
|
||||
|
||||
/// Parse <mesh> node of the file.
|
||||
void ParseNode_Mesh(XmlNode &node);
|
||||
|
||||
/// Parse <triangle> node of the file.
|
||||
void ParseNode_Triangle(XmlNode &node);
|
||||
|
||||
/// Parse <vertex> node of the file.
|
||||
void ParseNode_Vertex(XmlNode &node);
|
||||
|
||||
/// Parse <vertices> node of the file.
|
||||
void ParseNode_Vertices(XmlNode &node);
|
||||
|
||||
/// Parse <volume> node of the file.
|
||||
void ParseNode_Volume(XmlNode &node);
|
||||
|
||||
/// Parse <color> node of the file.
|
||||
void ParseNode_Color(XmlNode &node);
|
||||
|
||||
/// Parse <texmap> of <map> node of the file.
|
||||
/// \param [in] pUseOldName - if true then use old name of node(and children) - <map>, instead of new name - <texmap>.
|
||||
void ParseNode_TexMap(XmlNode &node, const bool pUseOldName = false);
|
||||
|
||||
public:
|
||||
/// Default constructor.
|
||||
AMFImporter() AI_NO_EXCEPT
|
||||
: mNodeElement_Cur(nullptr)
|
||||
, mXmlParser(nullptr) {
|
||||
// empty
|
||||
}
|
||||
|
||||
/// Default destructor.
|
||||
~AMFImporter();
|
||||
|
||||
/// Parse AMF file and fill scene graph. The function has no return value. Result can be found by analyzing the generated graph.
|
||||
/// Also exception can be thrown if trouble will found.
|
||||
/// \param [in] pFile - name of file to be parsed.
|
||||
/// \param [in] pIOHandler - pointer to IO helper object.
|
||||
void ParseFile(const std::string& pFile, IOSystem* pIOHandler);
|
||||
|
||||
bool CanRead(const std::string& pFile, IOSystem* pIOHandler, bool pCheckSig) const;
|
||||
void GetExtensionList(std::set<std::string>& pExtensionList);
|
||||
void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
||||
const aiImporterDesc* GetInfo ()const;
|
||||
|
||||
AMFImporter(const AMFImporter& pScene) = delete;
|
||||
AMFImporter& operator=(const AMFImporter& pScene) = delete;
|
||||
|
||||
private:
|
||||
static const aiImporterDesc Description;
|
||||
|
||||
AMFNodeElementBase* mNodeElement_Cur;///< Current element.
|
||||
std::list<AMFNodeElementBase*> mNodeElement_List;///< All elements of scene graph.
|
||||
XmlParser *mXmlParser;
|
||||
//irr::io::IrrXMLReader* mReader;///< Pointer to XML-reader object
|
||||
std::string mUnit;
|
||||
std::list<SPP_Material> mMaterial_Converted;///< List of converted materials for postprocessing step.
|
||||
std::list<SPP_Texture> mTexture_Converted;///< List of converted textures for postprocessing step.
|
||||
|
||||
};
|
||||
|
||||
}// namespace Assimp
|
||||
|
||||
#endif // INCLUDED_AI_AMF_IMPORTER_H
|
||||
@@ -1,319 +0,0 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/// \file AMFImporter_Material.cpp
|
||||
/// \brief Parsing data from material nodes.
|
||||
/// \date 2016
|
||||
/// \author smal.root@gmail.com
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_AMF_IMPORTER
|
||||
|
||||
#include "AMFImporter.hpp"
|
||||
//#include "AMFImporter_Macro.hpp"
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
|
||||
// <color
|
||||
// profile="" - The ICC color space used to interpret the three color channels <r>, <g> and <b>.
|
||||
// >
|
||||
// </color>
|
||||
// A color definition.
|
||||
// Multi elements - No.
|
||||
// Parent element - <material>, <object>, <volume>, <vertex>, <triangle>.
|
||||
//
|
||||
// "profile" can be one of "sRGB", "AdobeRGB", "Wide-Gamut-RGB", "CIERGB", "CIELAB", or "CIEXYZ".
|
||||
// Children elements:
|
||||
// <r>, <g>, <b>, <a>
|
||||
// Multi elements - No.
|
||||
// Red, Greed, Blue and Alpha (transparency) component of a color in sRGB space, values ranging from 0 to 1. The
|
||||
// values can be specified as constants, or as a formula depending on the coordinates.
|
||||
void AMFImporter::ParseNode_Color(XmlNode &node) {
|
||||
std::string profile = node.attribute("profile").as_string();
|
||||
|
||||
// create new color object.
|
||||
AMFNodeElementBase *ne = new AMFColor(mNodeElement_Cur);
|
||||
AMFColor& als = *((AMFColor*)ne);// alias for convenience
|
||||
|
||||
als.Profile = profile;
|
||||
if (!node.empty()) {
|
||||
bool read_flag[4] = { false, false, false, false };
|
||||
for (pugi::xml_node &child : node.children()) {
|
||||
if (child.name() == "r") {
|
||||
read_flag[0] = true;
|
||||
als.Color.r = atof(child.value());
|
||||
} else if (child.name() == "g") {
|
||||
read_flag[1] = true;
|
||||
als.Color.g = atof(child.value());
|
||||
} else if (child.name() == "b") {
|
||||
read_flag[2] = true;
|
||||
als.Color.b = atof(child.value());
|
||||
} else if (child.name() == "g") {
|
||||
read_flag[3] = true;
|
||||
als.Color.a = atof(child.value());
|
||||
}
|
||||
}
|
||||
// check that all components was defined
|
||||
if (!(read_flag[0] && read_flag[1] && read_flag[2])) {
|
||||
throw DeadlyImportError("Not all color components are defined.");
|
||||
}
|
||||
|
||||
// check if <a> is absent. Then manually add "a == 1".
|
||||
if (!read_flag[3]) {
|
||||
als.Color.a = 1;
|
||||
}
|
||||
} else {
|
||||
mNodeElement_Cur->Child.push_back(ne);// Add element to child list of current element
|
||||
}
|
||||
|
||||
als.Composed = false;
|
||||
mNodeElement_List.push_back(ne);// and to node element list because its a new object in graph.
|
||||
}
|
||||
|
||||
// <material
|
||||
// id="" - A unique material id. material ID "0" is reserved to denote no material (void) or sacrificial material.
|
||||
// >
|
||||
// </material>
|
||||
// An available material.
|
||||
// Multi elements - Yes.
|
||||
// Parent element - <amf>.
|
||||
void AMFImporter::ParseNode_Material(XmlNode &node) {
|
||||
// create new object and assign read data
|
||||
std::string id = node.attribute("id").as_string();
|
||||
AMFNodeElementBase *ne = new AMFMaterial(mNodeElement_Cur);
|
||||
((AMFMaterial*)ne)->ID = id;
|
||||
|
||||
// Check for child nodes
|
||||
if (!node.empty()) {
|
||||
bool col_read = false;
|
||||
for (pugi::xml_node &child : node.children()) {
|
||||
if (child.name() == "color") {
|
||||
col_read = true;
|
||||
ParseNode_Color(child);
|
||||
} else if (child.name() == "metadata") {
|
||||
ParseNode_Metadata(child);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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.
|
||||
}
|
||||
|
||||
// <texture
|
||||
// id="" - Assigns a unique texture id for the new texture.
|
||||
// width="" - Width (horizontal size, x) of the texture, in pixels.
|
||||
// height="" - Height (lateral size, y) of the texture, in pixels.
|
||||
// depth="" - Depth (vertical size, z) of the texture, in pixels.
|
||||
// type="" - Encoding of the data in the texture. Currently allowed values are "grayscale" only. In grayscale mode, each pixel is represented by one byte
|
||||
// in the range of 0-255. When the texture is referenced using the tex function, these values are converted into a single floating point number in the
|
||||
// range of 0-1 (see Annex 2). A full color graphics will typically require three textures, one for each of the color channels. A graphic involving
|
||||
// transparency may require a fourth channel.
|
||||
// tiled="" - If true then texture repeated when UV-coordinates is greater than 1.
|
||||
// >
|
||||
// </triangle>
|
||||
// Specifies an texture data to be used as a map. Lists a sequence of Base64 values specifying values for pixels from left to right then top to bottom,
|
||||
// then layer by layer.
|
||||
// Multi elements - Yes.
|
||||
// Parent element - <amf>.
|
||||
void AMFImporter::ParseNode_Texture(XmlNode &node) {
|
||||
std::string id = node.attribute("id").as_string();
|
||||
uint32_t width = node.attribute("width").as_uint();
|
||||
uint32_t height = node.attribute("height").as_uint();
|
||||
uint32_t depth = node.attribute("depth").as_uint();
|
||||
std::string type = node.attribute("type").as_string();
|
||||
bool tiled = node.attribute("tiled").as_bool();
|
||||
|
||||
// create new texture object.
|
||||
AMFNodeElementBase *ne = new AMFTexture(mNodeElement_Cur);
|
||||
|
||||
AMFTexture& als = *((AMFTexture*)ne);// alias for convenience
|
||||
|
||||
if (node.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string enc64_data = node.value();
|
||||
// Check for child nodes
|
||||
//if (!mXmlParser->isEmptyElement()) {
|
||||
// XML_ReadNode_GetVal_AsString(enc64_data);
|
||||
//}
|
||||
|
||||
// check that all components was defined
|
||||
if (id.empty()) {
|
||||
throw DeadlyImportError("ID for texture must be defined.");
|
||||
}
|
||||
if (width < 1) {
|
||||
throw DeadlyImportError("INvalid width for texture.");
|
||||
}
|
||||
if (height < 1) {
|
||||
throw DeadlyImportError("Invalid height for texture.");
|
||||
}
|
||||
if (depth < 1) {
|
||||
throw DeadlyImportError("Invalid depth for texture.");
|
||||
}
|
||||
if (type != "grayscale") {
|
||||
throw DeadlyImportError("Invalid type for texture.");
|
||||
}
|
||||
if (enc64_data.empty()) {
|
||||
throw DeadlyImportError("Texture data not defined.");
|
||||
}
|
||||
// copy data
|
||||
als.ID = id;
|
||||
als.Width = width;
|
||||
als.Height = height;
|
||||
als.Depth = depth;
|
||||
als.Tiled = tiled;
|
||||
ParseHelper_Decode_Base64(enc64_data, als.Data);
|
||||
|
||||
// check data size
|
||||
if ((width * height * depth) != als.Data.size()) {
|
||||
throw DeadlyImportError("Texture has incorrect data size.");
|
||||
}
|
||||
|
||||
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.
|
||||
}
|
||||
|
||||
// <texmap
|
||||
// rtexid="" - Texture ID for red color component.
|
||||
// gtexid="" - Texture ID for green color component.
|
||||
// btexid="" - Texture ID for blue color component.
|
||||
// atexid="" - Texture ID for alpha color component. Optional.
|
||||
// >
|
||||
// </texmap>, old name: <map>
|
||||
// Specifies texture coordinates for triangle.
|
||||
// Multi elements - No.
|
||||
// Parent element - <triangle>.
|
||||
// Children elements:
|
||||
// <utex1>, <utex2>, <utex3>, <vtex1>, <vtex2>, <vtex3>. Old name: <u1>, <u2>, <u3>, <v1>, <v2>, <v3>.
|
||||
// Multi elements - No.
|
||||
// Texture coordinates for every vertex of triangle.
|
||||
void AMFImporter::ParseNode_TexMap(XmlNode &node, const bool pUseOldName) {
|
||||
// Read attributes for node <color>.
|
||||
std::string rtexid = node.attribute("rtexid").as_string();
|
||||
std::string gtexid = node.attribute("gtexid").as_string();
|
||||
std::string btexid = node.attribute("btexid").as_string();
|
||||
std::string atexid = node.attribute("atexid").as_string();
|
||||
|
||||
|
||||
// create new texture coordinates object, alias for convenience
|
||||
AMFNodeElementBase *ne = new AMFTexMap(mNodeElement_Cur);
|
||||
AMFTexMap& als = *((AMFTexMap*)ne);//
|
||||
// check data
|
||||
if (rtexid.empty() && gtexid.empty() && btexid.empty()) {
|
||||
throw DeadlyImportError("ParseNode_TexMap. At least one texture ID must be defined.");
|
||||
}
|
||||
|
||||
// Check for children nodes
|
||||
//XML_CheckNode_MustHaveChildren();
|
||||
if (node.children().begin() == node.children().end()) {
|
||||
throw DeadlyImportError("Invalid children definition.");
|
||||
}
|
||||
// read children nodes
|
||||
bool read_flag[6] = { false, false, false, false, false, false };
|
||||
|
||||
if (!pUseOldName) {
|
||||
for (pugi::xml_attribute &attr : node.attributes()) {
|
||||
if (attr.name() == "utex1") {
|
||||
read_flag[0] = true;
|
||||
als.TextureCoordinate[0].x = attr.as_float();
|
||||
} else if (attr.name() == "utex2") {
|
||||
read_flag[1] = true;
|
||||
als.TextureCoordinate[1].x = attr.as_float();
|
||||
} else if (attr.name() == "utex3") {
|
||||
read_flag[2] = true;
|
||||
als.TextureCoordinate[2].x = attr.as_float();
|
||||
} else if (attr.name() == "vtex1") {
|
||||
read_flag[3] = true;
|
||||
als.TextureCoordinate[0].y = attr.as_float();
|
||||
} else if (attr.name() == "vtex2") {
|
||||
read_flag[4] = true;
|
||||
als.TextureCoordinate[1].y = attr.as_float();
|
||||
} else if (attr.name() == "vtex3") {
|
||||
read_flag[5] = true;
|
||||
als.TextureCoordinate[0].y = attr.as_float();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (pugi::xml_attribute &attr : node.attributes()) {
|
||||
if (attr.name() == "u") {
|
||||
read_flag[0] = true;
|
||||
als.TextureCoordinate[0].x = attr.as_float();
|
||||
} else if (attr.name() == "u2") {
|
||||
read_flag[1] = true;
|
||||
als.TextureCoordinate[1].x = attr.as_float();
|
||||
} else if (attr.name() == "u3") {
|
||||
read_flag[2] = true;
|
||||
als.TextureCoordinate[2].x = attr.as_float();
|
||||
} else if (attr.name() == "v1") {
|
||||
read_flag[3] = true;
|
||||
als.TextureCoordinate[0].y = attr.as_float();
|
||||
} else if (attr.name() == "v2") {
|
||||
read_flag[4] = true;
|
||||
als.TextureCoordinate[1].y = attr.as_float();
|
||||
} else if (attr.name() == "v3") {
|
||||
read_flag[5] = true;
|
||||
als.TextureCoordinate[0].y = attr.as_float();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check that all components was defined
|
||||
if (!(read_flag[0] && read_flag[1] && read_flag[2] && read_flag[3] && read_flag[4] && read_flag[5])) {
|
||||
throw DeadlyImportError("Not all texture coordinates are defined.");
|
||||
}
|
||||
|
||||
// copy attributes data
|
||||
als.TextureID_R = rtexid;
|
||||
als.TextureID_G = gtexid;
|
||||
als.TextureID_B = btexid;
|
||||
als.TextureID_A = atexid;
|
||||
|
||||
mNodeElement_List.push_back(ne);
|
||||
}
|
||||
|
||||
}// namespace Assimp
|
||||
|
||||
#endif // !ASSIMP_BUILD_NO_AMF_IMPORTER
|
||||
@@ -1,308 +0,0 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/// \file AMFImporter_Node.hpp
|
||||
/// \brief Elements of scene graph.
|
||||
/// \date 2016
|
||||
/// \author smal.root@gmail.com
|
||||
|
||||
#pragma once
|
||||
#ifndef INCLUDED_AI_AMF_IMPORTER_NODE_H
|
||||
#define INCLUDED_AI_AMF_IMPORTER_NODE_H
|
||||
|
||||
// Header files, stdlib.
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Header files, Assimp.
|
||||
#include "assimp/scene.h"
|
||||
#include "assimp/types.h"
|
||||
|
||||
/// \class CAMFImporter_NodeElement
|
||||
/// Base class for elements of nodes.
|
||||
class AMFNodeElementBase {
|
||||
public:
|
||||
/// Define what data type contain node element.
|
||||
enum EType {
|
||||
ENET_Color, ///< Color element: <color>.
|
||||
ENET_Constellation, ///< Grouping element: <constellation>.
|
||||
ENET_Coordinates, ///< Coordinates element: <coordinates>.
|
||||
ENET_Edge, ///< Edge element: <edge>.
|
||||
ENET_Instance, ///< Grouping element: <constellation>.
|
||||
ENET_Material, ///< Material element: <material>.
|
||||
ENET_Metadata, ///< Metadata element: <metadata>.
|
||||
ENET_Mesh, ///< Metadata element: <mesh>.
|
||||
ENET_Object, ///< Element which hold object: <object>.
|
||||
ENET_Root, ///< Root element: <amf>.
|
||||
ENET_Triangle, ///< Triangle element: <triangle>.
|
||||
ENET_TexMap, ///< Texture coordinates element: <texmap> or <map>.
|
||||
ENET_Texture, ///< Texture element: <texture>.
|
||||
ENET_Vertex, ///< Vertex element: <vertex>.
|
||||
ENET_Vertices, ///< Vertex element: <vertices>.
|
||||
ENET_Volume, ///< Volume element: <volume>.
|
||||
|
||||
ENET_Invalid ///< Element has invalid type and possible contain invalid data.
|
||||
};
|
||||
|
||||
const EType Type; ///< Type of element.
|
||||
std::string ID; ///< ID of element.
|
||||
AMFNodeElementBase *Parent; ///< Parent element. If nullptr then this node is root.
|
||||
std::list<AMFNodeElementBase *> Child; ///< Child elements.
|
||||
|
||||
public: /// Destructor, virtual..
|
||||
virtual ~AMFNodeElementBase() {
|
||||
// empty
|
||||
}
|
||||
|
||||
/// Disabled copy constructor and co.
|
||||
AMFNodeElementBase(const AMFNodeElementBase &pNodeElement) = delete;
|
||||
AMFNodeElementBase(AMFNodeElementBase &&) = delete;
|
||||
AMFNodeElementBase &operator=(const AMFNodeElementBase &pNodeElement) = delete;
|
||||
AMFNodeElementBase() = delete;
|
||||
|
||||
protected:
|
||||
/// In constructor inheritor must set element type.
|
||||
/// \param [in] pType - element type.
|
||||
/// \param [in] pParent - parent element.
|
||||
AMFNodeElementBase(const EType pType, AMFNodeElementBase *pParent) :
|
||||
Type(pType), ID(), Parent(pParent), Child() {
|
||||
// empty
|
||||
}
|
||||
}; // class IAMFImporter_NodeElement
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Constellation
|
||||
/// A collection of objects or constellations with specific relative locations.
|
||||
struct AMFConstellation : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFConstellation(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Constellation, pParent) {}
|
||||
|
||||
}; // struct CAMFImporter_NodeElement_Constellation
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Instance
|
||||
/// Part of constellation.
|
||||
struct AMFInstance : public AMFNodeElementBase {
|
||||
|
||||
std::string ObjectID; ///< ID of object for instantiation.
|
||||
/// \var Delta - The distance of translation in the x, y, or z direction, respectively, in the referenced object's coordinate system, to
|
||||
/// create an instance of the object in the current constellation.
|
||||
aiVector3D Delta;
|
||||
|
||||
/// \var Rotation - The rotation, in degrees, to rotate the referenced object about its x, y, and z axes, respectively, to create an
|
||||
/// instance of the object in the current constellation. Rotations shall be executed in order of x first, then y, then z.
|
||||
aiVector3D Rotation;
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFInstance(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Instance, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Metadata
|
||||
/// Structure that define metadata node.
|
||||
struct AMFMetadata : public AMFNodeElementBase {
|
||||
|
||||
std::string Type; ///< Type of "Value".
|
||||
std::string Value; ///< Value.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFMetadata(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Metadata, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Root
|
||||
/// Structure that define root node.
|
||||
struct AMFRoot : public AMFNodeElementBase {
|
||||
|
||||
std::string Unit; ///< The units to be used. May be "inch", "millimeter", "meter", "feet", or "micron".
|
||||
std::string Version; ///< Version of format.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFRoot(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Root, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Color
|
||||
/// Structure that define object node.
|
||||
struct AMFColor : public AMFNodeElementBase {
|
||||
bool Composed; ///< Type of color stored: if true then look for formula in \ref Color_Composed[4], else - in \ref Color.
|
||||
std::string Color_Composed[4]; ///< By components formulas of composed color. [0..3] - RGBA.
|
||||
aiColor4D Color; ///< Constant color.
|
||||
std::string Profile; ///< The ICC color space used to interpret the three color channels r, g and b..
|
||||
|
||||
/// @brief Constructor.
|
||||
/// @param [in] pParent - pointer to parent node.
|
||||
AMFColor(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Color, pParent), Composed(false), Color(), Profile() {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Material
|
||||
/// Structure that define material node.
|
||||
struct AMFMaterial : public AMFNodeElementBase {
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFMaterial(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Material, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Object
|
||||
/// Structure that define object node.
|
||||
struct AMFObject : public AMFNodeElementBase {
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFObject(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Object, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Mesh
|
||||
/// Structure that define mesh node.
|
||||
struct AMFMesh : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFMesh(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Mesh, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Vertex
|
||||
/// Structure that define vertex node.
|
||||
struct AMFVertex : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFVertex(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Vertex, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Edge
|
||||
/// Structure that define edge node.
|
||||
struct AMFEdge : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFEdge(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Edge, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Vertices
|
||||
/// Structure that define vertices node.
|
||||
struct AMFVertices : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFVertices(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Vertices, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Volume
|
||||
/// Structure that define volume node.
|
||||
struct AMFVolume : public AMFNodeElementBase {
|
||||
std::string MaterialID; ///< Which material to use.
|
||||
std::string Type; ///< What this volume describes can be “region” or “support”. If none specified, “object” is assumed.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFVolume(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Volume, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Coordinates
|
||||
/// Structure that define coordinates node.
|
||||
struct AMFCoordinates : public AMFNodeElementBase {
|
||||
aiVector3D Coordinate; ///< Coordinate.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFCoordinates(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Coordinates, pParent) {}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_TexMap
|
||||
/// Structure that define texture coordinates node.
|
||||
struct AMFTexMap : public AMFNodeElementBase {
|
||||
aiVector3D TextureCoordinate[3]; ///< Texture coordinates.
|
||||
std::string TextureID_R; ///< Texture ID for red color component.
|
||||
std::string TextureID_G; ///< Texture ID for green color component.
|
||||
std::string TextureID_B; ///< Texture ID for blue color component.
|
||||
std::string TextureID_A; ///< Texture ID for alpha color component.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFTexMap(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_TexMap, pParent), TextureCoordinate{}, TextureID_R(), TextureID_G(), TextureID_B(), TextureID_A() {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Triangle
|
||||
/// Structure that define triangle node.
|
||||
struct AMFTriangle : public AMFNodeElementBase {
|
||||
size_t V[3]; ///< Triangle vertices.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFTriangle(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Triangle, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define texture node.
|
||||
struct AMFTexture : public AMFNodeElementBase {
|
||||
size_t Width, Height, Depth; ///< Size of the texture.
|
||||
std::vector<uint8_t> Data; ///< Data of the texture.
|
||||
bool Tiled;
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFTexture(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Texture, pParent), Width(0), Height(0), Depth(0), Data(), Tiled(false) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
#endif // INCLUDED_AI_AMF_IMPORTER_NODE_H
|
||||
Reference in New Issue
Block a user