Commit: 8313283889ef1849a2232c58342233ffd28a05ee
Author: Campbell Barton
Date: Sun Mar 29 21:30:43 2015 +1100
Branches: temp-modifier-deltamush-experimental
https://developer.blender.org/rB8313283889ef1849a2232c58342233ffd28a05ee
pre-divide vertex-count, avoid zero checks in smooth loop
===================================================================
M source/blender/modifiers/intern/MOD_deltamush.c
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_deltamush.c
b/source/blender/modifiers/intern/MOD_deltamush.c
index 061d5e0..c29e160 100644
--- a/source/blender/modifiers/intern/MOD_deltamush.c
+++ b/source/blender/modifiers/intern/MOD_deltamush.c
@@ -186,13 +186,12 @@ typedef struct SmoothingData {
static void smooth_iter(
DeltaMushModifierData *dmmd, DerivedMesh *dm,
float(*vertexCos)[3], unsigned int numVerts,
- const short *boundaries, const float *vertex_edge_count,
+ const short *boundaries, const float *vertex_edge_count_idiv,
SmoothingData *smooth_data)
{
const unsigned int numEdges = (unsigned int)dm->getNumEdges(dm);
const MEdge *edges = dm->getEdgeArray(dm);
const float lambda = dmmd->lambda;
- const float eps = FLT_EPSILON * 10.0f;
unsigned int i;
for (i = 0; i < numEdges; i++) {
@@ -219,10 +218,7 @@ static void smooth_iter(
/* fast-path */
for (i = 0; i < numVerts; i++) {
SmoothingData *sd = &smooth_data[i];
- float div = vertex_edge_count[i];
- if (div > eps) {
- mul_v3_v3fl(vertexCos[i], sd->delta, 1.0f /
div);
- }
+ mul_v3_v3fl(vertexCos[i], sd->delta,
vertex_edge_count_idiv[i]);
/* zero for the next iteration (saves memset on entire
array) */
memset(sd, 0, sizeof(*sd));
}
@@ -231,23 +227,20 @@ static void smooth_iter(
for (i = 0; i < numVerts; i++) {
SmoothingData *sd = &smooth_data[i];
- float div = vertex_edge_count[i];
-
- if (div > eps) {
- float lambda_alt = 1.0;
- if (dmmd->smooth_weights) {
- lambda_alt *= dmmd->smooth_weights[i];
- }
+ float lambda_alt = 1.0;
- if (boundaries) {
- lambda_alt *= (boundaries[i] != 0 ?
0.0f : 1.0f);
- }
+ if (dmmd->smooth_weights) {
+ lambda_alt *= dmmd->smooth_weights[i];
+ }
- mul_v3_fl(sd->delta, 1.0f / div);
- interp_v3_v3v3(vertexCos[i], vertexCos[i],
sd->delta, lambda_alt);
+ if (boundaries) {
+ lambda_alt *= (boundaries[i] != 0 ? 0.0f :
1.0f);
}
+ mul_v3_fl(sd->delta, vertex_edge_count_idiv[i]);
+ interp_v3_v3v3(vertexCos[i], vertexCos[i], sd->delta,
lambda_alt);
+
memset(sd, 0, sizeof(*sd));
}
}
@@ -278,6 +271,10 @@ static void smooth_verts(
vertex_edge_count[edges[i].v2] += 1.0f;
}
+ for (i = 0; i < numVerts; i++) {
+ vertex_edge_count[i] = vertex_edge_count[i] ? (1.0f /
vertex_edge_count[i]) : 1.0f;
+ }
+
smooth_data = MEM_callocN((size_t)numVerts * sizeof(SmoothingData),
"delta mush smoothing data");
for (i = 0; i < (unsigned int)dmmd->repeat; i++) {
/* no need to memset each time, 'smooth_iter' cleans up after
its self */
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs