Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArystanbek Dyussenov <arystan.d@gmail.com>2010-03-11 18:37:19 +0300
committerArystanbek Dyussenov <arystan.d@gmail.com>2010-03-11 18:37:19 +0300
commit8da10f59eb10d2ee135f270c0e1a9ccd20f4f300 (patch)
tree655da7c1d50fd1d7063be4e7e778590f68be8f20 /source/blender/collada
parentce747a1c262421d6089d65395b891d455d3e1cd6 (diff)
Merge -c 27223 from COLLADA branch into trunk. Vertex color export was requested and reported to work by Blake Maltby.
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/DocumentExporter.cpp66
1 files changed, 56 insertions, 10 deletions
diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp
index dfc41074ae6..f90a494fd8d 100644
--- a/source/blender/collada/DocumentExporter.cpp
+++ b/source/blender/collada/DocumentExporter.cpp
@@ -359,6 +359,8 @@ public:
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 @@ public:
// 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 @@ public:
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 @@ public:
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 @@ public:
);
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 @@ public:
if (has_uvs)
polylist.appendValues(texindex + j);
+
+ if (has_color)
+ polylist.appendValues(texindex + j);
}
}
@@ -545,6 +555,42 @@ public:
}
+ 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 &param = 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];