Merge pull request #1338 from pdaehne/master

X3D importer: Support for binary X3D files
pull/1347/head^2
Kim Kulling 2017-07-15 11:08:08 +02:00 committed by GitHub
commit bd7fdfeeca
11 changed files with 3945 additions and 263 deletions

View File

@ -647,6 +647,9 @@ ADD_ASSIMP_IMPORTER(X3D
X3DImporter_Rendering.cpp
X3DImporter_Shape.cpp
X3DImporter_Texturing.cpp
FIReader.hpp
FIReader.cpp
X3DVocabulary.cpp
)
ADD_ASSIMP_IMPORTER( GLTF

1818
code/FIReader.cpp 100755

File diff suppressed because it is too large Load Diff

172
code/FIReader.hpp 100644
View File

@ -0,0 +1,172 @@
/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2017, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
/// \file FIReader.hpp
/// \brief Reader for Fast Infoset encoded binary XML files.
/// \date 2017
/// \author Patrick Daehne
#ifndef INCLUDED_AI_FI_READER_H
#define INCLUDED_AI_FI_READER_H
#include <irrXML.h>
#include <memory>
#include <string>
#include <vector>
#include <cstdint>
namespace Assimp {
struct FIValue {
virtual const std::string &toString() const = 0;
};
struct FIStringValue: public FIValue {
std::string value;
static std::shared_ptr<FIStringValue> create(std::string &&value);
};
struct FIByteValue: public FIValue {
std::vector<uint8_t> value;
};
struct FIHexValue: public FIByteValue {
static std::shared_ptr<FIHexValue> create(std::vector<uint8_t> &&value);
};
struct FIBase64Value: public FIByteValue {
static std::shared_ptr<FIBase64Value> create(std::vector<uint8_t> &&value);
};
struct FIShortValue: public FIValue {
std::vector<int16_t> value;
static std::shared_ptr<FIShortValue> create(std::vector<int16_t> &&value);
};
struct FIIntValue: public FIValue {
std::vector<int32_t> value;
static std::shared_ptr<FIIntValue> create(std::vector<int32_t> &&value);
};
struct FILongValue: public FIValue {
std::vector<int64_t> value;
static std::shared_ptr<FILongValue> create(std::vector<int64_t> &&value);
};
struct FIBoolValue: public FIValue {
std::vector<bool> value;
static std::shared_ptr<FIBoolValue> create(std::vector<bool> &&value);
};
struct FIFloatValue: public FIValue {
std::vector<float> value;
static std::shared_ptr<FIFloatValue> create(std::vector<float> &&value);
};
struct FIDoubleValue: public FIValue {
std::vector<double> value;
static std::shared_ptr<FIDoubleValue> create(std::vector<double> &&value);
};
struct FIUUIDValue: public FIByteValue {
static std::shared_ptr<FIUUIDValue> create(std::vector<uint8_t> &&value);
};
struct FICDATAValue: public FIStringValue {
static std::shared_ptr<FICDATAValue> create(std::string &&value);
};
struct FIDecoder {
virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) = 0;
};
struct FIQName {
const char *name;
const char *prefix;
const char *uri;
};
struct FIVocabulary {
const char **restrictedAlphabetTable;
size_t restrictedAlphabetTableSize;
const char **encodingAlgorithmTable;
size_t encodingAlgorithmTableSize;
const char **prefixTable;
size_t prefixTableSize;
const char **namespaceNameTable;
size_t namespaceNameTableSize;
const char **localNameTable;
size_t localNameTableSize;
const char **otherNCNameTable;
size_t otherNCNameTableSize;
const char **otherURITable;
size_t otherURITableSize;
const std::shared_ptr<const FIValue> *attributeValueTable;
size_t attributeValueTableSize;
const std::shared_ptr<const FIValue> *charactersTable;
size_t charactersTableSize;
const std::shared_ptr<const FIValue> *otherStringTable;
size_t otherStringTableSize;
const FIQName *elementNameTable;
size_t elementNameTableSize;
const FIQName *attributeNameTable;
size_t attributeNameTableSize;
};
class IOStream;
class FIReader: public irr::io::IIrrXMLReader<char, irr::io::IXMLBase> {
public:
virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(int idx) const = 0;
virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(const char *name) const = 0;
virtual void registerDecoder(const std::string &algorithmUri, std::unique_ptr<FIDecoder> decoder) = 0;
virtual void registerVocabulary(const std::string &vocabularyUri, const FIVocabulary *vocabulary) = 0;
static std::unique_ptr<FIReader> create(IOStream *stream);
};// class IFIReader
}// namespace Assimp
#endif // INCLUDED_AI_FI_READER_H

View File

