[Bf-blender-cvs] [b4edbff] mesh-transfer-data: Attempt to handle better normals stuff.
Bastien Montagne
noreply at git.blender.org
Wed Nov 12 20:50:42 CET 2014
Commit: b4edbff3492e554e84696d2ef35e5c5f728bf0d1
Author: Bastien Montagne
Date: Wed Nov 12 19:58:10 2014 +0100
Branches: mesh-transfer-data
https://developer.blender.org/rBb4edbff3492e554e84696d2ef35e5c5f728bf0d1
Attempt to handle better normals stuff.
Note we may ultimately decide to just always compute loop and poly nors...
This would be a shame in some cases (we'll have several modifiers using those data
soon), but caching it in a reliable way is not that easy.
===================================================================
M source/blender/blenkernel/BKE_customdata.h
M source/blender/blenkernel/BKE_data_transfer.h
M source/blender/blenkernel/BKE_mesh_mapping.h
M source/blender/blenkernel/intern/DerivedMesh.c
M source/blender/blenkernel/intern/data_transfer.c
M source/blender/blenkernel/intern/mesh_mapping.c
M source/blender/modifiers/intern/MOD_datatransfer.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 726414d..71a7ce7 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -399,17 +399,17 @@ enum {
};
enum {
- ME_VERT = 1,
- ME_EDGE = 2,
- ME_POLY = 3,
- ME_LOOP = 4,
+ ME_VERT = 1 << 0,
+ ME_EDGE = 1 << 1,
+ ME_POLY = 1 << 2,
+ ME_LOOP = 1 << 3,
};
/* How to filter out some elements (to leave untouched).
* Note those options are highly dependent on type of transferred data! */
enum {
CDT_MIX_NOMIX = -1, /* Special case, only used because we abuse 'copy' CD callback. */
- CDT_MIX_TRANSFER = 0,
+ CDT_MIX_TRANSFER = 0,
CDT_MIX_REPLACE_ABOVE_THRESHOLD = 1,
CDT_MIX_REPLACE_BELOW_THRESHOLD = 2,
CDT_MIX_MIX = 16,
diff --git a/source/blender/blenkernel/BKE_data_transfer.h b/source/blender/blenkernel/BKE_data_transfer.h
index 4c1691b..3672e98 100644
--- a/source/blender/blenkernel/BKE_data_transfer.h
+++ b/source/blender/blenkernel/BKE_data_transfer.h
@@ -66,6 +66,7 @@ enum {
CustomDataMask BKE_data_transfer_dttypes_to_cdmask(const int dtdata_types);
bool BKE_data_transfer_get_dttypes_capacity(
const int dtdata_types, bool *r_advanced_mixing, bool *r_threshold);
+int BKE_data_transfer_get_dttypes_item_types(const int dtdata_types);
int BKE_data_transfer_dttype_to_cdtype(const int dtdata_type);
int BKE_data_transfer_dttype_to_fromto_idx(const int dtdata_type);
diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h
index 47ffe1f..5e20fe5 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -282,26 +282,27 @@ enum {
void BKE_dm2mesh_mapping_verts_compute(
const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius,
- const struct MVert *verts_dst, const int numverts_dst,
+ const struct MVert *verts_dst, const int numverts_dst, const bool dirty_nors_dst,
struct DerivedMesh *dm_src, Mesh2MeshMapping *r_map);
void BKE_dm2mesh_mapping_edges_compute(
const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius,
const struct MVert *verts_dst, const int numverts_dst, const struct MEdge *edges_dst, const int numedges_dst,
- struct DerivedMesh *dm_src, Mesh2MeshMapping *r_map);
+ const bool dirty_nors_dst, struct DerivedMesh *dm_src, Mesh2MeshMapping *r_map);
void BKE_dm2mesh_mapping_loops_compute(
const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius,
struct MVert *verts_dst, const int numverts_dst, struct MEdge *edges_dst, const int numedges_dst,
struct MLoop *loops_dst, const int numloops_dst, struct MPoly *polys_dst, const int numpolys_dst,
struct CustomData *ldata_dst, struct CustomData *pdata_dst, const float split_angle_dst,
+ const bool dirty_nors_dst,
struct DerivedMesh *dm_src, loop_island_compute gen_islands_src, struct Mesh2MeshMapping *r_map);
void BKE_dm2mesh_mapping_polys_compute(
const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius,
struct MVert *verts_dst, const int numverts_dst, struct MLoop *loops_dst, const int numloops_dst,
- struct MPoly *polys_dst, const int numpolys_dst, struct CustomData *pdata_dst, struct DerivedMesh *dm_src,
- struct Mesh2MeshMapping *r_map);
+ struct MPoly *polys_dst, const int numpolys_dst, struct CustomData *pdata_dst, const bool dirty_nors_dst,
+ struct DerivedMesh *dm_src, struct Mesh2MeshMapping *r_map);
/* No good (portable) way to have exported inlined functions... */
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 81c03d8..de323a2 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1451,8 +1451,10 @@ static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob))
*/
static void dm_ensure_display_normals(DerivedMesh *dm)
{
- /* this is for final output only, up until now this layer should be missing */
- BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
+ /* Note: dm *may* have a poly CD_NORMAL layer (generated by a modifier needing poly normals e.g.).
+ * We do not use it here, though. And it should be tagged as temp!
+ */
+ /* BLI_assert((CustomData_has_layer(&dm->polyData, CD_NORMAL) == false)); */
if ((dm->type == DM_TYPE_CDDM) &&
((dm->dirty & DM_DIRTY_NORMALS) || CustomData_has_layer(&dm->faceData, CD_NORMAL) == false))
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index 829f793..f2dccc9 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -153,6 +153,34 @@ bool BKE_data_transfer_get_dttypes_capacity(
return ret;
}
+int BKE_data_transfer_get_dttypes_item_types(const int dtdata_types)
+{
+ int i, ret = 0;
+
+ for (i = 0; (i < 32) && (ret ^ (ME_VERT | ME_EDGE | ME_LOOP | ME_POLY)); i++) {
+ const int dtdata_type = 1 << i;
+
+ if (!(dtdata_types & dtdata_type)) {
+ continue;
+ }
+
+ if (DT_DATATYPE_IS_VERT(dtdata_type)) {
+ ret |= ME_VERT;
+ }
+ if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
+ ret |= ME_EDGE;
+ }
+ if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
+ ret |= ME_LOOP;
+ }
+ if (DT_DATATYPE_IS_POLY(dtdata_type)) {
+ ret |= ME_POLY;
+ }
+ }
+
+ return ret;
+}
+
int BKE_data_transfer_dttype_to_cdtype(const int dtdata_type)
{
switch (dtdata_type) {
@@ -749,6 +777,7 @@ bool BKE_data_transfer_dm(
DerivedMesh *dm_src;
Mesh *me_dst;
+ bool dirty_nors_dst = true; /* Assumed always true if not using a dm as destination. */
int i;
MDeformVert *mdef = NULL;
@@ -765,6 +794,9 @@ bool BKE_data_transfer_dm(
BLI_assert((ob_src != ob_dst) && (ob_src->type == OB_MESH) && (ob_dst->type == OB_MESH));
me_dst = ob_dst->data;
+ if (dm_dst) {
+ dirty_nors_dst = (dm_dst->dirty & DM_DIRTY_NORMALS) != 0;
+ }
if (vgroup_name) {
if (dm_dst) {
@@ -817,7 +849,7 @@ bool BKE_data_transfer_dm(
return changed;
}
BKE_dm2mesh_mapping_verts_compute(map_vert_mode, space_transform, max_distance, ray_radius,
- verts_dst, num_verts_dst, dm_src, &geom_map[VDATA]);
+ verts_dst, num_verts_dst, dirty_nors_dst, dm_src, &geom_map[VDATA]);
geom_map_init[VDATA] = true;
}
@@ -856,7 +888,7 @@ bool BKE_data_transfer_dm(
return changed;
}
BKE_dm2mesh_mapping_edges_compute(map_edge_mode, space_transform, max_distance, ray_radius,
- verts_dst, num_verts_dst, edges_dst, num_edges_dst,
+ verts_dst, num_verts_dst, edges_dst, num_edges_dst, dirty_nors_dst,
dm_src, &geom_map[EDATA]);
geom_map_init[EDATA] = true;
}
@@ -907,8 +939,8 @@ bool BKE_data_transfer_dm(
BKE_dm2mesh_mapping_loops_compute(map_loop_mode, space_transform, max_distance, ray_radius,
verts_dst, num_verts_dst, edges_dst, num_edges_dst,
loops_dst, num_loops_dst, polys_dst, num_polys_dst,
- ldata_dst, pdata_dst,
- me_dst->smoothresh, dm_src, island_callback, &geom_map[LDATA]);
+ ldata_dst, pdata_dst, me_dst->smoothresh, dirty_nors_dst,
+ dm_src, island_callback, &geom_map[LDATA]);
geom_map_init[LDATA] = true;
}
@@ -952,7 +984,8 @@ bool BKE_data_transfer_dm(
}
BKE_dm2mesh_mapping_polys_compute(map_poly_mode, space_transform, max_distance, ray_radius,
verts_dst, num_verts_dst, loops_dst, num_loops_dst,
- polys_dst, num_polys_dst, pdata_dst, dm_src, &geom_map[PDATA]);
+ polys_dst, num_polys_dst, pdata_dst, dirty_nors_dst,
+ dm_src, &geom_map[PDATA]);
geom_map_init[PDATA] = true;
}
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index 050c4cb..0fcada1 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -883,7 +883,7 @@ typedef struct IslandResult {
void BKE_dm2mesh_mapping_verts_compute(
const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius,
- const MVert *verts_dst, const int numverts_dst, DerivedMesh *dm_src,
+ const MVert *verts_dst, const int numverts_dst, const bool UNUSED(dirty_nors_dst), DerivedMesh *dm_src,
Mesh2MeshMapping *r_map)
{
const float full_weight = 1.0f;
@@ -1073,11 +1073,10 @@ void BKE_dm2mesh_mapping_verts_compute(
}
}
-/* TODO: all those 'nearest' edge computations could be hugely enhanced, not top priority though. */
void BKE_dm2mesh_mapping_edges_compute(
const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius,
const MVert *verts_dst, const int numverts_dst, const MEdge *edges_dst, const int numedges_dst,
- DerivedMesh *dm_src, Mesh2MeshMapping *r_map)
+ const bool UNUSED(dirty_nors_dst), DerivedMesh *dm_src, Mesh2MeshMapping *r_map)
{
const float full_weight = 1.0f;
const float max_dist_sq = max_dist * max_dist;
@@ -1403,7 +1402,7 @@ void BKE_dm2mesh_mapping_loops_compute(
const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius,
MVert *verts_dst, const int numverts_dst, MEdge *edges_dst, const int numedges_dst,
MLoop *loops_dst, const int numloops_dst, MPoly *polys_dst, const int
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list