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
// "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) {
std::string type, value;
AMFNodeElementBase *ne(nullptr);
AMFNodeElementBase *ne = nullptr;
type = node.attribute("type").as_string();
value = node.value();
std::string type = node.attribute("type").as_string(), value;
XmlParser::getValueAsString(node, value);
// read attribute
ne = new AMFMetadata(mNodeElement_Cur);

View File

@ -56,16 +56,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <memory>
using namespace Assimp;
//using namespace irr;
//using namespace irr::io;
// zlib is needed for compressed XGL files
#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
#include <zlib.h>
#else
#include <contrib/zlib/zlib.h>
#endif
# ifdef ASSIMP_BUILD_NO_OWN_ZLIB
# include <zlib.h>
# else
# include <contrib/zlib/zlib.h>
# endif
#endif
namespace Assimp { // this has to be in here because LogFunctions is in ::Assimp
@ -133,8 +131,7 @@ const aiImporterDesc *XGLImporter::GetInfo() const {
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
void XGLImporter::InternReadFile(const std::string &pFile,
aiScene *pScene, IOSystem *pIOHandler) {
void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL
std::vector<Bytef> uncompressed;
#endif
@ -207,8 +204,9 @@ void XGLImporter::InternReadFile(const std::string &pFile,
XmlNode root = mXmlParser->getRootNode();
TempScope scope;
if (!ASSIMP_stricmp(root.name(), "world")) {
ReadWorld(scope);
XmlNode *worldNode = mXmlParser->findNode("WORLD");
if (nullptr != worldNode) {
ReadWorld(*worldNode, scope);
}
std::vector<aiMesh *> &meshes = scope.meshes_linear;
@ -239,20 +237,20 @@ void XGLImporter::InternReadFile(const std::string &pFile,
}
// ------------------------------------------------------------------------------------------------
void XGLImporter::ReadWorld(TempScope &scope) {
XmlNode root = mXmlParser->getRootNode();
for (XmlNode &node : root.children()) {
const std::string &s = node.name();
void XGLImporter::ReadWorld(XmlNode &node, TempScope &scope) {
for (XmlNode &currentNode : node.children()) {
const std::string &s = ai_stdStrToLower(currentNode.name());
// XXX right now we'd skip <lighting> if it comes after
// <object> or <mesh>
if (s == "lighting") {
ReadLighting(node, scope);
ReadLighting(currentNode, scope);
} else if (s == "object" || s == "mesh" || s == "mat") {
break;
}
}
aiNode *const nd = ReadObject(root, scope, true);
aiNode *const nd = ReadObject(node, scope, true);
if (!nd) {
ThrowException("failure reading <world>");
}
@ -265,7 +263,7 @@ void XGLImporter::ReadWorld(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") {
scope.light = ReadDirectionalLight(node);
} else if (s == "ambient") {
@ -285,7 +283,7 @@ aiLight *XGLImporter::ReadDirectionalLight(XmlNode &node) {
return nullptr;
}
const std::string &s = child.name();
const std::string &s = ai_stdStrToLower(child.name());
if (s == "direction") {
l->mDirection = ReadVec3(child);
} else if (s == "diffuse") {
@ -308,7 +306,7 @@ aiNode *XGLImporter::ReadObject(XmlNode &node, TempScope &scope, bool skipFirst/
skipFirst = false;
const std::string &s = child.name();
const std::string &s = ai_stdStrToLower(child.name());
if (s == "mesh") {
const size_t prev = scope.meshes_linear.size();
if (ReadMesh(child, scope)) {
@ -389,13 +387,13 @@ aiMatrix4x4 XGLImporter::ReadTrafo(XmlNode &node) {
float scale = 1.0f;
aiMatrix4x4 m;
XmlNode child = node.child("transform");
XmlNode child = node.child("TRANSFORM");
if (child.empty()) {
return m;
}
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") {
forward = ReadVec3(sub_child);
} else if (s == "up") {
@ -502,7 +500,7 @@ bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope) {
const unsigned int mesh_id = ReadIDAttr(node);
for (XmlNode &child : node.children()) {
const std::string &s = child.name();
const std::string &s = ai_stdStrToLower(child.name());
if (s == "mat") {
ReadMaterial(child, scope);
@ -537,7 +535,7 @@ bool XGLImporter::ReadMesh(XmlNode &node, TempScope &scope) {
TempFace tf[3];
bool has[3] = { false };
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") {
ReadFaceVertex(sub_child, t, tf[0]);
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
aiMaterial *const m = (*it).second;
aiMaterial *const m = it->second;
unsigned int i = 0, mcount = static_cast<unsigned int>(scope.materials_linear.size());
for (; i < mcount; ++i) {
@ -651,7 +649,7 @@ void XGLImporter::ReadMaterial(XmlNode &node, TempScope &scope) {
aiMaterial *mat(new aiMaterial);
for (XmlNode &child : node.children()) {
const std::string &s = child.name();
const std::string &s = ai_stdStrToLower(child.name());
if (s == "amb") {
const aiColor3D c = ReadCol3(child);
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) {
bool havep = false;
for (XmlNode &child : node.children()) {
const std::string &s = child.name();
const std::string &s = ai_stdStrToLower(child.name());
if (s == "pref") {
const unsigned int id = ReadIndexFromText(child);
std::map<unsigned int, aiVector3D>::const_iterator it = t.points.find(id);

View File

@ -93,7 +93,9 @@ protected:
private:
struct TempScope {
TempScope() :
light() {}
light() {
// empty
}
~TempScope() {
for (aiMesh *m : meshes_linear) {
@ -126,7 +128,9 @@ private:
struct SortMeshByMaterialId {
SortMeshByMaterialId(const TempScope &scope) :
scope(scope) {}
scope(scope) {
// empty
}
bool operator()(unsigned int a, unsigned int b) const {
return scope.meshes_linear[a]->mMaterialIndex < scope.meshes_linear[b]->mMaterialIndex;
};
@ -142,7 +146,10 @@ private:
struct TempMaterialMesh {
TempMaterialMesh() :
pflags(), matid() {}
pflags(),
matid() {
// empty
}
std::vector<aiVector3D> positions, normals;
std::vector<aiVector2D> uvs;
@ -154,7 +161,10 @@ private:
struct TempFace {
TempFace() :
has_uv(), has_normal() {}
has_uv(),
has_normal() {
// empty
}
aiVector3D pos;
aiVector3D normal;
@ -172,7 +182,7 @@ private:
bool SkipToText();
unsigned int ReadIDAttr(XmlNode &node);
void ReadWorld(TempScope &scope);
void ReadWorld(XmlNode &node, TempScope &scope);
void ReadLighting(XmlNode &node, TempScope &scope);
aiLight *ReadDirectionalLight(XmlNode &node);
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 <vector>
#include <vector>
namespace Assimp {
// NOTE: the functions below are mostly intended as replacement for
@ -72,17 +70,13 @@ static const unsigned int BufferSize = 4096;
// ---------------------------------------------------------------------------------
template <class char_t>
AI_FORCE_INLINE
char_t
ToLower(char_t in) {
AI_FORCE_INLINE char_t ToLower(char_t in) {
return (in >= (char_t)'A' && in <= (char_t)'Z') ? (char_t)(in + 0x20) : in;
}
// ---------------------------------------------------------------------------------
template <class char_t>
AI_FORCE_INLINE
char_t
ToUpper(char_t in) {
AI_FORCE_INLINE char_t ToUpper(char_t 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 len Number of characters to check
*/
AI_FORCE_INLINE
bool TokenMatchI(const char *&in, const char *token, unsigned int len) {
AI_FORCE_INLINE bool TokenMatchI(const char *&in, const char *token, unsigned int len) {
if (!ASSIMP_strincmp(token, in, len) && IsSpaceOrNewLine(in[len])) {
in += len + 1;
return true;
@ -227,8 +220,7 @@ bool TokenMatchI(const char *&in, const char *token, unsigned int len) {
}
// ---------------------------------------------------------------------------------
AI_FORCE_INLINE
void SkipToken(const char *&in) {
AI_FORCE_INLINE void SkipToken(const char *&in) {
SkipSpaces(&in);
while (!IsSpaceOrNewLine(*in)) {
++in;
@ -236,8 +228,7 @@ void SkipToken(const char *&in) {
}
// ---------------------------------------------------------------------------------
AI_FORCE_INLINE
std::string GetNextToken(const char *&in) {
AI_FORCE_INLINE std::string GetNextToken(const char *&in) {
SkipSpacesAndLineEnd(&in);
const char *cur = 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());
}
// ---------------------------------------------------------------------------------
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