[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27414] trunk/blender/source/blender/ collada/DocumentExporter.cpp: Merge -c 27223 from COLLADA branch into trunk .
Arystanbek Dyussenov
arystan.d at gmail.com
Thu Mar 11 16:37:20 CET 2010
Revision: 27414
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27414
Author: kazanbas
Date: 2010-03-11 16:37:19 +0100 (Thu, 11 Mar 2010)
Log Message:
-----------
Merge -c 27223 from COLLADA branch into trunk. Vertex color export was requested and reported to work by Blake Maltby.
Modified Paths:
--------------
trunk/blender/source/blender/collada/DocumentExporter.cpp
Modified: trunk/blender/source/blender/collada/DocumentExporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentExporter.cpp 2010-03-11 15:28:22 UTC (rev 27413)
+++ trunk/blender/source/blender/collada/DocumentExporter.cpp 2010-03-11 15:37:19 UTC (rev 27414)
@@ -359,6 +359,8 @@
std::vector<Normal> nor;
std::vector<Face> norind;
+ bool has_color = (bool)CustomData_has_layer(&me->fdata, CD_MCOL);
+
create_normals(nor, norind, me);
// openMesh(geoId, geoName, meshId)
@@ -370,12 +372,15 @@
// writes <source> for normal coords
createNormalsSource(geom_id, me, nor);
- int has_uvs = CustomData_has_layer(&me->fdata, CD_MTFACE);
+ bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE);
// writes <source> for uv coords if mesh has uv coords
- if (has_uvs) {
- createTexcoordsSource(geom_id, (Mesh*)ob->data);
- }
+ if (has_uvs)
+ createTexcoordsSource(geom_id, me);
+
+ if (has_color)
+ createVertexColorSource(geom_id, me);
+
// <vertices>
COLLADASW::Vertices verts(mSW);
verts.setId(getIdBySemantics(geom_id, COLLADASW::VERTEX));
@@ -389,11 +394,11 @@
for(int a = 0; a < ob->totcol; a++) {
// account for NULL materials, this should not normally happen?
Material *ma = give_current_material(ob, a + 1);
- createPolylist(ma != NULL, a, has_uvs, ob, geom_id, norind);
+ createPolylist(ma != NULL, a, has_uvs, has_color, ob, geom_id, norind);
}
}
else {
- createPolylist(false, 0, has_uvs, ob, geom_id, norind);
+ createPolylist(false, 0, has_uvs, has_color, ob, geom_id, norind);
}
closeMesh();
@@ -408,14 +413,11 @@
void createPolylist(bool has_material,
int material_index,
bool has_uvs,
+ bool has_color,
Object *ob,
std::string& geom_id,
std::vector<Face>& norind)
{
-#if 0
- MFace *mfaces = dm->getFaceArray(dm);
- int totfaces = dm->getNumFaces(dm);
-#endif
Mesh *me = (Mesh*)ob->data;
MFace *mfaces = me->mface;
int totfaces = me->totface;
@@ -479,6 +481,11 @@
);
til.push_back(input3);
}
+
+ if (has_color) {
+ COLLADASW::Input input4(COLLADASW::COLOR, getUrlBySemantics(geom_id, COLLADASW::COLOR), has_uvs ? 3 : 2);
+ til.push_back(input4);
+ }
// sets <vcount>
polylist.setVCountList(vcount_list);
@@ -501,6 +508,9 @@
if (has_uvs)
polylist.appendValues(texindex + j);
+
+ if (has_color)
+ polylist.appendValues(texindex + j);
}
}
@@ -545,6 +555,42 @@
}
+ void createVertexColorSource(std::string geom_id, Mesh *me)
+ {
+ if (!CustomData_has_layer(&me->fdata, CD_MCOL))
+ return;
+
+ MFace *f;
+ int totcolor = 0, i, j;
+
+ for (i = 0, f = me->mface; i < me->totface; i++, f++)
+ totcolor += f->v4 ? 4 : 3;
+
+ COLLADASW::FloatSourceF source(mSW);
+ source.setId(getIdBySemantics(geom_id, COLLADASW::COLOR));
+ source.setArrayId(getIdBySemantics(geom_id, COLLADASW::COLOR) + ARRAY_ID_SUFFIX);
+ source.setAccessorCount(totcolor);
+ source.setAccessorStride(3);
+
+ COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
+ param.push_back("R");
+ param.push_back("G");
+ param.push_back("B");
+
+ source.prepareToAppendValues();
+
+ int index = CustomData_get_active_layer_index(&me->fdata, CD_MCOL);
+
+ MCol *mcol = (MCol*)me->fdata.layers[index].data;
+ MCol *c = mcol;
+
+ for (i = 0, f = me->mface; i < me->totface; i++, c += 4, f++)
+ for (j = 0; j < (f->v4 ? 4 : 3); j++)
+ source.appendValues(c[j].b / 255.0f, c[j].g / 255.0f, c[j].r / 255.0f);
+
+ source.finish();
+ }
+
std::string makeTexcoordSourceId(std::string& geom_id, int layer_index)
{
char suffix[20];
More information about the Bf-blender-cvs
mailing list