Corrected texture loading. Now symbolic material binding are respected during the traversal. Still to be cleaned up.
This commit is contained in:
parent
f614f1b5ac
commit
0b6af20c93
|
@ -52,46 +52,24 @@
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace tri {
|
namespace tri {
|
||||||
namespace io {
|
namespace io {
|
||||||
class InfoDAE
|
class InfoDAE : public AdditionalInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
InfoDAE()
|
InfoDAE() :AdditionalInfo(){
|
||||||
{
|
|
||||||
doc = NULL;
|
doc = NULL;
|
||||||
|
textureIdMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
~InfoDAE()
|
~InfoDAE(){
|
||||||
{
|
if(doc!=NULL) delete doc;
|
||||||
delete doc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QDomDocument* doc;
|
QDomDocument* doc;
|
||||||
};
|
QMap<QString,int> textureIdMap;
|
||||||
|
|
||||||
class AdditionalInfoDAE : public AdditionalInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
vcg::tri::io::InfoDAE* dae;
|
|
||||||
std::vector<QString> texturefile;
|
|
||||||
|
|
||||||
AdditionalInfoDAE()
|
|
||||||
:AdditionalInfo()
|
|
||||||
{
|
|
||||||
mask = 0;
|
|
||||||
numvert = 0;
|
|
||||||
numface = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
~AdditionalInfoDAE()
|
|
||||||
{
|
|
||||||
delete dae;
|
|
||||||
texturefile.clear();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class UtilDAE
|
class UtilDAE
|
||||||
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum DAEError
|
enum DAEError
|
||||||
|
@ -482,35 +460,33 @@ namespace io {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static QDomNode textureFinder(const QString& textname,const QDomDocument doc)
|
|
||||||
{
|
|
||||||
//visual_scene -> instance_material
|
|
||||||
QDomNodeList vis_scn = doc.elementsByTagName("library_visual_scenes");
|
|
||||||
if (vis_scn.size() != 1)
|
|
||||||
return QDomNode();
|
|
||||||
QDomNode symb = findNodeBySpecificAttributeValue(vis_scn.at(0),QString("instance_material"),QString("symbol"),textname);
|
|
||||||
if (symb.isNull())
|
|
||||||
return QDomNode();
|
|
||||||
QString tar = symb.toElement().attribute("target");
|
|
||||||
if (tar.isNull())
|
|
||||||
return QDomNode();
|
|
||||||
tar = tar.remove('#');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Very important procedure
|
||||||
|
it has the task to finde the name of the image node corresponding to a given material id,
|
||||||
|
it assuemes that the material name that is passed have already been bound with the current bindings
|
||||||
|
*/
|
||||||
|
|
||||||
|
inline static QDomNode textureFinder(QString& boundMaterialName, QString &textureFileName, const QDomDocument doc)
|
||||||
|
{
|
||||||
|
boundMaterialName.remove('#');
|
||||||
//library_material -> material -> instance_effect
|
//library_material -> material -> instance_effect
|
||||||
QDomNodeList lib_mat = doc.elementsByTagName("library_materials");
|
QDomNodeList lib_mat = doc.elementsByTagName("library_materials");
|
||||||
if (lib_mat.size() != 1)
|
if (lib_mat.size() != 1)
|
||||||
return QDomNode();
|
return QDomNode();
|
||||||
QDomNode material = findNodeBySpecificAttributeValue(lib_mat.at(0),QString("material"),QString("id"),tar);
|
QDomNode material = findNodeBySpecificAttributeValue(lib_mat.at(0),QString("material"),QString("id"),boundMaterialName);
|
||||||
if (material.isNull())
|
if (material.isNull())
|
||||||
return QDomNode();
|
return QDomNode();
|
||||||
QDomNodeList in_eff = material.toElement().elementsByTagName("instance_effect");
|
QDomNodeList in_eff = material.toElement().elementsByTagName("instance_effect");
|
||||||
if (vis_scn.size() == 0)
|
if (in_eff.size() == 0)
|
||||||
return QDomNode();
|
return QDomNode();
|
||||||
QString url = in_eff.at(0).toElement().attribute("url");
|
QString url = in_eff.at(0).toElement().attribute("url");
|
||||||
if ((url.isNull()) || (url == ""))
|
if ((url.isNull()) || (url == ""))
|
||||||
return QDomNode();
|
return QDomNode();
|
||||||
url = url.remove('#');
|
url = url.remove('#');
|
||||||
|
qDebug("====== searching among library_effects the effect with id '%s' ",qPrintable(url));
|
||||||
//library_effects -> effect -> instance_effect
|
//library_effects -> effect -> instance_effect
|
||||||
QDomNodeList lib_eff = doc.elementsByTagName("library_effects");
|
QDomNodeList lib_eff = doc.elementsByTagName("library_effects");
|
||||||
if (lib_eff.size() != 1)
|
if (lib_eff.size() != 1)
|
||||||
|
@ -526,13 +502,16 @@ namespace io {
|
||||||
return QDomNode();
|
return QDomNode();
|
||||||
|
|
||||||
//library_images -> image
|
//library_images -> image
|
||||||
QDomNodeList lib_img = doc.elementsByTagName("library_images");
|
QDomNodeList libraryImageNodeList = doc.elementsByTagName("library_images");
|
||||||
if (lib_img.size() != 1)
|
qDebug("====== searching among library_images the effect with id '%s' ",qPrintable(img_id));
|
||||||
|
if (libraryImageNodeList.size() != 1)
|
||||||
return QDomNode();
|
return QDomNode();
|
||||||
QDomNode img = findNodeBySpecificAttributeValue(lib_img.at(0),QString("image"),QString("id"),img_id);
|
QDomNode imageNode = findNodeBySpecificAttributeValue(libraryImageNodeList.at(0),QString("image"),QString("id"),img_id);
|
||||||
if (img.isNull())
|
QDomNodeList initfromNode = imageNode.toElement().elementsByTagName("init_from");
|
||||||
return QDomNode();
|
textureFileName= initfromNode.at(0).firstChild().nodeValue();
|
||||||
return img;
|
qDebug("====== the image '%s' has a %i init_from nodes text '%s'",qPrintable(img_id),initfromNode.size(),qPrintable(textureFileName));
|
||||||
|
|
||||||
|
return imageNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int indexTextureByImgNode(const QDomDocument doc,const QDomNode node)
|
static int indexTextureByImgNode(const QDomDocument doc,const QDomNode node)
|
||||||
|
|
|
@ -109,12 +109,12 @@ namespace io {
|
||||||
wed.offcl = findStringListAttribute(wed.wc,wed.wcsrc,nd,doc,"COLOR");
|
wed.offcl = findStringListAttribute(wed.wc,wed.wcsrc,nd,doc,"COLOR");
|
||||||
}
|
}
|
||||||
|
|
||||||
static DAEError LoadPolygonalMesh(QDomNodeList& polypatch,OpenMeshType& m,const size_t offset,AdditionalInfoDAE* info)
|
static DAEError LoadPolygonalMesh(QDomNodeList& polypatch,OpenMeshType& m,const size_t offset,InfoDAE* info)
|
||||||
{
|
{
|
||||||
return E_NOERROR;
|
return E_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DAEError LoadPolygonalListMesh(QDomNodeList& polylist,OpenMeshType& m,const size_t offset,AdditionalInfoDAE* info)
|
static DAEError LoadPolygonalListMesh(QDomNodeList& polylist,OpenMeshType& m,const size_t offset,InfoDAE* info)
|
||||||
{
|
{
|
||||||
typedef PolygonalMesh< MyPolygon<typename OpenMeshType::VertexType> > PolyMesh;
|
typedef PolygonalMesh< MyPolygon<typename OpenMeshType::VertexType> > PolyMesh;
|
||||||
PolyMesh pm;
|
PolyMesh pm;
|
||||||
|
@ -132,14 +132,15 @@ namespace io {
|
||||||
for(int pl = 0; pl < polylist_size;++pl)
|
for(int pl = 0; pl < polylist_size;++pl)
|
||||||
{
|
{
|
||||||
QString mat = polylist.at(pl).toElement().attribute(QString("material"));
|
QString mat = polylist.at(pl).toElement().attribute(QString("material"));
|
||||||
QDomNode txt_node = textureFinder(mat,*(info->dae->doc));
|
QString textureFilename;
|
||||||
|
QDomNode txt_node = textureFinder(mat,textureFilename,*(info->doc));
|
||||||
int ind_txt = -1;
|
int ind_txt = -1;
|
||||||
if (!txt_node.isNull())
|
if (!txt_node.isNull())
|
||||||
ind_txt = indexTextureByImgNode(*(info->dae->doc),txt_node);
|
ind_txt = indexTextureByImgNode(*(info->doc),txt_node);
|
||||||
|
|
||||||
//PolyMesh::PERWEDGEATTRIBUTETYPE att = PolyMesh::NONE;
|
//PolyMesh::PERWEDGEATTRIBUTETYPE att = PolyMesh::NONE;
|
||||||
WedgeAttribute wa;
|
WedgeAttribute wa;
|
||||||
FindStandardWedgeAttributes(wa,polylist.at(pl),*(info->dae->doc));
|
FindStandardWedgeAttributes(wa,polylist.at(pl),*(info->doc));
|
||||||
QStringList vertcount;
|
QStringList vertcount;
|
||||||
valueStringList(vertcount,polylist.at(pl),"vcount");
|
valueStringList(vertcount,polylist.at(pl),"vcount");
|
||||||
int indforpol = findOffSetForASingleSimplex(polylist.at(pl));
|
int indforpol = findOffSetForASingleSimplex(polylist.at(pl));
|
||||||
|
@ -177,32 +178,50 @@ namespace io {
|
||||||
pm.triangulate(m);
|
pm.triangulate(m);
|
||||||
return E_NOERROR;
|
return E_NOERROR;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
Called to load into a given mesh
|
||||||
|
*/
|
||||||
|
static DAEError LoadTriangularMesh(QDomNodeList& triNodeList, OpenMeshType& m, const size_t offset, InfoDAE* info,QMap<QString,QString> &materialBinding)
|
||||||
|
{
|
||||||
|
QDEBUG("****** LoadTriangularMesh (initial mesh size %i %i)",m.vn,m.fn);
|
||||||
|
for(int tript = 0; tript < triNodeList.size();++tript)
|
||||||
|
{
|
||||||
|
QString materialId = triNodeList.at(tript).toElement().attribute(QString("material"));
|
||||||
|
QDEBUG("****** material id '%s' -> '%s'",qPrintable(materialId),qPrintable(materialBinding[materialId]));
|
||||||
|
|
||||||
static DAEError LoadTriangularMesh(QDomNodeList& tripatch,OpenMeshType& m,const size_t offset,AdditionalInfoDAE* info)
|
QString textureFilename;
|
||||||
|
QDomNode img_node = textureFinder(materialBinding[materialId],textureFilename,*(info->doc));
|
||||||
|
if(img_node.isNull())
|
||||||
{
|
{
|
||||||
int tripatch_size = tripatch.size();
|
QDEBUG("****** but we were not able to find the corresponding image node");
|
||||||
for(int tript = 0; tript < tripatch_size;++tript)
|
}
|
||||||
{
|
|
||||||
QString mat = tripatch.at(tript).toElement().attribute(QString("material"));
|
|
||||||
QDomNode txt_node = textureFinder(mat,*(info->dae->doc));
|
|
||||||
int ind_txt = -1;
|
int ind_txt = -1;
|
||||||
if (!txt_node.isNull())
|
if (!img_node.isNull())
|
||||||
ind_txt = indexTextureByImgNode(*(info->dae->doc),txt_node);
|
{
|
||||||
|
if(info->textureIdMap.contains(textureFilename))
|
||||||
int nfcatt = tripatch.at(tript).toElement().elementsByTagName("input").size();
|
ind_txt=info->textureIdMap[textureFilename];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QDEBUG("Found use of Texture %s, adding it to texutres",qPrintable(textureFilename));
|
||||||
|
info->textureIdMap[textureFilename]=m.textures.size();
|
||||||
|
m.textures.push_back(qPrintable(textureFilename));
|
||||||
|
ind_txt=info->textureIdMap[textureFilename];
|
||||||
|
}
|
||||||
|
// ind_txt = indexTextureByImgNode(*(info->doc),txt_node);
|
||||||
|
}
|
||||||
|
int faceAttributeNum = triNodeList.at(tript).toElement().elementsByTagName("input").size();
|
||||||
|
|
||||||
QStringList face;
|
QStringList face;
|
||||||
valueStringList(face,tripatch.at(tript),"p");
|
valueStringList(face,triNodeList.at(tript),"p");
|
||||||
int face_size = face.size();
|
|
||||||
int offsetface = (int)m.face.size();
|
int offsetface = (int)m.face.size();
|
||||||
if (face_size != 0)
|
if (face.size() != 0)
|
||||||
{
|
{
|
||||||
vcg::tri::Allocator<OpenMeshType>::AddFaces(m,face_size / (nfcatt * 3));
|
vcg::tri::Allocator<OpenMeshType>::AddFaces(m,face.size() / (faceAttributeNum * 3));
|
||||||
WedgeAttribute wa;
|
WedgeAttribute wa;
|
||||||
FindStandardWedgeAttributes(wa,tripatch.at(tript),*(info->dae->doc));
|
FindStandardWedgeAttributes(wa,triNodeList.at(tript),*(info->doc));
|
||||||
|
|
||||||
int jj = 0;
|
int jj = 0;
|
||||||
//int dd = m.face.size();
|
|
||||||
for(int ff = offsetface;ff < (int) m.face.size();++ff)
|
for(int ff = offsetface;ff < (int) m.face.size();++ff)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -212,24 +231,24 @@ namespace io {
|
||||||
assert(indvt + offset < m.vert.size());
|
assert(indvt + offset < m.vert.size());
|
||||||
m.face[ff].V(tt) = &(m.vert[indvt + offset]);
|
m.face[ff].V(tt) = &(m.vert[indvt + offset]);
|
||||||
|
|
||||||
if(tri::HasPerWedgeNormal(m))
|
if(tri::HasPerWedgeNormal(m)) WedgeNormalAttribute(m,face,wa.wn,wa.wnsrc,ff,jj + wa.offnm,tt);
|
||||||
WedgeNormalAttribute(m,face,wa.wn,wa.wnsrc,ff,jj + wa.offnm,tt);
|
if(tri::HasPerWedgeColor(m)) WedgeColorAttribute(m,face,wa.wc,wa.wcsrc,ff,jj + wa.offcl,tt);
|
||||||
|
|
||||||
if(tri::HasPerWedgeTexCoord(m) && ind_txt != -1)
|
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.stride);
|
||||||
}
|
}
|
||||||
if(tri::HasPerWedgeColor(m))
|
|
||||||
WedgeColorAttribute(m,face,wa.wc,wa.wcsrc,ff,jj + wa.offcl,tt);
|
|
||||||
|
|
||||||
jj += nfcatt;
|
jj += faceAttributeNum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QDEBUG("****** LoadTriangularMesh (final mesh size %i %i - %i %i)",m.vn,m.vert.size(),m.fn,m.face.size());
|
||||||
return E_NOERROR;
|
return E_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LoadControllerMesh(OpenMeshType& m, AdditionalInfoDAE* info, const QDomElement& geo, CallBackPos *cb=0)
|
static int LoadControllerMesh(OpenMeshType& m, InfoDAE* info, const QDomElement& geo, CallBackPos *cb=0)
|
||||||
{
|
{
|
||||||
assert(geo.tagName() == "controller");
|
assert(geo.tagName() == "controller");
|
||||||
QDomNodeList skinList = geo.toElement().elementsByTagName("skin");
|
QDomNodeList skinList = geo.toElement().elementsByTagName("skin");
|
||||||
|
@ -239,34 +258,59 @@ namespace io {
|
||||||
QString geomNode_url;
|
QString geomNode_url;
|
||||||
referenceToANodeAttribute(skinNode,"source",geomNode_url);
|
referenceToANodeAttribute(skinNode,"source",geomNode_url);
|
||||||
QDEBUG("Found a controller referencing a skin with url '%s'", qPrintable(geomNode_url));
|
QDEBUG("Found a controller referencing a skin with url '%s'", qPrintable(geomNode_url));
|
||||||
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->dae->doc),"geometry","id",geomNode_url);
|
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->doc),"geometry","id",geomNode_url);
|
||||||
LoadMesh(m, info, refNode.toElement());
|
|
||||||
|
QDomNodeList bindingNodes = skinNode.toElement().elementsByTagName("bind_material");
|
||||||
|
QMap<QString,QString> materialBindingMap;
|
||||||
|
if( bindingNodes.size()>0) {
|
||||||
|
QDEBUG("** skin node of a controller has a material binding");
|
||||||
|
GenerateMaterialBinding(skinNode,materialBindingMap);
|
||||||
|
}
|
||||||
|
LoadGeometry(m, info, refNode.toElement(),materialBindingMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* before instancing a geometry you can make a binding that allow you to substitute next material names with other names.
|
||||||
Basic function that fills a mesh with the coord, norm and tristarting from node that is of kind <geometry>
|
this is very useful for instancing the same geometry with different materials. therefore when you encounter a material name in a mesh, this name can be a 'symbol' that you have to bind.
|
||||||
*/
|
*/
|
||||||
static int LoadMesh(OpenMeshType& m, AdditionalInfoDAE* info, const QDomElement& geo, CallBackPos *cb=0)
|
static bool GenerateMaterialBinding(QDomNode instanceGeomNode, QMap<QString,QString> &binding)
|
||||||
|
{
|
||||||
|
QDomNodeList instanceMaterialList=instanceGeomNode.toElement().elementsByTagName("instance_material");
|
||||||
|
QDEBUG("++++ Found %i instance_material binding",instanceMaterialList.size() );
|
||||||
|
for(int i=0;i<instanceMaterialList.size();++i)
|
||||||
|
{
|
||||||
|
QString symbol = instanceMaterialList.at(i).toElement().attribute("symbol");
|
||||||
|
QString target = instanceMaterialList.at(i).toElement().attribute("target");
|
||||||
|
binding[symbol]=target;
|
||||||
|
QDEBUG("++++++ %s -> %s",qPrintable(symbol),qPrintable(target));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Basic function that get in input a node <geometry> with a map from material names to texture names.
|
||||||
|
this map is necessary because when using a geometry when it is instanced its material can be bind with different names.
|
||||||
|
if the map fails you should directly search in the material library.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int LoadGeometry(OpenMeshType& m, InfoDAE* info, const QDomElement& geo, QMap<QString,QString> &materialBinding, CallBackPos *cb=0)
|
||||||
{
|
{
|
||||||
assert(geo.tagName() == "geometry");
|
assert(geo.tagName() == "geometry");
|
||||||
if (isThereTag(geo,"mesh"))
|
if (!isThereTag(geo,"mesh")) return E_NOMESH;
|
||||||
{
|
|
||||||
if ((cb !=NULL) && (((info->numvert + info->numface)%100)==0) && !(*cb)((100*(info->numvert + info->numface))/(info->numvert + info->numface), "Vertex Loading"))
|
if ((cb !=NULL) && (((info->numvert + info->numface)%100)==0) && !(*cb)((100*(info->numvert + info->numface))/(info->numvert + info->numface), "Vertex Loading"))
|
||||||
return E_CANTOPEN;
|
return E_CANTOPEN;
|
||||||
/*QDomNodeList geosrc = geo.toElement().elementsByTagName("source");
|
QDEBUG("**** Loading a Geometry Mesh **** (initial mesh size %i %i)",m.vn,m.fn);
|
||||||
int geosrc_size = geosrc.size();
|
|
||||||
if (geosrc_size < 1)
|
|
||||||
return E_NOVERTEXPOSITION;*/
|
|
||||||
QDEBUG("**** Loading a Geometry Mesh ****");
|
|
||||||
QDomNodeList vertices = geo.toElement().elementsByTagName("vertices");
|
QDomNodeList vertices = geo.toElement().elementsByTagName("vertices");
|
||||||
if (vertices.size() != 1) return E_INCOMPATIBLECOLLADA141FORMAT;
|
if (vertices.size() != 1) return E_INCOMPATIBLECOLLADA141FORMAT;
|
||||||
QDomElement vertNode = vertices.at(0).toElement();
|
QDomElement vertNode = vertices.at(0).toElement();
|
||||||
|
|
||||||
QDomNode srcnode = attributeSourcePerSimplex(vertNode,*(info->dae->doc),"POSITION");
|
QDomNode positionNode = attributeSourcePerSimplex(vertNode,*(info->doc),"POSITION");
|
||||||
if (srcnode.isNull()) return E_NOVERTEXPOSITION;
|
if (positionNode.isNull()) return E_NOVERTEXPOSITION;
|
||||||
|
|
||||||
QStringList geosrcposarr;
|
QStringList geosrcposarr;
|
||||||
valueStringList(geosrcposarr,srcnode,"float_array");
|
valueStringList(geosrcposarr, positionNode, "float_array");
|
||||||
|
|
||||||
int geosrcposarr_size = geosrcposarr.size();
|
int geosrcposarr_size = geosrcposarr.size();
|
||||||
if ((geosrcposarr_size % 3) != 0)
|
if ((geosrcposarr_size % 3) != 0)
|
||||||
|
@ -277,17 +321,17 @@ namespace io {
|
||||||
{
|
{
|
||||||
vcg::tri::Allocator<OpenMeshType>::AddVertices(m,nvert);
|
vcg::tri::Allocator<OpenMeshType>::AddVertices(m,nvert);
|
||||||
|
|
||||||
QDomNode srcnodenorm = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"NORMAL");
|
QDomNode srcnodenorm = attributeSourcePerSimplex(vertices.at(0),*(info->doc),"NORMAL");
|
||||||
QStringList geosrcvertnorm;
|
QStringList geosrcvertnorm;
|
||||||
if (!srcnodenorm.isNull())
|
if (!srcnodenorm.isNull())
|
||||||
valueStringList(geosrcvertnorm,srcnodenorm,"float_array");
|
valueStringList(geosrcvertnorm,srcnodenorm,"float_array");
|
||||||
|
|
||||||
QDomNode srcnodetext = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"TEXCOORD");
|
QDomNode srcnodetext = attributeSourcePerSimplex(vertices.at(0),*(info->doc),"TEXCOORD");
|
||||||
QStringList geosrcverttext;
|
QStringList geosrcverttext;
|
||||||
if (!srcnodetext.isNull())
|
if (!srcnodetext.isNull())
|
||||||
valueStringList(geosrcverttext,srcnodetext,"float_array");
|
valueStringList(geosrcverttext,srcnodetext,"float_array");
|
||||||
|
|
||||||
QDomNode srcnodecolor = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"COLOR");
|
QDomNode srcnodecolor = attributeSourcePerSimplex(vertices.at(0),*(info->doc),"COLOR");
|
||||||
QStringList geosrcvertcol;
|
QStringList geosrcvertcol;
|
||||||
if (!srcnodecolor.isNull())
|
if (!srcnodecolor.isNull())
|
||||||
valueStringList(geosrcvertcol,srcnodecolor,"float_array");
|
valueStringList(geosrcvertcol,srcnodecolor,"float_array");
|
||||||
|
@ -325,32 +369,23 @@ namespace io {
|
||||||
}
|
}
|
||||||
|
|
||||||
QDomNodeList tripatch = geo.toElement().elementsByTagName("triangles");
|
QDomNodeList tripatch = geo.toElement().elementsByTagName("triangles");
|
||||||
int tripatch_size = tripatch.size();
|
|
||||||
QDomNodeList polypatch = geo.toElement().elementsByTagName("polygons");
|
QDomNodeList polypatch = geo.toElement().elementsByTagName("polygons");
|
||||||
int polypatch_size = polypatch.size();
|
|
||||||
QDomNodeList polylist = geo.toElement().elementsByTagName("polylist");
|
QDomNodeList polylist = geo.toElement().elementsByTagName("polylist");
|
||||||
int polylist_size = polylist.size();
|
if (tripatch.isEmpty() && polypatch.isEmpty() && polylist.isEmpty())
|
||||||
if ((tripatch_size == 0) && (polypatch_size == 0) && (polylist_size == 0))
|
|
||||||
return E_NOPOLYGONALMESH;
|
return E_NOPOLYGONALMESH;
|
||||||
|
|
||||||
DAEError err = E_NOERROR;
|
DAEError err = E_NOERROR;
|
||||||
if (tripatch_size != 0)
|
err = LoadTriangularMesh(tripatch,m,offset,info,materialBinding);
|
||||||
err = LoadTriangularMesh(tripatch,m,offset,info);
|
//err = LoadPolygonalMesh(polypatch,m,offset,info);
|
||||||
else
|
//err = LoadPolygonalListMesh(polylist,m,offset,info);
|
||||||
if (polypatch_size != 0)
|
|
||||||
err = LoadPolygonalMesh(polypatch,m,offset,info);
|
|
||||||
else
|
|
||||||
if (polylist_size != 0)
|
|
||||||
err = LoadPolygonalListMesh(polylist,m,offset,info);
|
|
||||||
if (err != E_NOERROR)
|
if (err != E_NOERROR)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
QDEBUG("**** Loading a Geometry Mesh **** (final mesh size %i %i - %i %i)",m.vn,m.vert.size(),m.fn,m.face.size());
|
||||||
return E_NOERROR;
|
return E_NOERROR;
|
||||||
}
|
}
|
||||||
else return E_NOMESH;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void GetTexCoord(const QDomDocument& doc,AdditionalInfoDAE* inf)
|
static void GetTexCoord(const QDomDocument& doc, QStringList &texturefile)
|
||||||
{
|
{
|
||||||
QDomNodeList txlst = doc.elementsByTagName("library_images");
|
QDomNodeList txlst = doc.elementsByTagName("library_images");
|
||||||
for(int img = 0;img < txlst.at(0).childNodes().size();++img)
|
for(int img = 0;img < txlst.at(0).childNodes().size();++img)
|
||||||
|
@ -358,7 +393,7 @@ namespace io {
|
||||||
QDomNodeList nlst = txlst.at(0).childNodes().at(img).toElement().elementsByTagName("init_from");
|
QDomNodeList nlst = txlst.at(0).childNodes().at(img).toElement().elementsByTagName("init_from");
|
||||||
if (nlst.size() > 0)
|
if (nlst.size() > 0)
|
||||||
{
|
{
|
||||||
inf->texturefile.push_back(nlst.at(0).firstChild().nodeValue());
|
texturefile.push_back(nlst.at(0).firstChild().nodeValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,7 +404,7 @@ namespace io {
|
||||||
|
|
||||||
static void AddNodeToMesh(QDomElement node,
|
static void AddNodeToMesh(QDomElement node,
|
||||||
OpenMeshType& m, Matrix44f curTr,
|
OpenMeshType& m, Matrix44f curTr,
|
||||||
AdditionalInfoDAE*& info)
|
InfoDAE*& info)
|
||||||
{
|
{
|
||||||
QDEBUG("Starting processing <node> with id %s",qPrintable(node.attribute("id")));
|
QDEBUG("Starting processing <node> with id %s",qPrintable(node.attribute("id")));
|
||||||
|
|
||||||
|
@ -381,17 +416,24 @@ namespace io {
|
||||||
QDomElement instGeomNode= geomNodeList.at(ch).toElement();
|
QDomElement instGeomNode= geomNodeList.at(ch).toElement();
|
||||||
if(instGeomNode.parentNode()==node) // process only direct child
|
if(instGeomNode.parentNode()==node) // process only direct child
|
||||||
{
|
{
|
||||||
QDEBUG("Found a instance_geometry with url %s",qPrintable(instGeomNode.attribute("url")));
|
QDEBUG("** instance_geometry with url %s (intial mesh size %i %i T = %i)",qPrintable(instGeomNode.attribute("url")),m.vn,m.fn,m.textures.size());
|
||||||
|
//assert(m.textures.size()>0 == HasPerWedgeTexCoord(m));
|
||||||
QString geomNode_url;
|
QString geomNode_url;
|
||||||
referenceToANodeAttribute(instGeomNode,"url",geomNode_url);
|
referenceToANodeAttribute(instGeomNode,"url",geomNode_url);
|
||||||
QDEBUG("Found a instance_geometry with url '%s'", qPrintable(geomNode_url));
|
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->doc),"geometry","id",geomNode_url);
|
||||||
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->dae->doc),"geometry","id",geomNode_url);
|
QDomNodeList bindingNodes = instGeomNode.toElement().elementsByTagName("bind_material");
|
||||||
|
QMap<QString,QString> materialBindingMap;
|
||||||
|
if( bindingNodes.size()>0) {
|
||||||
|
QDEBUG("** instance_geometry has a material binding");
|
||||||
|
GenerateMaterialBinding(instGeomNode,materialBindingMap);
|
||||||
|
}
|
||||||
|
|
||||||
OpenMeshType newMesh;
|
OpenMeshType newMesh;
|
||||||
LoadMesh(newMesh, info, refNode.toElement());
|
newMesh.face.EnableWedgeTex();
|
||||||
|
LoadGeometry(newMesh, info, refNode.toElement(),materialBindingMap);
|
||||||
tri::UpdatePosition<OpenMeshType>::Matrix(newMesh,curTr);
|
tri::UpdatePosition<OpenMeshType>::Matrix(newMesh,curTr);
|
||||||
tri::Append<OpenMeshType,OpenMeshType>::Mesh(m,newMesh);
|
tri::Append<OpenMeshType,OpenMeshType>::Mesh(m,newMesh);
|
||||||
|
QDEBUG("** instance_geometry with url %s (final mesh size %i %i - %i %i)",qPrintable(instGeomNode.attribute("url")),m.vn,m.vert.size(),m.fn,m.face.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +448,7 @@ namespace io {
|
||||||
QString controllerNode_url;
|
QString controllerNode_url;
|
||||||
referenceToANodeAttribute(instContrNode,"url",controllerNode_url);
|
referenceToANodeAttribute(instContrNode,"url",controllerNode_url);
|
||||||
QDEBUG("Found a instance_controller with url '%s'", qPrintable(controllerNode_url));
|
QDEBUG("Found a instance_controller with url '%s'", qPrintable(controllerNode_url));
|
||||||
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->dae->doc),"controller","id",controllerNode_url);
|
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->doc),"controller","id",controllerNode_url);
|
||||||
|
|
||||||
OpenMeshType newMesh;
|
OpenMeshType newMesh;
|
||||||
LoadControllerMesh(newMesh, info, refNode.toElement());
|
LoadControllerMesh(newMesh, info, refNode.toElement());
|
||||||
|
@ -431,7 +473,7 @@ namespace io {
|
||||||
QString node_url;
|
QString node_url;
|
||||||
referenceToANodeAttribute(instanceNode,"url",node_url);
|
referenceToANodeAttribute(instanceNode,"url",node_url);
|
||||||
QDEBUG("Found a instance_node with url '%s'", qPrintable(node_url));
|
QDEBUG("Found a instance_node with url '%s'", qPrintable(node_url));
|
||||||
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->dae->doc),"node","id",node_url);
|
QDomNode refNode = findNodeBySpecificAttributeValue(*(info->doc),"node","id",node_url);
|
||||||
if(refNode.isNull())
|
if(refNode.isNull())
|
||||||
QDEBUG("findNodeBySpecificAttributeValue returned a null node for %s",qPrintable(node_url));
|
QDEBUG("findNodeBySpecificAttributeValue returned a null node for %s",qPrintable(node_url));
|
||||||
|
|
||||||
|
@ -479,11 +521,11 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
//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*& info, CallBackPos *cb=0)
|
static int Open(OpenMeshType& m,const char* filename,InfoDAE*& info, CallBackPos *cb=0)
|
||||||
{
|
{
|
||||||
QDEBUG("----- Starting the processing of %s ------",filename);
|
QDEBUG("----- Starting the processing of %s ------",filename);
|
||||||
AdditionalInfoDAE* inf = new AdditionalInfoDAE();
|
//AdditionalInfoDAE* inf = new AdditionalInfoDAE();
|
||||||
inf->dae = new InfoDAE();
|
info = new InfoDAE();
|
||||||
|
|
||||||
QDomDocument* doc = new QDomDocument(filename);
|
QDomDocument* doc = new QDomDocument(filename);
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
|
@ -496,11 +538,12 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
inf->dae->doc = doc;
|
info->doc = doc;
|
||||||
//GetTexture(*(info->doc),inf);
|
//GetTexture(*(info->doc),inf);
|
||||||
|
|
||||||
|
// GenerateMaterialToTextureMap(info);
|
||||||
//scene->instance_visual_scene
|
//scene->instance_visual_scene
|
||||||
QDomNodeList scenes = inf->dae->doc->elementsByTagName("scene");
|
QDomNodeList scenes = info->doc->elementsByTagName("scene");
|
||||||
int scn_size = scenes.size();
|
int scn_size = scenes.size();
|
||||||
if (scn_size == 0)
|
if (scn_size == 0)
|
||||||
return E_NO3DSCENE;
|
return E_NO3DSCENE;
|
||||||
|
@ -519,9 +562,11 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
each <visual_scene> contains a hierarchy of <node>
|
each <visual_scene> contains a hierarchy of <node>
|
||||||
each <node> contains
|
each <node> contains
|
||||||
transformation
|
transformation
|
||||||
other node
|
other nodes
|
||||||
instance of geometry
|
instance of geometry
|
||||||
instance of controller
|
instance of controller
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
for(int scn = 0;scn < scn_size;++scn)
|
for(int scn = 0;scn < scn_size;++scn)
|
||||||
{
|
{
|
||||||
|
@ -537,8 +582,8 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
|
referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
|
||||||
QDEBUG("instance_visual_scene %i refers %s ",instscn,qPrintable(libscn_url));
|
QDEBUG("instance_visual_scene %i refers %s ",instscn,qPrintable(libscn_url));
|
||||||
|
|
||||||
QDomNode nd = QDomNode(*(inf->dae->doc));
|
// QDomNode nd = QDomNode(*(inf->doc));
|
||||||
QDomNode visscn = findNodeBySpecificAttributeValue(*(inf->dae->doc),"visual_scene","id",libscn_url);
|
QDomNode visscn = findNodeBySpecificAttributeValue(*(info->doc),"visual_scene","id",libscn_url);
|
||||||
if(visscn.isNull()) return E_UNREFERENCEBLEDCOLLADAATTRIBUTE;
|
if(visscn.isNull()) return E_UNREFERENCEBLEDCOLLADAATTRIBUTE;
|
||||||
|
|
||||||
//assert (visscn.toElement().Attribute("id") == libscn_url);
|
//assert (visscn.toElement().Attribute("id") == libscn_url);
|
||||||
|
@ -555,14 +600,14 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
Matrix44f baseTr; baseTr.SetIdentity();
|
Matrix44f baseTr; baseTr.SetIdentity();
|
||||||
|
|
||||||
if(node.toElement().tagName()=="node")
|
if(node.toElement().tagName()=="node")
|
||||||
AddNodeToMesh(node.toElement(), m, baseTr,inf);
|
AddNodeToMesh(node.toElement(), m, baseTr,info);
|
||||||
} // end for each node of a given scene
|
} // end for each node of a given scene
|
||||||
} // end for each visual scene instance
|
} // end for each visual scene instance
|
||||||
} // end for each scene instance
|
} // end for each scene instance
|
||||||
return problem;
|
return problem;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool LoadMask(const char * filename, AdditionalInfoDAE*& addinfo)
|
static bool LoadMask(const char * filename, InfoDAE*& addinfo)
|
||||||
{
|
{
|
||||||
bool bHasPerWedgeTexCoord = false;
|
bool bHasPerWedgeTexCoord = false;
|
||||||
bool bHasPerWedgeNormal = false;
|
bool bHasPerWedgeNormal = false;
|
||||||
|
@ -571,10 +616,7 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
bool bHasPerVertexNormal = false;
|
bool bHasPerVertexNormal = false;
|
||||||
bool bHasPerVertexText = false;
|
bool bHasPerVertexText = false;
|
||||||
|
|
||||||
AdditionalInfoDAE* info = new AdditionalInfoDAE();
|
InfoDAE* info = new InfoDAE();
|
||||||
info->dae = new InfoDAE();
|
|
||||||
|
|
||||||
|
|
||||||
QDomDocument* doc = new QDomDocument(filename);
|
QDomDocument* doc = new QDomDocument(filename);
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (!file.open(QIODevice::ReadOnly))
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
@ -586,10 +628,10 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
QStringList textureFileList;
|
||||||
info->dae->doc = doc;
|
info->doc = doc;
|
||||||
GetTexCoord(*(info->dae->doc),info);
|
GetTexCoord(*(info->doc),textureFileList);
|
||||||
QDomNodeList scenes = info->dae->doc->elementsByTagName("scene");
|
QDomNodeList scenes = info->doc->elementsByTagName("scene");
|
||||||
int scn_size = scenes.size();
|
int scn_size = scenes.size();
|
||||||
|
|
||||||
|
|
||||||
|
@ -607,8 +649,8 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
{
|
{
|
||||||
QString libscn_url;
|
QString libscn_url;
|
||||||
referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
|
referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
|
||||||
QDomNode nd = QDomNode(*(info->dae->doc));
|
QDomNode nd = QDomNode(*(info->doc));
|
||||||
QDomNode visscn = findNodeBySpecificAttributeValue(*(info->dae->doc),"visual_scene","id",libscn_url);
|
QDomNode visscn = findNodeBySpecificAttributeValue(*(info->doc),"visual_scene","id",libscn_url);
|
||||||
if(visscn.isNull()) return false;
|
if(visscn.isNull()) return false;
|
||||||
|
|
||||||
//for each node in the libscn_url visual scene
|
//for each node in the libscn_url visual scene
|
||||||
|
@ -625,7 +667,7 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
{
|
{
|
||||||
|
|
||||||
geoinst_found |= true;
|
geoinst_found |= true;
|
||||||
QDomNodeList geolib = info->dae->doc->elementsByTagName("library_geometries");
|
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
|
||||||
assert(geolib.size() == 1);
|
assert(geolib.size() == 1);
|
||||||
//!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
|
//!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
|
||||||
info->numvert = 0;
|
info->numvert = 0;
|
||||||
|
@ -687,7 +729,7 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
|
|
||||||
if (!geoinst_found)
|
if (!geoinst_found)
|
||||||
{
|
{
|
||||||
QDomNodeList geolib = info->dae->doc->elementsByTagName("library_geometries");
|
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
|
||||||
assert(geolib.size() == 1);
|
assert(geolib.size() == 1);
|
||||||
QDomNodeList geochild = geolib.at(0).toElement().elementsByTagName("geometry");
|
QDomNodeList geochild = geolib.at(0).toElement().elementsByTagName("geometry");
|
||||||
//!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
|
//!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
@ -750,8 +792,8 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
delete (info->dae->doc);
|
delete (info->doc);
|
||||||
info->dae->doc = NULL;
|
info->doc = NULL;
|
||||||
addinfo = info;
|
addinfo = info;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue