added real supports for multiple textures
This commit is contained in:
parent
76721c28d1
commit
a1502da3fd
|
@ -26,7 +26,7 @@ namespace io {
|
|||
return indnm;
|
||||
}
|
||||
|
||||
static int WedgeTextureAttribute(OpenMeshType& m,const QStringList face,QString texture,const QStringList wt,const QDomNode wtsrc,const int meshfaceind,const int faceind,const int component)
|
||||
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)
|
||||
{
|
||||
int indtx = -1;
|
||||
if (!wtsrc.isNull())
|
||||
|
@ -37,7 +37,8 @@ namespace io {
|
|||
m.face[meshfaceind].WT(component).U() = wt.at(indtx * 2).toFloat();
|
||||
m.face[meshfaceind].WT(component).V() = wt.at(indtx * 2 + 1).toFloat();
|
||||
|
||||
m.face[meshfaceind].WT(component).N() = 1;
|
||||
m.face[meshfaceind].WT(component).N() = ind_txt;
|
||||
|
||||
}
|
||||
return indtx;
|
||||
}
|
||||
|
@ -124,11 +125,11 @@ namespace io {
|
|||
{
|
||||
QString mat = tripatch.at(tript).toElement().attribute(QString("material"));
|
||||
|
||||
QDomNodeList libim = info->dae->doc->elementsByTagName(QString("library_images"));
|
||||
if (libim.size() == 1)
|
||||
{
|
||||
QDomNode img = findNodeBySpecificAttributeValue(libim.at(0).childNodes(),QString("id"),mat);
|
||||
}
|
||||
QDomNode txt_node = textureFinder(mat,*(info->dae->doc));
|
||||
int ind_txt = -1;
|
||||
if (!txt_node.isNull())
|
||||
ind_txt = indexTextureByImgNode(*(info->dae->doc),txt_node);
|
||||
|
||||
int nfcatt = tripatch.at(tript).toElement().elementsByTagName("input").size();
|
||||
|
||||
QStringList face;
|
||||
|
@ -152,7 +153,8 @@ namespace io {
|
|||
|
||||
|
||||
int indnm = WedgeNormalAttribute(m,face,wa.wn,wa.wnsrc,ff,jj + wa.offnm,tt);
|
||||
int indtx = WedgeTextureAttribute(m,face,mat,wa.wt,wa.wtsrc,ff,jj + wa.offtx,tt);
|
||||
if (ind_txt != -1)
|
||||
int indtx = WedgeTextureAttribute(m,face,ind_txt,wa.wt,wa.wtsrc,ff,jj + wa.offtx,tt);
|
||||
int indcl = WedgeColorAttribute(m,face,wa.wc,wa.wcsrc,ff,jj + wa.offcl,tt);
|
||||
|
||||
jj += nfcatt;
|
||||
|
|
|
@ -263,7 +263,8 @@ namespace io {
|
|||
int ind = 0;
|
||||
while(ind < ndl_size)
|
||||
{
|
||||
if (ndl.at(ind).toElement().attribute(attrname) == attrvalue)
|
||||
QString st = ndl.at(ind).toElement().attribute(attrname);
|
||||
if (st == attrvalue)
|
||||
return ndl.at(ind);
|
||||
++ind;
|
||||
}
|
||||
|
@ -448,6 +449,80 @@ namespace io {
|
|||
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('#');
|
||||
|
||||
//library_material -> material -> instance_effect
|
||||
QDomNodeList lib_mat = doc.elementsByTagName("library_materials");
|
||||
if (lib_mat.size() != 1)
|
||||
return QDomNode();
|
||||
QDomNode material = findNodeBySpecificAttributeValue(lib_mat.at(0),QString("material"),QString("id"),tar);
|
||||
if (material.isNull())
|
||||
return QDomNode();
|
||||
QDomNodeList in_eff = material.toElement().elementsByTagName("instance_effect");
|
||||
if (vis_scn.size() == 0)
|
||||
return QDomNode();
|
||||
QString url = in_eff.at(0).toElement().attribute("url");
|
||||
if ((url.isNull()) || (url == ""))
|
||||
return QDomNode();
|
||||
url = url.remove('#');
|
||||
|
||||
//library_effects -> effect -> instance_effect
|
||||
QDomNodeList lib_eff = doc.elementsByTagName("library_effects");
|
||||
if (lib_eff.size() != 1)
|
||||
return QDomNode();
|
||||
QDomNode effect = findNodeBySpecificAttributeValue(lib_eff.at(0),QString("effect"),QString("id"),url);
|
||||
if (effect.isNull())
|
||||
return QDomNode();
|
||||
QDomNodeList init_from = effect.toElement().elementsByTagName("init_from");
|
||||
if (init_from.size() == 0)
|
||||
return QDomNode();
|
||||
QString img_id = init_from.at(0).toElement().text();
|
||||
if ((img_id.isNull()) || (img_id == ""))
|
||||
return QDomNode();
|
||||
|
||||
//library_images -> image
|
||||
QDomNodeList lib_img = doc.elementsByTagName("library_images");
|
||||
if (lib_img.size() != 1)
|
||||
return QDomNode();
|
||||
QDomNode img = findNodeBySpecificAttributeValue(lib_img.at(0),QString("image"),QString("id"),img_id);
|
||||
if (img.isNull())
|
||||
return QDomNode();
|
||||
return img;
|
||||
}
|
||||
|
||||
static int indexTextureByImgNode(const QDomDocument doc,const QDomNode node)
|
||||
{
|
||||
QDomNodeList libim = doc.elementsByTagName(QString("library_images"));
|
||||
if (libim.size() != 1)
|
||||
return -1;
|
||||
QDomNodeList imgs = libim.at(0).toElement().elementsByTagName("image");
|
||||
|
||||
int ii = 0;
|
||||
bool found = false;
|
||||
while((ii < imgs.size()) && (!found))
|
||||
{
|
||||
if (imgs.at(ii) == node)
|
||||
found = true;
|
||||
else ++ii;
|
||||
}
|
||||
if (found)
|
||||
return ii;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct WedgeAttribute
|
||||
{
|
||||
QDomNode wnsrc;
|
||||
|
|
Loading…
Reference in New Issue