Added import/export of color per vertex (only for triangular meshes for now)
This commit is contained in:
parent
7816e73d74
commit
0d98d0216e
|
|
@ -470,7 +470,7 @@ namespace Tags
|
||||||
class FloatArrayTag : public XMLLeafTag
|
class FloatArrayTag : public XMLLeafTag
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ARRAYSEMANTIC {VERTPOSITION,VERTNORMAL,FACENORMAL,WEDGETEXCOORD};
|
enum ARRAYSEMANTIC {VERTPOSITION,VERTNORMAL,VERTCOLOR, FACENORMAL,WEDGETEXCOORD};
|
||||||
|
|
||||||
template<typename MESHTYPE>
|
template<typename MESHTYPE>
|
||||||
FloatArrayTag(const QString& id,const int count,const MESHTYPE& m,ARRAYSEMANTIC sem,const unsigned int componenttype)
|
FloatArrayTag(const QString& id,const int count,const MESHTYPE& m,ARRAYSEMANTIC sem,const unsigned int componenttype)
|
||||||
|
|
@ -479,7 +479,7 @@ namespace Tags
|
||||||
_attributes.push_back(TagAttribute("id",id));
|
_attributes.push_back(TagAttribute("id",id));
|
||||||
_attributes.push_back(TagAttribute("count",QString::number(count)));
|
_attributes.push_back(TagAttribute("count",QString::number(count)));
|
||||||
|
|
||||||
if ((sem == VERTPOSITION) || (sem == VERTNORMAL))
|
if ((sem == VERTPOSITION) || (sem == VERTNORMAL) || (sem == VERTCOLOR))
|
||||||
{
|
{
|
||||||
for(typename MESHTYPE::ConstVertexIterator vit = m.vert.begin();vit != m.vert.end();++vit)
|
for(typename MESHTYPE::ConstVertexIterator vit = m.vert.begin();vit != m.vert.end();++vit)
|
||||||
{
|
{
|
||||||
|
|
@ -487,6 +487,8 @@ namespace Tags
|
||||||
{
|
{
|
||||||
if (sem == VERTPOSITION)
|
if (sem == VERTPOSITION)
|
||||||
_text.push_back(QString::number(vit->P()[ii]));
|
_text.push_back(QString::number(vit->P()[ii]));
|
||||||
|
else if (sem == VERTCOLOR)
|
||||||
|
_text.push_back(QString::number((vit->C()[ii])/255.0));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
typename MESHTYPE::VertexType::NormalType r = vit->cN();
|
typename MESHTYPE::VertexType::NormalType r = vit->cN();
|
||||||
|
|
@ -617,7 +619,7 @@ namespace Tags
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<typename MESHTYPE>
|
template<typename MESHTYPE>
|
||||||
PTag(const MESHTYPE& m,const unsigned int nedge,bool norm = false,bool texcoord = false)
|
PTag(const MESHTYPE& m,const unsigned int nedge,bool vcol=false, bool norm = false,bool texcoord = false)
|
||||||
:XMLLeafTag("p")
|
:XMLLeafTag("p")
|
||||||
{
|
{
|
||||||
int cont = 0;
|
int cont = 0;
|
||||||
|
|
@ -627,6 +629,8 @@ namespace Tags
|
||||||
{
|
{
|
||||||
int dist = it->V(ii) - &(*m.vert.begin());
|
int dist = it->V(ii) - &(*m.vert.begin());
|
||||||
_text.push_back(QString::number(dist));
|
_text.push_back(QString::number(dist));
|
||||||
|
if (vcol)
|
||||||
|
_text.push_back(QString::number(dist));
|
||||||
if (norm)
|
if (norm)
|
||||||
_text.push_back(QString::number(cont));
|
_text.push_back(QString::number(cont));
|
||||||
if (texcoord)
|
if (texcoord)
|
||||||
|
|
@ -637,7 +641,7 @@ namespace Tags
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename MESHTYPE>
|
template<typename MESHTYPE>
|
||||||
PTag(const MESHTYPE& m,const unsigned int nedge,QVector<int>& patchfaces,bool norm = false,bool texcoord = false)
|
PTag(const MESHTYPE& m,const unsigned int nedge,QVector<int>& patchfaces,bool vcol = false, bool norm = false,bool texcoord = false)
|
||||||
:XMLLeafTag("p")
|
:XMLLeafTag("p")
|
||||||
{
|
{
|
||||||
int cont = 0;
|
int cont = 0;
|
||||||
|
|
@ -648,6 +652,8 @@ namespace Tags
|
||||||
const typename MESHTYPE::FaceType& f = m.face[*it];
|
const typename MESHTYPE::FaceType& f = m.face[*it];
|
||||||
int dist = f.V(ii) - &(*m.vert.begin());
|
int dist = f.V(ii) - &(*m.vert.begin());
|
||||||
_text.push_back(QString::number(dist));
|
_text.push_back(QString::number(dist));
|
||||||
|
if (vcol)
|
||||||
|
_text.push_back(QString::number(dist));
|
||||||
if (norm)
|
if (norm)
|
||||||
_text.push_back(QString::number(*it));
|
_text.push_back(QString::number(*it));
|
||||||
if (texcoord)
|
if (texcoord)
|
||||||
|
|
@ -1017,6 +1023,34 @@ public:
|
||||||
meshnode->_sons.push_back(sourcenormal);
|
meshnode->_sons.push_back(sourcenormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CHANGE THIS PIECE OF CODE!
|
||||||
|
bool vcolormask = bool((mask & vcg::tri::io::Mask::IOM_VERTCOLOR));
|
||||||
|
if (vcolormask)
|
||||||
|
{
|
||||||
|
XNode* sourcevcolor = new XNode(new Tags::SourceTag(shape+"-lib-vcolor","vcolor"));
|
||||||
|
|
||||||
|
//we export only triangular face
|
||||||
|
XLeaf* floatvcolorarr = new XLeaf(new Tags::FloatArrayTag(shape+"-lib-vcolor-array",m.vert.size() * return_component_number,m,Tags::FloatArrayTag::VERTCOLOR,return_component_number));
|
||||||
|
XNode* techcommvcolornode = new XNode(new Tags::TechniqueCommonTag());
|
||||||
|
XNode* accessorvcolornode = new XNode(new Tags::AccessorTag(m.vert.size(),shape+"-lib-vcolor-array",return_component_number));
|
||||||
|
|
||||||
|
//I have to make up the following piece of code
|
||||||
|
XNode* paramvcolorx = new XNode(new Tags::ParamTag("R","float"));
|
||||||
|
XNode* paramvcolory = new XNode(new Tags::ParamTag("G","float"));
|
||||||
|
XNode* paramvcolorz = new XNode(new Tags::ParamTag("B","float"));
|
||||||
|
|
||||||
|
sourcevcolor->_sons.push_back(floatvcolorarr);
|
||||||
|
|
||||||
|
accessorvcolornode->_sons.push_back(paramvcolorx);
|
||||||
|
accessorvcolornode->_sons.push_back(paramvcolory);
|
||||||
|
accessorvcolornode->_sons.push_back(paramvcolorz);
|
||||||
|
|
||||||
|
techcommvcolornode->_sons.push_back(accessorvcolornode);
|
||||||
|
sourcevcolor->_sons.push_back(techcommvcolornode);
|
||||||
|
|
||||||
|
meshnode->_sons.push_back(sourcevcolor);
|
||||||
|
}
|
||||||
|
|
||||||
bool texmask = bool(mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD);
|
bool texmask = bool(mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD);
|
||||||
if (texmask)
|
if (texmask)
|
||||||
{
|
{
|
||||||
|
|
@ -1044,7 +1078,10 @@ public:
|
||||||
|
|
||||||
XNode* vertnode = new XNode(new Tags::VerticesTag(shape+"-lib-vertices"));
|
XNode* vertnode = new XNode(new Tags::VerticesTag(shape+"-lib-vertices"));
|
||||||
XNode* inputposnode = new XNode(new Tags::InputTag("POSITION",shape+"-lib-positions"));
|
XNode* inputposnode = new XNode(new Tags::InputTag("POSITION",shape+"-lib-positions"));
|
||||||
|
//XNode* inputvcolnode = new XNode(new Tags::InputTag("COLOR",shape+"-lib-vcolor"));
|
||||||
vertnode->_sons.push_back(inputposnode);
|
vertnode->_sons.push_back(inputposnode);
|
||||||
|
//vertnode->_sons.push_back(inputvcolnode);
|
||||||
|
|
||||||
meshnode->_sons.push_back(vertnode);
|
meshnode->_sons.push_back(vertnode);
|
||||||
XNode* trianglesnode = NULL;
|
XNode* trianglesnode = NULL;
|
||||||
//if ((m.textures.size() == 0) || (!texmask))
|
//if ((m.textures.size() == 0) || (!texmask))
|
||||||
|
|
@ -1083,23 +1120,33 @@ public:
|
||||||
|
|
||||||
XNode* inputtrinode = new XNode(new Tags::InputTag(0,"VERTEX",shape+"-lib-vertices"));
|
XNode* inputtrinode = new XNode(new Tags::InputTag(0,"VERTEX",shape+"-lib-vertices"));
|
||||||
trianglesnode->_sons.push_back(inputtrinode);
|
trianglesnode->_sons.push_back(inputtrinode);
|
||||||
|
int offs=1;
|
||||||
|
if (vcolormask)
|
||||||
|
{
|
||||||
|
XNode* inputvcolnode = new XNode(new Tags::InputTag(offs,"COLOR",shape+"-lib-vcolor"));
|
||||||
|
trianglesnode->_sons.push_back(inputvcolnode);
|
||||||
|
offs++;
|
||||||
|
}
|
||||||
|
|
||||||
if (normalmask)
|
if (normalmask)
|
||||||
{
|
{
|
||||||
XNode* inputnormnode = new XNode(new Tags::InputTag(1,"NORMAL",shape+"-lib-normals"));
|
XNode* inputnormnode = new XNode(new Tags::InputTag(offs,"NORMAL",shape+"-lib-normals"));
|
||||||
trianglesnode->_sons.push_back(inputnormnode);
|
trianglesnode->_sons.push_back(inputnormnode);
|
||||||
|
offs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texmask)
|
if (texmask)
|
||||||
{
|
{
|
||||||
XNode* inputwedgenode = new XNode(new Tags::InputTag(2,"TEXCOORD",shape+"-lib-map"));
|
XNode* inputwedgenode = new XNode(new Tags::InputTag(offs,"TEXCOORD",shape+"-lib-map"));
|
||||||
trianglesnode->_sons.push_back(inputwedgenode);
|
trianglesnode->_sons.push_back(inputwedgenode);
|
||||||
|
offs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
XLeaf* polyleaf = NULL;
|
XLeaf* polyleaf = NULL;
|
||||||
if (itp == mytripatches.end())
|
if (itp == mytripatches.end())
|
||||||
polyleaf = new XLeaf(new Tags::PTag(m,edgefacenum,normalmask,texmask));
|
polyleaf = new XLeaf(new Tags::PTag(m,edgefacenum,vcolormask,normalmask,texmask));
|
||||||
else
|
else
|
||||||
polyleaf = new XLeaf(new Tags::PTag(m,edgefacenum,(*itp),normalmask,texmask));
|
polyleaf = new XLeaf(new Tags::PTag(m,edgefacenum,(*itp),vcolormask,normalmask,texmask));
|
||||||
|
|
||||||
trianglesnode->_sons.push_back(polyleaf);
|
trianglesnode->_sons.push_back(polyleaf);
|
||||||
meshnode->_sons.push_back(trianglesnode);
|
meshnode->_sons.push_back(trianglesnode);
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ namespace io {
|
||||||
inline static void valueStringList(QStringList& res,const QDomNode srcnode,const QString& tag)
|
inline static void valueStringList(QStringList& res,const QDomNode srcnode,const QString& tag)
|
||||||
{
|
{
|
||||||
QDomNodeList list = srcnode.toElement().elementsByTagName(tag);
|
QDomNodeList list = srcnode.toElement().elementsByTagName(tag);
|
||||||
assert(list.size() == 1);
|
//assert(list.size() == 1);
|
||||||
QString nd = list.at(0).firstChild().nodeValue();
|
QString nd = list.at(0).firstChild().nodeValue();
|
||||||
res = nd.simplified().split(" ",QString::SkipEmptyParts);
|
res = nd.simplified().split(" ",QString::SkipEmptyParts);
|
||||||
if(res.empty())
|
if(res.empty())
|
||||||
|
|
|
||||||
|
|
@ -119,17 +119,17 @@ namespace io {
|
||||||
return indtx;
|
return indtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int WedgeColorAttribute(ColladaMesh& m,const QStringList face,const QStringList wc,const QDomNode wcsrc,const int meshfaceind,const int faceind,const int component)
|
static int VertexColorAttribute(ColladaMesh& m,const QStringList face,const QStringList wc,const QDomNode wcsrc,const int meshfaceind,const int faceind, const int vertind,const int component)
|
||||||
{
|
{
|
||||||
int indcl = -1;
|
int indcl = -1;
|
||||||
if (!wcsrc.isNull())
|
if (!wcsrc.isNull())
|
||||||
{
|
{
|
||||||
indcl = face.at(faceind).toInt();
|
indcl = face.at(faceind).toInt();
|
||||||
assert(indcl * 4 < wc.size());
|
assert(indcl * 3 < wc.size());
|
||||||
m.face[meshfaceind].WC(component) = vcg::Color4b( (unsigned char)(wc.at(indcl * 4).toFloat()),
|
m.vert[vertind].C() = vcg::Color4b( (unsigned char)(wc.at(indcl * 3).toFloat()*255.0),
|
||||||
(unsigned char)(wc.at(indcl * 4 + 1).toFloat()),
|
(unsigned char)(wc.at(indcl * 3 + 1).toFloat()*255.0),
|
||||||
(unsigned char)(wc.at(indcl * 4 + 2).toFloat()),
|
(unsigned char)(wc.at(indcl * 3 + 2).toFloat()*255.0),
|
||||||
(unsigned char)(wc.at(indcl * 4 + 3).toFloat()));
|
1.0);
|
||||||
}
|
}
|
||||||
return indcl;
|
return indcl;
|
||||||
}
|
}
|
||||||
|
|
@ -397,7 +397,7 @@ namespace io {
|
||||||
m.face[ff].V(tt) = &(m.vert[indvt + offset]);
|
m.face[ff].V(tt) = &(m.vert[indvt + offset]);
|
||||||
|
|
||||||
if(tri::HasPerWedgeNormal(m)) WedgeNormalAttribute(m,face,wa.wn,wa.wnsrc,ff,jj + wa.offnm,tt);
|
if(tri::HasPerWedgeNormal(m)) 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::HasPerVertexColor(m)) VertexColorAttribute(m,face,wa.wc,wa.wcsrc,ff,jj + wa.offcl,indvt + offset,tt);
|
||||||
|
|
||||||
if(tri::HasPerWedgeTexCoord(m) && ind_txt != -1)
|
if(tri::HasPerWedgeTexCoord(m) && ind_txt != -1)
|
||||||
{
|
{
|
||||||
|
|
@ -522,11 +522,11 @@ namespace io {
|
||||||
m.vert[vv].N() = normalCoord;
|
m.vert[vv].N() = normalCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (!srcnodecolor.isNull())
|
if (!srcnodecolor.isNull())
|
||||||
{
|
{
|
||||||
assert((ii * 4 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size()) && (ii * 4 + 2 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size()));
|
//assert((ii * 4 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size()) && (ii * 4 + 2 < geosrcvertcol.size()) && (ii * 4 + 1 < geosrcvertcol.size()));
|
||||||
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());
|
m.vert[vv].C() = vcg::Color4b(geosrcvertcol[ii * 3].toFloat()*255.0,geosrcvertcol[ii * 3 + 1].toFloat()*255.0,geosrcvertcol[ii * 3 + 2].toFloat()*255.0,1.0);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
if (!srcnodetext.isNull())
|
if (!srcnodetext.isNull())
|
||||||
{
|
{
|
||||||
|
|
@ -542,6 +542,20 @@ namespace io {
|
||||||
QDomNodeList tripatch = geo.toElement().elementsByTagName("triangles");
|
QDomNodeList tripatch = geo.toElement().elementsByTagName("triangles");
|
||||||
QDomNodeList polypatch = geo.toElement().elementsByTagName("polygons");
|
QDomNodeList polypatch = geo.toElement().elementsByTagName("polygons");
|
||||||
QDomNodeList polylist = geo.toElement().elementsByTagName("polylist");
|
QDomNodeList polylist = geo.toElement().elementsByTagName("polylist");
|
||||||
|
QStringList vertcount;
|
||||||
|
valueStringList(vertcount,polylist.at(0),"vcount");
|
||||||
|
int isTri=true;
|
||||||
|
for (int i=0; i<vertcount.size(); i++)
|
||||||
|
{
|
||||||
|
if (vertcount[i]!="3")
|
||||||
|
{
|
||||||
|
isTri=false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (isTri && tripatch.isEmpty())
|
||||||
|
tripatch=polylist;
|
||||||
if (tripatch.isEmpty() && polypatch.isEmpty() && polylist.isEmpty())
|
if (tripatch.isEmpty() && polypatch.isEmpty() && polylist.isEmpty())
|
||||||
return E_NOPOLYGONALMESH;
|
return E_NOPOLYGONALMESH;
|
||||||
|
|
||||||
|
|
@ -806,6 +820,7 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
{
|
{
|
||||||
bool bHasPerWedgeTexCoord = false;
|
bool bHasPerWedgeTexCoord = false;
|
||||||
bool bHasPerWedgeNormal = false;
|
bool bHasPerWedgeNormal = false;
|
||||||
|
//bool bHasPerWedgeColor = false;
|
||||||
bool bHasPerVertexColor = false;
|
bool bHasPerVertexColor = false;
|
||||||
bool bHasPerFaceColor = false;
|
bool bHasPerFaceColor = false;
|
||||||
bool bHasPerVertexNormal = false;
|
bool bHasPerVertexNormal = false;
|
||||||
|
|
@ -912,6 +927,9 @@ static Matrix44f getTransfMatrixFromNode(const QDomElement parentNode)
|
||||||
no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","NORMAL");
|
no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","NORMAL");
|
||||||
if (!no.isNull())
|
if (!no.isNull())
|
||||||
bHasPerWedgeNormal = true;
|
bHasPerWedgeNormal = true;
|
||||||
|
no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","COLOR");
|
||||||
|
if (!no.isNull())
|
||||||
|
bHasPerVertexColor = true;
|
||||||
no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","TEXCOORD");
|
no = findNodeBySpecificAttributeValue(facelist.at(face),"input","semantic","TEXCOORD");
|
||||||
if (!no.isNull())
|
if (!no.isNull())
|
||||||
bHasPerWedgeTexCoord = true;
|
bHasPerWedgeTexCoord = true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue