From de752ec206934cfcfe37621c6773c7e1af72c0ec Mon Sep 17 00:00:00 2001 From: granzuglia Date: Thu, 2 Nov 2006 23:57:42 +0000 Subject: [PATCH] added new file for DAE importer/exporter --- wrap/io_trimesh/util_dae.h | 201 +++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 wrap/io_trimesh/util_dae.h diff --git a/wrap/io_trimesh/util_dae.h b/wrap/io_trimesh/util_dae.h new file mode 100644 index 00000000..ae9a1d63 --- /dev/null +++ b/wrap/io_trimesh/util_dae.h @@ -0,0 +1,201 @@ +#ifndef __VCGLIB_UTILDAE +#define __VCGLIB_UTILDAE + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace vcg { +namespace tri { +namespace io { + class InfoDAE : public AdditionalInfo + { + public: + + InfoDAE() + { + mask = 0; + numvert = 0; + numface = 0; + doc = NULL; + } + + ~InfoDAE() + { + delete doc; + texturefile.clear(); + } + + QDomDocument* doc; + std::vector texturefile; + }; + + class AdditionalInfoDAE : public AdditionalInfo + { + public: + vcg::tri::io::InfoDAE* dae; + + AdditionalInfoDAE() + :AdditionalInfo() + { + } + + ~AdditionalInfoDAE() + { + delete dae; + } + }; + + class UtilDAE + { + public: + enum DAEError + { + E_NOERROR, // 0 + E_CANTOPEN, // 1 + E_NOGEOMETRYLIBRARY, // 2 + E_NOMESH, // 3 + E_NOVERTEXPOSITION, // 4 + E_NO3DVERTEXPOSITION, // 5 + E_NO3DSCENE, // 6 + E_INCOMPATIBLECOLLADA141FORMAT, //7 + E_UNREFERENCEBLEDCOLLADAATTRIBUTE, // 8 + E_NOTRIANGLES + }; + + static const char *ErrorMsg(int error) + { + static const char * dae_error_msg[] = + { + "No errors", + "Can't open file", + "File without a geometry library", + "There isn't mesh in file", + "The meshes in file haven't the vertex position attribute", + "The importer assumes that the OpenMeshType uses a 3D point for the vertex position", + "There isn't any scene in Collada file", + "The input file is not compatible with COLLADA 1.41 standard format", + "Collada file is trying to referece an attribute that is not in the file", + "This version of Collada Importer support only triangular mesh file" + }; + + if(error>9 || error<0) return "Unknown error"; + else return dae_error_msg[error]; + }; + protected: + inline static void referenceToANodeAttribute(const QDomNode& n,const QString& attr,QString& url_st) + { + url_st = n.toElement().attribute(attr); + int sz = url_st.size() - 1; + url_st = url_st.right(sz); + assert(url_st.size() != 0); + } + + inline static QDomNode findNodeBySpecificAttributeValue(const QDomNode& n,const QString& tag,const QString& attrname,const QString& attrvalue) + { + QDomNode ndl = n.toElement(); + return findNodeBySpecificAttributeValue((QDomDocument&) ndl,tag,attrname,attrvalue); + } + + inline static QDomNode findNodeBySpecificAttributeValue(const QDomDocument& n,const QString& tag,const QString& attrname,const QString& attrvalue) + { + QDomNodeList ndl = n.elementsByTagName(tag); + int ndl_size = ndl.size(); + assert(ndl_size != 0); + int ind = 0; + while(ind < ndl_size) + { + if (ndl.at(ind).toElement().attribute(attrname) == attrvalue) + return ndl.at(ind); + ++ind; + } + return QDomNode(); + } + + inline static bool isThereTag(const QDomNode& n,const QString& tagname) + { + QDomNode ndl = n.toElement(); + return isThereTag((QDomDocument&) n,tagname); + } + + inline static bool isThereTag(const QDomDocument& n,const QString& tagname) + { + return ((n.toElement().elementsByTagName(tagname).size() > 0)? true : false); + } + + + inline static QDomNode attributeSourcePerSimplex(const QDomNode& n,const QDomDocument& startpoint,const QString& sem) + { + QDomNodeList vertattr = n.toElement().elementsByTagName("input"); + for(int ind = 0;ind < vertattr.size();++ind) + { + if (vertattr.at(ind).toElement().attribute("semantic") == sem) + { + QString url; + referenceToANodeAttribute(vertattr.at(ind),"source",url); + return findNodeBySpecificAttributeValue(startpoint,"source","id",url); + } + } + return QDomNode(); + } + + inline static void valueStringList(QStringList& res,const QDomNode& srcnode,const QString& tag) + { + QDomNodeList list = srcnode.toElement().elementsByTagName(tag); + int list_size = list.size(); + assert(list_size == 1); + QString nd = list.at(0).firstChild().nodeValue(); + res = nd.split(" "); + if (res.last() == "") + res.removeLast(); + + } + + inline static bool removeChildNode(QDomNodeList& nodelst,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") + { + for(int jj = 0;jj < nodelst.size();++jj) + { + removeChildNode(nodelst.at(jj),tag,attribname,attribvalue); + } + return true; + } + + inline static bool removeChildNode(QDomNode& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") + { + return removeChildNode((QDomDocument&) node.toElement(),tag,attribname,attribvalue); + } + + inline static bool removeChildNode(QDomDocument& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") + { + QDomNodeList clst = node.childNodes(); + for(int ii = 0;ii < clst.size();++ii) + { + QDomNode oldchild = node.childNodes().at(ii); + if (tag != "") + { + if ((attribname != "") && (attribvalue != "")) + { + if (clst.at(ii).toElement().attribute(attribname) == attribvalue) + node.removeChild(oldchild); + } + else if (clst.at(ii).nodeName() == tag) + node.removeChild(oldchild); + } + else node.removeChild(oldchild); + } + return true; + } + }; +} +} +} + +#endif \ No newline at end of file