full (almost...) texture supports

This commit is contained in:
granzuglia 2006-11-08 16:59:22 +00:00
parent 288172b62f
commit 654ababe38
3 changed files with 80 additions and 4 deletions

View File

@ -13,6 +13,43 @@ template<typename SaveMeshType>
class ExporterDAE : public UtilDAE class ExporterDAE : public UtilDAE
{ {
private: private:
static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector<QString>& 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<std::string>& 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) static void CreateVertInput(QDomDocument& doc,QDomNode& vert,const QString& attr,const QString& ref)
{ {
QDomElement vinp_pos = doc.createElement("input"); QDomElement vinp_pos = doc.createElement("input");
@ -233,6 +270,8 @@ public:
QDomElement ass = doc.createElement("asset"); QDomElement ass = doc.createElement("asset");
coll.appendChild(ass); coll.appendChild(ass);
if (m.textures.size() != 0)
SaveTexture(doc,doc.firstChild(),m.textures);
QDomElement geolib = doc.createElement("library_geometries"); QDomElement geolib = doc.createElement("library_geometries");
QDomElement geonode = doc.createElement("geometry"); QDomElement geonode = doc.createElement("geometry");
@ -297,6 +336,8 @@ public:
//removeChildNode(scenelst,"instance_visual_scene"); //removeChildNode(scenelst,"instance_visual_scene");
assert(scenelst.size() == 1); 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"); QDomNodeList vsscene = info->doc->elementsByTagName("library_visual_scenes");
if (info->doc->elementsByTagName("instance_geometry").size() != 0) if (info->doc->elementsByTagName("instance_geometry").size() != 0)

View File

@ -15,10 +15,12 @@ namespace io {
private: 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 (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"); /*QDomNodeList geosrc = geo.toElement().elementsByTagName("source");
int geosrc_size = geosrc.size(); int geosrc_size = geosrc.size();
if (geosrc_size < 1) if (geosrc_size < 1)
@ -61,6 +63,7 @@ namespace io {
int ii = 0; int ii = 0;
for(size_t vv = offset;vv < m.vert.size();++vv) 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)); 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); 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()); m.vert[vv].P() = vcg::Point3f(tmp.X(),tmp.Y(),tmp.Z());
@ -167,7 +170,10 @@ namespace io {
assert(indtx * 2 < wt.size()); assert(indtx * 2 < wt.size());
m.face[ff].WT(0) = vcg::TCoord2<float>(); m.face[ff].WT(0) = vcg::TCoord2<float>();
m.face[ff].WT(0).u() = wt.at(indtx * 2).toFloat(); 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<float> ttt = m.face[ff].WT(0);
int hh = 0;
} }
/*int indcl; /*int indcl;
@ -196,6 +202,9 @@ namespace io {
m.face[ff].WT(1) = vcg::TCoord2<float>(); m.face[ff].WT(1) = vcg::TCoord2<float>();
m.face[ff].WT(1).u() = wt.at(indtx * 2).toFloat(); 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).v() = wt.at(indtx * 2 + 1).toFloat();
m.face[ff].WT(1).n() = 1;
vcg::TCoord2<float> ttt = m.face[ff].WT(1);
int hh = 0;
} }
/*if (!wcsrc.isNull()) /*if (!wcsrc.isNull())
@ -223,6 +232,9 @@ namespace io {
m.face[ff].WT(2) = vcg::TCoord2<float>(); m.face[ff].WT(2) = vcg::TCoord2<float>();
m.face[ff].WT(2).u() = wt.at(indtx * 2).toFloat(); 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).v() = wt.at(indtx * 2 + 1).toFloat();
m.face[ff].WT(2).n() = 1;
vcg::TCoord2<float> ttt = m.face[ff].WT(2);
int hh = 0;
} }
/*if (!wcsrc.isNull()) /*if (!wcsrc.isNull())
@ -252,12 +264,13 @@ namespace io {
} }
} }
} }
public: public:
//merge all meshes in the collada's file in the templeted mesh m //merge all meshes in the collada's file in the templeted mesh m
//I assume the mesh //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(); AdditionalInfoDAE* inf = new AdditionalInfoDAE();
inf->dae = new InfoDAE(); inf->dae = new InfoDAE();

View File

@ -14,6 +14,7 @@
#include<vcg/space/point3.h> #include<vcg/space/point3.h>
#include<vcg/space/tcoord2.h> #include<vcg/space/tcoord2.h>
#include<vcg/space/color4.h> #include<vcg/space/color4.h>
#include <wrap/callback.h>
namespace vcg { namespace vcg {
namespace tri { 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(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(); QDomNodeList clst = node.childNodes();
for(int ii = 0;ii < clst.size();++ii) for(int ii = 0;ii < clst.size();++ii)
@ -197,6 +198,27 @@ namespace io {
return true; 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<QDomNode>& t) static void ParseRotationMatrix(vcg::Matrix44f& m,const std::vector<QDomNode>& t)
{ {
vcg::Matrix44f tmp; vcg::Matrix44f tmp;