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:
authorGaia Clary <gaia.clary@machinimatrix.org>2015-04-16 20:02:00 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2015-04-16 20:02:26 +0300
commitbbae0664a3df0ec3b3dcc199ab3a52a998bc5290 (patch)
tree352cf84873fa800290838b5f40fa76bed791dbc2 /source/blender/collada
parenta7cae2987d078da8a3cb9a293fbcdf3b6ab43ddb (diff)
Added Support for Custom Vertex Normals to Collada exporter
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/GeometryExporter.cpp38
-rw-r--r--source/blender/collada/GeometryExporter.h19
2 files changed, 41 insertions, 16 deletions
diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp
index 28cee05ec4b..1353d988137 100644
--- a/source/blender/collada/GeometryExporter.cpp
+++ b/source/blender/collada/GeometryExporter.cpp
@@ -82,6 +82,9 @@ void GeometryExporter::operator()(Object *ob)
this->export_settings->apply_modifiers,
this->export_settings->triangulate);
+ Mesh *mesh = (Mesh *) ob->data;
+ me->flag = mesh->flag;
+
std::string geom_id = get_geometry_id(ob, use_instantiation);
std::vector<Normal> nor;
std::vector<BCPolygonNormalsIndices> norind;
@@ -563,6 +566,11 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me)
}
}
+bool operator<(const Normal &a, const Normal &b)
+{
+ /* only needed to sort normal vectors and find() them later in a map.*/
+ return a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && a.z < b.z)));
+}
//creates <source> for normals
void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal>& nor)
@@ -596,11 +604,18 @@ void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::v
void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector<BCPolygonNormalsIndices> &polygons_normals, Mesh *me)
{
- std::map<unsigned int, unsigned int> shared_normal_indices;
+ std::map<Normal, unsigned int> shared_normal_indices;
int last_normal_index = -1;
MVert *verts = me->mvert;
MLoop *mloops = me->mloop;
+ float(*lnors)[3];
+
+ BKE_mesh_calc_normals_split(me);
+ if (CustomData_has_layer(&me->ldata, CD_NORMAL)) {
+ lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL);
+ }
+
for (int poly_index = 0; poly_index < me->totpoly; poly_index++) {
MPoly *mpoly = &me->mpoly[poly_index];
@@ -615,25 +630,24 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector<
last_normal_index++;
}
-
MLoop *mloop = mloops + mpoly->loopstart;
BCPolygonNormalsIndices poly_indices;
for (int loop_index = 0; loop_index < mpoly->totloop; loop_index++) {
- unsigned int vertex_index = mloop[loop_index].v;
+ unsigned int loop_idx = mpoly->loopstart + loop_index;
if (mpoly->flag & ME_SMOOTH) {
- if (shared_normal_indices.find(vertex_index) != shared_normal_indices.end())
- poly_indices.add_index (shared_normal_indices[vertex_index]);
- else {
- float vector[3];
- normal_short_to_float_v3(vector, verts[vertex_index].no);
+ float normalized[3];
+ normalize_v3_v3(normalized, lnors[loop_idx]);
+ Normal n = { normalized[0], normalized[1], normalized[2] };
- Normal n = { vector[0], vector[1], vector[2] };
- normals.push_back(n);
+ if (shared_normal_indices.find(n) != shared_normal_indices.end()) {
+ poly_indices.add_index(shared_normal_indices[n]);
+ }
+ else {
last_normal_index++;
-
poly_indices.add_index(last_normal_index);
- shared_normal_indices[vertex_index] = last_normal_index;
+ shared_normal_indices[n] = last_normal_index;
+ normals.push_back(n);
}
}
else {
diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h
index 4d54e79d796..69d1067e6f4 100644
--- a/source/blender/collada/GeometryExporter.h
+++ b/source/blender/collada/GeometryExporter.h
@@ -48,6 +48,20 @@
extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob);
+class Normal
+{
+ public:
+ float x;
+ float y;
+ float z;
+
+ friend bool operator< (const Normal &, const Normal &);
+
+};
+
+bool operator< (const Normal &, const Normal &);
+
+
// TODO: optimize UV sets by making indexed list with duplicates removed
class GeometryExporter : COLLADASW::LibraryGeometries
{
@@ -56,10 +70,7 @@ class GeometryExporter : COLLADASW::LibraryGeometries
unsigned int v1, v2, v3, v4;
};
- struct Normal
- {
- float x, y, z;
- };
+ Normal n;
Scene *mScene;