xml-migration: migration of XGLImporter.
parent
1a8d5667b6
commit
979153522c
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -90,9 +88,9 @@ void AMFImporter::Clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
AMFImporter::~AMFImporter() {
|
AMFImporter::~AMFImporter() {
|
||||||
if (mReader != nullptr) {
|
if (mXmlParser != nullptr) {
|
||||||
delete mReader;
|
delete mXmlParser;
|
||||||
mReader = nullptr;
|
mXmlParser = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -106,7 +104,9 @@ 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 (CAMFImporter_NodeElement *ne : mNodeElement_List) {
|
for (CAMFImporter_NodeElement *ne : mNodeElement_List) {
|
||||||
if ((ne->ID == pID) && (ne->Type == pType)) {
|
if ((ne->ID == pID) && (ne->Type == pType)) {
|
||||||
if (pNodeElement != nullptr) *pNodeElement = ne;
|
if (pNodeElement != nullptr) {
|
||||||
|
*pNodeElement = ne;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -173,10 +173,9 @@ void AMFImporter::Throw_ID_NotFound(const std::string &pID) const {
|
||||||
/************************************************************* Functions: XML set ************************************************************/
|
/************************************************************* Functions: XML set ************************************************************/
|
||||||
/*********************************************************************************************************************************************/
|
/*********************************************************************************************************************************************/
|
||||||
|
|
||||||
void AMFImporter::XML_CheckNode_MustHaveChildren( XmlNode *node ) {
|
void AMFImporter::XML_CheckNode_MustHaveChildren( XmlNode &node ) {
|
||||||
//if (mReader->isEmptyElement()) throw DeadlyImportError(std::string("Node <") + mReader->getNodeName() + "> must have children.");
|
if (node.children().begin() == node.children().end()) {
|
||||||
if (node->getNode()->children().begin() == node->getNode()->children().end()) {
|
throw DeadlyImportError(std::string("Node <") + std::string(node.name()) + "> must have children.");
|
||||||
throw DeadlyImportError(std::string("Node <") + std::string(node->getNode()->name()) + "> must have children.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,20 +220,23 @@ casu_cres:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
bool AMFImporter::XML_SearchNode(const std::string &pNodeName) {
|
bool AMFImporter::XML_SearchNode(const std::string &nodeName) {
|
||||||
|
XmlNode *root = mXmlParser->getRootNode();
|
||||||
mReader->while (mReader->read()) {
|
if (nullptr == root) {
|
||||||
//if((mReader->getNodeType() == irr::io::EXN_ELEMENT) && XML_CheckNode_NameEqual(pNodeName)) return true;
|
|
||||||
if ((mReader->getNodeType() == pugi::node_element) && XML_CheckNode_NameEqual(pNodeName)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_node_by_name_predicate predicate(nodeName);
|
||||||
|
XmlNode node = root->find_node(predicate);
|
||||||
|
if (node.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool AMFImporter::XML_ReadNode_GetAttrVal_AsBool (const int pAttrIdx) {
|
bool AMFImporter::XML_ReadNode_GetAttrVal_AsBool (const int pAttrIdx) {
|
||||||
std::string val(mReader->getAttributeValue(pAttrIdx));
|
std::string val(mXmlParser->getAttributeValue(pAttrIdx));
|
||||||
|
|
||||||
if ((val == "false") || (val == "0"))
|
if ((val == "false") || (val == "0"))
|
||||||
return false;
|
return false;
|
||||||
|
@ -248,42 +250,42 @@ float AMFImporter::XML_ReadNode_GetAttrVal_AsFloat(const int pAttrIdx) {
|
||||||
std::string val;
|
std::string val;
|
||||||
float tvalf;
|
float tvalf;
|
||||||
|
|
||||||
ParseHelper_FixTruncatedFloatString(mReader->getAttributeValue(pAttrIdx), val);
|
ParseHelper_FixTruncatedFloatString(mXmlParser->getAttributeValue(pAttrIdx), val);
|
||||||
fast_atoreal_move(val.c_str(), tvalf, false);
|
fast_atoreal_move(val.c_str(), tvalf, false);
|
||||||
|
|
||||||
return tvalf;
|
return tvalf;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t AMFImporter::XML_ReadNode_GetAttrVal_AsU32(const int pAttrIdx) {
|
uint32_t AMFImporter::XML_ReadNode_GetAttrVal_AsU32(const int pAttrIdx) {
|
||||||
return strtoul10(mReader->getAttributeValue(pAttrIdx));
|
return strtoul10(mXmlParser->getAttributeValue(pAttrIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
float AMFImporter::XML_ReadNode_GetVal_AsFloat() {
|
float AMFImporter::XML_ReadNode_GetVal_AsFloat() {
|
||||||
std::string val;
|
std::string val;
|
||||||
float tvalf;
|
float tvalf;
|
||||||
|
|
||||||
if (!mReader->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsFloat. No data, seems file is corrupt.");
|
if (!mXmlParser->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsFloat. No data, seems file is corrupt.");
|
||||||
if (mReader->getNodeType() != irr::io::EXN_TEXT) throw DeadlyImportError("XML_ReadNode_GetVal_AsFloat. Invalid type of XML element, seems file is corrupt.");
|
if (mXmlParser->getNodeType() != irr::io::EXN_TEXT) throw DeadlyImportError("XML_ReadNode_GetVal_AsFloat. Invalid type of XML element, seems file is corrupt.");
|
||||||
|
|
||||||
ParseHelper_FixTruncatedFloatString(mReader->getNodeData(), val);
|
ParseHelper_FixTruncatedFloatString(mXmlParser->getNodeData(), val);
|
||||||
fast_atoreal_move(val.c_str(), tvalf, false);
|
fast_atoreal_move(val.c_str(), tvalf, false);
|
||||||
|
|
||||||
return tvalf;
|
return tvalf;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t AMFImporter::XML_ReadNode_GetVal_AsU32() {
|
uint32_t AMFImporter::XML_ReadNode_GetVal_AsU32() {
|
||||||
if (!mReader->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsU32. No data, seems file is corrupt.");
|
if (!mXmlParser->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsU32. No data, seems file is corrupt.");
|
||||||
if (mReader->getNodeType() != irr::io::EXN_TEXT) throw DeadlyImportError("XML_ReadNode_GetVal_AsU32. Invalid type of XML element, seems file is corrupt.");
|
if (mXmlParser->getNodeType() != irr::io::EXN_TEXT) throw DeadlyImportError("XML_ReadNode_GetVal_AsU32. Invalid type of XML element, seems file is corrupt.");
|
||||||
|
|
||||||
return strtoul10(mReader->getNodeData());
|
return strtoul10(mXmlParser->getNodeData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AMFImporter::XML_ReadNode_GetVal_AsString(std::string &pValue) {
|
void AMFImporter::XML_ReadNode_GetVal_AsString(std::string &pValue) {
|
||||||
if (!mReader->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsString. No data, seems file is corrupt.");
|
if (!mXmlParser->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsString. No data, seems file is corrupt.");
|
||||||
if (mReader->getNodeType() != irr::io::EXN_TEXT)
|
if (mXmlParser->getNodeType() != irr::io::EXN_TEXT)
|
||||||
throw DeadlyImportError("XML_ReadNode_GetVal_AsString. Invalid type of XML element, seems file is corrupt.");
|
throw DeadlyImportError("XML_ReadNode_GetVal_AsString. Invalid type of XML element, seems file is corrupt.");
|
||||||
|
|
||||||
pValue = mReader->getNodeData();
|
pValue = mXmlParser->getNodeData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************************************************************/
|
/*********************************************************************************************************************************************/
|
||||||
|
@ -383,8 +385,8 @@ void AMFImporter::ParseFile(const std::string &pFile, IOSystem *pIOHandler) {
|
||||||
throw DeadlyImportError("Failed to open AMF file " + pFile + ".");
|
throw DeadlyImportError("Failed to open AMF file " + pFile + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
mReader = new XmlParser;
|
mXmlParser = new XmlParser;
|
||||||
XmlNode *root = mReader->parse(file.get());
|
XmlNode *root = mXmlParser->parse(file.get());
|
||||||
if (nullptr == root) {
|
if (nullptr == root) {
|
||||||
throw DeadlyImportError("Failed to create XML reader for file" + pFile + ".");
|
throw DeadlyImportError("Failed to create XML reader for file" + pFile + ".");
|
||||||
}
|
}
|
||||||
|
@ -398,8 +400,8 @@ void AMFImporter::ParseFile(const std::string &pFile, IOSystem *pIOHandler) {
|
||||||
|
|
||||||
ParseNode_Root(root);
|
ParseNode_Root(root);
|
||||||
|
|
||||||
delete mReader;
|
delete mXmlParser;
|
||||||
mReader = nullptr;
|
mXmlParser = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <amf
|
// <amf
|
||||||
|
@ -502,7 +504,7 @@ void AMFImporter::ParseNode_Constellation() {
|
||||||
|
|
||||||
// Read attributes for node <constellation>.
|
// Read attributes for node <constellation>.
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
MACRO_ATTRREAD_LOOPBEG;
|
||||||
MACRO_ATTRREAD_CHECK_RET("id", id, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("id", id, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
MACRO_ATTRREAD_LOOPEND;
|
||||||
|
|
||||||
// create and if needed - define new grouping object.
|
// create and if needed - define new grouping object.
|
||||||
|
@ -512,7 +514,7 @@ void AMFImporter::ParseNode_Constellation() {
|
||||||
|
|
||||||
if (!id.empty()) als.ID = id;
|
if (!id.empty()) als.ID = id;
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if (!mReader->isEmptyElement()) {
|
if (!mXmlParser->isEmptyElement()) {
|
||||||
ParseHelper_Node_Enter(ne);
|
ParseHelper_Node_Enter(ne);
|
||||||
MACRO_NODECHECK_LOOPBEGIN("constellation");
|
MACRO_NODECHECK_LOOPBEGIN("constellation");
|
||||||
if (XML_CheckNode_NameEqual("instance")) {
|
if (XML_CheckNode_NameEqual("instance")) {
|
||||||
|
@ -546,7 +548,7 @@ void AMFImporter::ParseNode_Instance() {
|
||||||
|
|
||||||
// Read attributes for node <constellation>.
|
// Read attributes for node <constellation>.
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
MACRO_ATTRREAD_LOOPBEG;
|
||||||
MACRO_ATTRREAD_CHECK_RET("objectid", objectid, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("objectid", objectid, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
MACRO_ATTRREAD_LOOPEND;
|
||||||
|
|
||||||
// used object id must be defined, check that.
|
// used object id must be defined, check that.
|
||||||
|
@ -558,7 +560,7 @@ void AMFImporter::ParseNode_Instance() {
|
||||||
|
|
||||||
als.ObjectID = objectid;
|
als.ObjectID = objectid;
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if (!mReader->isEmptyElement()) {
|
if (!mXmlParser->isEmptyElement()) {
|
||||||
bool read_flag[6] = { false, false, false, false, false, false };
|
bool read_flag[6] = { false, false, false, false, false, false };
|
||||||
|
|
||||||
als.Delta.Set(0, 0, 0);
|
als.Delta.Set(0, 0, 0);
|
||||||
|
@ -625,7 +627,7 @@ void AMFImporter::ParseNode_Object(XmlNode *nodeInst) {
|
||||||
ParseNode_Metadata(*it);
|
ParseNode_Metadata(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!mReader->isEmptyElement()) {
|
if (!mXmlParser->isEmptyElement()) {
|
||||||
bool col_read = false;
|
bool col_read = false;
|
||||||
|
|
||||||
ParseHelper_Node_Enter(ne);
|
ParseHelper_Node_Enter(ne);
|
||||||
|
@ -682,10 +684,10 @@ void AMFImporter::ParseNode_Metadata() {
|
||||||
|
|
||||||
// read attribute
|
// read attribute
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
MACRO_ATTRREAD_LOOPBEG;
|
||||||
MACRO_ATTRREAD_CHECK_RET("type", type, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("type", type, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
MACRO_ATTRREAD_LOOPEND;
|
||||||
// and value of node.
|
// and value of node.
|
||||||
value = mReader->getNodeData();
|
value = mXmlParser->getNodeData();
|
||||||
// Create node element and assign read data.
|
// Create node element and assign read data.
|
||||||
ne = new CAMFImporter_NodeElement_Metadata(mNodeElement_Cur);
|
ne = new CAMFImporter_NodeElement_Metadata(mNodeElement_Cur);
|
||||||
((CAMFImporter_NodeElement_Metadata *)ne)->Type = type;
|
((CAMFImporter_NodeElement_Metadata *)ne)->Type = type;
|
||||||
|
|
|
@ -63,8 +63,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
class XmlNode;
|
|
||||||
|
|
||||||
/// \class AMFImporter
|
/// \class AMFImporter
|
||||||
/// Class that holding scene graph which include: geometry, metadata, materials etc.
|
/// Class that holding scene graph which include: geometry, metadata, materials etc.
|
||||||
///
|
///
|
||||||
|
@ -280,7 +278,7 @@ private:
|
||||||
void Throw_ID_NotFound(const std::string& pID) const;
|
void Throw_ID_NotFound(const std::string& pID) const;
|
||||||
|
|
||||||
/// Check if current node have children: <node>...</node>. If not then exception will thrown.
|
/// Check if current node have children: <node>...</node>. If not then exception will thrown.
|
||||||
void XML_CheckNode_MustHaveChildren(XmlNode *node);
|
void XML_CheckNode_MustHaveChildren( XmlNode &node);
|
||||||
|
|
||||||
/// Check if current node name is equal to pNodeName.
|
/// Check if current node name is equal to pNodeName.
|
||||||
/// \param [in] pNodeName - name for checking.
|
/// \param [in] pNodeName - name for checking.
|
||||||
|
@ -345,49 +343,49 @@ private:
|
||||||
void ParseHelper_Decode_Base64(const std::string& pInputBase64, std::vector<uint8_t>& pOutputData) const;
|
void ParseHelper_Decode_Base64(const std::string& pInputBase64, std::vector<uint8_t>& pOutputData) const;
|
||||||
|
|
||||||
/// Parse <AMF> node of the file.
|
/// Parse <AMF> node of the file.
|
||||||
void ParseNode_Root(XmlNode *root);
|
void ParseNode_Root(XmlNode &root);
|
||||||
|
|
||||||
/// Parse <constellation> node of the file.
|
/// Parse <constellation> node of the file.
|
||||||
void ParseNode_Constellation(XmlNode *node);
|
void ParseNode_Constellation(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <instance> node of the file.
|
/// Parse <instance> node of the file.
|
||||||
void ParseNode_Instance(XmlNode *node);
|
void ParseNode_Instance(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <material> node of the file.
|
/// Parse <material> node of the file.
|
||||||
void ParseNode_Material(XmlNode *node);
|
void ParseNode_Material(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <metadata> node.
|
/// Parse <metadata> node.
|
||||||
void ParseNode_Metadata(XmlNode *node);
|
void ParseNode_Metadata(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <object> node of the file.
|
/// Parse <object> node of the file.
|
||||||
void ParseNode_Object(XmlNode *node);
|
void ParseNode_Object(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <texture> node of the file.
|
/// Parse <texture> node of the file.
|
||||||
void ParseNode_Texture(XmlNode *node);
|
void ParseNode_Texture(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <coordinates> node of the file.
|
/// Parse <coordinates> node of the file.
|
||||||
void ParseNode_Coordinates(XmlNode *node);
|
void ParseNode_Coordinates(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <edge> node of the file.
|
/// Parse <edge> node of the file.
|
||||||
void ParseNode_Edge(XmlNode *node);
|
void ParseNode_Edge(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <mesh> node of the file.
|
/// Parse <mesh> node of the file.
|
||||||
void ParseNode_Mesh(XmlNode *node);
|
void ParseNode_Mesh(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <triangle> node of the file.
|
/// Parse <triangle> node of the file.
|
||||||
void ParseNode_Triangle(XmlNode *node);
|
void ParseNode_Triangle(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <vertex> node of the file.
|
/// Parse <vertex> node of the file.
|
||||||
void ParseNode_Vertex(XmlNode *node);
|
void ParseNode_Vertex(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <vertices> node of the file.
|
/// Parse <vertices> node of the file.
|
||||||
void ParseNode_Vertices(XmlNode *node);
|
void ParseNode_Vertices(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <volume> node of the file.
|
/// Parse <volume> node of the file.
|
||||||
void ParseNode_Volume(XmlNode *node);
|
void ParseNode_Volume(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <color> node of the file.
|
/// Parse <color> node of the file.
|
||||||
void ParseNode_Color(XmlNode *node);
|
void ParseNode_Color(XmlNode &node);
|
||||||
|
|
||||||
/// Parse <texmap> of <map> node of the file.
|
/// 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>.
|
/// \param [in] pUseOldName - if true then use old name of node(and children) - <map>, instead of new name - <texmap>.
|
||||||
|
@ -397,7 +395,7 @@ public:
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
AMFImporter() AI_NO_EXCEPT
|
AMFImporter() AI_NO_EXCEPT
|
||||||
: mNodeElement_Cur(nullptr)
|
: mNodeElement_Cur(nullptr)
|
||||||
, mReader(nullptr) {
|
, mXmlParser(nullptr) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +421,7 @@ private:
|
||||||
|
|
||||||
CAMFImporter_NodeElement* mNodeElement_Cur;///< Current element.
|
CAMFImporter_NodeElement* mNodeElement_Cur;///< Current element.
|
||||||
std::list<CAMFImporter_NodeElement*> mNodeElement_List;///< All elements of scene graph.
|
std::list<CAMFImporter_NodeElement*> mNodeElement_List;///< All elements of scene graph.
|
||||||
XmlParser *mReader;
|
XmlParser *mXmlParser;
|
||||||
//irr::io::IrrXMLReader* mReader;///< Pointer to XML-reader object
|
//irr::io::IrrXMLReader* mReader;///< Pointer to XML-reader object
|
||||||
std::string mUnit;
|
std::string mUnit;
|
||||||
std::list<SPP_Material> mMaterial_Converted;///< List of converted materials for postprocessing step.
|
std::list<SPP_Material> mMaterial_Converted;///< List of converted materials for postprocessing step.
|
||||||
|
|
|
@ -66,7 +66,7 @@ void AMFImporter::ParseNode_Mesh()
|
||||||
// create new mesh object.
|
// create new mesh object.
|
||||||
ne = new CAMFImporter_NodeElement_Mesh(mNodeElement_Cur);
|
ne = new CAMFImporter_NodeElement_Mesh(mNodeElement_Cur);
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
bool vert_read = false;
|
bool vert_read = false;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ CAMFImporter_NodeElement* ne;
|
||||||
// create new mesh object.
|
// create new mesh object.
|
||||||
ne = new CAMFImporter_NodeElement_Vertices(mNodeElement_Cur);
|
ne = new CAMFImporter_NodeElement_Vertices(mNodeElement_Cur);
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
ParseHelper_Node_Enter(ne);
|
ParseHelper_Node_Enter(ne);
|
||||||
MACRO_NODECHECK_LOOPBEGIN("vertices");
|
MACRO_NODECHECK_LOOPBEGIN("vertices");
|
||||||
|
@ -135,7 +135,7 @@ CAMFImporter_NodeElement* ne;
|
||||||
// create new mesh object.
|
// create new mesh object.
|
||||||
ne = new CAMFImporter_NodeElement_Vertex(mNodeElement_Cur);
|
ne = new CAMFImporter_NodeElement_Vertex(mNodeElement_Cur);
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
bool col_read = false;
|
bool col_read = false;
|
||||||
bool coord_read = false;
|
bool coord_read = false;
|
||||||
|
@ -196,7 +196,7 @@ CAMFImporter_NodeElement* ne;
|
||||||
CAMFImporter_NodeElement_Coordinates& als = *((CAMFImporter_NodeElement_Coordinates*)ne);// alias for convenience
|
CAMFImporter_NodeElement_Coordinates& als = *((CAMFImporter_NodeElement_Coordinates*)ne);// alias for convenience
|
||||||
|
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
bool read_flag[3] = { false, false, false };
|
bool read_flag[3] = { false, false, false };
|
||||||
|
|
||||||
|
@ -236,8 +236,8 @@ CAMFImporter_NodeElement* ne;
|
||||||
|
|
||||||
// Read attributes for node <color>.
|
// Read attributes for node <color>.
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
MACRO_ATTRREAD_LOOPBEG;
|
||||||
MACRO_ATTRREAD_CHECK_RET("materialid", materialid, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("materialid", materialid, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_CHECK_RET("type", type, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("type", type, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
MACRO_ATTRREAD_LOOPEND;
|
||||||
|
|
||||||
// create new object.
|
// create new object.
|
||||||
|
@ -246,7 +246,7 @@ CAMFImporter_NodeElement* ne;
|
||||||
((CAMFImporter_NodeElement_Volume*)ne)->MaterialID = materialid;
|
((CAMFImporter_NodeElement_Volume*)ne)->MaterialID = materialid;
|
||||||
((CAMFImporter_NodeElement_Volume*)ne)->Type = type;
|
((CAMFImporter_NodeElement_Volume*)ne)->Type = type;
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
bool col_read = false;
|
bool col_read = false;
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ CAMFImporter_NodeElement* ne;
|
||||||
CAMFImporter_NodeElement_Triangle& als = *((CAMFImporter_NodeElement_Triangle*)ne);// alias for convenience
|
CAMFImporter_NodeElement_Triangle& als = *((CAMFImporter_NodeElement_Triangle*)ne);// alias for convenience
|
||||||
|
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
bool col_read = false, tex_read = false;
|
bool col_read = false, tex_read = false;
|
||||||
bool read_flag[3] = { false, false, false };
|
bool read_flag[3] = { false, false, false };
|
||||||
|
|
|
@ -74,7 +74,7 @@ void AMFImporter::ParseNode_Color() {
|
||||||
|
|
||||||
// Read attributes for node <color>.
|
// Read attributes for node <color>.
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
MACRO_ATTRREAD_LOOPBEG;
|
||||||
MACRO_ATTRREAD_CHECK_RET("profile", profile, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("profile", profile, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
MACRO_ATTRREAD_LOOPEND;
|
||||||
|
|
||||||
// create new color object.
|
// create new color object.
|
||||||
|
@ -84,7 +84,7 @@ void AMFImporter::ParseNode_Color() {
|
||||||
|
|
||||||
als.Profile = profile;
|
als.Profile = profile;
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
bool read_flag[4] = { false, false, false, false };
|
bool read_flag[4] = { false, false, false, false };
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ void AMFImporter::ParseNode_Material() {
|
||||||
|
|
||||||
// Read attributes for node <color>.
|
// Read attributes for node <color>.
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
MACRO_ATTRREAD_LOOPBEG;
|
||||||
MACRO_ATTRREAD_CHECK_RET("id", id, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("id", id, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
MACRO_ATTRREAD_LOOPEND;
|
||||||
|
|
||||||
// create new object.
|
// create new object.
|
||||||
|
@ -138,7 +138,7 @@ void AMFImporter::ParseNode_Material() {
|
||||||
((CAMFImporter_NodeElement_Material*)ne)->ID = id;
|
((CAMFImporter_NodeElement_Material*)ne)->ID = id;
|
||||||
|
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if(!mReader->isEmptyElement())
|
if(!mXmlParser->isEmptyElement())
|
||||||
{
|
{
|
||||||
bool col_read = false;
|
bool col_read = false;
|
||||||
|
|
||||||
|
@ -183,25 +183,13 @@ void AMFImporter::ParseNode_Material() {
|
||||||
// then layer by layer.
|
// then layer by layer.
|
||||||
// Multi elements - Yes.
|
// Multi elements - Yes.
|
||||||
// Parent element - <amf>.
|
// Parent element - <amf>.
|
||||||
void AMFImporter::ParseNode_Texture()
|
void AMFImporter::ParseNode_Texture(XmlNode &node) {
|
||||||
{
|
std::string id = node.attribute("id").as_string();
|
||||||
std::string id;
|
uint32_t width = node.attribute("width").as_uint();
|
||||||
uint32_t width = 0;
|
uint32_t height = node.attribute("height").as_uint();
|
||||||
uint32_t height = 0;
|
uint32_t depth = node.attribute("depth").as_uint();
|
||||||
uint32_t depth = 1;
|
std::string type = node.attribute("type").as_string();
|
||||||
std::string type;
|
bool tiled = node.attribute("tiled").as_bool();
|
||||||
bool tiled = false;
|
|
||||||
std::string enc64_data;
|
|
||||||
|
|
||||||
// Read attributes for node <color>.
|
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
|
||||||
MACRO_ATTRREAD_CHECK_RET("id", id, mReader->getAttributeValue);
|
|
||||||
MACRO_ATTRREAD_CHECK_RET("width", width, XML_ReadNode_GetAttrVal_AsU32);
|
|
||||||
MACRO_ATTRREAD_CHECK_RET("height", height, XML_ReadNode_GetAttrVal_AsU32);
|
|
||||||
MACRO_ATTRREAD_CHECK_RET("depth", depth, XML_ReadNode_GetAttrVal_AsU32);
|
|
||||||
MACRO_ATTRREAD_CHECK_RET("type", type, mReader->getAttributeValue);
|
|
||||||
MACRO_ATTRREAD_CHECK_RET("tiled", tiled, XML_ReadNode_GetAttrVal_AsBool);
|
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
|
||||||
|
|
||||||
// create new texture object.
|
// create new texture object.
|
||||||
CAMFImporter_NodeElement *ne = new CAMFImporter_NodeElement_Texture(mNodeElement_Cur);
|
CAMFImporter_NodeElement *ne = new CAMFImporter_NodeElement_Texture(mNodeElement_Cur);
|
||||||
|
@ -209,7 +197,7 @@ void AMFImporter::ParseNode_Texture()
|
||||||
CAMFImporter_NodeElement_Texture& als = *((CAMFImporter_NodeElement_Texture*)ne);// alias for convenience
|
CAMFImporter_NodeElement_Texture& als = *((CAMFImporter_NodeElement_Texture*)ne);// alias for convenience
|
||||||
|
|
||||||
// Check for child nodes
|
// Check for child nodes
|
||||||
if (!mReader->isEmptyElement()) {
|
if (!mXmlParser->isEmptyElement()) {
|
||||||
XML_ReadNode_GetVal_AsString(enc64_data);
|
XML_ReadNode_GetVal_AsString(enc64_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,10 +256,10 @@ void AMFImporter::ParseNode_TexMap(const bool pUseOldName) {
|
||||||
|
|
||||||
// Read attributes for node <color>.
|
// Read attributes for node <color>.
|
||||||
MACRO_ATTRREAD_LOOPBEG;
|
MACRO_ATTRREAD_LOOPBEG;
|
||||||
MACRO_ATTRREAD_CHECK_RET("rtexid", rtexid, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("rtexid", rtexid, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_CHECK_RET("gtexid", gtexid, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("gtexid", gtexid, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_CHECK_RET("btexid", btexid, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("btexid", btexid, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_CHECK_RET("atexid", atexid, mReader->getAttributeValue);
|
MACRO_ATTRREAD_CHECK_RET("atexid", atexid, mXmlParser->getAttributeValue);
|
||||||
MACRO_ATTRREAD_LOOPEND;
|
MACRO_ATTRREAD_LOOPEND;
|
||||||
|
|
||||||
// create new texture coordinates object.
|
// create new texture coordinates object.
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -68,11 +66,8 @@ using namespace Assimp::Formatter;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
ColladaParser::ColladaParser(IOSystem* pIOHandler, const std::string& pFile)
|
ColladaParser::ColladaParser(IOSystem* pIOHandler, const std::string& pFile) :
|
||||||
: mFileName(pFile)
|
mFileName(pFile), mXmlParser(nullptr), mDataLibrary(), mAccessorLibrary()
|
||||||
, mReader(nullptr)
|
|
||||||
, mDataLibrary()
|
|
||||||
, mAccessorLibrary()
|
|
||||||
, mMeshLibrary()
|
, mMeshLibrary()
|
||||||
, mNodeLibrary()
|
, mNodeLibrary()
|
||||||
, mImageLibrary()
|
, mImageLibrary()
|
||||||
|
@ -1532,7 +1527,7 @@ void ColladaParser::ReadLight(Collada::Light& pLight)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Reads a camera entry into the given light
|
// Reads a camera entry into the given light
|
||||||
void ColladaParser::ReadCamera(Collada::Camera& pCamera)
|
void ColladaParser::ReadCamera(Collada::Camera& camera)
|
||||||
{
|
{
|
||||||
while (mReader->read())
|
while (mReader->read())
|
||||||
{
|
{
|
||||||
|
@ -1541,26 +1536,26 @@ void ColladaParser::ReadCamera(Collada::Camera& pCamera)
|
||||||
SkipElement();
|
SkipElement();
|
||||||
}
|
}
|
||||||
else if (IsElement("orthographic")) {
|
else if (IsElement("orthographic")) {
|
||||||
pCamera.mOrtho = true;
|
camera.mOrtho = true;
|
||||||
}
|
}
|
||||||
else if (IsElement("xfov") || IsElement("xmag")) {
|
else if (IsElement("xfov") || IsElement("xmag")) {
|
||||||
pCamera.mHorFov = ReadFloatFromTextContent();
|
camera.mHorFov = ReadFloatFromTextContent();
|
||||||
TestClosing((pCamera.mOrtho ? "xmag" : "xfov"));
|
TestClosing((camera.mOrtho ? "xmag" : "xfov"));
|
||||||
}
|
}
|
||||||
else if (IsElement("yfov") || IsElement("ymag")) {
|
else if (IsElement("yfov") || IsElement("ymag")) {
|
||||||
pCamera.mVerFov = ReadFloatFromTextContent();
|
camera.mVerFov = ReadFloatFromTextContent();
|
||||||
TestClosing((pCamera.mOrtho ? "ymag" : "yfov"));
|
TestClosing((camera.mOrtho ? "ymag" : "yfov"));
|
||||||
}
|
}
|
||||||
else if (IsElement("aspect_ratio")) {
|
else if (IsElement("aspect_ratio")) {
|
||||||
pCamera.mAspect = ReadFloatFromTextContent();
|
camera.mAspect = ReadFloatFromTextContent();
|
||||||
TestClosing("aspect_ratio");
|
TestClosing("aspect_ratio");
|
||||||
}
|
}
|
||||||
else if (IsElement("znear")) {
|
else if (IsElement("znear")) {
|
||||||
pCamera.mZNear = ReadFloatFromTextContent();
|
camera.mZNear = ReadFloatFromTextContent();
|
||||||
TestClosing("znear");
|
TestClosing("znear");
|
||||||
}
|
}
|
||||||
else if (IsElement("zfar")) {
|
else if (IsElement("zfar")) {
|
||||||
pCamera.mZFar = ReadFloatFromTextContent();
|
camera.mZFar = ReadFloatFromTextContent();
|
||||||
TestClosing("zfar");
|
TestClosing("zfar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -55,6 +54,7 @@
|
||||||
namespace Assimp
|
namespace Assimp
|
||||||
{
|
{
|
||||||
class ZipArchiveIOSystem;
|
class ZipArchiveIOSystem;
|
||||||
|
class XmlParser;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
/** Parser helper class for the Collada loader.
|
/** Parser helper class for the Collada loader.
|
||||||
|
@ -112,7 +112,7 @@ namespace Assimp
|
||||||
/** Reads an animation into the given parent structure */
|
/** Reads an animation into the given parent structure */
|
||||||
void ReadAnimation( Collada::Animation* pParent);
|
void ReadAnimation( Collada::Animation* pParent);
|
||||||
|
|
||||||
/** Reads an animation sampler into the given anim channel */
|
/** Reads an animation sampler into the given animation channel */
|
||||||
void ReadAnimationSampler( Collada::AnimationChannel& pChannel);
|
void ReadAnimationSampler( Collada::AnimationChannel& pChannel);
|
||||||
|
|
||||||
/** Reads the skeleton controller library */
|
/** Reads the skeleton controller library */
|
||||||
|
@ -157,16 +157,16 @@ namespace Assimp
|
||||||
/** Reads an effect entry into the given effect*/
|
/** Reads an effect entry into the given effect*/
|
||||||
void ReadEffect( Collada::Effect& pEffect);
|
void ReadEffect( Collada::Effect& pEffect);
|
||||||
|
|
||||||
/** Reads an COMMON effect profile */
|
/// Reads an COMMON effect profile
|
||||||
void ReadEffectProfileCommon( Collada::Effect& pEffect);
|
void ReadEffectProfileCommon( Collada::Effect& pEffect);
|
||||||
|
|
||||||
/** Read sampler properties */
|
/// Read sampler properties
|
||||||
void ReadSamplerProperties( Collada::Sampler& pSampler);
|
void ReadSamplerProperties( Collada::Sampler& pSampler);
|
||||||
|
|
||||||
/** Reads an effect entry containing a color or a texture defining that color */
|
/// Reads an effect entry containing a color or a texture defining that color
|
||||||
void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler);
|
void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler);
|
||||||
|
|
||||||
/** Reads an effect entry containing a float */
|
/// Reads an effect entry containing a float
|
||||||
void ReadEffectFloat( ai_real& pFloat);
|
void ReadEffectFloat( ai_real& pFloat);
|
||||||
|
|
||||||
/** Reads an effect parameter specification of any kind */
|
/** Reads an effect parameter specification of any kind */
|
||||||
|
@ -182,7 +182,7 @@ namespace Assimp
|
||||||
void ReadMesh( Collada::Mesh* pMesh);
|
void ReadMesh( Collada::Mesh* pMesh);
|
||||||
|
|
||||||
/** Reads a source element - a combination of raw data and an accessor defining
|
/** Reads a source element - a combination of raw data and an accessor defining
|
||||||
* things that should not be redefinable. Yes, that's another rant.
|
* things that should not be re-definable. Yes, that's another rant.
|
||||||
*/
|
*/
|
||||||
void ReadSource();
|
void ReadSource();
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ namespace Assimp
|
||||||
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
||||||
size_t currentPrimitive, const std::vector<size_t>& indices);
|
size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||||
|
|
||||||
/** Reads one triangle of a tristrip into the mesh */
|
/** Reads one triangle of a triangle-strip into the mesh */
|
||||||
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh,
|
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh,
|
||||||
std::vector<Collada::InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices);
|
std::vector<Collada::InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||||
|
|
||||||
|
@ -298,7 +298,8 @@ namespace Assimp
|
||||||
std::string mFileName;
|
std::string mFileName;
|
||||||
|
|
||||||
/** XML reader, member for everyday use */
|
/** XML reader, member for everyday use */
|
||||||
irr::io::IrrXMLReader* mReader;
|
//irr::io::IrrXMLReader* mReader;
|
||||||
|
XmlParser *mXmlParser;
|
||||||
|
|
||||||
/** All data arrays found in the file by ID. Might be referred to by actually
|
/** All data arrays found in the file by ID. Might be referred to by actually
|
||||||
everyone. Collada, you are a steaming pile of indirection. */
|
everyone. Collada, you are a steaming pile of indirection. */
|
||||||
|
@ -359,19 +360,24 @@ namespace Assimp
|
||||||
/** Size unit: how large compared to a meter */
|
/** Size unit: how large compared to a meter */
|
||||||
ai_real mUnitSize;
|
ai_real mUnitSize;
|
||||||
|
|
||||||
/** Which is the up vector */
|
/// Which is the up vector.
|
||||||
enum { UP_X, UP_Y, UP_Z } mUpDirection;
|
enum {
|
||||||
|
UP_X,
|
||||||
|
UP_Y,
|
||||||
|
UP_Z
|
||||||
|
} mUpDirection;
|
||||||
|
|
||||||
/** Asset metadata (global for scene) */
|
/// Asset metadata (global for scene)
|
||||||
StringMetaData mAssetMetaData;
|
StringMetaData mAssetMetaData;
|
||||||
|
|
||||||
/** Collada file format version */
|
/// Collada file format version
|
||||||
Collada::FormatVersion mFormat;
|
Collada::FormatVersion mFormat;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Check for element match
|
// Check for element match
|
||||||
inline bool ColladaParser::IsElement( const char* pName) const
|
inline
|
||||||
|
bool ColladaParser::IsElement( const char* pName) const
|
||||||
{
|
{
|
||||||
ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
||||||
return ::strcmp( mReader->getNodeName(), pName) == 0;
|
return ::strcmp( mReader->getNodeName(), pName) == 0;
|
||||||
|
@ -380,11 +386,11 @@ namespace Assimp
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Finds the item in the given library by its reference, throws if not found
|
// Finds the item in the given library by its reference, throws if not found
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const
|
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& library, const std::string& url) const
|
||||||
{
|
{
|
||||||
typename std::map<std::string, Type>::const_iterator it = pLibrary.find( pURL);
|
typename std::map<std::string, Type>::const_iterator it = library.find( url);
|
||||||
if( it == pLibrary.end())
|
if( it == library.end())
|
||||||
ThrowException( Formatter::format() << "Unable to resolve library reference \"" << pURL << "\"." );
|
ThrowException( Formatter::format() << "Unable to resolve library reference \"" << url << "\"." );
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -40,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @file IRRLoader.h
|
/** @file IRRLoader.h
|
||||||
* @brief Declaration of the .irrMesh (Irrlight Engine Mesh Format)
|
* @brief Declaration of the .irrMesh (Irrlight Engine Mesh Format)
|
||||||
* importer class.
|
* importer class.
|
||||||
|
@ -83,7 +81,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Data structure for a scenegraph node animator
|
/** Data structure for a scene-graph node animator
|
||||||
*/
|
*/
|
||||||
struct Animator {
|
struct Animator {
|
||||||
// Type of the animator
|
// Type of the animator
|
||||||
|
@ -129,7 +127,7 @@ private:
|
||||||
int timeForWay;
|
int timeForWay;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Data structure for a scenegraph node in an IRR file
|
/** Data structure for a scene-graph node in an IRR file
|
||||||
*/
|
*/
|
||||||
struct Node
|
struct Node
|
||||||
{
|
{
|
||||||
|
@ -227,8 +225,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Fill the scenegraph recursively
|
/// Fill the scene-graph recursively
|
||||||
*/
|
|
||||||
void GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
|
void GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
|
||||||
BatchLoader& batch,
|
BatchLoader& batch,
|
||||||
std::vector<aiMesh*>& meshes,
|
std::vector<aiMesh*>& meshes,
|
||||||
|
@ -237,27 +234,22 @@ private:
|
||||||
std::vector<aiMaterial*>& materials,
|
std::vector<aiMaterial*>& materials,
|
||||||
unsigned int& defaultMatIdx);
|
unsigned int& defaultMatIdx);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Generate a mesh that consists of just a single quad
|
/// Generate a mesh that consists of just a single quad
|
||||||
*/
|
|
||||||
aiMesh* BuildSingleQuadMesh(const SkyboxVertex& v1,
|
aiMesh* BuildSingleQuadMesh(const SkyboxVertex& v1,
|
||||||
const SkyboxVertex& v2,
|
const SkyboxVertex& v2,
|
||||||
const SkyboxVertex& v3,
|
const SkyboxVertex& v3,
|
||||||
const SkyboxVertex& v4);
|
const SkyboxVertex& v4);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Build a skybox
|
/// Build a sky-box
|
||||||
*
|
///
|
||||||
* @param meshes Receives 6 output meshes
|
/// @param meshes Receives 6 output meshes
|
||||||
* @param materials The last 6 materials are assigned to the newly
|
/// @param materials The last 6 materials are assigned to the newly
|
||||||
* created meshes. The names of the materials are adjusted.
|
/// created meshes. The names of the materials are adjusted.
|
||||||
*/
|
|
||||||
void BuildSkybox(std::vector<aiMesh*>& meshes,
|
void BuildSkybox(std::vector<aiMesh*>& meshes,
|
||||||
std::vector<aiMaterial*> materials);
|
std::vector<aiMaterial*> materials);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Copy a material for a mesh to the output material list
|
/** Copy a material for a mesh to the output material list
|
||||||
*
|
*
|
||||||
|
@ -271,7 +263,6 @@ private:
|
||||||
unsigned int& defMatIdx,
|
unsigned int& defMatIdx,
|
||||||
aiMesh* mesh);
|
aiMesh* mesh);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Compute animations for a specific node
|
/** Compute animations for a specific node
|
||||||
*
|
*
|
||||||
|
@ -281,13 +272,11 @@ private:
|
||||||
void ComputeAnimations(Node* root, aiNode* real,
|
void ComputeAnimations(Node* root, aiNode* real,
|
||||||
std::vector<aiNodeAnim*>& anims);
|
std::vector<aiNodeAnim*>& anims);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// Configuration option: desired output FPS
|
||||||
/** Configuration option: desired output FPS */
|
|
||||||
double fps;
|
double fps;
|
||||||
|
|
||||||
/** Configuration option: speed flag was set? */
|
/// Configuration option: speed flag was set?
|
||||||
bool configSpeedFlag;
|
bool configSpeedFlag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,23 +14,14 @@
|
||||||
#include <assimp/Exporter.hpp>
|
#include <assimp/Exporter.hpp>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
|
|
||||||
using namespace std;
|
namespace Assimp {
|
||||||
|
|
||||||
namespace Assimp
|
void ExportSceneX3D(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties) {
|
||||||
{
|
|
||||||
|
|
||||||
void ExportSceneX3D(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
|
||||||
{
|
|
||||||
X3DExporter exporter(pFile, pIOSystem, pScene, pProperties);
|
X3DExporter exporter(pFile, pIOSystem, pScene, pProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace Assimp
|
|
||||||
|
|
||||||
namespace Assimp
|
void X3DExporter::IndentationStringSet(const size_t pNewLevel) {
|
||||||
{
|
|
||||||
|
|
||||||
void X3DExporter::IndentationStringSet(const size_t pNewLevel)
|
|
||||||
{
|
|
||||||
if(pNewLevel > mIndentationString.size())
|
if(pNewLevel > mIndentationString.size())
|
||||||
{
|
{
|
||||||
if(pNewLevel > mIndentationString.capacity()) mIndentationString.reserve(pNewLevel + 1);
|
if(pNewLevel > mIndentationString.capacity()) mIndentationString.reserve(pNewLevel + 1);
|
||||||
|
@ -43,14 +34,17 @@ void X3DExporter::IndentationStringSet(const size_t pNewLevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void X3DExporter::XML_Write(const string& pData)
|
void X3DExporter::XML_Write(const std::string& pData) {
|
||||||
{
|
if (pData.empty() ) {
|
||||||
if(pData.size() == 0) return;
|
return;
|
||||||
if(mOutFile->Write((void*)pData.data(), pData.length(), 1) != 1) throw DeadlyExportError("Failed to write scene data!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aiMatrix4x4 X3DExporter::Matrix_GlobalToCurrent(const aiNode& pNode) const
|
if (mOutFile->Write((void *)pData.data(), pData.length(), 1) != 1) {
|
||||||
{
|
throw DeadlyExportError("Failed to write scene data!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aiMatrix4x4 X3DExporter::Matrix_GlobalToCurrent(const aiNode& pNode) const {
|
||||||
aiNode *cur_node;
|
aiNode *cur_node;
|
||||||
std::list<aiMatrix4x4> matr;
|
std::list<aiMatrix4x4> matr;
|
||||||
aiMatrix4x4 out_matr;
|
aiMatrix4x4 out_matr;
|
||||||
|
@ -60,14 +54,13 @@ aiMatrix4x4 out_matr;
|
||||||
cur_node = pNode.mParent;
|
cur_node = pNode.mParent;
|
||||||
if(cur_node != nullptr)
|
if(cur_node != nullptr)
|
||||||
{
|
{
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
matr.push_back(cur_node->mTransformation);
|
matr.push_back(cur_node->mTransformation);
|
||||||
cur_node = cur_node->mParent;
|
cur_node = cur_node->mParent;
|
||||||
} while(cur_node != nullptr);
|
} while(cur_node != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiplicate all matrices in reverse order
|
// Multiplication of all matrices in reverse order
|
||||||
for(std::list<aiMatrix4x4>::reverse_iterator rit = matr.rbegin(); rit != matr.rend(); ++rit) out_matr = out_matr * (*rit);
|
for(std::list<aiMatrix4x4>::reverse_iterator rit = matr.rbegin(); rit != matr.rend(); ++rit) out_matr = out_matr * (*rit);
|
||||||
|
|
||||||
return out_matr;
|
return out_matr;
|
||||||
|
|
|
@ -47,6 +47,8 @@ namespace Assimp
|
||||||
///
|
///
|
||||||
class X3DExporter
|
class X3DExporter
|
||||||
{
|
{
|
||||||
|
using AttrubuteList = std::list<SAttribute>;
|
||||||
|
|
||||||
/***********************************************/
|
/***********************************************/
|
||||||
/******************** Types ********************/
|
/******************** Types ********************/
|
||||||
/***********************************************/
|
/***********************************************/
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -43,24 +41,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
/** @file Implementation of the XGL/ZGL importer class */
|
/** @file Implementation of the XGL/ZGL importer class */
|
||||||
|
|
||||||
|
|
||||||
#ifndef ASSIMP_BUILD_NO_XGL_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_XGL_IMPORTER
|
||||||
|
|
||||||
#include "XGLLoader.h"
|
#include "XGLLoader.h"
|
||||||
#include <assimp/ParsingUtils.h>
|
#include <assimp/ParsingUtils.h>
|
||||||
#include <assimp/fast_atof.h>
|
#include <assimp/fast_atof.h>
|
||||||
|
|
||||||
#include <assimp/StreamReader.h>
|
|
||||||
#include <assimp/MemoryIOWrapper.h>
|
#include <assimp/MemoryIOWrapper.h>
|
||||||
|
#include <assimp/StreamReader.h>
|
||||||
|
#include <assimp/importerdesc.h>
|
||||||
#include <assimp/mesh.h>
|
#include <assimp/mesh.h>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/importerdesc.h>
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
using namespace irr;
|
//using namespace irr;
|
||||||
using namespace irr::io;
|
//using namespace irr::io;
|
||||||
|
|
||||||
// zlib is needed for compressed XGL files
|
// zlib is needed for compressed XGL files
|
||||||
#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL
|
#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL
|
||||||
|
@ -71,14 +68,13 @@ using namespace irr::io;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Assimp { // this has to be in here because LogFunctions is in ::Assimp
|
namespace Assimp { // this has to be in here because LogFunctions is in ::Assimp
|
||||||
template<> const char* LogFunctions<XGLImporter>::Prefix()
|
template <>
|
||||||
{
|
const char *LogFunctions<XGLImporter>::Prefix() {
|
||||||
static auto prefix = "XGL: ";
|
static auto prefix = "XGL: ";
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
}
|
} // namespace Assimp
|
||||||
|
|
||||||
static const aiImporterDesc desc = {
|
static const aiImporterDesc desc = {
|
||||||
"XGL Importer",
|
"XGL Importer",
|
||||||
|
@ -93,12 +89,10 @@ static const aiImporterDesc desc = {
|
||||||
"xgl zgl"
|
"xgl zgl"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
XGLImporter::XGLImporter()
|
XGLImporter::XGLImporter() :
|
||||||
: m_reader( nullptr )
|
m_xmlParser(nullptr), m_scene(nullptr) {
|
||||||
, m_scene( nullptr ) {
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +104,7 @@ XGLImporter::~XGLImporter() {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// Returns whether the class can handle the format of the given file.
|
||||||
bool XGLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
bool XGLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||||
{
|
|
||||||
/* NOTE: A simple check for the file extension is not enough
|
/* NOTE: A simple check for the file extension is not enough
|
||||||
* here. XGL and ZGL are ok, but xml is too generic
|
* here. XGL and ZGL are ok, but xml is too generic
|
||||||
* and might be collada as well. So open the file and
|
* and might be collada as well. So open the file and
|
||||||
|
@ -121,8 +114,7 @@ bool XGLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
||||||
|
|
||||||
if (extension == "xgl" || extension == "zgl") {
|
if (extension == "xgl" || extension == "zgl") {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (extension == "xml" || checkSig) {
|
||||||
else if (extension == "xml" || checkSig) {
|
|
||||||
ai_assert(pIOHandler != NULL);
|
ai_assert(pIOHandler != NULL);
|
||||||
|
|
||||||
const char *tokens[] = { "<world>", "<World>", "<WORLD>" };
|
const char *tokens[] = { "<world>", "<World>", "<WORLD>" };
|
||||||
|
@ -133,16 +125,14 @@ bool XGLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Get a list of all file extensions which are handled by this class
|
// Get a list of all file extensions which are handled by this class
|
||||||
const aiImporterDesc* XGLImporter::GetInfo () const
|
const aiImporterDesc *XGLImporter::GetInfo() const {
|
||||||
{
|
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
void XGLImporter::InternReadFile(const std::string &pFile,
|
void XGLImporter::InternReadFile(const std::string &pFile,
|
||||||
aiScene* pScene, IOSystem* pIOHandler)
|
aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
{
|
|
||||||
#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL
|
#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL
|
||||||
std::vector<Bytef> uncompressed;
|
std::vector<Bytef> uncompressed;
|
||||||
#endif
|
#endif
|
||||||
|
@ -197,8 +187,7 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
||||||
total += have;
|
total += have;
|
||||||
uncompressed.resize(total);
|
uncompressed.resize(total);
|
||||||
memcpy(uncompressed.data() + total - have, block, have);
|
memcpy(uncompressed.data() + total - have, block, have);
|
||||||
}
|
} while (ret != Z_STREAM_END);
|
||||||
while (ret != Z_STREAM_END);
|
|
||||||
|
|
||||||
// terminate zlib
|
// terminate zlib
|
||||||
inflateEnd(&zstream);
|
inflateEnd(&zstream);
|
||||||
|
@ -209,18 +198,25 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct the irrXML parser
|
// construct the irrXML parser
|
||||||
CIrrXML_IOStreamReader st(stream.get());
|
/*CIrrXML_IOStreamReader st(stream.get());
|
||||||
m_reader.reset( createIrrXMLReader( ( IFileReadCallBack* ) &st ) );
|
m_reader.reset( createIrrXMLReader( ( IFileReadCallBack* ) &st ) );*/
|
||||||
|
m_xmlParser = new XmlParser;
|
||||||
|
XmlNode *root = m_xmlParser->parse(stream.get());
|
||||||
|
if (nullptr == root) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// parse the XML file
|
// parse the XML file
|
||||||
TempScope scope;
|
TempScope scope;
|
||||||
|
if (!ASSIMP_stricmp(root->name(), "world")) {
|
||||||
|
ReadWorld(scope);
|
||||||
|
}
|
||||||
|
|
||||||
while (ReadElement()) {
|
/* while (ReadElement()) {
|
||||||
if (!ASSIMP_stricmp(m_reader->getNodeName(),"world")) {
|
if (!ASSIMP_stricmp(m_reader->getNodeName(),"world")) {
|
||||||
ReadWorld(scope);
|
ReadWorld(scope);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
std::vector<aiMesh *> &meshes = scope.meshes_linear;
|
std::vector<aiMesh *> &meshes = scope.meshes_linear;
|
||||||
std::vector<aiMaterial *> &materials = scope.materials_linear;
|
std::vector<aiMaterial *> &materials = scope.materials_linear;
|
||||||
|
@ -250,75 +246,20 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
bool XGLImporter::ReadElement()
|
void XGLImporter::ReadWorld(TempScope &scope) {
|
||||||
{
|
XmlNode *root = m_xmlParser->getRootNode();
|
||||||
while(m_reader->read()) {
|
for (XmlNode &node : root->children()) {
|
||||||
if (m_reader->getNodeType() == EXN_ELEMENT) {
|
const std::string &s = node.name();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
bool XGLImporter::ReadElementUpToClosing(const char* closetag)
|
|
||||||
{
|
|
||||||
while(m_reader->read()) {
|
|
||||||
if (m_reader->getNodeType() == EXN_ELEMENT) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (m_reader->getNodeType() == EXN_ELEMENT_END && !ASSIMP_stricmp(m_reader->getNodeName(),closetag)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LogError("unexpected EOF, expected closing <" + std::string(closetag) + "> tag");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
bool XGLImporter::SkipToText()
|
|
||||||
{
|
|
||||||
while(m_reader->read()) {
|
|
||||||
if (m_reader->getNodeType() == EXN_TEXT) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (m_reader->getNodeType() == EXN_ELEMENT || m_reader->getNodeType() == EXN_ELEMENT_END) {
|
|
||||||
ThrowException("expected text contents but found another element (or element end)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
std::string XGLImporter::GetElementName()
|
|
||||||
{
|
|
||||||
const char* s = m_reader->getNodeName();
|
|
||||||
size_t len = strlen(s);
|
|
||||||
|
|
||||||
std::string ret;
|
|
||||||
ret.resize(len);
|
|
||||||
|
|
||||||
std::transform(s,s+len,ret.begin(),::tolower);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
void XGLImporter::ReadWorld(TempScope& scope)
|
|
||||||
{
|
|
||||||
while (ReadElementUpToClosing("world")) {
|
|
||||||
const std::string& s = GetElementName();
|
|
||||||
// XXX right now we'd skip <lighting> if it comes after
|
// XXX right now we'd skip <lighting> if it comes after
|
||||||
// <object> or <mesh>
|
// <object> or <mesh>
|
||||||
if (s == "lighting") {
|
if (s == "lighting") {
|
||||||
ReadLighting(scope);
|
ReadLighting(node, scope);
|
||||||
}
|
} else if (s == "object" || s == "mesh" || s == "mat") {
|
||||||
else if (s == "object" || s == "mesh" || s == "mat") {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aiNode *const nd = ReadObject(*root, scope, true, "world");
|
||||||
aiNode* const nd = ReadObject(scope,true,"world");
|
|
||||||
if (!nd) {
|
if (!nd) {
|
||||||
ThrowException("failure reading <world>");
|
ThrowException("failure reading <world>");
|
||||||
}
|
}
|
||||||
|
@ -330,75 +271,67 @@ void XGLImporter::ReadWorld(TempScope& scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void XGLImporter::ReadLighting(TempScope& scope)
|
void XGLImporter::ReadLighting(XmlNode &node, TempScope &scope) {
|
||||||
{
|
const std::string &s = node.name();
|
||||||
while (ReadElementUpToClosing("lighting")) {
|
|
||||||
const std::string& s = GetElementName();
|
|
||||||
if (s == "directionallight") {
|
if (s == "directionallight") {
|
||||||
scope.light = ReadDirectionalLight();
|
scope.light = ReadDirectionalLight(node);
|
||||||
}
|
} else if (s == "ambient") {
|
||||||
else if (s == "ambient") {
|
|
||||||
LogWarn("ignoring <ambient> tag");
|
LogWarn("ignoring <ambient> tag");
|
||||||
}
|
} else if (s == "spheremap") {
|
||||||
else if (s == "spheremap") {
|
|
||||||
LogWarn("ignoring <spheremap> tag");
|
LogWarn("ignoring <spheremap> tag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiLight* XGLImporter::ReadDirectionalLight()
|
aiLight *XGLImporter::ReadDirectionalLight(XmlNode &node) {
|
||||||
{
|
|
||||||
std::unique_ptr<aiLight> l(new aiLight());
|
std::unique_ptr<aiLight> l(new aiLight());
|
||||||
l->mType = aiLightSource_DIRECTIONAL;
|
l->mType = aiLightSource_DIRECTIONAL;
|
||||||
|
find_node_by_name_predicate predicate("directionallight");
|
||||||
|
XmlNode child = node.find_child(predicate);
|
||||||
|
if (child.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
while (ReadElementUpToClosing("directionallight")) {
|
const std::string &s = child.name();
|
||||||
const std::string& s = GetElementName();
|
|
||||||
if (s == "direction") {
|
if (s == "direction") {
|
||||||
l->mDirection = ReadVec3();
|
l->mDirection = ReadVec3(child);
|
||||||
}
|
} else if (s == "diffuse") {
|
||||||
else if (s == "diffuse") {
|
l->mColorDiffuse = ReadCol3(child);
|
||||||
l->mColorDiffuse = ReadCol3();
|
} else if (s == "specular") {
|
||||||
}
|
l->mColorSpecular = ReadCol3(child);
|
||||||
else if (s == "specular") {
|
|
||||||
l->mColorSpecular = ReadCol3();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.release();
|
return l.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* closetag)
|
aiNode *XGLImporter::ReadObject(XmlNode &node, TempScope &scope, bool skipFirst, const char *closetag) {
|
||||||
{
|
|
||||||
aiNode *nd = new aiNode;
|
aiNode *nd = new aiNode;
|
||||||
std::vector<aiNode *> children;
|
std::vector<aiNode *> children;
|
||||||
std::vector<unsigned int> meshes;
|
std::vector<unsigned int> meshes;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (skipFirst || ReadElementUpToClosing(closetag)) {
|
for (XmlNode &child : node.children()) {
|
||||||
|
|
||||||
skipFirst = false;
|
skipFirst = false;
|
||||||
|
|
||||||
const std::string& s = GetElementName();
|
const std::string &s = child.name();
|
||||||
if (s == "mesh") {
|
if (s == "mesh") {
|
||||||
const size_t prev = scope.meshes_linear.size();
|
const size_t prev = scope.meshes_linear.size();
|
||||||
if(ReadMesh(scope)) {
|
if (ReadMesh(child, scope)) {
|
||||||
const size_t newc = scope.meshes_linear.size();
|
const size_t newc = scope.meshes_linear.size();
|
||||||
for (size_t i = 0; i < newc - prev; ++i) {
|
for (size_t i = 0; i < newc - prev; ++i) {
|
||||||
meshes.push_back(static_cast<unsigned int>(i + prev));
|
meshes.push_back(static_cast<unsigned int>(i + prev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (s == "mat") {
|
||||||
else if (s == "mat") {
|
ReadMaterial(child, scope);
|
||||||
ReadMaterial(scope);
|
} else if (s == "object") {
|
||||||
}
|
children.push_back(ReadObject(child, scope));
|
||||||
else if (s == "object") {
|
} else if (s == "objectref") {
|
||||||
children.push_back(ReadObject(scope));
|
|
||||||
}
|
|
||||||
else if (s == "objectref") {
|
|
||||||
// XXX
|
// XXX
|
||||||
}
|
} else if (s == "meshref") {
|
||||||
else if (s == "meshref") {
|
const unsigned int id = static_cast<unsigned int>(ReadIndexFromText(child));
|
||||||
const unsigned int id = static_cast<unsigned int>( ReadIndexFromText() );
|
|
||||||
|
|
||||||
std::multimap<unsigned int, aiMesh *>::iterator it = scope.meshes.find(id), end = scope.meshes.end();
|
std::multimap<unsigned int, aiMesh *>::iterator it = scope.meshes.find(id), end = scope.meshes.end();
|
||||||
if (it == end) {
|
if (it == end) {
|
||||||
|
@ -407,8 +340,7 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl
|
||||||
|
|
||||||
for (; it != end && (*it).first == id; ++it) {
|
for (; it != end && (*it).first == id; ++it) {
|
||||||
// ok, this is n^2 and should get optimized one day
|
// ok, this is n^2 and should get optimized one day
|
||||||
aiMesh* const m = (*it).second;
|
aiMesh *const m = it->second;
|
||||||
|
|
||||||
unsigned int i = 0, mcount = static_cast<unsigned int>(scope.meshes_linear.size());
|
unsigned int i = 0, mcount = static_cast<unsigned int>(scope.meshes_linear.size());
|
||||||
for (; i < mcount; ++i) {
|
for (; i < mcount; ++i) {
|
||||||
if (scope.meshes_linear[i] == m) {
|
if (scope.meshes_linear[i] == m) {
|
||||||
|
@ -419,12 +351,10 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl
|
||||||
|
|
||||||
ai_assert(i < mcount);
|
ai_assert(i < mcount);
|
||||||
}
|
}
|
||||||
}
|
} else if (s == "transform") {
|
||||||
else if (s == "transform") {
|
nd->mTransformation = ReadTrafo(child);
|
||||||
nd->mTransformation = ReadTrafo();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
for (aiNode *ch : children) {
|
for (aiNode *ch : children) {
|
||||||
delete ch;
|
delete ch;
|
||||||
|
@ -440,7 +370,7 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl
|
||||||
|
|
||||||
// link meshes to node
|
// link meshes to node
|
||||||
nd->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
nd->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
||||||
if (nd->mNumMeshes) {
|
if (0 != nd->mNumMeshes) {
|
||||||
nd->mMeshes = new unsigned int[nd->mNumMeshes]();
|
nd->mMeshes = new unsigned int[nd->mNumMeshes]();
|
||||||
for (unsigned int i = 0; i < nd->mNumMeshes; ++i) {
|
for (unsigned int i = 0; i < nd->mNumMeshes; ++i) {
|
||||||
nd->mMeshes[i] = meshes[i];
|
nd->mMeshes[i] = meshes[i];
|
||||||
|
@ -461,24 +391,27 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiMatrix4x4 XGLImporter::ReadTrafo()
|
aiMatrix4x4 XGLImporter::ReadTrafo(XmlNode &node) {
|
||||||
{
|
|
||||||
aiVector3D forward, up, right, position;
|
aiVector3D forward, up, right, position;
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
|
|
||||||
while (ReadElementUpToClosing("transform")) {
|
aiMatrix4x4 m;
|
||||||
const std::string& s = GetElementName();
|
XmlNode child = node.child("transform");
|
||||||
|
if (child.empty()) {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (XmlNode &sub_child : child.children()) {
|
||||||
|
const std::string &s = sub_child.name();
|
||||||
if (s == "forward") {
|
if (s == "forward") {
|
||||||
forward = ReadVec3();
|
forward = ReadVec3(sub_child);
|
||||||
}
|
} else if (s == "up") {
|
||||||
else if (s == "up") {
|
up = ReadVec3(sub_child);
|
||||||
up = ReadVec3();
|
} else if (s == "position") {
|
||||||
}
|
position = ReadVec3(sub_child);
|
||||||
else if (s == "position") {
|
|
||||||
position = ReadVec3();
|
|
||||||
}
|
}
|
||||||
if (s == "scale") {
|
if (s == "scale") {
|
||||||
scale = ReadFloat();
|
scale = ReadFloat(sub_child);
|
||||||
if (scale < 0.f) {
|
if (scale < 0.f) {
|
||||||
// this is wrong, but we can leave the value and pass it to the caller
|
// this is wrong, but we can leave the value and pass it to the caller
|
||||||
LogError("found negative scaling in <transform>, ignoring");
|
LogError("found negative scaling in <transform>, ignoring");
|
||||||
|
@ -486,7 +419,6 @@ aiMatrix4x4 XGLImporter::ReadTrafo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aiMatrix4x4 m;
|
|
||||||
if (forward.SquareLength() < 1e-4 || up.SquareLength() < 1e-4) {
|
if (forward.SquareLength() < 1e-4 || up.SquareLength() < 1e-4) {
|
||||||
LogError("A direction vector in <transform> is zero, ignoring trafo");
|
LogError("A direction vector in <transform> is zero, ignoring trafo");
|
||||||
return m;
|
return m;
|
||||||
|
@ -527,8 +459,7 @@ aiMatrix4x4 XGLImporter::ReadTrafo()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiMesh* XGLImporter::ToOutputMesh(const TempMaterialMesh& m)
|
aiMesh *XGLImporter::ToOutputMesh(const TempMaterialMesh &m) {
|
||||||
{
|
|
||||||
std::unique_ptr<aiMesh> mesh(new aiMesh());
|
std::unique_ptr<aiMesh> mesh(new aiMesh());
|
||||||
|
|
||||||
mesh->mNumVertices = static_cast<unsigned int>(m.positions.size());
|
mesh->mNumVertices = static_cast<unsigned int>(m.positions.size());
|
||||||
|
@ -566,82 +497,73 @@ aiMesh* XGLImporter::ToOutputMesh(const TempMaterialMesh& m)
|
||||||
|
|
||||||
mesh->mPrimitiveTypes = m.pflags;
|
mesh->mPrimitiveTypes = m.pflags;
|
||||||
mesh->mMaterialIndex = m.matid;
|
mesh->mMaterialIndex = m.matid;
|
||||||
|
|
||||||
return mesh.release();
|
return mesh.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
bool XGLImporter::ReadMesh(TempScope& scope)
|
bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope) {
|
||||||
{
|
|
||||||
TempMesh t;
|
TempMesh t;
|
||||||
|
|
||||||
std::map<unsigned int, TempMaterialMesh> bymat;
|
std::map<unsigned int, TempMaterialMesh> bymat;
|
||||||
const unsigned int mesh_id = ReadIDAttr();
|
const unsigned int mesh_id = ReadIDAttr(node);
|
||||||
|
|
||||||
while (ReadElementUpToClosing("mesh")) {
|
for (XmlNode &child : node.children()) {
|
||||||
const std::string& s = GetElementName();
|
const std::string &s = child.name();
|
||||||
|
|
||||||
if (s == "mat") {
|
if (s == "mat") {
|
||||||
ReadMaterial(scope);
|
ReadMaterial(child, scope);
|
||||||
}
|
} else if (s == "p") {
|
||||||
else if (s == "p") {
|
pugi::xml_attribute attr = child.attribute("ID");
|
||||||
if (!m_reader->getAttributeValue("ID")) {
|
if (attr.empty()) {
|
||||||
LogWarn("no ID attribute on <p>, ignoring");
|
LogWarn("no ID attribute on <p>, ignoring");
|
||||||
|
} else {
|
||||||
|
int id = attr.as_int();
|
||||||
|
t.points[id] = ReadVec3(child);
|
||||||
}
|
}
|
||||||
else {
|
} else if (s == "n") {
|
||||||
int id = m_reader->getAttributeValueAsInt("ID");
|
pugi::xml_attribute attr = child.attribute("ID");
|
||||||
t.points[id] = ReadVec3();
|
if (attr.empty()) {
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (s == "n") {
|
|
||||||
if (!m_reader->getAttributeValue("ID")) {
|
|
||||||
LogWarn("no ID attribute on <n>, ignoring");
|
LogWarn("no ID attribute on <n>, ignoring");
|
||||||
|
} else {
|
||||||
|
int id = attr.as_int();
|
||||||
|
t.normals[id] = ReadVec3(child);
|
||||||
}
|
}
|
||||||
else {
|
} else if (s == "tc") {
|
||||||
int id = m_reader->getAttributeValueAsInt("ID");
|
pugi::xml_attribute attr = child.attribute("ID");
|
||||||
t.normals[id] = ReadVec3();
|
if (attr.empty()) {
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (s == "tc") {
|
|
||||||
if (!m_reader->getAttributeValue("ID")) {
|
|
||||||
LogWarn("no ID attribute on <tc>, ignoring");
|
LogWarn("no ID attribute on <tc>, ignoring");
|
||||||
|
} else {
|
||||||
|
int id = attr.as_int();
|
||||||
|
t.uvs[id] = ReadVec2(child);
|
||||||
}
|
}
|
||||||
else {
|
} else if (s == "f" || s == "l" || s == "p") {
|
||||||
int id = m_reader->getAttributeValueAsInt("ID");
|
|
||||||
t.uvs[id] = ReadVec2();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (s == "f" || s == "l" || s == "p") {
|
|
||||||
const unsigned int vcount = s == "f" ? 3 : (s == "l" ? 2 : 1);
|
const unsigned int vcount = s == "f" ? 3 : (s == "l" ? 2 : 1);
|
||||||
|
|
||||||
unsigned int mid = ~0u;
|
unsigned int mid = ~0u;
|
||||||
TempFace tf[3];
|
TempFace tf[3];
|
||||||
bool has[3] = {0};
|
bool has[3] = { false };
|
||||||
|
for (XmlNode &sub_child : child.children()) {
|
||||||
while (ReadElementUpToClosing(s.c_str())) {
|
const std::string &s = sub_child.name();
|
||||||
const std::string& s = GetElementName();
|
|
||||||
if (s == "fv1" || s == "lv1" || s == "pv1") {
|
if (s == "fv1" || s == "lv1" || s == "pv1") {
|
||||||
ReadFaceVertex(t,tf[0]);
|
ReadFaceVertex(sub_child, t, tf[0]);
|
||||||
has[0] = true;
|
has[0] = true;
|
||||||
}
|
} else if (s == "fv2" || s == "lv2") {
|
||||||
else if (s == "fv2" || s == "lv2") {
|
ReadFaceVertex(sub_child, t, tf[1]);
|
||||||
ReadFaceVertex(t,tf[1]);
|
|
||||||
has[1] = true;
|
has[1] = true;
|
||||||
}
|
} else if (s == "fv3") {
|
||||||
else if (s == "fv3") {
|
ReadFaceVertex(sub_child, t, tf[2]);
|
||||||
ReadFaceVertex(t,tf[2]);
|
|
||||||
has[2] = true;
|
has[2] = true;
|
||||||
}
|
} else if (s == "mat") {
|
||||||
else if (s == "mat") {
|
|
||||||
if (mid != ~0u) {
|
if (mid != ~0u) {
|
||||||
LogWarn("only one material tag allowed per <f>");
|
LogWarn("only one material tag allowed per <f>");
|
||||||
}
|
}
|
||||||
mid = ResolveMaterialRef(scope);
|
mid = ResolveMaterialRef(sub_child, scope);
|
||||||
}
|
} else if (s == "matref") {
|
||||||
else if (s == "matref") {
|
|
||||||
if (mid != ~0u) {
|
if (mid != ~0u) {
|
||||||
LogWarn("only one material tag allowed per <f>");
|
LogWarn("only one material tag allowed per <f>");
|
||||||
}
|
}
|
||||||
mid = ResolveMaterialRef(scope);
|
mid = ResolveMaterialRef(sub_child, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,15 +623,14 @@ bool XGLImporter::ReadMesh(TempScope& scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------
|
||||||
unsigned int XGLImporter::ResolveMaterialRef(TempScope& scope)
|
unsigned int XGLImporter::ResolveMaterialRef(XmlNode &node, TempScope &scope) {
|
||||||
{
|
const std::string &s = node.name();
|
||||||
const std::string& s = GetElementName();
|
|
||||||
if (s == "mat") {
|
if (s == "mat") {
|
||||||
ReadMaterial(scope);
|
ReadMaterial(node, scope);
|
||||||
return static_cast<unsigned int>(scope.materials_linear.size() - 1);
|
return static_cast<unsigned int>(scope.materials_linear.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int id = ReadIndexFromText();
|
const int id = ReadIndexFromText(node);
|
||||||
|
|
||||||
std::map<unsigned int, aiMaterial *>::iterator it = scope.materials.find(id), end = scope.materials.end();
|
std::map<unsigned int, aiMaterial *>::iterator it = scope.materials.find(id), end = scope.materials.end();
|
||||||
if (it == end) {
|
if (it == end) {
|
||||||
|
@ -727,38 +648,34 @@ unsigned int XGLImporter::ResolveMaterialRef(TempScope& scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
ai_assert(false);
|
ai_assert(false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void XGLImporter::ReadMaterial(TempScope& scope) {
|
void XGLImporter::ReadMaterial(XmlNode &node, TempScope &scope) {
|
||||||
const unsigned int mat_id = ReadIDAttr();
|
const unsigned int mat_id = ReadIDAttr(node);
|
||||||
|
|
||||||
aiMaterial *mat(new aiMaterial);
|
aiMaterial *mat(new aiMaterial);
|
||||||
while (ReadElementUpToClosing("mat")) {
|
for (XmlNode &child : node.children()) {
|
||||||
const std::string& s = GetElementName();
|
const std::string &s = child.name();
|
||||||
if (s == "amb") {
|
if (s == "amb") {
|
||||||
const aiColor3D c = ReadCol3();
|
const aiColor3D c = ReadCol3(child);
|
||||||
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_AMBIENT);
|
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_AMBIENT);
|
||||||
}
|
} else if (s == "diff") {
|
||||||
else if (s == "diff") {
|
const aiColor3D c = ReadCol3(child);
|
||||||
const aiColor3D c = ReadCol3();
|
|
||||||
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_DIFFUSE);
|
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
}
|
} else if (s == "spec") {
|
||||||
else if (s == "spec") {
|
const aiColor3D c = ReadCol3(child);
|
||||||
const aiColor3D c = ReadCol3();
|
|
||||||
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_SPECULAR);
|
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_SPECULAR);
|
||||||
}
|
} else if (s == "emiss") {
|
||||||
else if (s == "emiss") {
|
const aiColor3D c = ReadCol3(child);
|
||||||
const aiColor3D c = ReadCol3();
|
|
||||||
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_EMISSIVE);
|
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||||
}
|
} else if (s == "alpha") {
|
||||||
else if (s == "alpha") {
|
const float f = ReadFloat(child);
|
||||||
const float f = ReadFloat();
|
|
||||||
mat->AddProperty(&f, 1, AI_MATKEY_OPACITY);
|
mat->AddProperty(&f, 1, AI_MATKEY_OPACITY);
|
||||||
}
|
} else if (s == "shine") {
|
||||||
else if (s == "shine") {
|
const float f = ReadFloat(child);
|
||||||
const float f = ReadFloat();
|
|
||||||
mat->AddProperty(&f, 1, AI_MATKEY_SHININESS);
|
mat->AddProperty(&f, 1, AI_MATKEY_SHININESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -768,15 +685,15 @@ void XGLImporter::ReadMaterial(TempScope& scope) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------
|
||||||
void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out)
|
void XGLImporter::ReadFaceVertex(XmlNode &node, const TempMesh &t, TempFace &out) {
|
||||||
{
|
const std::string &end = node.name();
|
||||||
const std::string& end = GetElementName();
|
|
||||||
|
|
||||||
bool havep = false;
|
bool havep = false;
|
||||||
while (ReadElementUpToClosing(end.c_str())) {
|
//while (ReadElementUpToClosing(end.c_str())) {
|
||||||
const std::string& s = GetElementName();
|
for (XmlNode &child : node.children()) {
|
||||||
|
const std::string &s = child.name();
|
||||||
if (s == "pref") {
|
if (s == "pref") {
|
||||||
const unsigned int id = ReadIndexFromText();
|
const unsigned int id = ReadIndexFromText(child);
|
||||||
std::map<unsigned int, aiVector3D>::const_iterator it = t.points.find(id);
|
std::map<unsigned int, aiVector3D>::const_iterator it = t.points.find(id);
|
||||||
if (it == t.points.end()) {
|
if (it == t.points.end()) {
|
||||||
ThrowException("point index out of range");
|
ThrowException("point index out of range");
|
||||||
|
@ -784,9 +701,8 @@ void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out)
|
||||||
|
|
||||||
out.pos = (*it).second;
|
out.pos = (*it).second;
|
||||||
havep = true;
|
havep = true;
|
||||||
}
|
} else if (s == "nref") {
|
||||||
else if (s == "nref") {
|
const unsigned int id = ReadIndexFromText(child);
|
||||||
const unsigned int id = ReadIndexFromText();
|
|
||||||
std::map<unsigned int, aiVector3D>::const_iterator it = t.normals.find(id);
|
std::map<unsigned int, aiVector3D>::const_iterator it = t.normals.find(id);
|
||||||
if (it == t.normals.end()) {
|
if (it == t.normals.end()) {
|
||||||
ThrowException("normal index out of range");
|
ThrowException("normal index out of range");
|
||||||
|
@ -794,9 +710,8 @@ void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out)
|
||||||
|
|
||||||
out.normal = (*it).second;
|
out.normal = (*it).second;
|
||||||
out.has_normal = true;
|
out.has_normal = true;
|
||||||
}
|
} else if (s == "tcref") {
|
||||||
else if (s == "tcref") {
|
const unsigned int id = ReadIndexFromText(child);
|
||||||
const unsigned int id = ReadIndexFromText();
|
|
||||||
std::map<unsigned int, aiVector2D>::const_iterator it = t.uvs.find(id);
|
std::map<unsigned int, aiVector2D>::const_iterator it = t.uvs.find(id);
|
||||||
if (it == t.uvs.end()) {
|
if (it == t.uvs.end()) {
|
||||||
ThrowException("uv index out of range");
|
ThrowException("uv index out of range");
|
||||||
|
@ -804,15 +719,12 @@ void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out)
|
||||||
|
|
||||||
out.uv = (*it).second;
|
out.uv = (*it).second;
|
||||||
out.has_uv = true;
|
out.has_uv = true;
|
||||||
}
|
} else if (s == "p") {
|
||||||
else if (s == "p") {
|
out.pos = ReadVec3(child);
|
||||||
out.pos = ReadVec3();
|
} else if (s == "n") {
|
||||||
}
|
out.normal = ReadVec3(child);
|
||||||
else if (s == "n") {
|
} else if (s == "tc") {
|
||||||
out.normal = ReadVec3();
|
out.uv = ReadVec2(child);
|
||||||
}
|
|
||||||
else if (s == "tc") {
|
|
||||||
out.uv = ReadVec2();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,34 +734,25 @@ void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
unsigned int XGLImporter::ReadIDAttr()
|
unsigned int XGLImporter::ReadIDAttr(XmlNode &node) {
|
||||||
{
|
for (pugi::xml_attribute attr : node.attributes()) {
|
||||||
for(int i = 0, e = m_reader->getAttributeCount(); i < e; ++i) {
|
if (!ASSIMP_stricmp(attr.name(), "id")) {
|
||||||
|
return attr.as_int();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!ASSIMP_stricmp(m_reader->getAttributeName(i),"id")) {
|
|
||||||
return m_reader->getAttributeValueAsInt(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ~0u;
|
return ~0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
float XGLImporter::ReadFloat()
|
float XGLImporter::ReadFloat(XmlNode &node) {
|
||||||
{
|
const char *s = node.value(), *se;
|
||||||
if(!SkipToText()) {
|
|
||||||
LogError("unexpected EOF reading float element contents");
|
|
||||||
return 0.f;
|
|
||||||
}
|
|
||||||
const char* s = m_reader->getNodeData(), *se;
|
|
||||||
|
|
||||||
if (!SkipSpaces(&s)) {
|
if (!SkipSpaces(&s)) {
|
||||||
LogError("unexpected EOL, failed to parse float");
|
LogError("unexpected EOL, failed to parse index element");
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float t;
|
float t;
|
||||||
se = fast_atoreal_move(s, t);
|
se = fast_atoreal_move(s, t);
|
||||||
|
|
||||||
if (se == s) {
|
if (se == s) {
|
||||||
LogError("failed to read float text");
|
LogError("failed to read float text");
|
||||||
return 0.f;
|
return 0.f;
|
||||||
|
@ -859,18 +762,13 @@ float XGLImporter::ReadFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
unsigned int XGLImporter::ReadIndexFromText()
|
unsigned int XGLImporter::ReadIndexFromText(XmlNode &node) {
|
||||||
{
|
const char *s = node.value();
|
||||||
if(!SkipToText()) {
|
|
||||||
LogError("unexpected EOF reading index element contents");
|
|
||||||
return ~0u;
|
|
||||||
}
|
|
||||||
const char* s = m_reader->getNodeData(), *se;
|
|
||||||
if (!SkipSpaces(&s)) {
|
if (!SkipSpaces(&s)) {
|
||||||
LogError("unexpected EOL, failed to parse index element");
|
LogError("unexpected EOL, failed to parse index element");
|
||||||
return ~0u;
|
return ~0u;
|
||||||
}
|
}
|
||||||
|
const char *se;
|
||||||
const unsigned int t = strtoul10(s, &se);
|
const unsigned int t = strtoul10(s, &se);
|
||||||
|
|
||||||
if (se == s) {
|
if (se == s) {
|
||||||
|
@ -882,16 +780,9 @@ unsigned int XGLImporter::ReadIndexFromText()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiVector2D XGLImporter::ReadVec2()
|
aiVector2D XGLImporter::ReadVec2(XmlNode &node) {
|
||||||
{
|
|
||||||
aiVector2D vec;
|
aiVector2D vec;
|
||||||
|
const char *s = node.value();
|
||||||
if(!SkipToText()) {
|
|
||||||
LogError("unexpected EOF reading vec2 contents");
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
const char* s = m_reader->getNodeData();
|
|
||||||
|
|
||||||
ai_real v[2];
|
ai_real v[2];
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
if (!SkipSpaces(&s)) {
|
if (!SkipSpaces(&s)) {
|
||||||
|
@ -915,16 +806,9 @@ aiVector2D XGLImporter::ReadVec2()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiVector3D XGLImporter::ReadVec3()
|
aiVector3D XGLImporter::ReadVec3(XmlNode &node) {
|
||||||
{
|
|
||||||
aiVector3D vec;
|
aiVector3D vec;
|
||||||
|
const char *s = node.value();
|
||||||
if(!SkipToText()) {
|
|
||||||
LogError("unexpected EOF reading vec3 contents");
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
const char* s = m_reader->getNodeData();
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
if (!SkipSpaces(&s)) {
|
if (!SkipSpaces(&s)) {
|
||||||
LogError("unexpected EOL, failed to parse vec3");
|
LogError("unexpected EOL, failed to parse vec3");
|
||||||
|
@ -944,9 +828,8 @@ aiVector3D XGLImporter::ReadVec3()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiColor3D XGLImporter::ReadCol3()
|
aiColor3D XGLImporter::ReadCol3(XmlNode &node) {
|
||||||
{
|
const aiVector3D &v = ReadVec3(node);
|
||||||
const aiVector3D& v = ReadVec3();
|
|
||||||
if (v.x < 0.f || v.x > 1.0f || v.y < 0.f || v.y > 1.0f || v.z < 0.f || v.z > 1.0f) {
|
if (v.x < 0.f || v.x > 1.0f || v.y < 0.f || v.y > 1.0f || v.z < 0.f || v.z > 1.0f) {
|
||||||
LogWarn("color values out of range, ignoring");
|
LogWarn("color values out of range, ignoring");
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/mesh.h>
|
#include <assimp/mesh.h>
|
||||||
#include <assimp/light.h>
|
#include <assimp/light.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
@ -65,16 +66,11 @@ namespace Assimp {
|
||||||
*
|
*
|
||||||
* Spec: http://vizstream.aveva.com/release/vsplatform/XGLSpec.htm
|
* Spec: http://vizstream.aveva.com/release/vsplatform/XGLSpec.htm
|
||||||
*/
|
*/
|
||||||
class XGLImporter : public BaseImporter, public LogFunctions<XGLImporter>
|
class XGLImporter : public BaseImporter, public LogFunctions<XGLImporter> {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
XGLImporter();
|
XGLImporter();
|
||||||
~XGLImporter();
|
~XGLImporter();
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns whether the class can handle the format of the given file.
|
/** Returns whether the class can handle the format of the given file.
|
||||||
* See BaseImporter::CanRead() for details. */
|
* See BaseImporter::CanRead() for details. */
|
||||||
|
@ -95,8 +91,6 @@ protected:
|
||||||
IOSystem* pIOHandler);
|
IOSystem* pIOHandler);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
struct TempScope
|
struct TempScope
|
||||||
{
|
{
|
||||||
TempScope()
|
TempScope()
|
||||||
|
@ -180,34 +174,30 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Cleanup();
|
void Cleanup();
|
||||||
|
|
||||||
std::string GetElementName();
|
unsigned int ReadIDAttr(XmlNode &node);
|
||||||
bool ReadElement();
|
|
||||||
bool ReadElementUpToClosing(const char* closetag);
|
|
||||||
bool SkipToText();
|
|
||||||
unsigned int ReadIDAttr();
|
|
||||||
|
|
||||||
void ReadWorld(TempScope& scope);
|
void ReadWorld(TempScope& scope);
|
||||||
void ReadLighting(TempScope& scope);
|
void ReadLighting(XmlNode &node, TempScope &scope);
|
||||||
aiLight* ReadDirectionalLight();
|
aiLight *ReadDirectionalLight(XmlNode &node);
|
||||||
aiNode* ReadObject(TempScope& scope,bool skipFirst = false,const char* closetag = "object");
|
aiNode *ReadObject(XmlNode &node, TempScope &scope, bool skipFirst = false, const char *closetag = "object");
|
||||||
bool ReadMesh(TempScope& scope);
|
bool ReadMesh(XmlNode &node, TempScope &scope);
|
||||||
void ReadMaterial(TempScope& scope);
|
void ReadMaterial(XmlNode &node, TempScope &scope);
|
||||||
aiVector2D ReadVec2();
|
aiVector2D ReadVec2(XmlNode &node );
|
||||||
aiVector3D ReadVec3();
|
aiVector3D ReadVec3(XmlNode &node );
|
||||||
aiColor3D ReadCol3();
|
aiColor3D ReadCol3(XmlNode &node );
|
||||||
aiMatrix4x4 ReadTrafo();
|
aiMatrix4x4 ReadTrafo(XmlNode &node );
|
||||||
unsigned int ReadIndexFromText();
|
unsigned int ReadIndexFromText(XmlNode &node);
|
||||||
float ReadFloat();
|
float ReadFloat(XmlNode &node );
|
||||||
|
|
||||||
aiMesh* ToOutputMesh(const TempMaterialMesh& m);
|
aiMesh* ToOutputMesh(const TempMaterialMesh& m);
|
||||||
void ReadFaceVertex(const TempMesh& t, TempFace& out);
|
void ReadFaceVertex(XmlNode &node, const TempMesh &t, TempFace &out);
|
||||||
unsigned int ResolveMaterialRef(TempScope& scope);
|
unsigned int ResolveMaterialRef(XmlNode &node, TempScope &scope);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<irr::io::IrrXMLReader> m_reader;
|
//std::shared_ptr<irr::io::IrrXMLReader> m_reader;
|
||||||
|
XmlParser *m_xmlParser;
|
||||||
aiScene* m_scene;
|
aiScene* m_scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,96 +51,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
|
||||||
/** @brief Utility class to make IrrXML work together with our custom IO system
|
|
||||||
* See the IrrXML docs for more details.
|
|
||||||
*
|
|
||||||
* Construct IrrXML-Reader in BaseImporter::InternReadFile():
|
|
||||||
* @code
|
|
||||||
* // open the file
|
|
||||||
* std::unique_ptr<IOStream> file( pIOHandler->Open( pFile));
|
|
||||||
* if( file.get() == NULL) {
|
|
||||||
* throw DeadlyImportError( "Failed to open file " + pFile + ".");
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* // generate a XML reader for it
|
|
||||||
* std::unique_ptr<CIrrXML_IOStreamReader> mIOWrapper( new CIrrXML_IOStreamReader( file.get()));
|
|
||||||
* mReader = irr::io::createIrrXMLReader( mIOWrapper.get());
|
|
||||||
* if( !mReader) {
|
|
||||||
* ThrowException( "xxxx: Unable to open file.");
|
|
||||||
* }
|
|
||||||
* @endcode
|
|
||||||
**/
|
|
||||||
/*class CIrrXML_IOStreamReader : public irr::io::IFileReadCallBack {
|
|
||||||
public:
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
|
||||||
//! Construction from an existing IOStream
|
|
||||||
explicit CIrrXML_IOStreamReader(IOStream* _stream)
|
|
||||||
: stream (_stream)
|
|
||||||
, t (0)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Map the buffer into memory and convert it to UTF8. IrrXML provides its
|
|
||||||
// own conversion, which is merely a cast from uintNN_t to uint8_t. Thus,
|
|
||||||
// it is not suitable for our purposes and we have to do it BEFORE IrrXML
|
|
||||||
// gets the buffer. Sadly, this forces us to map the whole file into
|
|
||||||
// memory.
|
|
||||||
|
|
||||||
data.resize(stream->FileSize());
|
|
||||||
stream->Read(&data[0],data.size(),1);
|
|
||||||
|
|
||||||
// Remove null characters from the input sequence otherwise the parsing will utterly fail
|
|
||||||
// std::find is usually much faster than manually iterating
|
|
||||||
// It is very unlikely that there will be any null characters
|
|
||||||
auto null_char_iter = std::find(data.begin(), data.end(), '\0');
|
|
||||||
|
|
||||||
while (null_char_iter != data.end())
|
|
||||||
{
|
|
||||||
null_char_iter = data.erase(null_char_iter);
|
|
||||||
null_char_iter = std::find(null_char_iter, data.end(), '\0');
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseImporter::ConvertToUTF8(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
|
||||||
//! Virtual destructor
|
|
||||||
virtual ~CIrrXML_IOStreamReader() {}*/
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
|
||||||
//! Reads an amount of bytes from the file.
|
|
||||||
/** @param buffer: Pointer to output buffer.
|
|
||||||
* @param sizeToRead: Amount of bytes to read
|
|
||||||
* @return Returns how much bytes were read. */
|
|
||||||
/*virtual int read(void* buffer, int sizeToRead) {
|
|
||||||
if(sizeToRead<0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(t+sizeToRead>data.size()) {
|
|
||||||
sizeToRead = static_cast<int>(data.size()-t);
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(buffer,&data.front()+t,sizeToRead);
|
|
||||||
|
|
||||||
t += sizeToRead;
|
|
||||||
return sizeToRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
|
||||||
//! Returns size of file in bytes
|
|
||||||
virtual int getSize() {
|
|
||||||
return (int)data.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IOStream* stream;
|
|
||||||
std::vector<char> data;
|
|
||||||
size_t t;
|
|
||||||
|
|
||||||
}; // ! class CIrrXML_IOStreamReader
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct find_node_by_name_predicate {
|
struct find_node_by_name_predicate {
|
||||||
std::string mName;
|
std::string mName;
|
||||||
find_node_by_name_predicate(const std::string &name) :
|
find_node_by_name_predicate(const std::string &name) :
|
||||||
|
@ -153,6 +63,14 @@ struct find_node_by_name_predicate {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class TNodeType>
|
||||||
|
struct NodeConverter {
|
||||||
|
public:
|
||||||
|
static int to_int(TNodeType &node, const char *attribName ) {
|
||||||
|
ai_assert(nullptr != attribName);
|
||||||
|
return node.attribute(attribName).to_int();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<class TNodeType>
|
template<class TNodeType>
|
||||||
class TXmlParser {
|
class TXmlParser {
|
||||||
|
@ -177,6 +95,7 @@ public:
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nullptr == mDoc) {
|
if (nullptr == mDoc) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -187,6 +106,7 @@ public:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &node;
|
||||||
}
|
}
|
||||||
|
|
||||||
TNodeType *parse(IOStream *stream) {
|
TNodeType *parse(IOStream *stream) {
|
||||||
|
@ -220,6 +140,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
using XmlParser = TXmlParser<pugi::xml_node>;
|
using XmlParser = TXmlParser<pugi::xml_node>;
|
||||||
|
using XmlNode = pugi::xml_node;
|
||||||
|
|
||||||
} // namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue