enhanced version of exporter
This commit is contained in:
parent
0812a3d1bc
commit
2b46528dec
|
@ -214,185 +214,383 @@ public:
|
||||||
AdditionalInfoDAE* inf = static_cast<AdditionalInfoDAE*>(in);
|
AdditionalInfoDAE* inf = static_cast<AdditionalInfoDAE*>(in);
|
||||||
InfoDAE* info = inf->dae;
|
InfoDAE* info = inf->dae;
|
||||||
QDomNodeList scenelst = info->doc->elementsByTagName("scene");
|
QDomNodeList scenelst = info->doc->elementsByTagName("scene");
|
||||||
removeChildNode(scenelst,"instance_visual_scene");
|
//removeChildNode(scenelst,"instance_visual_scene");
|
||||||
for(int vsscn = 0;vsscn < scenelst.size();++vsscn)
|
assert(scenelst.size() == 1);
|
||||||
{
|
|
||||||
QString url = scenelst.at(vsscn).toElement().attribute("url");
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement vsnode = info->doc->createElement("instance_visual_scene");
|
|
||||||
vsnode.setAttribute("url","#vcg-scene-node");
|
|
||||||
scenelst.at(0).appendChild(vsnode);
|
|
||||||
|
|
||||||
QDomNodeList vsscene = info->doc->elementsByTagName("library_visual_scenes");
|
QDomNodeList vsscene = info->doc->elementsByTagName("library_visual_scenes");
|
||||||
int vsscene_size = vsscene.size();
|
|
||||||
assert(vsscene.size() == 1);
|
|
||||||
removeChildNode(vsscene,"visual_scene","id","vcg-scene-node");
|
|
||||||
QDomElement vslnode = info->doc->createElement("visual_scene");
|
|
||||||
vslnode.setAttribute("id","vcg-scene-node");
|
|
||||||
vslnode.setAttribute("name","vcg-untitled");
|
|
||||||
|
|
||||||
QDomElement vcgnode = info->doc->createElement("node");
|
if (info->doc->elementsByTagName("instance_geometry").size() != 0)
|
||||||
vcgnode.setAttribute("id","vcg-node");
|
|
||||||
vcgnode.setAttribute("name","vcg-untitled");
|
|
||||||
|
|
||||||
QDomElement vcginst = info->doc->createElement("instance_geometry");
|
|
||||||
vcginst.setAttribute("url","#vcg-mesh-lib");
|
|
||||||
vcgnode.appendChild(vcginst);
|
|
||||||
vslnode.appendChild(vcgnode);
|
|
||||||
vsscene.at(0).appendChild(vslnode);
|
|
||||||
|
|
||||||
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
|
|
||||||
assert(geolib.size() == 1);
|
|
||||||
//removeChildNode(geolib.at(0));
|
|
||||||
|
|
||||||
/*QDomElement mshnode;
|
|
||||||
mshnode.setTagName("mesh");*/
|
|
||||||
|
|
||||||
removeChildNode(geolib.at(0),"geometry","id","vcg-mesh-lib");
|
|
||||||
QDomElement geonode = info->doc->createElement("geometry");
|
|
||||||
geonode.setAttribute("id","vcg-mesh-lib");
|
|
||||||
geonode.setAttribute("name","vcg-mesh");
|
|
||||||
|
|
||||||
QDomElement meshnode = info->doc->createElement("mesh");
|
|
||||||
|
|
||||||
QDomElement srcposnode = info->doc->createElement("source");
|
|
||||||
srcposnode.setAttribute("id","vcg-mesh-positions");
|
|
||||||
srcposnode.setAttribute("name","vcg-mesh-positions");
|
|
||||||
|
|
||||||
QDomElement arrayposnode = info->doc->createElement("float_array");
|
|
||||||
arrayposnode.setAttribute("id","vcg-mesh-positions-array");
|
|
||||||
|
|
||||||
QString arrp;
|
|
||||||
arrp.reserve(8 * m.vert.size());
|
|
||||||
QString arrn;
|
|
||||||
arrn.reserve(8 * m.vert.size());
|
|
||||||
int nvert = 0;
|
|
||||||
for(SaveMeshType::VertexIterator it = m.vert.begin();it != m.vert.end();++it)
|
|
||||||
{
|
{
|
||||||
if (!(it->IsD()))
|
QDomNodeList invisscnlst = info->doc->elementsByTagName("instance_visual_scene");
|
||||||
|
assert(invisscnlst.size() == 1);
|
||||||
|
QString url;
|
||||||
|
referenceToANodeAttribute(invisscnlst.at(0),"url",url);
|
||||||
|
assert(vsscene.size() == 1);
|
||||||
|
QDomNode sc = findNodeBySpecificAttributeValue(vsscene.at(0),"visual_scene","id",url);
|
||||||
|
//removeChildNode(sc.childNodes(),"instance_geometry");
|
||||||
|
for(int no = 0;no < sc.childNodes().size();++no)
|
||||||
{
|
{
|
||||||
arrp.append(QString::number(it->P().X()) + " " +QString::number(it->P().Y()) + " " + QString::number(it->P().Z()) + " ");
|
QDomNode oldnode = sc.childNodes().at(no);
|
||||||
arrn.append(QString::number(it->N().X()) + " " + QString::number(it->N().Y()) + " " + QString::number(it->N().Z())+ " ");
|
if (sc.childNodes().at(no).toElement().elementsByTagName("instance_geometry").size() != 0)
|
||||||
//arrp.append(QString::number(it->P().X()).append(" ").append(QString::number(it->P().Y())).append(" ").append(QString::number(it->P().Z())).append(" "));
|
|
||||||
//arrp.append(QString::number(it->N().X()).append(" ").append(QString::number(it->N().Y())).append(" ").append(QString::number(it->N().Z())).append(" "));
|
|
||||||
++nvert;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
arrayposnode.setAttribute("count",QString::number(nvert * 3));
|
|
||||||
QDomText ap = info->doc->createTextNode(arrp);
|
|
||||||
|
|
||||||
QDomElement technode = info->doc->createElement("technique_common");
|
|
||||||
QDomElement accnode = info->doc->createElement("accessor");
|
|
||||||
accnode.setAttribute("source","#vcg-mesh-positions-array");
|
|
||||||
accnode.setAttribute("count",QString::number(nvert));
|
|
||||||
accnode.setAttribute("stride","3");
|
|
||||||
|
|
||||||
QDomElement parxnode = info->doc->createElement("param");
|
|
||||||
parxnode.setAttribute("name","X");
|
|
||||||
parxnode.setAttribute("type","float");
|
|
||||||
QDomElement parynode = info->doc->createElement("param");
|
|
||||||
parynode.setAttribute("name","Y");
|
|
||||||
parynode.setAttribute("type","float");
|
|
||||||
QDomElement parznode = info->doc->createElement("param");
|
|
||||||
parznode.setAttribute("name","Z");
|
|
||||||
parznode.setAttribute("type","float");
|
|
||||||
|
|
||||||
accnode.appendChild(parxnode);
|
|
||||||
accnode.appendChild(parynode);
|
|
||||||
accnode.appendChild(parznode);
|
|
||||||
technode.appendChild(accnode);
|
|
||||||
arrayposnode.appendChild(ap);
|
|
||||||
srcposnode.appendChild(arrayposnode);
|
|
||||||
srcposnode.appendChild(technode);
|
|
||||||
|
|
||||||
meshnode.appendChild(srcposnode);
|
|
||||||
|
|
||||||
QDomElement srcnmnode = info->doc->createElement("source");
|
|
||||||
srcnmnode.setAttribute("id","vcg-mesh-normals");
|
|
||||||
srcnmnode.setAttribute("name","vcg-mesh-normals");
|
|
||||||
|
|
||||||
QDomElement arraynmnode = info->doc->createElement("float_array");
|
|
||||||
arraynmnode.setAttribute("id","vcg-mesh-normals-array");
|
|
||||||
arraynmnode.setAttribute("count",QString::number(nvert * 3));
|
|
||||||
|
|
||||||
QDomElement technode2 = info->doc->createElement("technique_common");
|
|
||||||
QDomElement accnode2 = info->doc->createElement("accessor");
|
|
||||||
accnode2.setAttribute("source","#vcg-mesh-normals-array");
|
|
||||||
accnode2.setAttribute("count",QString::number(nvert));
|
|
||||||
accnode2.setAttribute("stride","3");
|
|
||||||
|
|
||||||
QDomElement parxnode2 = info->doc->createElement("param");
|
|
||||||
parxnode2.setAttribute("name","X");
|
|
||||||
parxnode2.setAttribute("type","float");
|
|
||||||
QDomElement parynode2 = info->doc->createElement("param");
|
|
||||||
parynode2.setAttribute("name","Y");
|
|
||||||
parynode2.setAttribute("type","float");
|
|
||||||
QDomElement parznode2 = info->doc->createElement("param");
|
|
||||||
parznode2.setAttribute("name","Z");
|
|
||||||
parznode2.setAttribute("type","float");
|
|
||||||
|
|
||||||
QDomText an = info->doc->createTextNode(arrn);
|
|
||||||
|
|
||||||
|
|
||||||
accnode2.appendChild(parxnode2);
|
|
||||||
accnode2.appendChild(parynode2);
|
|
||||||
accnode2.appendChild(parznode2);
|
|
||||||
technode2.appendChild(accnode2);
|
|
||||||
arraynmnode.appendChild(an);
|
|
||||||
srcnmnode.appendChild(arraynmnode);
|
|
||||||
srcnmnode.appendChild(technode2);
|
|
||||||
|
|
||||||
meshnode.appendChild(srcnmnode);
|
|
||||||
|
|
||||||
QDomElement vert = info->doc->createElement("vertices");
|
|
||||||
vert.setAttribute("id","vcg-mesh-vertices");
|
|
||||||
QDomElement vinp_pos = info->doc->createElement("input");
|
|
||||||
vinp_pos.setAttribute("semantic","POSITION");
|
|
||||||
vinp_pos.setAttribute("source","#vcg-mesh-positions");
|
|
||||||
QDomElement vinp_nm = info->doc->createElement("input");
|
|
||||||
vinp_nm.setAttribute("semantic","NORMAL");
|
|
||||||
vinp_nm.setAttribute("source","#vcg-mesh-normals");
|
|
||||||
|
|
||||||
vert.appendChild(vinp_pos);
|
|
||||||
vert.appendChild(vinp_nm);
|
|
||||||
|
|
||||||
meshnode.appendChild(vert);
|
|
||||||
|
|
||||||
QDomElement tri = info->doc->createElement("triangles");
|
|
||||||
|
|
||||||
|
|
||||||
QDomElement tinp_vert = info->doc->createElement("input");
|
|
||||||
tinp_vert.setAttribute("offset","0");
|
|
||||||
tinp_vert.setAttribute("semantic","VERTEX");
|
|
||||||
tinp_vert.setAttribute("source","#vcg-mesh-vertices");
|
|
||||||
QDomElement poly = info->doc->createElement("p");
|
|
||||||
QString triangles_tess;
|
|
||||||
int nface = 0;
|
|
||||||
triangles_tess.reserve(9*m.face.size());
|
|
||||||
for(SaveMeshType::FaceIterator itf = m.face.begin();itf != m.face.end();++itf)
|
|
||||||
{
|
|
||||||
if (!(itf->IsD()))
|
|
||||||
{
|
|
||||||
for(unsigned int ii = 0;ii < 3;++ii)
|
|
||||||
{
|
{
|
||||||
int ind_v = (*itf).V(ii) - &(m.vert[0]);
|
sc.removeChild(oldnode);
|
||||||
if (triangles_tess == "")
|
|
||||||
triangles_tess = QString::number(ind_v);
|
|
||||||
else triangles_tess = triangles_tess.append(" ").append(QString::number(ind_v));
|
|
||||||
}
|
}
|
||||||
++nface;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
tri.setAttribute("count",nface);
|
|
||||||
|
|
||||||
QDomText tri_list = info->doc->createTextNode(triangles_tess);
|
|
||||||
poly.appendChild(tri_list);
|
QDomElement vcgnode = info->doc->createElement("node");
|
||||||
tri.appendChild(tinp_vert);
|
vcgnode.setAttribute("id","vcg-node");
|
||||||
tri.appendChild(poly);
|
vcgnode.setAttribute("name","vcg-untitled");
|
||||||
meshnode.appendChild(tri);
|
|
||||||
geonode.appendChild(meshnode);
|
QDomElement vcginst = info->doc->createElement("instance_geometry");
|
||||||
geolib.at(0).appendChild(geonode);
|
vcginst.setAttribute("url","#vcg-mesh-lib");
|
||||||
|
vcgnode.appendChild(vcginst);
|
||||||
|
sc.appendChild(vcgnode);
|
||||||
|
vsscene.at(0).appendChild(sc);
|
||||||
|
|
||||||
|
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
|
||||||
|
assert(geolib.size() == 1);
|
||||||
|
//removeChildNode(geolib.at(0));
|
||||||
|
|
||||||
|
/*QDomElement mshnode;
|
||||||
|
mshnode.setTagName("mesh");*/
|
||||||
|
|
||||||
|
removeChildNode(geolib.at(0),"geometry","id","vcg-mesh-lib");
|
||||||
|
QDomElement geonode = info->doc->createElement("geometry");
|
||||||
|
geonode.setAttribute("id","vcg-mesh-lib");
|
||||||
|
geonode.setAttribute("name","vcg-mesh");
|
||||||
|
|
||||||
|
QDomElement meshnode = info->doc->createElement("mesh");
|
||||||
|
|
||||||
|
QDomElement srcposnode = info->doc->createElement("source");
|
||||||
|
srcposnode.setAttribute("id","vcg-mesh-positions");
|
||||||
|
srcposnode.setAttribute("name","vcg-mesh-positions");
|
||||||
|
|
||||||
|
QDomElement arrayposnode = info->doc->createElement("float_array");
|
||||||
|
arrayposnode.setAttribute("id","vcg-mesh-positions-array");
|
||||||
|
|
||||||
|
QString arrp;
|
||||||
|
arrp.reserve(8 * m.vert.size());
|
||||||
|
QString arrn;
|
||||||
|
arrn.reserve(8 * m.vert.size());
|
||||||
|
int nvert = 0;
|
||||||
|
for(SaveMeshType::VertexIterator it = m.vert.begin();it != m.vert.end();++it)
|
||||||
|
{
|
||||||
|
if (!(it->IsD()))
|
||||||
|
{
|
||||||
|
arrp.append(QString::number(it->P().X()) + " " +QString::number(it->P().Y()) + " " + QString::number(it->P().Z()) + " ");
|
||||||
|
arrn.append(QString::number(it->N().X()) + " " + QString::number(it->N().Y()) + " " + QString::number(it->N().Z())+ " ");
|
||||||
|
//arrp.append(QString::number(it->P().X()).append(" ").append(QString::number(it->P().Y())).append(" ").append(QString::number(it->P().Z())).append(" "));
|
||||||
|
//arrp.append(QString::number(it->N().X()).append(" ").append(QString::number(it->N().Y())).append(" ").append(QString::number(it->N().Z())).append(" "));
|
||||||
|
++nvert;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arrayposnode.setAttribute("count",QString::number(nvert * 3));
|
||||||
|
QDomText ap = info->doc->createTextNode(arrp);
|
||||||
|
|
||||||
|
QDomElement technode = info->doc->createElement("technique_common");
|
||||||
|
QDomElement accnode = info->doc->createElement("accessor");
|
||||||
|
accnode.setAttribute("source","#vcg-mesh-positions-array");
|
||||||
|
accnode.setAttribute("count",QString::number(nvert));
|
||||||
|
accnode.setAttribute("stride","3");
|
||||||
|
|
||||||
|
QDomElement parxnode = info->doc->createElement("param");
|
||||||
|
parxnode.setAttribute("name","X");
|
||||||
|
parxnode.setAttribute("type","float");
|
||||||
|
QDomElement parynode = info->doc->createElement("param");
|
||||||
|
parynode.setAttribute("name","Y");
|
||||||
|
parynode.setAttribute("type","float");
|
||||||
|
QDomElement parznode = info->doc->createElement("param");
|
||||||
|
parznode.setAttribute("name","Z");
|
||||||
|
parznode.setAttribute("type","float");
|
||||||
|
|
||||||
|
accnode.appendChild(parxnode);
|
||||||
|
accnode.appendChild(parynode);
|
||||||
|
accnode.appendChild(parznode);
|
||||||
|
technode.appendChild(accnode);
|
||||||
|
arrayposnode.appendChild(ap);
|
||||||
|
srcposnode.appendChild(arrayposnode);
|
||||||
|
srcposnode.appendChild(technode);
|
||||||
|
|
||||||
|
meshnode.appendChild(srcposnode);
|
||||||
|
|
||||||
|
QDomElement srcnmnode = info->doc->createElement("source");
|
||||||
|
srcnmnode.setAttribute("id","vcg-mesh-normals");
|
||||||
|
srcnmnode.setAttribute("name","vcg-mesh-normals");
|
||||||
|
|
||||||
|
QDomElement arraynmnode = info->doc->createElement("float_array");
|
||||||
|
arraynmnode.setAttribute("id","vcg-mesh-normals-array");
|
||||||
|
arraynmnode.setAttribute("count",QString::number(nvert * 3));
|
||||||
|
|
||||||
|
QDomElement technode2 = info->doc->createElement("technique_common");
|
||||||
|
QDomElement accnode2 = info->doc->createElement("accessor");
|
||||||
|
accnode2.setAttribute("source","#vcg-mesh-normals-array");
|
||||||
|
accnode2.setAttribute("count",QString::number(nvert));
|
||||||
|
accnode2.setAttribute("stride","3");
|
||||||
|
|
||||||
|
QDomElement parxnode2 = info->doc->createElement("param");
|
||||||
|
parxnode2.setAttribute("name","X");
|
||||||
|
parxnode2.setAttribute("type","float");
|
||||||
|
QDomElement parynode2 = info->doc->createElement("param");
|
||||||
|
parynode2.setAttribute("name","Y");
|
||||||
|
parynode2.setAttribute("type","float");
|
||||||
|
QDomElement parznode2 = info->doc->createElement("param");
|
||||||
|
parznode2.setAttribute("name","Z");
|
||||||
|
parznode2.setAttribute("type","float");
|
||||||
|
|
||||||
|
QDomText an = info->doc->createTextNode(arrn);
|
||||||
|
|
||||||
|
|
||||||
|
accnode2.appendChild(parxnode2);
|
||||||
|
accnode2.appendChild(parynode2);
|
||||||
|
accnode2.appendChild(parznode2);
|
||||||
|
technode2.appendChild(accnode2);
|
||||||
|
arraynmnode.appendChild(an);
|
||||||
|
srcnmnode.appendChild(arraynmnode);
|
||||||
|
srcnmnode.appendChild(technode2);
|
||||||
|
|
||||||
|
meshnode.appendChild(srcnmnode);
|
||||||
|
|
||||||
|
QDomElement vert = info->doc->createElement("vertices");
|
||||||
|
vert.setAttribute("id","vcg-mesh-vertices");
|
||||||
|
QDomElement vinp_pos = info->doc->createElement("input");
|
||||||
|
vinp_pos.setAttribute("semantic","POSITION");
|
||||||
|
vinp_pos.setAttribute("source","#vcg-mesh-positions");
|
||||||
|
QDomElement vinp_nm = info->doc->createElement("input");
|
||||||
|
vinp_nm.setAttribute("semantic","NORMAL");
|
||||||
|
vinp_nm.setAttribute("source","#vcg-mesh-normals");
|
||||||
|
|
||||||
|
vert.appendChild(vinp_pos);
|
||||||
|
vert.appendChild(vinp_nm);
|
||||||
|
|
||||||
|
meshnode.appendChild(vert);
|
||||||
|
|
||||||
|
QDomElement tri = info->doc->createElement("triangles");
|
||||||
|
|
||||||
|
|
||||||
|
QDomElement tinp_vert = info->doc->createElement("input");
|
||||||
|
tinp_vert.setAttribute("offset","0");
|
||||||
|
tinp_vert.setAttribute("semantic","VERTEX");
|
||||||
|
tinp_vert.setAttribute("source","#vcg-mesh-vertices");
|
||||||
|
QDomElement poly = info->doc->createElement("p");
|
||||||
|
QString triangles_tess;
|
||||||
|
int nface = 0;
|
||||||
|
triangles_tess.reserve(9*m.face.size());
|
||||||
|
for(SaveMeshType::FaceIterator itf = m.face.begin();itf != m.face.end();++itf)
|
||||||
|
{
|
||||||
|
if (!(itf->IsD()))
|
||||||
|
{
|
||||||
|
for(unsigned int ii = 0;ii < 3;++ii)
|
||||||
|
{
|
||||||
|
int ind_v = (*itf).V(ii) - &(m.vert[0]);
|
||||||
|
if (triangles_tess == "")
|
||||||
|
triangles_tess = QString::number(ind_v);
|
||||||
|
else triangles_tess = triangles_tess.append(" ").append(QString::number(ind_v));
|
||||||
|
}
|
||||||
|
++nface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tri.setAttribute("count",nface);
|
||||||
|
|
||||||
|
QDomText tri_list = info->doc->createTextNode(triangles_tess);
|
||||||
|
poly.appendChild(tri_list);
|
||||||
|
tri.appendChild(tinp_vert);
|
||||||
|
tri.appendChild(poly);
|
||||||
|
meshnode.appendChild(tri);
|
||||||
|
geonode.appendChild(meshnode);
|
||||||
|
geolib.at(0).appendChild(geonode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
removeChildNode(scenelst,"instance_visual_scene");
|
||||||
|
for(int vsscn = 0;vsscn < scenelst.size();++vsscn)
|
||||||
|
{
|
||||||
|
QString url = scenelst.at(vsscn).toElement().attribute("url");
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement vsnode = info->doc->createElement("instance_visual_scene");
|
||||||
|
vsnode.setAttribute("url","#vcg-scene-node");
|
||||||
|
scenelst.at(0).appendChild(vsnode);
|
||||||
|
|
||||||
|
|
||||||
|
int vsscene_size = vsscene.size();
|
||||||
|
assert(vsscene.size() == 1);
|
||||||
|
removeChildNode(vsscene,"visual_scene","id","vcg-scene-node");
|
||||||
|
QDomElement vslnode = info->doc->createElement("visual_scene");
|
||||||
|
vslnode.setAttribute("id","vcg-scene-node");
|
||||||
|
vslnode.setAttribute("name","vcg-untitled");
|
||||||
|
|
||||||
|
QDomElement vcgnode = info->doc->createElement("node");
|
||||||
|
vcgnode.setAttribute("id","vcg-node");
|
||||||
|
vcgnode.setAttribute("name","vcg-untitled");
|
||||||
|
|
||||||
|
/*QDomNodeList instgeo = info->doc->elementsByTagName("instance_geometry");
|
||||||
|
for(int jj = 0;jj < instgeo.size();++jj)
|
||||||
|
{
|
||||||
|
if (!instgeo.at(jj).isNull())
|
||||||
|
{
|
||||||
|
QDomNode par = instegeo.at(jj).parent();
|
||||||
|
par
|
||||||
|
}*/
|
||||||
|
|
||||||
|
QDomElement vcginst = info->doc->createElement("instance_geometry");
|
||||||
|
vcginst.setAttribute("url","#vcg-mesh-lib");
|
||||||
|
vcgnode.appendChild(vcginst);
|
||||||
|
vslnode.appendChild(vcgnode);
|
||||||
|
vsscene.at(0).appendChild(vslnode);
|
||||||
|
|
||||||
|
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
|
||||||
|
assert(geolib.size() == 1);
|
||||||
|
//removeChildNode(geolib.at(0));
|
||||||
|
|
||||||
|
/*QDomElement mshnode;
|
||||||
|
mshnode.setTagName("mesh");*/
|
||||||
|
|
||||||
|
removeChildNode(geolib.at(0),"geometry","id","vcg-mesh-lib");
|
||||||
|
QDomElement geonode = info->doc->createElement("geometry");
|
||||||
|
geonode.setAttribute("id","vcg-mesh-lib");
|
||||||
|
geonode.setAttribute("name","vcg-mesh");
|
||||||
|
|
||||||
|
QDomElement meshnode = info->doc->createElement("mesh");
|
||||||
|
|
||||||
|
QDomElement srcposnode = info->doc->createElement("source");
|
||||||
|
srcposnode.setAttribute("id","vcg-mesh-positions");
|
||||||
|
srcposnode.setAttribute("name","vcg-mesh-positions");
|
||||||
|
|
||||||
|
QDomElement arrayposnode = info->doc->createElement("float_array");
|
||||||
|
arrayposnode.setAttribute("id","vcg-mesh-positions-array");
|
||||||
|
|
||||||
|
QString arrp;
|
||||||
|
arrp.reserve(8 * m.vert.size());
|
||||||
|
QString arrn;
|
||||||
|
arrn.reserve(8 * m.vert.size());
|
||||||
|
int nvert = 0;
|
||||||
|
for(SaveMeshType::VertexIterator it = m.vert.begin();it != m.vert.end();++it)
|
||||||
|
{
|
||||||
|
if (!(it->IsD()))
|
||||||
|
{
|
||||||
|
arrp.append(QString::number(it->P().X()) + " " +QString::number(it->P().Y()) + " " + QString::number(it->P().Z()) + " ");
|
||||||
|
arrn.append(QString::number(it->N().X()) + " " + QString::number(it->N().Y()) + " " + QString::number(it->N().Z())+ " ");
|
||||||
|
//arrp.append(QString::number(it->P().X()).append(" ").append(QString::number(it->P().Y())).append(" ").append(QString::number(it->P().Z())).append(" "));
|
||||||
|
//arrp.append(QString::number(it->N().X()).append(" ").append(QString::number(it->N().Y())).append(" ").append(QString::number(it->N().Z())).append(" "));
|
||||||
|
++nvert;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arrayposnode.setAttribute("count",QString::number(nvert * 3));
|
||||||
|
QDomText ap = info->doc->createTextNode(arrp);
|
||||||
|
|
||||||
|
QDomElement technode = info->doc->createElement("technique_common");
|
||||||
|
QDomElement accnode = info->doc->createElement("accessor");
|
||||||
|
accnode.setAttribute("source","#vcg-mesh-positions-array");
|
||||||
|
accnode.setAttribute("count",QString::number(nvert));
|
||||||
|
accnode.setAttribute("stride","3");
|
||||||
|
|
||||||
|
QDomElement parxnode = info->doc->createElement("param");
|
||||||
|
parxnode.setAttribute("name","X");
|
||||||
|
parxnode.setAttribute("type","float");
|
||||||
|
QDomElement parynode = info->doc->createElement("param");
|
||||||
|
parynode.setAttribute("name","Y");
|
||||||
|
parynode.setAttribute("type","float");
|
||||||
|
QDomElement parznode = info->doc->createElement("param");
|
||||||
|
parznode.setAttribute("name","Z");
|
||||||
|
parznode.setAttribute("type","float");
|
||||||
|
|
||||||
|
accnode.appendChild(parxnode);
|
||||||
|
accnode.appendChild(parynode);
|
||||||
|
accnode.appendChild(parznode);
|
||||||
|
technode.appendChild(accnode);
|
||||||
|
arrayposnode.appendChild(ap);
|
||||||
|
srcposnode.appendChild(arrayposnode);
|
||||||
|
srcposnode.appendChild(technode);
|
||||||
|
|
||||||
|
meshnode.appendChild(srcposnode);
|
||||||
|
|
||||||
|
QDomElement srcnmnode = info->doc->createElement("source");
|
||||||
|
srcnmnode.setAttribute("id","vcg-mesh-normals");
|
||||||
|
srcnmnode.setAttribute("name","vcg-mesh-normals");
|
||||||
|
|
||||||
|
QDomElement arraynmnode = info->doc->createElement("float_array");
|
||||||
|
arraynmnode.setAttribute("id","vcg-mesh-normals-array");
|
||||||
|
arraynmnode.setAttribute("count",QString::number(nvert * 3));
|
||||||
|
|
||||||
|
QDomElement technode2 = info->doc->createElement("technique_common");
|
||||||
|
QDomElement accnode2 = info->doc->createElement("accessor");
|
||||||
|
accnode2.setAttribute("source","#vcg-mesh-normals-array");
|
||||||
|
accnode2.setAttribute("count",QString::number(nvert));
|
||||||
|
accnode2.setAttribute("stride","3");
|
||||||
|
|
||||||
|
QDomElement parxnode2 = info->doc->createElement("param");
|
||||||
|
parxnode2.setAttribute("name","X");
|
||||||
|
parxnode2.setAttribute("type","float");
|
||||||
|
QDomElement parynode2 = info->doc->createElement("param");
|
||||||
|
parynode2.setAttribute("name","Y");
|
||||||
|
parynode2.setAttribute("type","float");
|
||||||
|
QDomElement parznode2 = info->doc->createElement("param");
|
||||||
|
parznode2.setAttribute("name","Z");
|
||||||
|
parznode2.setAttribute("type","float");
|
||||||
|
|
||||||
|
QDomText an = info->doc->createTextNode(arrn);
|
||||||
|
|
||||||
|
|
||||||
|
accnode2.appendChild(parxnode2);
|
||||||
|
accnode2.appendChild(parynode2);
|
||||||
|
accnode2.appendChild(parznode2);
|
||||||
|
technode2.appendChild(accnode2);
|
||||||
|
arraynmnode.appendChild(an);
|
||||||
|
srcnmnode.appendChild(arraynmnode);
|
||||||
|
srcnmnode.appendChild(technode2);
|
||||||
|
|
||||||
|
meshnode.appendChild(srcnmnode);
|
||||||
|
|
||||||
|
QDomElement vert = info->doc->createElement("vertices");
|
||||||
|
vert.setAttribute("id","vcg-mesh-vertices");
|
||||||
|
QDomElement vinp_pos = info->doc->createElement("input");
|
||||||
|
vinp_pos.setAttribute("semantic","POSITION");
|
||||||
|
vinp_pos.setAttribute("source","#vcg-mesh-positions");
|
||||||
|
QDomElement vinp_nm = info->doc->createElement("input");
|
||||||
|
vinp_nm.setAttribute("semantic","NORMAL");
|
||||||
|
vinp_nm.setAttribute("source","#vcg-mesh-normals");
|
||||||
|
|
||||||
|
vert.appendChild(vinp_pos);
|
||||||
|
vert.appendChild(vinp_nm);
|
||||||
|
|
||||||
|
meshnode.appendChild(vert);
|
||||||
|
|
||||||
|
QDomElement tri = info->doc->createElement("triangles");
|
||||||
|
|
||||||
|
|
||||||
|
QDomElement tinp_vert = info->doc->createElement("input");
|
||||||
|
tinp_vert.setAttribute("offset","0");
|
||||||
|
tinp_vert.setAttribute("semantic","VERTEX");
|
||||||
|
tinp_vert.setAttribute("source","#vcg-mesh-vertices");
|
||||||
|
QDomElement poly = info->doc->createElement("p");
|
||||||
|
QString triangles_tess;
|
||||||
|
int nface = 0;
|
||||||
|
triangles_tess.reserve(9*m.face.size());
|
||||||
|
for(SaveMeshType::FaceIterator itf = m.face.begin();itf != m.face.end();++itf)
|
||||||
|
{
|
||||||
|
if (!(itf->IsD()))
|
||||||
|
{
|
||||||
|
for(unsigned int ii = 0;ii < 3;++ii)
|
||||||
|
{
|
||||||
|
int ind_v = (*itf).V(ii) - &(m.vert[0]);
|
||||||
|
if (triangles_tess == "")
|
||||||
|
triangles_tess = QString::number(ind_v);
|
||||||
|
else triangles_tess = triangles_tess.append(" ").append(QString::number(ind_v));
|
||||||
|
}
|
||||||
|
++nface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tri.setAttribute("count",nface);
|
||||||
|
|
||||||
|
QDomText tri_list = info->doc->createTextNode(triangles_tess);
|
||||||
|
poly.appendChild(tri_list);
|
||||||
|
tri.appendChild(tinp_vert);
|
||||||
|
tri.appendChild(poly);
|
||||||
|
meshnode.appendChild(tri);
|
||||||
|
geonode.appendChild(meshnode);
|
||||||
|
geolib.at(0).appendChild(geonode);
|
||||||
|
}
|
||||||
|
|
||||||
QString st = info->doc->toString();
|
QString st = info->doc->toString();
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
|
|
Loading…
Reference in New Issue