XGL: next steps.

pull/2966/head
kimkulling 2020-09-10 17:31:30 +02:00
parent cca9eddb1c
commit 6ec07e4dc7
4 changed files with 55 additions and 51 deletions

View File

@ -503,11 +503,10 @@ void AMFImporter::ParseNode_Object(XmlNode &node) {
// "Tolerance" - specifies the desired manufacturing tolerance of the entity in entity's unit system // "Tolerance" - specifies the desired manufacturing tolerance of the entity in entity's unit system
// "Volume" - specifies the total volume of the entity, in the entity's unit system, to be used for verification (object and volume only) // "Volume" - specifies the total volume of the entity, in the entity's unit system, to be used for verification (object and volume only)
void AMFImporter::ParseNode_Metadata(XmlNode &node) { void AMFImporter::ParseNode_Metadata(XmlNode &node) {
std::string type, value; AMFNodeElementBase *ne = nullptr;
AMFNodeElementBase *ne(nullptr);
type = node.attribute("type").as_string(); std::string type = node.attribute("type").as_string(), value;
value = node.value(); XmlParser::getValueAsString(node, value);
// read attribute // read attribute
ne = new AMFMetadata(mNodeElement_Cur); ne = new AMFMetadata(mNodeElement_Cur);

View File

@ -56,8 +56,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <memory> #include <memory>
using namespace Assimp; using namespace Assimp;
//using namespace irr;
//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
@ -133,8 +131,7 @@ const aiImporterDesc *XGLImporter::GetInfo() const {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// 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
@ -207,8 +204,9 @@ void XGLImporter::InternReadFile(const std::string &pFile,
XmlNode root = mXmlParser->getRootNode(); XmlNode root = mXmlParser->getRootNode();
TempScope scope; TempScope scope;
if (!ASSIMP_stricmp(root.name(), "world")) { XmlNode *worldNode = mXmlParser->findNode("WORLD");
ReadWorld(scope); if (nullptr != worldNode) {
ReadWorld(*worldNode, scope);
} }
std::vector<aiMesh *> &meshes = scope.meshes_linear; std::vector<aiMesh *> &meshes = scope.meshes_linear;
@ -239,20 +237,20 @@ void XGLImporter::InternReadFile(const std::string &pFile,
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void XGLImporter::ReadWorld(TempScope &scope) { void XGLImporter::ReadWorld(XmlNode &node, TempScope &scope) {
XmlNode root = mXmlParser->getRootNode(); for (XmlNode &currentNode : node.children()) {
for (XmlNode &node : root.children()) { const std::string &s = ai_stdStrToLower(currentNode.name());
const std::string &s = node.name();
// 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(node, scope); ReadLighting(currentNode, 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); aiNode *const nd = ReadObject(node, scope, true);
if (!nd) { if (!nd) {
ThrowException("failure reading <world>"); ThrowException("failure reading <world>");
} }
@ -265,7 +263,7 @@ void XGLImporter::ReadWorld(TempScope &scope) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void XGLImporter::ReadLighting(XmlNode &node, TempScope &scope) { void XGLImporter::ReadLighting(XmlNode &node, TempScope &scope) {
const std::string &s = node.name(); const std::string &s = ai_stdStrToLower(node.name());
if (s == "directionallight") { if (s == "directionallight") {
scope.light = ReadDirectionalLight(node); scope.light = ReadDirectionalLight(node);
} else if (s == "ambient") { } else if (s == "ambient") {
@ -285,7 +283,7 @@ aiLight *XGLImporter::ReadDirectionalLight(XmlNode &node) {
return nullptr; return nullptr;
} }
const std::string &s = child.name(); const std::string &s = ai_stdStrToLower(child.name());
if (s == "direction") { if (s == "direction") {
l->mDirection = ReadVec3(child); l->mDirection = ReadVec3(child);
} else if (s == "diffuse") { } else if (s == "diffuse") {
@ -308,7 +306,7 @@ aiNode *XGLImporter::ReadObject(XmlNode &node, TempScope &scope, bool skipFirst/
skipFirst = false; skipFirst = false;
const std::string &s = child.name(); const std::string &s = ai_stdStrToLower(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(child, scope)) { if (ReadMesh(child, scope)) {
@ -389,13 +387,13 @@ aiMatrix4x4 XGLImporter::ReadTrafo(XmlNode &node) {
float scale = 1.0f; float scale = 1.0f;
aiMatrix4x4 m; aiMatrix4x4 m;
XmlNode child = node.child("transform"); XmlNode child = node.child("TRANSFORM");
if (child.empty()) { if (child.empty()) {
return m; return m;
} }
for (XmlNode &sub_child : child.children()) { for (XmlNode &sub_child : child.children()) {
const std::string &s = sub_child.name(); const std::string &s = ai_stdStrToLower(sub_child.name());
if (s == "forward") { if (s == "forward") {
forward = ReadVec3(sub_child); forward = ReadVec3(sub_child);
} else if (s == "up") { } else if (s == "up") {
@ -502,7 +500,7 @@ bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope) {
const unsigned int mesh_id = ReadIDAttr(node); const unsigned int mesh_id = ReadIDAttr(node);
for (XmlNode &child : node.children()) { for (XmlNode &child : node.children()) {
const std::string &s = child.name(); const std::string &s = ai_stdStrToLower(child.name());
if (s == "mat") { if (s == "mat") {
ReadMaterial(child, scope); ReadMaterial(child, scope);
@ -537,7 +535,7 @@ bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope) {
TempFace tf[3]; TempFace tf[3];
bool has[3] = { false }; bool has[3] = { false };
for (XmlNode &sub_child : child.children()) { for (XmlNode &sub_child : child.children()) {
const std::string &scn = sub_child.name(); const std::string &scn = ai_stdStrToLower(sub_child.name());
if (scn == "fv1" || scn == "lv1" || scn == "pv1") { if (scn == "fv1" || scn == "lv1" || scn == "pv1") {
ReadFaceVertex(sub_child, t, tf[0]); ReadFaceVertex(sub_child, t, tf[0]);
has[0] = true; has[0] = true;
@ -631,7 +629,7 @@ unsigned int XGLImporter::ResolveMaterialRef(XmlNode &node, TempScope &scope) {
} }
// ok, this is n^2 and should get optimized one day // ok, this is n^2 and should get optimized one day
aiMaterial *const m = (*it).second; aiMaterial *const m = it->second;
unsigned int i = 0, mcount = static_cast<unsigned int>(scope.materials_linear.size()); unsigned int i = 0, mcount = static_cast<unsigned int>(scope.materials_linear.size());
for (; i < mcount; ++i) { for (; i < mcount; ++i) {
@ -651,7 +649,7 @@ void XGLImporter::ReadMaterial(XmlNode &node, TempScope &scope) {
aiMaterial *mat(new aiMaterial); aiMaterial *mat(new aiMaterial);
for (XmlNode &child : node.children()) { for (XmlNode &child : node.children()) {
const std::string &s = child.name(); const std::string &s = ai_stdStrToLower(child.name());
if (s == "amb") { if (s == "amb") {
const aiColor3D c = ReadCol3(child); const aiColor3D c = ReadCol3(child);
mat->AddProperty(&c, 1, AI_MATKEY_COLOR_AMBIENT); mat->AddProperty(&c, 1, AI_MATKEY_COLOR_AMBIENT);
@ -681,7 +679,7 @@ void XGLImporter::ReadMaterial(XmlNode &node, TempScope &scope) {
void XGLImporter::ReadFaceVertex(XmlNode &node, const TempMesh &t, TempFace &out) { void XGLImporter::ReadFaceVertex(XmlNode &node, const TempMesh &t, TempFace &out) {
bool havep = false; bool havep = false;
for (XmlNode &child : node.children()) { for (XmlNode &child : node.children()) {
const std::string &s = child.name(); const std::string &s = ai_stdStrToLower(child.name());
if (s == "pref") { if (s == "pref") {
const unsigned int id = ReadIndexFromText(child); 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);

View File

@ -93,7 +93,9 @@ protected:
private: private:
struct TempScope { struct TempScope {
TempScope() : TempScope() :
light() {} light() {
// empty
}
~TempScope() { ~TempScope() {
for (aiMesh *m : meshes_linear) { for (aiMesh *m : meshes_linear) {
@ -126,7 +128,9 @@ private:
struct SortMeshByMaterialId { struct SortMeshByMaterialId {
SortMeshByMaterialId(const TempScope &scope) : SortMeshByMaterialId(const TempScope &scope) :
scope(scope) {} scope(scope) {
// empty
}
bool operator()(unsigned int a, unsigned int b) const { bool operator()(unsigned int a, unsigned int b) const {
return scope.meshes_linear[a]->mMaterialIndex < scope.meshes_linear[b]->mMaterialIndex; return scope.meshes_linear[a]->mMaterialIndex < scope.meshes_linear[b]->mMaterialIndex;
}; };
@ -142,7 +146,10 @@ private:
struct TempMaterialMesh { struct TempMaterialMesh {
TempMaterialMesh() : TempMaterialMesh() :
pflags(), matid() {} pflags(),
matid() {
// empty
}
std::vector<aiVector3D> positions, normals; std::vector<aiVector3D> positions, normals;
std::vector<aiVector2D> uvs; std::vector<aiVector2D> uvs;
@ -154,7 +161,10 @@ private:
struct TempFace { struct TempFace {
TempFace() : TempFace() :
has_uv(), has_normal() {} has_uv(),
has_normal() {
// empty
}
aiVector3D pos; aiVector3D pos;
aiVector3D normal; aiVector3D normal;
@ -172,7 +182,7 @@ private:
bool SkipToText(); bool SkipToText();
unsigned int ReadIDAttr(XmlNode &node); unsigned int ReadIDAttr(XmlNode &node);
void ReadWorld(TempScope &scope); void ReadWorld(XmlNode &node, TempScope &scope);
void ReadLighting(XmlNode &node, TempScope &scope); void ReadLighting(XmlNode &node, TempScope &scope);
aiLight *ReadDirectionalLight(XmlNode &node); aiLight *ReadDirectionalLight(XmlNode &node);
aiNode *ReadObject(XmlNode &node, TempScope &scope, bool skipFirst = false/*, const char *closetag = "object"*/); aiNode *ReadObject(XmlNode &node, TempScope &scope, bool skipFirst = false/*, const char *closetag = "object"*/);

View File

@ -55,8 +55,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/defs.h> #include <assimp/defs.h>
#include <vector> #include <vector>
#include <vector>
namespace Assimp { namespace Assimp {
// NOTE: the functions below are mostly intended as replacement for // NOTE: the functions below are mostly intended as replacement for
@ -72,17 +70,13 @@ static const unsigned int BufferSize = 4096;
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
template <class char_t> template <class char_t>
AI_FORCE_INLINE AI_FORCE_INLINE char_t ToLower(char_t in) {
char_t
ToLower(char_t in) {
return (in >= (char_t)'A' && in <= (char_t)'Z') ? (char_t)(in + 0x20) : in; return (in >= (char_t)'A' && in <= (char_t)'Z') ? (char_t)(in + 0x20) : in;
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
template <class char_t> template <class char_t>
AI_FORCE_INLINE AI_FORCE_INLINE char_t ToUpper(char_t in) {
char_t
ToUpper(char_t in) {
return (in >= (char_t)'a' && in <= (char_t)'z') ? (char_t)(in - 0x20) : in; return (in >= (char_t)'a' && in <= (char_t)'z') ? (char_t)(in - 0x20) : in;
} }
@ -217,8 +211,7 @@ AI_FORCE_INLINE bool TokenMatch(char_t *&in, const char *token, unsigned int len
* @param token Token to check for * @param token Token to check for
* @param len Number of characters to check * @param len Number of characters to check
*/ */
AI_FORCE_INLINE AI_FORCE_INLINE bool TokenMatchI(const char *&in, const char *token, unsigned int len) {
bool TokenMatchI(const char *&in, const char *token, unsigned int len) {
if (!ASSIMP_strincmp(token, in, len) && IsSpaceOrNewLine(in[len])) { if (!ASSIMP_strincmp(token, in, len) && IsSpaceOrNewLine(in[len])) {
in += len + 1; in += len + 1;
return true; return true;
@ -227,8 +220,7 @@ bool TokenMatchI(const char *&in, const char *token, unsigned int len) {
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
AI_FORCE_INLINE AI_FORCE_INLINE void SkipToken(const char *&in) {
void SkipToken(const char *&in) {
SkipSpaces(&in); SkipSpaces(&in);
while (!IsSpaceOrNewLine(*in)) { while (!IsSpaceOrNewLine(*in)) {
++in; ++in;
@ -236,8 +228,7 @@ void SkipToken(const char *&in) {
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
AI_FORCE_INLINE AI_FORCE_INLINE std::string GetNextToken(const char *&in) {
std::string GetNextToken(const char *&in) {
SkipSpacesAndLineEnd(&in); SkipSpacesAndLineEnd(&in);
const char *cur = in; const char *cur = in;
while (!IsSpaceOrNewLine(*in)) { while (!IsSpaceOrNewLine(*in)) {
@ -277,7 +268,13 @@ AI_FORCE_INLINE unsigned int tokenize(const string_type &str, std::vector<string
return static_cast<unsigned int>(tokens.size()); return static_cast<unsigned int>(tokens.size());
} }
// --------------------------------------------------------------------------------- inline std::string ai_stdStrToLower(const std::string &str) {
std::string out(str);
for (size_t i = 0; i < str.size(); ++i) {
out[i] =(char) tolower(out[i]);
}
return out;
}
} // namespace Assimp } // namespace Assimp