From 654ababe3892c75c85baa1c6464137a7c27eabe7 Mon Sep 17 00:00:00 2001 From: granzuglia Date: Wed, 8 Nov 2006 16:59:22 +0000 Subject: [PATCH] full (almost...) texture supports --- wrap/io_trimesh/export_dae.h | 41 ++++++++++++++++++++++++++++++++++++ wrap/io_trimesh/import_dae.h | 19 ++++++++++++++--- wrap/io_trimesh/util_dae.h | 24 ++++++++++++++++++++- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/wrap/io_trimesh/export_dae.h b/wrap/io_trimesh/export_dae.h index ad01ff2f..b7fd088c 100644 --- a/wrap/io_trimesh/export_dae.h +++ b/wrap/io_trimesh/export_dae.h @@ -13,6 +13,43 @@ template class ExporterDAE : public UtilDAE { private: + + static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector& stv) + { + removeChildNode(doc,"library_images"); + QDomElement el = doc.createElement("library_images"); + for(int img = 0;img < stv.size();++img) + { + QDomElement imgnode = doc.createElement("image"); + imgnode.setAttribute("id","file"+QString::number(img)); + imgnode.setAttribute("name","file"+QString::number(img)); + QDomElement tex = doc.createElement("init_from"); + QDomText txname = doc.createTextNode(stv[img]); + tex.appendChild(txname); + imgnode.appendChild(tex); + el.appendChild(imgnode); + } + n.appendChild(el); + } + + static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector& stv) + { + removeChildNode(doc,"library_images"); + QDomElement el = doc.createElement("library_images"); + for(int img = 0;img < stv.size();++img) + { + QDomElement imgnode = doc.createElement("image"); + imgnode.setAttribute("id","file"+QString::number(img)); + imgnode.setAttribute("name","file"+QString::number(img)); + QDomElement tex = doc.createElement("init_from"); + QDomText txname = doc.createTextNode(QString(stv[img].c_str())); + tex.appendChild(txname); + imgnode.appendChild(tex); + el.appendChild(imgnode); + } + n.appendChild(el); + } + static void CreateVertInput(QDomDocument& doc,QDomNode& vert,const QString& attr,const QString& ref) { QDomElement vinp_pos = doc.createElement("input"); @@ -233,6 +270,8 @@ public: QDomElement ass = doc.createElement("asset"); coll.appendChild(ass); + if (m.textures.size() != 0) + SaveTexture(doc,doc.firstChild(),m.textures); QDomElement geolib = doc.createElement("library_geometries"); QDomElement geonode = doc.createElement("geometry"); @@ -297,6 +336,8 @@ public: //removeChildNode(scenelst,"instance_visual_scene"); assert(scenelst.size() == 1); + if (m.textures.size() != 0) + SaveTexture(*(info->doc),info->doc->firstChild(),m.textures); QDomNodeList vsscene = info->doc->elementsByTagName("library_visual_scenes"); if (info->doc->elementsByTagName("instance_geometry").size() != 0) diff --git a/wrap/io_trimesh/import_dae.h b/wrap/io_trimesh/import_dae.h index faacca10..1affc681 100644 --- a/wrap/io_trimesh/import_dae.h +++ b/wrap/io_trimesh/import_dae.h @@ -15,10 +15,12 @@ namespace io { private: - static int LoadMesh(OpenMeshType& m,InfoDAE* info,const QDomNode& geo,const vcg::Matrix44f& t) + static int LoadMesh(OpenMeshType& m,InfoDAE* info,const QDomNode& geo,const vcg::Matrix44f& t, CallBackPos *cb=0) { if (isThereTag(geo,"mesh")) { + if ((cb !=NULL) && (((info->numvert + info->numface)%100)==0) && !(*cb)((100*(info->numvert + info->numface))/(info->numvert + info->numface), "Vertex Loading")) + return E_CANTOPEN; /*QDomNodeList geosrc = geo.toElement().elementsByTagName("source"); int geosrc_size = geosrc.size(); if (geosrc_size < 1) @@ -61,6 +63,7 @@ namespace io { int ii = 0; for(size_t vv = offset;vv < m.vert.size();++vv) { + assert((ii * 3 < geosrcposarr_size) && (ii * 3 + 1 < geosrcposarr_size) && (ii * 3 + 2 < geosrcposarr_size)); vcg::Point4f tmp = t * vcg::Point4f(geosrcposarr[ii * 3].toFloat(),geosrcposarr[ii * 3 + 1].toFloat(),geosrcposarr[ii * 3 + 2].toFloat(),1.0f); m.vert[vv].P() = vcg::Point3f(tmp.X(),tmp.Y(),tmp.Z()); @@ -167,7 +170,10 @@ namespace io { assert(indtx * 2 < wt.size()); m.face[ff].WT(0) = vcg::TCoord2(); m.face[ff].WT(0).u() = wt.at(indtx * 2).toFloat(); - m.face[ff].WT(0).v() = wt.at(indtx * 2 + 1).toFloat(); + m.face[ff].WT(0).v() = wt.at(indtx * 2 + 1).toFloat(); + m.face[ff].WT(0).n() = 1; + vcg::TCoord2 ttt = m.face[ff].WT(0); + int hh = 0; } /*int indcl; @@ -196,6 +202,9 @@ namespace io { m.face[ff].WT(1) = vcg::TCoord2(); m.face[ff].WT(1).u() = wt.at(indtx * 2).toFloat(); m.face[ff].WT(1).v() = wt.at(indtx * 2 + 1).toFloat(); + m.face[ff].WT(1).n() = 1; + vcg::TCoord2 ttt = m.face[ff].WT(1); + int hh = 0; } /*if (!wcsrc.isNull()) @@ -223,6 +232,9 @@ namespace io { m.face[ff].WT(2) = vcg::TCoord2(); m.face[ff].WT(2).u() = wt.at(indtx * 2).toFloat(); m.face[ff].WT(2).v() = wt.at(indtx * 2 + 1).toFloat(); + m.face[ff].WT(2).n() = 1; + vcg::TCoord2 ttt = m.face[ff].WT(2); + int hh = 0; } /*if (!wcsrc.isNull()) @@ -252,12 +264,13 @@ namespace io { } } } + public: //merge all meshes in the collada's file in the templeted mesh m //I assume the mesh - static int Open(OpenMeshType& m,const char* filename,AdditionalInfo*& addinfo) + static int Open(OpenMeshType& m,const char* filename,AdditionalInfo*& addinfo, CallBackPos *cb=0) { AdditionalInfoDAE* inf = new AdditionalInfoDAE(); inf->dae = new InfoDAE(); diff --git a/wrap/io_trimesh/util_dae.h b/wrap/io_trimesh/util_dae.h index f791473c..d8b6ed86 100644 --- a/wrap/io_trimesh/util_dae.h +++ b/wrap/io_trimesh/util_dae.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace vcg { namespace tri { @@ -176,7 +177,7 @@ namespace io { }*/ //inline static bool removeChildNode(QDomDocument& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") - inline static bool removeChildNode(QDomNode node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") + inline static bool removeChildNode(QDomNode& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") { QDomNodeList clst = node.childNodes(); for(int ii = 0;ii < clst.size();++ii) @@ -197,6 +198,27 @@ namespace io { return true; } + /*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; + }*/ + static void ParseRotationMatrix(vcg::Matrix44f& m,const std::vector& t) { vcg::Matrix44f tmp;