From 48065edaf27ae78a9dc031fa733c3a0466bd629e Mon Sep 17 00:00:00 2001 From: granzuglia Date: Wed, 23 Oct 2013 16:59:24 +0000 Subject: [PATCH] - collada format is now fully compliant to the collada standard v 1.4.1 --- wrap/io_trimesh/export_dae.h | 1 + wrap/io_trimesh/import_dae.h | 84 +++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/wrap/io_trimesh/export_dae.h b/wrap/io_trimesh/export_dae.h index 5ad962fa..a9914a2b 100644 --- a/wrap/io_trimesh/export_dae.h +++ b/wrap/io_trimesh/export_dae.h @@ -60,6 +60,7 @@ namespace io //capability |= MeshModel::IOM_CAMERA; //vert + capability |= Mask::IOM_VERTCOORD; capability |= Mask::IOM_VERTNORMAL; capability |= Mask::IOM_VERTTEXCOORD; capability |= Mask::IOM_VERTCOLOR; diff --git a/wrap/io_trimesh/import_dae.h b/wrap/io_trimesh/import_dae.h index f5df4b70..3836e62a 100644 --- a/wrap/io_trimesh/import_dae.h +++ b/wrap/io_trimesh/import_dae.h @@ -27,6 +27,7 @@ //importer for collada's files #include +#include // uncomment one of the following line to enable the Verbose debugging for the parsing //#define QDEBUG if(1) ; else {assert(0);} @@ -119,20 +120,29 @@ namespace io { return indtx; } - static int VertexColorAttribute(ColladaMesh& m,const QStringList face,const QStringList wc,const QDomNode wcsrc,const int meshfaceind,const int faceind, const int vertind,const int component) - { - int indcl = -1; - if (!wcsrc.isNull()) - { - indcl = face.at(faceind).toInt(); - assert(indcl * 3 < wc.size()); - m.vert[vertind].C() = vcg::Color4b( (unsigned char)(wc.at(indcl * 3).toFloat()*255.0), - (unsigned char)(wc.at(indcl * 3 + 1).toFloat()*255.0), - (unsigned char)(wc.at(indcl * 3 + 2).toFloat()*255.0), - 1.0); - } - return indcl; - } + //static int VertexColorAttribute(ColladaMesh& m,const QStringList face,const QStringList wc,const QDomNode wcsrc,const int meshfaceind,const int faceind, const int vertind,const int component) + //{ + // int indcl = -1; + // if (!wcsrc.isNull()) + // { + // indcl = face.at(faceind).toInt(); + // assert(indcl * component < wc.size()); + // assert((component == 4) || (component == 3)); + // vcg::Color4b c; + // if (component == 3) + // c[3] = 255; + // for(unsigned int ii = 0;ii < component;++ii) + // c[ii] = (unsigned char)(wc.at(indcl * component + ii).toFloat()*255.0); + // /*m.vert[vertind].C() = vcg::Color4b( (unsigned char)(wc.at(indcl * component).toFloat()*255.0), + // (unsigned char)(wc.at(indcl * component + 1).toFloat()*255.0), + // (unsigned char)(wc.at(indcl * component + 2).toFloat()*255.0), + // (unsigned char)(wc.at(indcl * component + 3).toFloat()*255.0));*/ + // m.vert[vertind].C() = c; + + // } + // return indcl; + //} + static void FindStandardWedgeAttributes(WedgeAttribute& wed,const QDomNode nd,const QDomDocument doc) { @@ -146,17 +156,30 @@ namespace io { if (isThereTag(src,"accessor")) { QDomNodeList wedatts = src.toElement().elementsByTagName("accessor"); - wed.stride = wedatts.at(0).toElement().attribute("stride").toInt(); + wed.stridetx = wedatts.at(0).toElement().attribute("stride").toInt(); } else - wed.stride = 2; + wed.stridetx = 2; } - else - wed.stride = 2; + //else + // wed.stridetx = 2; wed.offtx = findStringListAttribute(wed.wt,wed.wtsrc,nd,doc,"TEXCOORD"); wed.wcsrc = findNodeBySpecificAttributeValue(nd,"input","semantic","COLOR"); + if (!wed.wtsrc.isNull()) + { + QDomNode src = attributeSourcePerSimplex(nd,doc,"COLOR"); + if (isThereTag(src,"accessor")) + { + QDomNodeList wedatts = src.toElement().elementsByTagName("accessor"); + wed.stridecl = wedatts.at(0).toElement().attribute("stride").toInt(); + } + else + wed.stridecl = 3; + } + /*else + wed.stridecl = 3;*/ wed.offcl = findStringListAttribute(wed.wc,wed.wcsrc,nd,doc,"COLOR"); } @@ -229,7 +252,7 @@ namespace io { polyTemp._pv[tt] = &(m.vert[indvt + offset]); faceIndexCnt +=faceAttributeNum; - WedgeTextureAttribute(polyTemp._txc[tt],faceIndexList,ind_txt, wa.wt ,wa.wtsrc, jj + wa.offtx,wa.stride); + WedgeTextureAttribute(polyTemp._txc[tt],faceIndexList,ind_txt, wa.wt ,wa.wtsrc, jj + wa.offtx,wa.stridetx); /**************** @@ -396,12 +419,16 @@ namespace io { assert(indvt + offset < m.vert.size()); m.face[ff].V(tt) = &(m.vert[indvt + offset]); - if(tri::HasPerWedgeNormal(m)) WedgeNormalAttribute(m,face,wa.wn,wa.wnsrc,ff,jj + wa.offnm,tt); - if(tri::HasPerVertexColor(m)) VertexColorAttribute(m,face,wa.wc,wa.wcsrc,ff,jj + wa.offcl,indvt + offset,tt); + //if(tri::HasPerWedgeNormal(m)) + // //WedgeNormalAttribute(m,face,wa.wn,wa.wnsrc,ff,jj + wa.offnm,tt); + //if(tri::HasPerVertexColor(m)) + //{ + // //VertexColorAttribute(m,face,wa.wc,wa.wcsrc,ff,jj + wa.offcl,indvt + offset,wa.stridecl); + //} if(tri::HasPerWedgeTexCoord(m) && ind_txt != -1) { - WedgeTextureAttribute(m,face,ind_txt,wa.wt,wa.wtsrc,ff,jj + wa.offtx,tt,wa.stride); + WedgeTextureAttribute(m,face,ind_txt,wa.wt,wa.wtsrc,ff,jj + wa.offtx,tt,wa.stridetx); } jj += faceAttributeNum; @@ -503,6 +530,8 @@ namespace io { valueStringList(geosrcverttext,srcnodetext,"float_array"); QDomNode srcnodecolor = attributeSourcePerSimplex(vertices.at(0),*(info.doc),"COLOR"); + QDomNodeList accesslist = srcnodecolor.toElement().elementsByTagName("accessor"); + QStringList geosrcvertcol; if (!srcnodecolor.isNull()) valueStringList(geosrcvertcol,srcnodecolor,"float_array"); @@ -524,8 +553,15 @@ namespace io { if (!srcnodecolor.isNull()) { - //assert((ii * 4 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size()) && (ii * 4 + 2 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size())); - m.vert[vv].C() = vcg::Color4b(geosrcvertcol[ii * 3].toFloat()*255.0,geosrcvertcol[ii * 3 + 1].toFloat()*255.0,geosrcvertcol[ii * 3 + 2].toFloat()*255.0,1.0); + if (accesslist.size() > 0) + { + //component per color...obviously we assume they are RGB or RGBA if ARGB you get fancy effects.... + if (accesslist.at(0).childNodes().size() == 4) + m.vert[vv].C() = vcg::Color4b(geosrcvertcol[ii * 4].toFloat()*255.0,geosrcvertcol[ii * 4 + 1].toFloat()*255.0,geosrcvertcol[ii * 4 + 2].toFloat()*255.0,geosrcvertcol[ii * 4 + 3].toFloat()*255.0); + else + if (accesslist.at(0).childNodes().size() == 3) + m.vert[vv].C() = vcg::Color4b(geosrcvertcol[ii * 3].toFloat()*255.0,geosrcvertcol[ii * 3 + 1].toFloat()*255.0,geosrcvertcol[ii * 3 + 2].toFloat()*255.0,255.0); + } } if (!srcnodetext.isNull())