collada:custom normals generated by normals modifier have not been exported correctly. Also triangulating during export did not work.

This commit is contained in:
2015-05-06 17:03:24 +02:00
parent 14d55ab7a3
commit 51f33a2e55
2 changed files with 11 additions and 10 deletions

View File

@@ -82,9 +82,6 @@ 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;
@@ -610,16 +607,19 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector<
MVert *verts = me->mvert;
MLoop *mloops = me->mloop;
float(*lnors)[3];
bool use_custom_normals = false;
BKE_mesh_calc_normals_split(me);
if (CustomData_has_layer(&me->ldata, CD_NORMAL)) {
lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL);
use_custom_normals = true;
}
for (int poly_index = 0; poly_index < me->totpoly; poly_index++) {
MPoly *mpoly = &me->mpoly[poly_index];
bool use_vertex_normals = use_custom_normals || mpoly->flag & ME_SMOOTH;
if (!(mpoly->flag & ME_SMOOTH)) {
if (!use_vertex_normals) {
// For flat faces use face normal as vertex normal:
float vector[3];
@@ -634,7 +634,7 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector<
BCPolygonNormalsIndices poly_indices;
for (int loop_index = 0; loop_index < mpoly->totloop; loop_index++) {
unsigned int loop_idx = mpoly->loopstart + loop_index;
if (mpoly->flag & ME_SMOOTH) {
if (use_vertex_normals) {
float normalized[3];
normalize_v3_v3(normalized, lnors[loop_idx]);

View File

@@ -144,6 +144,7 @@ Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh
{
Mesh *tmpmesh;
CustomDataMask mask = CD_MASK_MESH;
Mesh *mesh = (Mesh *)ob->data;
DerivedMesh *dm = NULL;
if (apply_modifiers) {
switch (export_mesh_type) {
@@ -165,14 +166,14 @@ Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh
tmpmesh = BKE_mesh_add(G.main, "ColladaMesh"); // name is not important here
DM_to_mesh(dm, tmpmesh, ob, CD_MASK_MESH, true);
tmpmesh->flag = mesh->flag;
if (triangulate) {
bc_triangulate_mesh(tmpmesh);
BKE_mesh_tessface_calc(tmpmesh);
}
// XXX Not sure if we need that for ngon_export as well.
else {
BKE_mesh_tessface_ensure(tmpmesh);
}
return tmpmesh;
}