@ -52,10 +52,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Header files, Assimp.
#include <assimp/DefaultIOSystem.h>
#include "fast_atof.h"
#include "FIReader.hpp"
// Header files, stdlib.
#include <memory>
#include <string>
#include <iterator>
namespace Assimp {
@ -66,15 +68,52 @@ const aiImporterDesc X3DImporter::Description = {
"smalcom",
"",
"See documentation in source code. Chapter: Limitations.",
aiImporterFlags_SupportTextFlavour | aiImporterFlags_LimitedSupport | aiImporterFlags_Experimental,
aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_LimitedSupport | aiImporterFlags_Experimental,
0,
0,
0,
0,
"x3d"
"x3d x3db"
};
const std::string X3DImporter::whitespace(" ,\t\n\r");
//const std::regex X3DImporter::pattern_nws(R"([^, \t\r\n]+)");
//const std::regex X3DImporter::pattern_true(R"(^\s*(?:true|1)\s*$)", std::regex::icase);
struct WordIterator: public std::iterator<std::input_iterator_tag, const char*> {
static const char *whitespace;
const char *start_, *end_;
WordIterator(const char *start, const char *end): start_(start), end_(end) {
start_ = start + strspn(start, whitespace);
if (start_ >= end_) {
start_ = 0;
}
}
WordIterator(): start_(0), end_(0) {}
WordIterator(const WordIterator &other): start_(other.start_), end_(other.end_) {}
WordIterator &operator=(const WordIterator &other) {
start_ = other.start_;
end_ = other.end_;
return *this;
}
bool operator==(WordIterator &other) const { return start_ == other.start_; }
bool operator!=(WordIterator &other) const { return start_ != other.start_; }
WordIterator &operator++() {
start_ += strcspn(start_, whitespace);
start_ += strspn(start_, whitespace);
if (start_ >= end_) {
start_ = 0;
}
return *this;
}
WordIterator operator++(int) {
WordIterator result(*this);
++(*this);
return result;
}
const char *operator*() const { return start_; }
};
const char *WordIterator::whitespace = ", \t\r\n";
X3DImporter::X3DImporter()
: NodeElement_Cur( nullptr )
@ -83,7 +122,6 @@ X3DImporter::X3DImporter()
}
X3DImporter::~X3DImporter() {
delete mReader;
// Clear() is accounting if data already is deleted. So, just check again if all data is deleted.
Clear();
}
@ -370,38 +408,65 @@ bool X3DImporter::XML_SearchNode(const std::string& pNodeName)
bool X3DImporter::XML_ReadNode_GetAttrVal_AsBool(const int pAttrIdx)
{
std::string val(mReader->getAttributeValue(pAttrIdx));
auto boolValue = std::dynamic_pointer_cast<const FIBoolValue>(mReader->getAttributeEncodedValue(pAttrIdx));
if (boolValue) {
if (boolValue->value.size() == 1) {
return boolValue->value.front();
}
throw DeadlyImportError("Invalid bool value");
}
else {
std::string val(mReader->getAttributeValue(pAttrIdx));
if(val == "false")
return false;
else if(val == "true")
return true;
else
throw DeadlyImportError("Bool attribute value can contain \"false\" or \"true\" not the \"" + val + "\"");
if(val == "false")
return false;
else if(val == "true")
return true;
else
throw DeadlyImportError("Bool attribute value can contain \"false\" or \"true\" not the \"" + val + "\"");
}
}
float X3DImporter::XML_ReadNode_GetAttrVal_AsFloat(const int pAttrIdx)
{
std::string val;
float tvalf;
auto floatValue = std::dynamic_pointer_cast<const FIFloatValue>(mReader->getAttributeEncodedValue(pAttrIdx));
if (floatValue) {
if (floatValue->value.size() == 1) {
return floatValue->value.front();
}
throw DeadlyImportError("Invalid float value");
}
else {
std::string val;
float tvalf;
ParseHelper_FixTruncatedFloatString(mReader->getAttributeValue(pAttrIdx), val);
fast_atoreal_move(val.c_str(), tvalf, false);
ParseHelper_FixTruncatedFloatString(mReader->getAttributeValue(pAttrIdx), val);
fast_atoreal_move(val.c_str(), tvalf, false);
return tvalf;
return tvalf;
}
}
int32_t X3DImporter::XML_ReadNode_GetAttrVal_AsI32(const int pAttrIdx)
{
return strtol10(mReader->getAttributeValue(pAttrIdx));
auto intValue = std::dynamic_pointer_cast<const FIIntValue>(mReader->getAttributeEncodedValue(pAttrIdx));
if (intValue) {
if (intValue->value.size() == 1) {
return intValue->value.front();
}
throw DeadlyImportError("Invalid int value");
}
else {
return strtol10(mReader->getAttributeValue(pAttrIdx));
}
}
void X3DImporter::XML_ReadNode_GetAttrVal_AsCol3f(const int pAttrIdx, aiColor3D& pValue)
{
std::list<float> tlist;
std::list<float>::iterator it;
std::vector<float> tlist;
std::vector<float>::iterator it;
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);
XML_ReadNode_GetAttrVal_AsArrF(pAttrIdx, tlist);
if(tlist.size() != 3) Throw_ConvertFail_Str2ArrF(mReader->getAttributeValue(pAttrIdx));
it = tlist.begin();
@ -412,10 +477,10 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsCol3f(const int pAttrIdx, aiColor3D&
void X3DImporter::XML_ReadNode_GetAttrVal_AsVec2f(const int pAttrIdx, aiVector2D& pValue)
{
std::list<float> tlist;
std::list<float>::iterator it;
std::vector<float> tlist;
std::vector<float>::iterator it;
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);
XML_ReadNode_GetAttrVal_AsArrF(pAttrIdx, tlist);
if(tlist.size() != 2) Throw_ConvertFail_Str2ArrF(mReader->getAttributeValue(pAttrIdx));
it = tlist.begin();
@ -425,10 +490,10 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsVec2f(const int pAttrIdx, aiVector2D
void X3DImporter::XML_ReadNode_GetAttrVal_AsVec3f(const int pAttrIdx, aiVector3D& pValue)
{
std::list<float> tlist;
std::list<float>::iterator it;
std::vector<float> tlist;
std::vector<float>::iterator it;
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);
XML_ReadNode_GetAttrVal_AsArrF(pAttrIdx, tlist);
if(tlist.size() != 3) Throw_ConvertFail_Str2ArrF(mReader->getAttributeValue(pAttrIdx));
it = tlist.begin();
@ -437,166 +502,95 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsVec3f(const int pAttrIdx, aiVector3D
pValue.z = *it;
}
void X3DImporter::XML_ReadNode_GetAttrVal_AsListB(const int pAttrIdx, std::list<bool>& pValue)
{
const char *tok_cur = mReader->getAttributeValue(pAttrIdx);
const char *tok_end = tok_cur + strlen(tok_cur);
for(;;)
{
while((tok_cur < tok_end) && (whitespace.find_first_of(*tok_cur) != std::string::npos)) tok_cur++;// skip spaces between values.
if (tok_cur >= tok_end)
break;
if(strncmp(tok_cur, "true", 4) == 0)
{
pValue.push_back(true);
tok_cur += 4;
}
else if(strncmp(tok_cur, "false", 5) == 0)
{
pValue.push_back(false);
tok_cur += 5;
}
else
{
Throw_IncorrectAttrValue(mReader->getAttributeName(pAttrIdx));
}
}// for(;;)
}
void X3DImporter::XML_ReadNode_GetAttrVal_AsArrB(const int pAttrIdx, std::vector<bool>& pValue)
{
std::list<bool> tlist;
auto boolValue = std::dynamic_pointer_cast<const FIBoolValue>(mReader->getAttributeEncodedValue(pAttrIdx));
if (boolValue) {
pValue = boolValue->value;
}
else {
const char *val = mReader->getAttributeValue(pAttrIdx);
pValue.clear();
XML_ReadNode_GetAttrVal_AsListB(pAttrIdx, tlist);// read as list
// and copy to array
if(tlist.size() > 0)
{
pValue.reserve(tlist.size());
for(std::list<bool>::iterator it = tlist.begin(); it != tlist.end(); it++) pValue.push_back(*it);
}
}
//std::cregex_iterator wordItBegin(val, val + strlen(val), pattern_nws);
//const std::cregex_iterator wordItEnd;
//std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const std::cmatch &match) { return std::regex_match(match.str(), pattern_true); });
void X3DImporter::XML_ReadNode_GetAttrVal_AsListI32(const int pAttrIdx, std::list<int32_t>& pValue)
{
const char* tstr = mReader->getAttributeValue(pAttrIdx);
const char* tstr_end = tstr + strlen(tstr);
do
{
const char* ostr;
int32_t tval32;
while((tstr < tstr_end) && (whitespace.find_first_of(*tstr) != std::string::npos)) tstr++;// skip spaces between values.
tval32 = strtol10(tstr, &ostr);
if(ostr == tstr) break;
tstr = ostr;
pValue.push_back(tval32);
} while(tstr < tstr_end);
WordIterator wordItBegin(val, val + strlen(val));
WordIterator wordItEnd;
std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const char *match) { return (::tolower(match[0]) == 't') || (match[0] == '1'); });
}
}
void X3DImporter::XML_ReadNode_GetAttrVal_AsArrI32(const int pAttrIdx, std::vector<int32_t>& pValue)
{
std::list<int32_t> tlist;
auto intValue = std::dynamic_pointer_cast<const FIIntValue>(mReader->getAttributeEncodedValue(pAttrIdx));
if (intValue) {
pValue = intValue->value;
}
else {
const char *val = mReader->getAttributeValue(pAttrIdx);
pValue.clear();
XML_ReadNode_GetAttrVal_AsListI32(pAttrIdx, tlist);// read as list
// and copy to array
if(tlist.size() > 0)
{
pValue.reserve(tlist.size());
for(std::list<int32_t>::iterator it = tlist.begin(); it != tlist.end(); it++) pValue.push_back(*it);
}
}
//std::cregex_iterator wordItBegin(val, val + strlen(val), pattern_nws);
//const std::cregex_iterator wordItEnd;
//std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const std::cmatch &match) { return std::stoi(match.str()); });
void X3DImporter::XML_ReadNode_GetAttrVal_AsListF(const int pAttrIdx, std::list<float>& pValue)
{
std::string str_fixed;
// at first check string values like '.xxx'.
ParseHelper_FixTruncatedFloatString(mReader->getAttributeValue(pAttrIdx), str_fixed);
// and convert all values and place it in list.
const char* pstr = str_fixed.c_str();
const char* pstr_end = pstr + str_fixed.size();
do
{
float tvalf;
while((pstr < pstr_end) && (whitespace.find_first_of(*pstr) != std::string::npos)) pstr++;// skip spaces between values.
if(pstr < pstr_end)// additional check, because attribute value can be ended with spaces.
{
pstr = fast_atoreal_move(pstr, tvalf, false);
pValue.push_back(tvalf);
}
} while(pstr < pstr_end);
WordIterator wordItBegin(val, val + strlen(val));
WordIterator wordItEnd;
std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const char *match) { return atoi(match); });
}
}
void X3DImporter::XML_ReadNode_GetAttrVal_AsArrF(const int pAttrIdx, std::vector<float>& pValue)
{
std::list<float> tlist;
auto floatValue = std::dynamic_pointer_cast<const FIFloatValue>(mReader->getAttributeEncodedValue(pAttrIdx));
if (floatValue) {
pValue = floatValue->value;
}
else {
const char *val = mReader->getAttributeValue(pAttrIdx);
pValue.clear();
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);// read as list
// and copy to array
if(tlist.size() > 0)
{
pValue.reserve(tlist.size());
for(std::list<float>::iterator it = tlist.begin(); it != tlist.end(); it++) pValue.push_back(*it);
}
}
//std::cregex_iterator wordItBegin(val, val + strlen(val), pattern_nws);
//const std::cregex_iterator wordItEnd;
//std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const std::cmatch &match) { return std::stof(match.str()); });
void X3DImporter::XML_ReadNode_GetAttrVal_AsListD(const int pAttrIdx, std::list<double>& pValue)
{
std::string str_fixed;
// at first check string values like '.xxx'.
ParseHelper_FixTruncatedFloatString(mReader->getAttributeValue(pAttrIdx), str_fixed);
// and convert all values and place it in list.
const char* pstr = str_fixed.c_str();
const char* pstr_end = pstr + str_fixed.size();
do
{
double tvald;
while((pstr < pstr_end) && (whitespace.find_first_of(*pstr) != std::string::npos)) pstr++;// skip spaces between values.
if(pstr < pstr_end)// additional check, because attribute value can be ended with spaces.
{
pstr = fast_atoreal_move(pstr, tvald, false);
pValue.push_back(tvald);
}
} while(pstr < pstr_end);
WordIterator wordItBegin(val, val + strlen(val));
WordIterator wordItEnd;
std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const char *match) { return atof(match); });
}
}
void X3DImporter::XML_ReadNode_GetAttrVal_AsArrD(const int pAttrIdx, std::vector<double>& pValue)
{
std::list<double> tlist;
auto doubleValue = std::dynamic_pointer_cast<const FIDoubleValue>(mReader->getAttributeEncodedValue(pAttrIdx));
if (doubleValue) {
pValue = doubleValue->value;
}
else {
const char *val = mReader->getAttributeValue(pAttrIdx);
pValue.clear();
XML_ReadNode_GetAttrVal_AsListD(pAttrIdx, tlist);// read as list
// and copy to array
if(tlist.size() > 0)
{
pValue.reserve(tlist.size());
for(std::list<double>::iterator it = tlist.begin(); it != tlist.end(); it++) pValue.push_back(*it);
}
//std::cregex_iterator wordItBegin(val, val + strlen(val), pattern_nws);
//const std::cregex_iterator wordItEnd;
//std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const std::cmatch &match) { return std::stod(match.str()); });
WordIterator wordItBegin(val, val + strlen(val));
WordIterator wordItEnd;
std::transform(wordItBegin, wordItEnd, std::back_inserter(pValue), [](const char *match) { return atof(match); });
}
}
void X3DImporter::XML_ReadNode_GetAttrVal_AsListCol3f(const int pAttrIdx, std::list<aiColor3D>& pValue)
{
std::list<float> tlist;
std::vector<float> tlist;
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);// read as list
XML_ReadNode_GetAttrVal_AsArrF(pAttrIdx, tlist);// read as list
if(tlist.size() % 3) Throw_ConvertFail_Str2ArrF(mReader->getAttributeValue(pAttrIdx));
// copy data to array
for(std::list<float>::iterator it = tlist.begin(); it != tlist.end();)
for(std::vector<float>::iterator it = tlist.begin(); it != tlist.end();)
{
aiColor3D tcol;
@ -622,13 +616,13 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsArrCol3f(const int pAttrIdx, std::ve
void X3DImporter::XML_ReadNode_GetAttrVal_AsListCol4f(const int pAttrIdx, std::list<aiColor4D>& pValue)
{
std::list<float> tlist;
std::vector<float> tlist;
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);// read as list
XML_ReadNode_GetAttrVal_AsArrF(pAttrIdx, tlist);// read as list
if(tlist.size() % 4) Throw_ConvertFail_Str2ArrF(mReader->getAttributeValue(pAttrIdx));
// copy data to array
for(std::list<float>::iterator it = tlist.begin(); it != tlist.end();)
for(std::vector<float>::iterator it = tlist.begin(); it != tlist.end();)
{
aiColor4D tcol;
@ -658,16 +652,16 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsArrCol4f(const int pAttrIdx, std::ve
void X3DImporter::XML_ReadNode_GetAttrVal_AsListVec2f(const int pAttrIdx, std::list<aiVector2D>& pValue)
{
std::list<float> tlist;
std::vector<float> tlist;
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);// read as list
XML_ReadNode_GetAttrVal_AsArrF(pAttrIdx, tlist);// read as list
if ( tlist.size() % 2 )
{
Throw_ConvertFail_Str2ArrF( mReader->getAttributeValue( pAttrIdx ) );
}
// copy data to array
for(std::list<float>::iterator it = tlist.begin(); it != tlist.end();)
for(std::vector<float>::iterator it = tlist.begin(); it != tlist.end();)
{
aiVector2D tvec;
@ -695,16 +689,16 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsArrVec2f(const int pAttrIdx, std::ve
void X3DImporter::XML_ReadNode_GetAttrVal_AsListVec3f(const int pAttrIdx, std::list<aiVector3D>& pValue)
{
std::list<float> tlist;
std::vector<float> tlist;
XML_ReadNode_GetAttrVal_AsListF(pAttrIdx, tlist);// read as list
XML_ReadNode_GetAttrVal_AsArrF(pAttrIdx, tlist);// read as list
if ( tlist.size() % 3 )
{
Throw_ConvertFail_Str2ArrF( mReader->getAttributeValue( pAttrIdx ) );
}
// copy data to array
for(std::list<float>::iterator it = tlist.begin(); it != tlist.end();)
for(std::vector<float>::iterator it = tlist.begin(); it != tlist.end();)
{
aiVector3D tvec;
@ -894,9 +888,9 @@ void X3DImporter::GeometryHelper_MakeQL_RectParallelepiped(const aiVector3D& pSi
#undef MESH_RectParallelepiped_CREATE_VERT
void X3DImporter::GeometryHelper_CoordIdxStr2FacesArr(const std::list<int32_t>& pCoordIdx, std::vector<aiFace>& pFaces, unsigned int& pPrimitiveTypes) const
void X3DImporter::GeometryHelper_CoordIdxStr2FacesArr(const std::vector<int32_t>& pCoordIdx, std::vector<aiFace>& pFaces, unsigned int& pPrimitiveTypes) const
{
std::list<int32_t> f_data(pCoordIdx);
std::vector<int32_t> f_data(pCoordIdx);
std::vector<unsigned int> inds;
unsigned int prim_type = 0;
@ -909,7 +903,7 @@ void X3DImporter::GeometryHelper_CoordIdxStr2FacesArr(const std::list<int32_t>&
pFaces.reserve(f_data.size() / 3);
inds.reserve(4);
//PrintVectorSet("build. ci", pCoordIdx);
for(std::list<int32_t>::iterator it = f_data.begin(); it != f_data.end(); it++)
for(std::vector<int32_t>::iterator it = f_data.begin(); it != f_data.end(); it++)
{
// when face is got count how many indices in it.
if(*it == (-1))
@ -1001,7 +995,7 @@ void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::list<aiColor4D
}// if(pColorPerVertex) else
}
void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pColorIdx,
void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pColorIdx,
const std::list<aiColor3D>& pColors, const bool pColorPerVertex) const
{
std::list<aiColor4D> tcol;
@ -1016,7 +1010,7 @@ void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>&
MeshGeometry_AddColor(pMesh, pCoordIdx, pColorIdx, tcol, pColorPerVertex);
}
void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pColorIdx,
void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pColorIdx,
const std::list<aiColor4D>& pColors, const bool pColorPerVertex) const
{
std::vector<aiColor4D> col_tgt_arr;
@ -1047,7 +1041,7 @@ void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>&
}
// create list with colors for every vertex.
col_tgt_arr.resize(pMesh.mNumVertices);
for(std::list<int32_t>::const_iterator colidx_it = pColorIdx.begin(), coordidx_it = pCoordIdx.begin(); colidx_it != pColorIdx.end(); colidx_it++, coordidx_it++)
for(std::vector<int32_t>::const_iterator colidx_it = pColorIdx.begin(), coordidx_it = pCoordIdx.begin(); colidx_it != pColorIdx.end(); colidx_it++, coordidx_it++)
{
if ( *colidx_it == ( -1 ) )
{
@ -1095,7 +1089,7 @@ void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>&
// create list with colors for every vertex using faces indices.
col_tgt_arr.resize(pMesh.mNumFaces);
std::list<int32_t>::const_iterator colidx_it = pColorIdx.begin();
std::vector<int32_t>::const_iterator colidx_it = pColorIdx.begin();
for(size_t fi = 0; fi < pMesh.mNumFaces; fi++)
{
if((unsigned int)*colidx_it > pMesh.mNumFaces) throw DeadlyImportError("MeshGeometry_AddColor2. Face idx is out of range.");
@ -1125,7 +1119,7 @@ void X3DImporter::MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>&
MeshGeometry_AddColor(pMesh, col_tgt_list, pColorPerVertex);
}
void X3DImporter::MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pNormalIdx,
void X3DImporter::MeshGeometry_AddNormal(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pNormalIdx,
const std::list<aiVector3D>& pNormals, const bool pNormalPerVertex) const
{
std::vector<size_t> tind;
@ -1146,7 +1140,7 @@ void X3DImporter::MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<int32_t>
if(pNormalIdx.size() != pCoordIdx.size()) throw DeadlyImportError("Normals and Coords inidces count must be equal.");
tind.reserve(pNormalIdx.size());
for(std::list<int32_t>::const_iterator it = pNormalIdx.begin(); it != pNormalIdx.end(); it++)
for(std::vector<int32_t>::const_iterator it = pNormalIdx.begin(); it != pNormalIdx.end(); it++)
{
if(*it != (-1)) tind.push_back(*it);
}
@ -1178,7 +1172,7 @@ void X3DImporter::MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<int32_t>
{
if(pMesh.mNumFaces != pNormalIdx.size()) throw DeadlyImportError("Normals faces count must be equal to mesh faces count.");
std::list<int32_t>::const_iterator normidx_it = pNormalIdx.begin();
std::vector<int32_t>::const_iterator normidx_it = pNormalIdx.begin();
tind.reserve(pNormalIdx.size());
for(size_t i = 0, i_e = pNormalIdx.size(); i < i_e; i++) tind.push_back(*normidx_it++);
@ -1231,7 +1225,7 @@ void X3DImporter::MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<aiVector
}// if(pNormalPerVertex) else
}
void X3DImporter::MeshGeometry_AddTexCoord(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pTexCoordIdx,
void X3DImporter::MeshGeometry_AddTexCoord(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pTexCoordIdx,
const std::list<aiVector2D>& pTexCoords) const
{
std::vector<aiVector3D> texcoord_arr_copy;
@ -1304,7 +1298,7 @@ void X3DImporter::MeshGeometry_AddTexCoord(aiMesh& pMesh, const std::list<aiVect
}
}
aiMesh* X3DImporter::GeometryHelper_MakeMesh(const std::list<int32_t>& pCoordIdx, const std::list<aiVector3D>& pVertices) const
aiMesh* X3DImporter::GeometryHelper_MakeMesh(const std::vector<int32_t>& pCoordIdx, const std::list<aiVector3D>& pVertices) const
{
std::vector<aiFace> faces;
unsigned int prim_type = 0;
@ -1407,9 +1401,12 @@ void X3DImporter::ParseHelper_FixTruncatedFloatString(const char* pInStr, std::s
}
}
extern FIVocabulary X3D_vocabulary_3_2;
extern FIVocabulary X3D_vocabulary_3_3;
void X3DImporter::ParseFile(const std::string& pFile, IOSystem* pIOHandler)
{
irr::io::IrrXMLReader* OldReader = mReader;// store current XMLreader.
std::unique_ptr<FIReader> OldReader = std::move(mReader);// store current XMLreader.
std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
// Check whether we can read from the file
@ -1417,19 +1414,18 @@ void X3DImporter::ParseFile(const std::string& pFile, IOSystem* pIOHandler)
{
throw DeadlyImportError( "Failed to open X3D 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());
mReader = FIReader::create(file.get());
if ( !mReader )
{
throw DeadlyImportError( "Failed to create XML reader for file" + pFile + "." );
}
mReader->registerVocabulary("urn:web3d:x3d:fi-vocabulary-3.2", &X3D_vocabulary_3_2);
mReader->registerVocabulary("urn:web3d:x3d:fi-vocabulary-3.3", &X3D_vocabulary_3_3);
// start reading
ParseNode_Root();
delete mReader;
// restore old XMLreader
mReader = OldReader;
mReader = std::move(OldReader);
}
void X3DImporter::ParseNode_Root()
@ -1643,7 +1639,7 @@ bool X3DImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool p
{
const std::string extension = GetExtension(pFile);
if(extension == "x3d") return true;
if((extension == "x3d") || (extension == "x3db")) return true;
if(!extension.length() || pCheckSig)
{
@ -1658,6 +1654,7 @@ bool X3DImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool p
void X3DImporter::GetExtensionList(std::set<std::string>& pExtensionList)
{
pExtensionList.insert("x3d");
pExtensionList.insert("x3db");
}
const aiImporterDesc* X3DImporter::GetInfo () const
@ -1670,8 +1667,10 @@ void X3DImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOSy
mpIOHandler = pIOHandler;
Clear();// delete old graph.
pIOHandler->PushDirectory(DefaultIOSystem::absolutePath(pFile));
std::string::size_type slashPos = pFile.find_last_of("\\/");
pIOHandler->PushDirectory(slashPos == std::string::npos ? std::string() : pFile.substr(0, slashPos + 1));
ParseFile(pFile, pIOHandler);
pIOHandler->PopDirectory();
//
// Assimp use static arrays of objects for fast speed of rendering. That's good, but need some additional operations/
// We know that geometry objects(meshes) are stored in <Shape>, also in <Shape>-><Appearance> materials(in Assimp logical view)

View File

@ -56,6 +56,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/types.h>
#include "BaseImporter.h"
#include "irrXMLWrapper.h"
#include "FIReader.hpp"
//#include <regex>
namespace Assimp {
@ -449,33 +451,21 @@ private:
/// Read attribute value.
/// \param [in] pAttrIdx - attribute index (\ref mReader->getAttribute* set).
/// \param [out] pValue - read data.
void XML_ReadNode_GetAttrVal_AsListB(const int pAttrIdx, std::list<bool>& pValue);
/// \overload void XML_ReadNode_GetAttrVal_AsListBool(const int pAttrIdx, std::list<bool>& pValue)
void XML_ReadNode_GetAttrVal_AsArrB(const int pAttrIdx, std::vector<bool>& pValue);
/// Read attribute value.
/// \param [in] pAttrIdx - attribute index (\ref mReader->getAttribute* set).
/// \param [out] pValue - read data.
void XML_ReadNode_GetAttrVal_AsListI32(const int pAttrIdx, std::list<int32_t>& pValue);
/// \overload void XML_ReadNode_GetAttrVal_AsListI32(const int pAttrIdx, std::list<int32_t>& pValue)
void XML_ReadNode_GetAttrVal_AsArrI32(const int pAttrIdx, std::vector<int32_t>& pValue);
/// Read attribute value.
/// \param [in] pAttrIdx - attribute index (\ref mReader->getAttribute* set).
/// \param [out] pValue - read data.
void XML_ReadNode_GetAttrVal_AsListF(const int pAttrIdx, std::list<float>& pValue);
/// \overload void XML_ReadNode_GetAttrVal_AsListF(const int pAttrIdx, std::list<float>& pValue)
void XML_ReadNode_GetAttrVal_AsArrF(const int pAttrIdx, std::vector<float>& pValue);
/// Read attribute value.
/// \param [in] pAttrIdx - attribute index (\ref mReader->getAttribute* set).
/// \param [out] pValue - read data.
void XML_ReadNode_GetAttrVal_AsListD(const int pAttrIdx, std::list<double>& pValue);
/// \overload void XML_ReadNode_GetAttrVal_AsListD(const int pAttrIdx, std::list<double>& pValue)
void XML_ReadNode_GetAttrVal_AsArrD(const int pAttrIdx, std::vector<double>& pValue);
/// Read attribute value.
@ -554,7 +544,7 @@ private:
/// \param [in] pCoordIdx - vertices indices divided by delimiter "-1".
/// \param [in] pFaces - created faces array.
/// \param [in] pPrimitiveTypes - type of primitives in faces.
void GeometryHelper_CoordIdxStr2FacesArr(const std::list<int32_t>& pCoordIdx, std::vector<aiFace>& pFaces, unsigned int& pPrimitiveTypes) const;
void GeometryHelper_CoordIdxStr2FacesArr(const std::vector<int32_t>& pCoordIdx, std::vector<aiFace>& pFaces, unsigned int& pPrimitiveTypes) const;
/// Add colors to mesh.
/// a. If colorPerVertex is FALSE, colours are applied to each face, as follows:
@ -573,11 +563,11 @@ private:
/// then pColorIdx contain color indices for every faces and must not contain delimiter "-1".
/// \param [in] pColors - defined colors.
/// \param [in] pColorPerVertex - if \ref pColorPerVertex is true then color in \ref pColors defined for every vertex, if false - for every face.
void MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pColorIdx,
void MeshGeometry_AddColor(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pColorIdx,
const std::list<aiColor4D>& pColors, const bool pColorPerVertex) const;
/// \overload void MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pColorIdx, const std::list<aiColor4D>& pColors, const bool pColorPerVertex) const;
void MeshGeometry_AddColor(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pColorIdx,
void MeshGeometry_AddColor(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pColorIdx,
const std::list<aiColor3D>& pColors, const bool pColorPerVertex) const;
/// Add colors to mesh.
@ -590,14 +580,14 @@ private:
void MeshGeometry_AddColor(aiMesh& pMesh, const std::list<aiColor3D>& pColors, const bool pColorPerVertex) const;
/// Add normals to mesh. Function work similar to \ref MeshGeometry_AddColor;
void MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pNormalIdx,
void MeshGeometry_AddNormal(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pNormalIdx,
const std::list<aiVector3D>& pNormals, const bool pNormalPerVertex) const;
/// Add normals to mesh. Function work similar to \ref MeshGeometry_AddColor;
void MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<aiVector3D>& pNormals, const bool pNormalPerVertex) const;
/// Add texture coordinates to mesh. Function work similar to \ref MeshGeometry_AddColor;
void MeshGeometry_AddTexCoord(aiMesh& pMesh, const std::list<int32_t>& pCoordIdx, const std::list<int32_t>& pTexCoordIdx,
void MeshGeometry_AddTexCoord(aiMesh& pMesh, const std::vector<int32_t>& pCoordIdx, const std::vector<int32_t>& pTexCoordIdx,
const std::list<aiVector2D>& pTexCoords) const;
/// Add texture coordinates to mesh. Function work similar to \ref MeshGeometry_AddColor;
@ -607,7 +597,7 @@ private:
/// \param [in] pCoordIdx - vertices indices divided by delimiter "-1".
/// \param [in] pVertices - vertices of mesh.
/// \return created mesh.
aiMesh* GeometryHelper_MakeMesh(const std::list<int32_t>& pCoordIdx, const std::list<aiVector3D>& pVertices) const;
aiMesh* GeometryHelper_MakeMesh(const std::vector<int32_t>& pCoordIdx, const std::list<aiVector3D>& pVertices) const;
/***********************************************/
/******** Functions: parse set private *********/
@ -826,13 +816,15 @@ private:
/****************** Constants ******************/
/***********************************************/
static const aiImporterDesc Description;
static const std::string whitespace;
//static const std::regex pattern_nws;
//static const std::regex pattern_true;
/***********************************************/
/****************** Variables ******************/
/***********************************************/
CX3DImporter_NodeElement* NodeElement_Cur;///< Current element.
irr::io::IrrXMLReader* mReader;///< Pointer to XML-reader object
std::unique_ptr<FIReader> mReader;///< Pointer to XML-reader object
IOSystem *mpIOHandler;
};// class X3DImporter

View File

@ -285,7 +285,7 @@ void X3DImporter::ParseNode_Geometry3D_ElevationGrid()
bool ccw = true;
bool colorPerVertex = true;
float creaseAngle = 0;
std::list<float> height;
std::vector<float> height;
bool normalPerVertex = true;
bool solid = true;
int32_t xDimension = 0;
@ -301,7 +301,7 @@ void X3DImporter::ParseNode_Geometry3D_ElevationGrid()
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("normalPerVertex", normalPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("creaseAngle", creaseAngle, XML_ReadNode_GetAttrVal_AsFloat);
MACRO_ATTRREAD_CHECK_REF("height", height, XML_ReadNode_GetAttrVal_AsListF);
MACRO_ATTRREAD_CHECK_REF("height", height, XML_ReadNode_GetAttrVal_AsArrF);
MACRO_ATTRREAD_CHECK_RET("xDimension", xDimension, XML_ReadNode_GetAttrVal_AsI32);
MACRO_ATTRREAD_CHECK_RET("xSpacing", xSpacing, XML_ReadNode_GetAttrVal_AsFloat);
MACRO_ATTRREAD_CHECK_RET("zDimension", zDimension, XML_ReadNode_GetAttrVal_AsI32);
@ -326,7 +326,7 @@ void X3DImporter::ParseNode_Geometry3D_ElevationGrid()
CX3DImporter_NodeElement_ElevationGrid& grid_alias = *((CX3DImporter_NodeElement_ElevationGrid*)ne);// create alias for conveience
{// create grid vertices list
std::list<float>::const_iterator he_it = height.begin();
std::vector<float>::const_iterator he_it = height.begin();
for(int32_t zi = 0; zi < zDimension; zi++)// rows
{
@ -863,29 +863,29 @@ void X3DImporter::ParseNode_Geometry3D_IndexedFaceSet()
{
std::string use, def;
bool ccw = true;
std::list<int32_t> colorIndex;
std::vector<int32_t> colorIndex;
bool colorPerVertex = true;
bool convex = true;
std::list<int32_t> coordIndex;
std::vector<int32_t> coordIndex;
float creaseAngle = 0;
std::list<int32_t> normalIndex;
std::vector<int32_t> normalIndex;
bool normalPerVertex = true;
bool solid = true;
std::list<int32_t> texCoordIndex;
std::vector<int32_t> texCoordIndex;
CX3DImporter_NodeElement* ne( nullptr );
MACRO_ATTRREAD_LOOPBEG;
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("ccw", ccw, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("colorIndex", colorIndex, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("colorIndex", colorIndex, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("convex", convex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("coordIndex", coordIndex, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("coordIndex", coordIndex, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("creaseAngle", creaseAngle, XML_ReadNode_GetAttrVal_AsFloat);
MACRO_ATTRREAD_CHECK_REF("normalIndex", normalIndex, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("normalIndex", normalIndex, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("normalPerVertex", normalPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("solid", solid, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("texCoordIndex", texCoordIndex, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("texCoordIndex", texCoordIndex, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_LOOPEND;
// if "USE" defined then find already defined element.

View File

@ -123,14 +123,14 @@ void X3DImporter::ParseNode_MetadataBoolean()
{
std::string def, use;
std::string name, reference;
std::list<bool> value;
std::vector<bool> value;
CX3DImporter_NodeElement* ne( nullptr );
MACRO_ATTRREAD_LOOPBEG;
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("name", name, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_RET("reference", reference, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsListB);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsArrB);
MACRO_ATTRREAD_LOOPEND;
MACRO_METADATA_FINDCREATE(def, use, reference, value, ne, CX3DImporter_NodeElement_MetaBoolean, "MetadataBoolean", ENET_MetaBoolean);
@ -147,14 +147,14 @@ void X3DImporter::ParseNode_MetadataDouble()
{
std::string def, use;
std::string name, reference;
std::list<double> value;
std::vector<double> value;
CX3DImporter_NodeElement* ne( nullptr );
MACRO_ATTRREAD_LOOPBEG;
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("name", name, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_RET("reference", reference, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsListD);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsArrD);
MACRO_ATTRREAD_LOOPEND;
MACRO_METADATA_FINDCREATE(def, use, reference, value, ne, CX3DImporter_NodeElement_MetaDouble, "MetadataDouble", ENET_MetaDouble);
@ -171,14 +171,14 @@ void X3DImporter::ParseNode_MetadataFloat()
{
std::string def, use;
std::string name, reference;
std::list<float> value;
std::vector<float> value;
CX3DImporter_NodeElement* ne( nullptr );
MACRO_ATTRREAD_LOOPBEG;
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("name", name, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_RET("reference", reference, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsListF);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsArrF);
MACRO_ATTRREAD_LOOPEND;
MACRO_METADATA_FINDCREATE(def, use, reference, value, ne, CX3DImporter_NodeElement_MetaFloat, "MetadataFloat", ENET_MetaFloat);
@ -195,14 +195,14 @@ void X3DImporter::ParseNode_MetadataInteger()
{
std::string def, use;
std::string name, reference;
std::list<int32_t> value;
std::vector<int32_t> value;
CX3DImporter_NodeElement* ne( nullptr );
MACRO_ATTRREAD_LOOPBEG;
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("name", name, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_RET("reference", reference, mReader->getAttributeValue);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("value", value, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_LOOPEND;
MACRO_METADATA_FINDCREATE(def, use, reference, value, ne, CX3DImporter_NodeElement_MetaInteger, "MetadataInteger", ENET_MetaInteger);

View File

@ -51,9 +51,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Header files, Assimp.
#include <assimp/DefaultIOSystem.h>
//#include <regex>
namespace Assimp
{
//static std::regex pattern_parentDir(R"((^|/)[^/]+/../)");
static std::string parentDir("/../");
// <Inline
// DEF="" ID
// USE="" IDREF
@ -89,11 +94,28 @@ void X3DImporter::ParseNode_Networking_Inline()
if(load && (url.size() > 0))
{
std::string full_path;
std::string full_path = mpIOHandler->CurrentDirectory() + url.front();
full_path = mpIOHandler->CurrentDirectory() + "/" + url.front();
//full_path = std::regex_replace(full_path, pattern_parentDir, "$1");
for (std::string::size_type pos = full_path.find(parentDir); pos != std::string::npos; pos = full_path.find(parentDir, pos)) {
if (pos > 0) {
std::string::size_type pos2 = full_path.rfind('/', pos - 1);
if (pos2 != std::string::npos) {
full_path.erase(pos2, pos - pos2 + 3);
pos = pos2;
}
else {
full_path.erase(0, pos + 4);
pos = 0;
}
}
else {
pos += 3;
}
}
// Attribute "url" can contain list of strings. But we need only one - first.
mpIOHandler->PushDirectory(DefaultIOSystem::absolutePath(full_path));
std::string::size_type slashPos = full_path.find_last_of("\\/");
mpIOHandler->PushDirectory(slashPos == std::string::npos ? std::string() : full_path.substr(0, slashPos + 1));
ParseFile(full_path, mpIOHandler);
mpIOHandler->PopDirectory();
}

View File

@ -52,6 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Header files, stdlib.
#include <list>
#include <vector>
#include <string>
/// \class CX3DImporter_NodeElement
@ -264,7 +265,7 @@ public:
/// This struct describe metavalue of type boolean.
struct CX3DImporter_NodeElement_MetaBoolean : public CX3DImporter_NodeElement_Meta
{
std::list<bool> Value;///< Stored value.
std::vector<bool> Value;///< Stored value.
/// \fn CX3DImporter_NodeElement_MetaBoolean(CX3DImporter_NodeElement* pParent)
/// Constructor
@ -279,7 +280,7 @@ struct CX3DImporter_NodeElement_MetaBoolean : public CX3DImporter_NodeElement_Me
/// This struct describe metavalue of type double.
struct CX3DImporter_NodeElement_MetaDouble : public CX3DImporter_NodeElement_Meta
{
std::list<double> Value;///< Stored value.
std::vector<double> Value;///< Stored value.
/// \fn CX3DImporter_NodeElement_MetaDouble(CX3DImporter_NodeElement* pParent)
/// Constructor
@ -294,7 +295,7 @@ struct CX3DImporter_NodeElement_MetaDouble : public CX3DImporter_NodeElement_Met
/// This struct describe metavalue of type float.
struct CX3DImporter_NodeElement_MetaFloat : public CX3DImporter_NodeElement_Meta
{
std::list<float> Value;///< Stored value.
std::vector<float> Value;///< Stored value.
/// \fn CX3DImporter_NodeElement_MetaFloat(CX3DImporter_NodeElement* pParent)
/// Constructor
@ -309,7 +310,7 @@ struct CX3DImporter_NodeElement_MetaFloat : public CX3DImporter_NodeElement_Meta
/// This struct describe metavalue of type integer.
struct CX3DImporter_NodeElement_MetaInteger : public CX3DImporter_NodeElement_Meta
{
std::list<int32_t> Value;///< Stored value.
std::vector<int32_t> Value;///< Stored value.
/// \fn CX3DImporter_NodeElement_MetaInteger(CX3DImporter_NodeElement* pParent)
/// Constructor
@ -508,7 +509,7 @@ public:
/// If the angle between the geometric normals of two adjacent faces is less than the crease angle, normals shall be calculated so that the faces are
/// shaded smoothly across the edge; otherwise, normals shall be calculated so that a lighting discontinuity across the edge is produced.
float CreaseAngle;
std::list<int32_t> CoordIdx;///< Coordinates list by faces. In X3D format: "-1" - delimiter for faces.
std::vector<int32_t> CoordIdx;///< Coordinates list by faces. In X3D format: "-1" - delimiter for faces.
/***********************************************/
/****************** Functions ******************/
@ -554,21 +555,21 @@ public:
/// direction. If normals are not generated but are supplied using a Normal node, and the orientation of the normals does not match the setting of the
/// ccw field, results are undefined.
bool CCW;
std::list<int32_t> ColorIndex;///< Field to specify the polygonal faces by indexing into the <Color> or <ColorRGBA>.
std::vector<int32_t> ColorIndex;///< Field to specify the polygonal faces by indexing into the <Color> or <ColorRGBA>.
bool ColorPerVertex;///< If true then colors are defined for every vertex, else for every face(line).
/// \var Convex
/// The convex field indicates whether all polygons in the shape are convex (TRUE). A polygon is convex if it is planar, does not intersect itself,
/// and all of the interior angles at its vertices are less than 180 degrees. Non planar and self intersecting polygons may produce undefined results
/// even if the convex field is FALSE.
bool Convex;
std::list<int32_t> CoordIndex;///< Field to specify the polygonal faces by indexing into the <Coordinate>.
std::vector<int32_t> CoordIndex;///< Field to specify the polygonal faces by indexing into the <Coordinate>.
/// \var CreaseAngle
/// If the angle between the geometric normals of two adjacent faces is less than the crease angle, normals shall be calculated so that the faces are
/// shaded smoothly across the edge; otherwise, normals shall be calculated so that a lighting discontinuity across the edge is produced.
float CreaseAngle;
std::list<int32_t> NormalIndex;///< Field to specify the polygonal faces by indexing into the <Normal>.
std::vector<int32_t> NormalIndex;///< Field to specify the polygonal faces by indexing into the <Normal>.
bool NormalPerVertex;///< If true then normals are defined for every vertex, else for every face(line).
std::list<int32_t> TexCoordIndex;///< Field to specify the polygonal faces by indexing into the <TextureCoordinate>.
std::vector<int32_t> TexCoordIndex;///< Field to specify the polygonal faces by indexing into the <TextureCoordinate>.
/***********************************************/
/****************** Functions ******************/
@ -616,10 +617,10 @@ public:
bool CCW;
bool ColorPerVertex;///< If true then colors are defined for every vertex, else for every face(line).
bool NormalPerVertex;///< If true then normals are defined for every vertex, else for every face(line).
std::list<int32_t> CoordIndex;///< Field to specify the polygonal faces by indexing into the <Coordinate>.
std::list<int32_t> NormalIndex;///< Field to specify the polygonal faces by indexing into the <Normal>.
std::list<int32_t> TexCoordIndex;///< Field to specify the polygonal faces by indexing into the <TextureCoordinate>.
std::list<int32_t> VertexCount;///< Field describes how many vertices are to be used in each polyline(polygon) from the <Coordinate> field.
std::vector<int32_t> CoordIndex;///< Field to specify the polygonal faces by indexing into the <Coordinate>.
std::vector<int32_t> NormalIndex;///< Field to specify the polygonal faces by indexing into the <Normal>.
std::vector<int32_t> TexCoordIndex;///< Field to specify the polygonal faces by indexing into the <TextureCoordinate>.
std::vector<int32_t> VertexCount;///< Field describes how many vertices are to be used in each polyline(polygon) from the <Coordinate> field.
/***********************************************/
/****************** Functions ******************/

View File

@ -180,16 +180,16 @@ void X3DImporter::ParseNode_Rendering_Coordinate()
void X3DImporter::ParseNode_Rendering_IndexedLineSet()
{
std::string use, def;
std::list<int32_t> colorIndex;
std::vector<int32_t> colorIndex;
bool colorPerVertex = true;
std::list<int32_t> coordIndex;
std::vector<int32_t> coordIndex;
CX3DImporter_NodeElement* ne( nullptr );
MACRO_ATTRREAD_LOOPBEG;
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_REF("colorIndex", colorIndex, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("colorIndex", colorIndex, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("coordIndex", coordIndex, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("coordIndex", coordIndex, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_LOOPEND;
// if "USE" defined then find already defined element.
@ -256,7 +256,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleFanSet()
std::string use, def;
bool ccw = true;
bool colorPerVertex = true;
std::list<int32_t> index;
std::vector<int32_t> index;
bool normalPerVertex = true;
bool solid = true;
CX3DImporter_NodeElement* ne( nullptr );
@ -265,7 +265,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleFanSet()
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("ccw", ccw, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("index", index, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("index", index, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("normalPerVertex", normalPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("solid", solid, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_LOOPEND;
@ -294,7 +294,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleFanSet()
ne_alias.CoordIndex.clear();
int counter = 0;
int32_t idx[3];
for(std::list<int32_t>::const_iterator idx_it = index.begin(); idx_it != index.end(); idx_it++)
for(std::vector<int32_t>::const_iterator idx_it = index.begin(); idx_it != index.end(); idx_it++)
{
idx[2] = *idx_it;
if (idx[2] < 0)
@ -374,7 +374,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleSet()
std::string use, def;
bool ccw = true;
bool colorPerVertex = true;
std::list<int32_t> index;
std::vector<int32_t> index;
bool normalPerVertex = true;
bool solid = true;
CX3DImporter_NodeElement* ne( nullptr );
@ -383,7 +383,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleSet()
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("ccw", ccw, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("index", index, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("index", index, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("normalPerVertex", normalPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("solid", solid, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_LOOPEND;
@ -412,7 +412,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleSet()
ne_alias.CoordIndex.clear();
int counter = 0;
int32_t idx[3];
for(std::list<int32_t>::const_iterator idx_it = index.begin(); idx_it != index.end(); idx_it++)
for(std::vector<int32_t>::const_iterator idx_it = index.begin(); idx_it != index.end(); idx_it++)
{
idx[counter++] = *idx_it;
if (counter > 2)
@ -480,7 +480,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleStripSet()
std::string use, def;
bool ccw = true;
bool colorPerVertex = true;
std::list<int32_t> index;
std::vector<int32_t> index;
bool normalPerVertex = true;
bool solid = true;
CX3DImporter_NodeElement* ne( nullptr );
@ -489,7 +489,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleStripSet()
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("ccw", ccw, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("index", index, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("index", index, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("normalPerVertex", normalPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("solid", solid, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_LOOPEND;
@ -518,7 +518,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleStripSet()
ne_alias.CoordIndex.clear();
int counter = 0;
int32_t idx[3];
for(std::list<int32_t>::const_iterator idx_it = index.begin(); idx_it != index.end(); idx_it++)
for(std::vector<int32_t>::const_iterator idx_it = index.begin(); idx_it != index.end(); idx_it++)
{
idx[2] = *idx_it;
if (idx[2] < 0)
@ -587,12 +587,12 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleStripSet()
void X3DImporter::ParseNode_Rendering_LineSet()
{
std::string use, def;
std::list<int32_t> vertexCount;
std::vector<int32_t> vertexCount;
CX3DImporter_NodeElement* ne( nullptr );
MACRO_ATTRREAD_LOOPBEG;
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_REF("vertexCount", vertexCount, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("vertexCount", vertexCount, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_LOOPEND;
// if "USE" defined then find already defined element.
@ -616,7 +616,7 @@ void X3DImporter::ParseNode_Rendering_LineSet()
size_t coord_num = 0;
ne_alias.CoordIndex.clear();
for(std::list<int32_t>::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); vc_it++)
for(std::vector<int32_t>::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); vc_it++)
{
if(*vc_it < 2) throw DeadlyImportError("LineSet. vertexCount shall be greater than or equal to two.");
@ -722,7 +722,7 @@ void X3DImporter::ParseNode_Rendering_TriangleFanSet()
std::string use, def;
bool ccw = true;
bool colorPerVertex = true;
std::list<int32_t> fanCount;
std::vector<int32_t> fanCount;
bool normalPerVertex = true;
bool solid = true;
CX3DImporter_NodeElement* ne( nullptr );
@ -731,7 +731,7 @@ void X3DImporter::ParseNode_Rendering_TriangleFanSet()
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("ccw", ccw, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("fanCount", fanCount, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("fanCount", fanCount, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("normalPerVertex", normalPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("solid", solid, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_LOOPEND;
@ -764,7 +764,7 @@ void X3DImporter::ParseNode_Rendering_TriangleFanSet()
// assign indices for first triangle
coord_num_first = 0;
coord_num_prev = 1;
for(std::list<int32_t>::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); vc_it++)
for(std::vector<int32_t>::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); vc_it++)
{
if(*vc_it < 3) throw DeadlyImportError("TriangleFanSet. fanCount shall be greater than or equal to three.");
@ -913,7 +913,7 @@ void X3DImporter::ParseNode_Rendering_TriangleStripSet()
std::string use, def;
bool ccw = true;
bool colorPerVertex = true;
std::list<int32_t> stripCount;
std::vector<int32_t> stripCount;
bool normalPerVertex = true;
bool solid = true;
CX3DImporter_NodeElement* ne( nullptr );
@ -922,7 +922,7 @@ void X3DImporter::ParseNode_Rendering_TriangleStripSet()
MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
MACRO_ATTRREAD_CHECK_RET("ccw", ccw, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("colorPerVertex", colorPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_REF("stripCount", stripCount, XML_ReadNode_GetAttrVal_AsListI32);
MACRO_ATTRREAD_CHECK_REF("stripCount", stripCount, XML_ReadNode_GetAttrVal_AsArrI32);
MACRO_ATTRREAD_CHECK_RET("normalPerVertex", normalPerVertex, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_CHECK_RET("solid", solid, XML_ReadNode_GetAttrVal_AsBool);
MACRO_ATTRREAD_LOOPEND;
@ -955,7 +955,7 @@ void X3DImporter::ParseNode_Rendering_TriangleStripSet()
ne_alias.CoordIndex.clear();
coord_num_sb = 0;
for(std::list<int32_t>::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); vc_it++)
for(std::vector<int32_t>::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); vc_it++)
{
if(*vc_it < 3) throw DeadlyImportError("TriangleStripSet. stripCount shall be greater than or equal to three.");

File diff suppressed because it is too large Load Diff