Debian Codegraph @

vcg/wrap/io_trimesh/import_dae.h

raw symbols SCIP
1 #ifndef __VCGLIB_IMPORTERDAE
2 #define __VCGLIB_IMPORTERDAE
3
4 //importer for collada's files
5
6 #include<wrap/dae/util_dae.h>
7
8 namespace vcg {
9 namespace tri {
10 namespace io {
11
12 template<typename OpenMeshType>
13 class ImporterDAE : public UtilDAE
14 {
15
16 private:
17 static int WedgeNormalAttribute(OpenMeshType& m,const QStringList face,const QStringList wn,const QDomNode wnsrc,const int meshfaceind,const int faceind,const int component)
18 {
19 int indnm = -1;
20 if (!wnsrc.isNull())
21 {
22 indnm = face.at(faceind).toInt();
23 assert(indnm * 3 < wn.size());
24 m.face[meshfaceind].WN(component) = vcg::Point3f(wn.at(indnm * 3).toFloat(),wn.at(indnm * 3 + 1).toFloat(),wn.at(indnm * 3 + 2).toFloat());
25 }
26 return indnm;
27 }
28
29 static int WedgeTextureAttribute(OpenMeshType& m,const QStringList face,int ind_txt,const QStringList wt,const QDomNode wtsrc,const int meshfaceind,const int faceind,const int component,const int stride = 2)
30 {
31 int indtx = -1;
32 if (!wtsrc.isNull())
33 {
34 indtx = face.at(faceind).toInt();
35 int num = wt.size();
36 assert(indtx * stride < wt.size());
37 m.face[meshfaceind].WT(component) = vcg::TexCoord2<float>();
38 m.face[meshfaceind].WT(component).U() = wt.at(indtx * stride).toFloat();
39 m.face[meshfaceind].WT(component).V() = wt.at(indtx * stride + 1).toFloat();
40
41 m.face[meshfaceind].WT(component).N() = ind_txt;
42
43 }
44 return indtx;
45 }
46
47 static int WedgeColorAttribute(OpenMeshType& m,const QStringList face,const QStringList wc,const QDomNode wcsrc,const int meshfaceind,const int faceind,const int component)
48 {
49 int indcl;
50 if (!wcsrc.isNull())
51 {
52 indcl = face.at(faceind).toInt();
53 assert(indcl * 4 < wc.size());
54 m.face[meshfaceind].WC(component) = vcg::Color4b(wc.at(indcl * 4).toFloat(),wc.at(indcl * 4 + 1).toFloat(),wc.at(indcl * 4 + 2).toFloat(),wc.at(indcl * 4 + 3).toFloat());
55 }
56 return indcl;
57 }
58
59 static void FindStandardWedgeAttributes(WedgeAttribute& wed,const QDomNode nd,const QDomDocument doc)
60 {
61 wed.wnsrc = findNodeBySpecificAttributeValue(nd,"input","semantic","NORMAL");
62 wed.offnm = findStringListAttribute(wed.wn,wed.wnsrc,nd,doc,"NORMAL");
63
64 wed.wtsrc = findNodeBySpecificAttributeValue(nd,"input","semantic","TEXCOORD");
65 if (!wed.wtsrc.isNull())
66 {
67 QDomNode src = attributeSourcePerSimplex(nd,doc,"TEXCOORD");
68 if (isThereTag(src,"accessor"))
69 {
70 QDomNodeList wedatts = src.toElement().elementsByTagName("accessor");
71 wed.stride = wedatts.at(0).toElement().attribute("stride").toInt();
72 }
73 else
74 wed.stride = 2;
75 }
76 else
77 wed.stride = 2;
78
79 wed.offtx = findStringListAttribute(wed.wt,wed.wtsrc,nd,doc,"TEXCOORD");
80
81 wed.wcsrc = findNodeBySpecificAttributeValue(nd,"input","semantic","COLOR");
82 wed.offcl = findStringListAttribute(wed.wc,wed.wcsrc,nd,doc,"COLOR");
83 }
84
85 static DAEError LoadPolygonalMesh(QDomNodeList& polypatch,OpenMeshType& m,const size_t offset,AdditionalInfoDAE* info)
86 {
87 return E_NOERROR;
88 }
89
90 static DAEError LoadPolygonalListMesh(QDomNodeList& polylist,OpenMeshType& m,const size_t offset,AdditionalInfoDAE* info)
91 {
92 typedef PolygonalMesh< MyPolygon<typename OpenMeshType::VertexType> > PolyMesh;
93 PolyMesh pm;
94
95 //copying vertices
96 for(typename OpenMeshType::VertexIterator itv = m.vert.begin();itv != m.vert.end();++itv)
97 {
98 vcg::Point3f p(itv->P().X(),itv->P().Y(),itv->P().Z());
99 typename PolyMesh::VertexType v;
100 v.P() = p;
101 pm.vert.push_back(v);
102 }
103
104 int polylist_size = polylist.size();
105 for(int pl = 0; pl < polylist_size;++pl)
106 {
107 QString mat = polylist.at(pl).toElement().attribute(QString("material"));
108 QDomNode txt_node = textureFinder(mat,*(info->dae->doc));
109 int ind_txt = -1;
110 if (!txt_node.isNull())
111 ind_txt = indexTextureByImgNode(*(info->dae->doc),txt_node);
112
113 //PolyMesh::PERWEDGEATTRIBUTETYPE att = PolyMesh::NONE;
114 WedgeAttribute wa;
115 FindStandardWedgeAttributes(wa,polylist.at(pl),*(info->dae->doc));
116 QStringList vertcount;
117 valueStringList(vertcount,polylist.at(pl),"vcount");
118 int indforpol = findOffSetForASingleSimplex(polylist.at(pl));
119 int offpols = 0;
120 int npolig = vertcount.size();
121 QStringList polyind;
122 valueStringList(polyind,polylist.at(pl),"p");
123 for(int ii = 0;ii < npolig;++ii)
124 {
125 int nvert = vertcount.at(ii).toInt();
126 typename PolyMesh::FaceType p(nvert);
127
128 for(int iv = 0;iv < nvert;++iv)
129 {
130 int index = offset + polyind.at(offpols + iv * indforpol).toInt();
131 p._pv[iv] = &(pm.vert[index]);
132 int nmindex = -1;
133
134 if (!wa.wnsrc.isNull())
135 nmindex = offset + polyind.at(offpols + iv * indforpol + wa.offnm).toInt();
136
137 int txindex = -1;
138 if (!wa.wtsrc.isNull())
139 {
140 txindex = offset + polyind.at(offpols + iv * indforpol + wa.offtx).toInt();
141 /*p._txc[iv].U() = wa.wt.at(txindex * 2).toFloat();
142 p._txc[iv].V() = wa.wt.at(txindex * 2 + 1).toFloat();
143 p._txc[iv].N() = ind_txt;*/
144 }
145 }
146 pm._pols.push_back(p);
147 offpols += nvert * indforpol;
148 }
149 }
150 pm.triangulate(m);
151 return E_NOERROR;
152 }
153
154 static DAEError LoadTriangularMesh(QDomNodeList& tripatch,OpenMeshType& m,const size_t offset,AdditionalInfoDAE* info)
155 {
156 int tripatch_size = tripatch.size();
157 for(int tript = 0; tript < tripatch_size;++tript)
158 {
159 QString mat = tripatch.at(tript).toElement().attribute(QString("material"));
160 QDomNode txt_node = textureFinder(mat,*(info->dae->doc));
161 int ind_txt = -1;
162 if (!txt_node.isNull())
163 ind_txt = indexTextureByImgNode(*(info->dae->doc),txt_node);
164
165 int nfcatt = tripatch.at(tript).toElement().elementsByTagName("input").size();
166
167 QStringList face;
168 valueStringList(face,tripatch.at(tript),"p");
169 int face_size = face.size();
170 int offsetface = (int)m.face.size();
171 if (face_size != 0)
172 {
173 vcg::tri::Allocator<OpenMeshType>::AddFaces(m,face_size / (nfcatt * 3));
174 WedgeAttribute wa;
175 FindStandardWedgeAttributes(wa,tripatch.at(tript),*(info->dae->doc));
176
177 int jj = 0;
178 //int dd = m.face.size();
179 for(int ff = offsetface;ff < (int) m.face.size();++ff)
180 {
181
182 for(unsigned int tt = 0;tt < 3;++tt)
183 {
184 int indvt = face.at(jj).toInt();
185 assert(indvt + offset < m.vert.size());
186 m.face[ff].V(tt) = &(m.vert[indvt + offset]);
187
188 if(tri::HasPerWedgeNormal(m))
189 WedgeNormalAttribute(m,face,wa.wn,wa.wnsrc,ff,jj + wa.offnm,tt);
190 if(tri::HasPerWedgeTexCoord(m) && ind_txt != -1)
191 {
192 WedgeTextureAttribute(m,face,ind_txt,wa.wt,wa.wtsrc,ff,jj + wa.offtx,tt,wa.stride);
193 }
194 if(tri::HasPerWedgeColor(m))
195 WedgeColorAttribute(m,face,wa.wc,wa.wcsrc,ff,jj + wa.offcl,tt);
196
197 jj += nfcatt;
198 }
199 }
200 }
201 }
202 return E_NOERROR;
203 }
204
205
206 static int LoadMesh(OpenMeshType& m,AdditionalInfoDAE* info,const QDomNode& geo,const vcg::Matrix44f& t, CallBackPos *cb=0)
207 {
208 if (isThereTag(geo,"mesh"))
209 {
210 if ((cb !=NULL) && (((info->numvert + info->numface)%100)==0) && !(*cb)((100*(info->numvert + info->numface))/(info->numvert + info->numface), "Vertex Loading"))
211 return E_CANTOPEN;
212 /*QDomNodeList geosrc = geo.toElement().elementsByTagName("source");
213 int geosrc_size = geosrc.size();
214 if (geosrc_size < 1)
215 return E_NOVERTEXPOSITION;*/
216
217 QDomNodeList vertices = geo.toElement().elementsByTagName("vertices");
218 int vertices_size = vertices.size();
219 if (vertices_size != 1)
220 return E_INCOMPATIBLECOLLADA141FORMAT;
221
222 QDomNode srcnode = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"POSITION");
223 if (srcnode.isNull())
224 return E_NOVERTEXPOSITION;
225
226 QStringList geosrcposarr;
227 valueStringList(geosrcposarr,srcnode,"float_array");
228
229 int geosrcposarr_size = geosrcposarr.size();
230 if ((geosrcposarr_size % 3) != 0)
231 return E_CANTOPEN;
232 int nvert = geosrcposarr_size / 3;
233 size_t offset = m.vert.size();
234 if (geosrcposarr_size != 0)
235 {
236 vcg::tri::Allocator<OpenMeshType>::AddVertices(m,nvert);
237
238 QDomNode srcnodenorm = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"NORMAL");
239 QStringList geosrcvertnorm;
240 if (!srcnodenorm.isNull())
241 valueStringList(geosrcvertnorm,srcnodenorm,"float_array");
242
243 QDomNode srcnodetext = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"TEXCOORD");
244 QStringList geosrcverttext;
245 if (!srcnodetext.isNull())
246 valueStringList(geosrcverttext,srcnodetext,"float_array");
247
248 QDomNode srcnodecolor = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"COLOR");
249 QStringList geosrcvertcol;
250 if (!srcnodecolor.isNull())
251 valueStringList(geosrcvertcol,srcnodecolor,"float_array");
252
253 int ii = 0;
254 for(size_t vv = offset;vv < m.vert.size();++vv)
255 {
256
257 assert((ii * 3 < geosrcposarr_size) && (ii * 3 + 1 < geosrcposarr_size) && (ii * 3 + 2 < geosrcposarr_size));
258 vcg::Point4f tmp = t * vcg::Point4f(geosrcposarr[ii * 3].toFloat(),geosrcposarr[ii * 3 + 1].toFloat(),geosrcposarr[ii * 3 + 2].toFloat(),1.0f);
259 m.vert[vv].P() = vcg::Point3f(tmp.X(),tmp.Y(),tmp.Z());
260
261 if (!srcnodenorm.isNull())
262 {
263 assert((ii * 3 < geosrcvertnorm.size()) && (ii * 3 + 1 < geosrcvertnorm.size()) && (ii * 3 + 2 < geosrcvertnorm.size()));
264 vcg::Matrix44f intr44 = vcg::Inverse(t);
265 vcg::Transpose(intr44);
266 Matrix33f intr33;
267 for(unsigned int rr = 0; rr < 2; ++rr)
268 {
269 for(unsigned int cc = 0;cc < 2;++cc)
270 intr33[rr][cc] = intr44[rr][cc];
271 }
272 m.vert[vv].N() = (intr33 * vcg::Point3f(geosrcvertnorm[ii * 3].toFloat(),geosrcvertnorm[ii * 3 + 1].toFloat(),geosrcvertnorm[ii * 3 + 2].toFloat())).Normalize();
273 }
274
275 /*if (!srcnodecolor.isNull())
276 {
277 assert((ii * 4 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size()) && (ii * 4 + 2 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size()));
278 m.vert[vv].C() = vcg::Color4b(geosrcvertcol[ii * 4].toFloat(),geosrcvertcol[ii * 4 + 1].toFloat(),geosrcvertcol[ii * 4 + 2].toFloat(),geosrcvertcol[ii * 4 + 3].toFloat());
279 }*/
280
281 if (!srcnodetext.isNull())
282 {
283
284 assert((ii * 2 < geosrcverttext.size()) && (ii * 2 + 1 < geosrcverttext.size()));
285 m.vert[vv].T() = vcg::TexCoord2<float>();
286 m.vert[vv].T().u() = geosrcverttext[ii * 2].toFloat();
287 m.vert[vv].T().v() = geosrcverttext[ii * 2 + 1].toFloat();
288 }
289 ++ii;
290 }
291
292 QDomNodeList tripatch = geo.toElement().elementsByTagName("triangles");
293 int tripatch_size = tripatch.size();
294 QDomNodeList polypatch = geo.toElement().elementsByTagName("polygons");
295 int polypatch_size = polypatch.size();
296 QDomNodeList polylist = geo.toElement().elementsByTagName("polylist");
297 int polylist_size = polylist.size();
298 if ((tripatch_size == 0) && (polypatch_size == 0) && (polylist_size == 0))
299 return E_NOPOLYGONALMESH;
300
301 DAEError err = E_NOERROR;
302 if (tripatch_size != 0)
303 err = LoadTriangularMesh(tripatch,m,offset,info);
304 else
305 if (polypatch_size != 0)
306 err = LoadPolygonalMesh(polypatch,m,offset,info);
307 else
308 if (polylist_size != 0)
309 err = LoadPolygonalListMesh(polylist,m,offset,info);
310 if (err != E_NOERROR)
311 return err;
312 }
313 return E_NOERROR;
314 }
315 else return E_NOMESH;
316 }
317
318 static void GetTexCoord(const QDomDocument& doc,AdditionalInfoDAE* inf)
319 {
320 QDomNodeList txlst = doc.elementsByTagName("library_images");
321 for(int img = 0;img < txlst.at(0).childNodes().size();++img)
322 {
323 QDomNodeList nlst = txlst.at(0).childNodes().at(img).toElement().elementsByTagName("init_from");
324 if (nlst.size() > 0)
325 {
326 inf->texturefile.push_back(nlst.at(0).firstChild().nodeValue());
327 }
328 }
329 }
330
331 public:
332
333 //merge all meshes in the collada's file in the templeted mesh m
334 //I assume the mesh
335
336 static int Open(OpenMeshType& m,const char* filename,AdditionalInfo*& info, CallBackPos *cb=0)
337 {
338 AdditionalInfoDAE* inf = new AdditionalInfoDAE();
339 inf->dae = new InfoDAE();
340
341 QDomDocument* doc = new QDomDocument(filename);
342 QFile file(filename);
343 if (!file.open(QIODevice::ReadOnly))
344 return E_CANTOPEN;
345 if (!doc->setContent(&file))
346 {
347 file.close();
348 return E_CANTOPEN;
349 }
350 file.close();
351
352 inf->dae->doc = doc;
353 //GetTexture(*(info->doc),inf);
354
355 //scene->instance_visual_scene
356 QDomNodeList scenes = inf->dae->doc->elementsByTagName("scene");
357 int scn_size = scenes.size();
358 if (scn_size == 0)
359 return E_NO3DSCENE;
360
361 int problem = E_NOERROR;
362 bool found_a_mesh = false;
363 //Is there geometry in the file?
364 bool geoinst_found = false;
365 //for each scene in COLLADA FILE
366 for(int scn = 0;scn < scn_size;++scn)
367 {
368 QDomNodeList instscenes = scenes.at(scn).toElement().elementsByTagName("instance_visual_scene");
369 int instscn_size = instscenes.size();
370 if (instscn_size == 0)
371 return E_INCOMPATIBLECOLLADA141FORMAT;
372
373 //for each scene instance in a COLLADA scene
374 for(int instscn = 0;instscn < instscn_size; ++instscn)
375 {
376 QString libscn_url;
377 referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
378 QDomNode nd = QDomNode(*(inf->dae->doc));
379 QDomNode visscn = findNodeBySpecificAttributeValue(*(inf->dae->doc),"visual_scene","id",libscn_url);
380 if(visscn.isNull())
381 return E_UNREFERENCEBLEDCOLLADAATTRIBUTE;
382
383 //for each node in the libscn_url visual scene
384 QDomNodeList visscn_child = visscn.childNodes();
385
386 //for each direct child of a libscn_url visual scene find if there is some geometry instance
387 for(int chdind = 0; chdind < visscn_child.size();++chdind)
388 {
389 QDomNodeList geoinst = visscn_child.at(chdind).toElement().elementsByTagName("instance_geometry");
390 int geoinst_size = geoinst.size();
391 if (geoinst_size != 0)
392 {
393
394 geoinst_found |= true;
395 QDomNodeList geolib = inf->dae->doc->elementsByTagName("library_geometries");
396 assert(geolib.size() == 1);
397 //!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
398 for(int geoinst_ind = 0;geoinst_ind < geoinst_size;++geoinst_ind)
399 {
400 QString geo_url;
401 referenceToANodeAttribute(geoinst.at(geoinst_ind),"url",geo_url);
402
403 QDomNode geo = findNodeBySpecificAttributeValue(geolib.at(0),"geometry","id",geo_url);
404 if (geo.isNull())
405 return E_UNREFERENCEBLEDCOLLADAATTRIBUTE;
406 vcg::Matrix44f tr;
407 tr.SetIdentity();
408 TransfMatrix(visscn,geoinst.at(geoinst_ind),tr);
409 problem |= LoadMesh(m,inf,geo,tr);
410 if (problem & E_NOMESH)
411 found_a_mesh |= false;
412 else
413 found_a_mesh = true;
414 }
415 }
416 }
417 //if there is at least a mesh I clean the problem status variable from E_NOMESH ERROR
418
419 if (((problem & E_NOMESH) || (problem & E_NOPOLYGONALMESH)) && (found_a_mesh))
420 {
421 if (problem & E_NOMESH)
422 problem = problem & ~E_NOMESH;
423 if (problem & E_NOPOLYGONALMESH)
424 problem = problem & ~E_NOPOLYGONALMESH;
425 }
426 }
427 }
428
429 if (!geoinst_found)
430 {
431 QDomNodeList geolib = inf->dae->doc->elementsByTagName("library_geometries");
432 assert(geolib.size() == 1);
433 QDomNodeList geochild = geolib.at(0).childNodes();
434 int geochild_size = geochild.size();
435 int problem = 0;
436 for(int chd = 0;chd < geochild_size;++chd)
437 {
438 vcg::Matrix44f tmp;
439 tmp.SetIdentity();
440 problem |= LoadMesh(m,inf,geochild.at(chd),tmp);
441 }
442 }
443 //if there is at least a mesh I clean the problem status variable from E_NOMESH or E_NOPOLYGONALMESH ERROR
444 if (((problem & E_NOMESH) || (problem & E_NOPOLYGONALMESH)) && (found_a_mesh))
445 {
446 if (problem & E_NOMESH)
447 problem = problem & ~E_NOMESH;
448 if (problem & E_NOPOLYGONALMESH)
449 problem = problem & ~E_NOPOLYGONALMESH;
450 }
451 info = inf;
452 return problem;
453 }
454
455 static bool LoadMask(const char * filename, AdditionalInfoDAE*& addinfo)
456 {
457 bool bHasPerWedgeTexCoord = false;
458 bool bHasPerWedgeNormal = false;
459 bool bHasPerVertexColor = false;
460 bool bHasPerFaceColor = false;
461 bool bHasPerVertexNormal = false;
462 bool bHasPerVertexText = false;
463
464 AdditionalInfoDAE* info = new AdditionalInfoDAE();
465 info->dae = new InfoDAE();
466
467
468 QDomDocument* doc = new QDomDocument(filename);
469 QFile file(filename);
470 if (!file.open(QIODevice::ReadOnly))
471 return false;
472 if (!doc->setContent(&file))
473 {
474 file.close();
475 return false;
476 }
477 file.close();
478
479
480 info->dae->doc = doc;
481 GetTexCoord(*(info->dae->doc),info);
482 QDomNodeList scenes = info->dae->doc->elementsByTagName("scene");
483 int scn_size = scenes.size();
484
485
486 //Is there geometry in the file?
487 bool geoinst_found = false;
488 //for each scene in COLLADA FILE
489 for(int scn = 0;scn < scn_size;++scn)
490 {
491 QDomNodeList instscenes = scenes.at(scn).toElement().elementsByTagName("instance_visual_scene");
492 int instscn_size = instscenes.size();
493 if (instscn_size == 0)
494 return false;
495
496 //for each scene instance in a COLLADA scene
497 for(int instscn = 0;instscn < instscn_size; ++instscn)
498 {
499 QString libscn_url;
500 referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
501 QDomNode nd = QDomNode(*(info->dae->doc));
502 QDomNode visscn = findNodeBySpecificAttributeValue(*(info->dae->doc),"visual_scene","id",libscn_url);
503 if(visscn.isNull())
504 return false;
505
506 //for each node in the libscn_url visual scene
507 //QDomNodeList& visscn_child = visscn.childNodes();
508 QDomNodeList visscn_child = visscn.childNodes();
509
510 //for each direct child of a libscn_url visual scene find if there is some geometry instance
511 for(int chdind = 0; chdind < visscn_child.size();++chdind)
512 {
513 //QDomNodeList& geoinst = visscn_child.at(chdind).toElement().elementsByTagName("instance_geometry");
514 QDomNodeList geoinst = visscn_child.at(chdind).toElement().elementsByTagName("instance_geometry");
515 int geoinst_size = geoinst.size();
516 if (geoinst_size != 0)
517 {
518
519 geoinst_found |= true;
520 QDomNodeList geolib = info->dae->doc->elementsByTagName("library_geometries");
521 assert(geolib.size() == 1);
522 //!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
523 info->numvert = 0;
524 info->numface = 0;
525 for(int geoinst_ind = 0;geoinst_ind < geoinst_size;++geoinst_ind)
526 {
527 QString geo_url;
528 referenceToANodeAttribute(geoinst.at(geoinst_ind),"url",geo_url);
529
530 QDomNode geo = findNodeBySpecificAttributeValue(geolib.at(0),"geometry","id",geo_url);
531 if (geo.isNull())
532 return false;
533
534 QDomNodeList vertlist = geo.toElement().elementsByTagName("vertices");
535
536 for(int vert = 0;vert < vertlist.size();++vert)
537 {
538 QDomNode no;
539 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","POSITION");
540 QString srcurl;
541 referenceToANodeAttribute(no,"source",srcurl);
542 no = findNodeBySpecificAttributeValue(geo,"source","id",srcurl);
543 QDomNodeList fa = no.toElement().elementsByTagName("float_array");
544 assert(fa.size() == 1);
545 info->numvert += (fa.at(0).toElement().attribute("count").toInt() / 3);
546 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","COLOR");
547 if (!no.isNull())
548 bHasPerVertexColor = true;
549 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","NORMAL");
550 if (!no.isNull())
551 bHasPerVertexNormal = true;
552 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","TEXCOORD");
553 if (!no.isNull())
554 bHasPerVertexText = true;
555 }
556
557 const char* arr[] = {"triangles","polylist","polygons"};
558
559 for(unsigned int tt= 0;tt < 3;++tt)
560 {
561 QDomNodeList facelist = geo.toElement().elementsByTagName(arr[tt]);
562 for(int face = 0;face < facelist.size();++face)
563 {
564 info->numface += facelist.at(face).toElement().attribute("count").toInt() ;
565 QDomNode no;
566 no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","NORMAL");
567 if (!no.isNull())
568 bHasPerWedgeNormal = true;
569 no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","TEXCOORD");
570 if (!no.isNull())
571 bHasPerWedgeTexCoord = true;
572 }
573 }
574 }
575 }
576 }
577 }
578 }
579
580 if (!geoinst_found)
581 {
582 QDomNodeList geolib = info->dae->doc->elementsByTagName("library_geometries");
583 assert(geolib.size() == 1);
584 QDomNodeList geochild = geolib.at(0).toElement().elementsByTagName("geometry");
585 //!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
586 info->numvert = 0;
587 info->numface = 0;
588 for(int geoinst_ind = 0;geoinst_ind < geochild.size();++geoinst_ind)
589 {
590 QDomNodeList vertlist = geochild.at(geoinst_ind).toElement().elementsByTagName("vertices");
591
592 for(int vert = 0;vert < vertlist.size();++vert)
593 {
594 QDomNode no;
595 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","POSITION");
596 QString srcurl;
597 referenceToANodeAttribute(no,"source",srcurl);
598 no = findNodeBySpecificAttributeValue(geochild.at(geoinst_ind),"source","id",srcurl);
599 QDomNodeList fa = no.toElement().elementsByTagName("float_array");
600 assert(fa.size() == 1);
601 info->numvert += (fa.at(0).toElement().attribute("count").toInt() / 3);
602 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","COLOR");
603 if (!no.isNull())
604 bHasPerVertexColor = true;
605 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","NORMAL");
606 if (!no.isNull())
607 bHasPerVertexNormal = true;
608 no = findNodeBySpecificAttributeValue(vertlist.at(vert),"input","semantic","TEXCOORD");
609 if (!no.isNull())
610 bHasPerVertexText = true;
611 }
612
613 QDomNodeList facelist = geochild.at(geoinst_ind).toElement().elementsByTagName("triangles");
614 for(int face = 0;face < facelist.size();++face)
615 {
616 info->numface += facelist.at(face).toElement().attribute("count").toInt() ;
617 QDomNode no;
618 no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","NORMAL");
619 if (!no.isNull())
620 bHasPerWedgeNormal = true;
621 no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","TEXCOORD");
622 if (!no.isNull())
623 bHasPerWedgeTexCoord = true;
624 }
625 }
626 }
627
628 info->mask = 0;
629
630 if (bHasPerWedgeTexCoord)
631 info->mask |= vcg::tri::io::Mask::IOM_WEDGTEXCOORD;
632 if (bHasPerWedgeNormal)
633 info->mask |= vcg::tri::io::Mask::IOM_WEDGNORMAL;
634 if (bHasPerVertexColor)
635 info->mask |= vcg::tri::io::Mask::IOM_VERTCOLOR;
636 if (bHasPerFaceColor)
637 info->mask |= vcg::tri::io::Mask::IOM_FACECOLOR;
638 if (bHasPerVertexNormal)
639 info->mask |= vcg::tri::io::Mask::IOM_VERTNORMAL;
640 if (bHasPerVertexText)
641 info->mask |= vcg::tri::io::Mask::IOM_VERTTEXCOORD;
642
643
644
645 delete (info->dae->doc);
646 info->dae->doc = NULL;
647 addinfo = info;
648 return true;
649 }
650 };
651 }
652 }
653 }
654
655 #endif