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:
authorPablo Dobarro <pablodp606@gmail.com>2021-02-10 03:38:28 +0300
committerPablo Dobarro <pablodp606@gmail.com>2021-02-10 20:06:56 +0300
commit4818ed1c76cad447b59a36056b170282732dde0d (patch)
tree4964d5a6fba57742b0bd6a8569b61c755d45c4ff /source/blender/editors/sculpt_paint/sculpt_cloth.c
parent54cbfeedd7852b160696ca1571de5f28e4e88511 (diff)
Cleanup: Unindent if statements in sculpt tools code
This removes indentations from if statements by converting them to early returns and continue. Most of the code of brushes and tools has loops with a full indented body inside of an if, which was also copied into some of the new tools. Reviewed By: JacquesLucke Differential Revision: https://developer.blender.org/D10333
Diffstat (limited to 'source/blender/editors/sculpt_paint/sculpt_cloth.c')
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_cloth.c283
1 files changed, 146 insertions, 137 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index c97f31fa682..16d10f6d6bb 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -540,97 +540,98 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata,
cloth_brush_apply_force_to_vertex(ss, ss->cache->cloth_sim, vertex_gravity, vd.index);
/* When using the plane falloff mode the falloff is not constrained by the brush radius. */
- if (sculpt_brush_test_sq_fn(&test, current_vertex_location) || use_falloff_plane) {
-
- float dist = sqrtf(test.dist);
+ if (!sculpt_brush_test_sq_fn(&test, current_vertex_location) && !use_falloff_plane) {
+ continue;
+ }
- if (use_falloff_plane) {
- dist = dist_to_plane_v3(current_vertex_location, deform_plane);
- }
+ float dist = sqrtf(test.dist);
- const float fade = sim_factor * bstrength *
- SCULPT_brush_strength_factor(ss,
- brush,
- current_vertex_location,
- dist,
- vd.no,
- vd.fno,
- vd.mask ? *vd.mask : 0.0f,
- vd.index,
- thread_id);
-
- float brush_disp[3];
- float normal[3];
- if (vd.no) {
- normal_short_to_float_v3(normal, vd.no);
- }
- else {
- copy_v3_v3(normal, vd.fno);
- }
+ if (use_falloff_plane) {
+ dist = dist_to_plane_v3(current_vertex_location, deform_plane);
+ }
- switch (brush->cloth_deform_type) {
- case BRUSH_CLOTH_DEFORM_DRAG:
- sub_v3_v3v3(brush_disp, ss->cache->location, ss->cache->last_location);
- normalize_v3(brush_disp);
- mul_v3_v3fl(force, brush_disp, fade);
- break;
- case BRUSH_CLOTH_DEFORM_PUSH:
- /* Invert the fade to push inwards. */
- mul_v3_v3fl(force, offset, -fade);
- break;
- case BRUSH_CLOTH_DEFORM_GRAB:
- madd_v3_v3v3fl(cloth_sim->deformation_pos[vd.index],
- cloth_sim->init_pos[vd.index],
- ss->cache->grab_delta_symmetry,
- fade);
- if (use_falloff_plane) {
- cloth_sim->deformation_strength[vd.index] = clamp_f(fade, 0.0f, 1.0f);
- }
- else {
- cloth_sim->deformation_strength[vd.index] = 1.0f;
- }
- zero_v3(force);
- break;
- case BRUSH_CLOTH_DEFORM_SNAKE_HOOK:
- copy_v3_v3(cloth_sim->deformation_pos[vd.index], cloth_sim->pos[vd.index]);
- madd_v3_v3fl(cloth_sim->deformation_pos[vd.index], ss->cache->grab_delta_symmetry, fade);
- cloth_sim->deformation_strength[vd.index] = fade;
- zero_v3(force);
- break;
- case BRUSH_CLOTH_DEFORM_PINCH_POINT:
- if (use_falloff_plane) {
- float distance = dist_signed_to_plane_v3(vd.co, deform_plane);
- copy_v3_v3(brush_disp, plane_normal);
- mul_v3_fl(brush_disp, -distance);
- }
- else {
- sub_v3_v3v3(brush_disp, ss->cache->location, vd.co);
- }
- normalize_v3(brush_disp);
- mul_v3_v3fl(force, brush_disp, fade);
- break;
- case BRUSH_CLOTH_DEFORM_PINCH_PERPENDICULAR: {
- float disp_center[3];
- float x_disp[3];
- float z_disp[3];
- sub_v3_v3v3(disp_center, ss->cache->location, vd.co);
- normalize_v3(disp_center);
- mul_v3_v3fl(x_disp, x_object_space, dot_v3v3(disp_center, x_object_space));
- mul_v3_v3fl(z_disp, z_object_space, dot_v3v3(disp_center, z_object_space));
- add_v3_v3v3(disp_center, x_disp, z_disp);
- mul_v3_v3fl(force, disp_center, fade);
- } break;
- case BRUSH_CLOTH_DEFORM_INFLATE:
- mul_v3_v3fl(force, normal, fade);
- break;
- case BRUSH_CLOTH_DEFORM_EXPAND:
- cloth_sim->length_constraint_tweak[vd.index] += fade * 0.1f;
- zero_v3(force);
- break;
- }
+ const float fade = sim_factor * bstrength *
+ SCULPT_brush_strength_factor(ss,
+ brush,
+ current_vertex_location,
+ dist,
+ vd.no,
+ vd.fno,
+ vd.mask ? *vd.mask : 0.0f,
+ vd.index,
+ thread_id);
+
+ float brush_disp[3];
+ float normal[3];
+ if (vd.no) {
+ normal_short_to_float_v3(normal, vd.no);
+ }
+ else {
+ copy_v3_v3(normal, vd.fno);
+ }
- cloth_brush_apply_force_to_vertex(ss, ss->cache->cloth_sim, force, vd.index);
+ switch (brush->cloth_deform_type) {
+ case BRUSH_CLOTH_DEFORM_DRAG:
+ sub_v3_v3v3(brush_disp, ss->cache->location, ss->cache->last_location);
+ normalize_v3(brush_disp);
+ mul_v3_v3fl(force, brush_disp, fade);
+ break;
+ case BRUSH_CLOTH_DEFORM_PUSH:
+ /* Invert the fade to push inwards. */
+ mul_v3_v3fl(force, offset, -fade);
+ break;
+ case BRUSH_CLOTH_DEFORM_GRAB:
+ madd_v3_v3v3fl(cloth_sim->deformation_pos[vd.index],
+ cloth_sim->init_pos[vd.index],
+ ss->cache->grab_delta_symmetry,
+ fade);
+ if (use_falloff_plane) {
+ cloth_sim->deformation_strength[vd.index] = clamp_f(fade, 0.0f, 1.0f);
+ }
+ else {
+ cloth_sim->deformation_strength[vd.index] = 1.0f;
+ }
+ zero_v3(force);
+ break;
+ case BRUSH_CLOTH_DEFORM_SNAKE_HOOK:
+ copy_v3_v3(cloth_sim->deformation_pos[vd.index], cloth_sim->pos[vd.index]);
+ madd_v3_v3fl(cloth_sim->deformation_pos[vd.index], ss->cache->grab_delta_symmetry, fade);
+ cloth_sim->deformation_strength[vd.index] = fade;
+ zero_v3(force);
+ break;
+ case BRUSH_CLOTH_DEFORM_PINCH_POINT:
+ if (use_falloff_plane) {
+ float distance = dist_signed_to_plane_v3(vd.co, deform_plane);
+ copy_v3_v3(brush_disp, plane_normal);
+ mul_v3_fl(brush_disp, -distance);
+ }
+ else {
+ sub_v3_v3v3(brush_disp, ss->cache->location, vd.co);
+ }
+ normalize_v3(brush_disp);
+ mul_v3_v3fl(force, brush_disp, fade);
+ break;
+ case BRUSH_CLOTH_DEFORM_PINCH_PERPENDICULAR: {
+ float disp_center[3];
+ float x_disp[3];
+ float z_disp[3];
+ sub_v3_v3v3(disp_center, ss->cache->location, vd.co);
+ normalize_v3(disp_center);
+ mul_v3_v3fl(x_disp, x_object_space, dot_v3v3(disp_center, x_object_space));
+ mul_v3_v3fl(z_disp, z_object_space, dot_v3v3(disp_center, z_object_space));
+ add_v3_v3v3(disp_center, x_disp, z_disp);
+ mul_v3_v3fl(force, disp_center, fade);
+ } break;
+ case BRUSH_CLOTH_DEFORM_INFLATE:
+ mul_v3_v3fl(force, normal, fade);
+ break;
+ case BRUSH_CLOTH_DEFORM_EXPAND:
+ cloth_sim->length_constraint_tweak[vd.index] += fade * 0.1f;
+ zero_v3(force);
+ break;
}
+
+ cloth_brush_apply_force_to_vertex(ss, ss->cache->cloth_sim, force, vd.index);
}
BKE_pbvh_vertex_iter_end;
}
@@ -644,17 +645,22 @@ static ListBase *cloth_brush_collider_cache_create(Depsgraph *depsgraph)
DEG_ITER_OBJECT_FLAG_DUPLI) {
CollisionModifierData *cmd = (CollisionModifierData *)BKE_modifiers_findby_type(
ob, eModifierType_Collision);
- if (cmd && cmd->bvhtree) {
- if (cache == NULL) {
- cache = MEM_callocN(sizeof(ListBase), "ColliderCache array");
- }
+ if (!cmd) {
+ continue;
+ }
- ColliderCache *col = MEM_callocN(sizeof(ColliderCache), "ColliderCache");
- col->ob = ob;
- col->collmd = cmd;
- collision_move_object(cmd, 1.0, 0.0, true);
- BLI_addtail(cache, col);
+ if (!cmd->bvhtree) {
+ continue;
}
+ if (cache == NULL) {
+ cache = MEM_callocN(sizeof(ListBase), "ColliderCache array");
+ }
+
+ ColliderCache *col = MEM_callocN(sizeof(ColliderCache), "ColliderCache");
+ col->ob = ob;
+ col->collmd = cmd;
+ collision_move_object(cmd, 1.0, 0.0, true);
+ BLI_addtail(cache, col);
}
DEG_OBJECT_ITER_END;
return cache;
@@ -734,26 +740,27 @@ static void cloth_brush_solve_collision(Object *object,
&col,
raycast_flag);
- if (hit.index != -1) {
-
- float collision_disp[3];
- float movement_disp[3];
- mul_v3_v3fl(collision_disp, hit.no, 0.005f);
- sub_v3_v3v3(movement_disp, pos_world_space, prev_pos_world_space);
- float friction_plane[4];
- float pos_on_friction_plane[3];
- plane_from_point_normal_v3(friction_plane, hit.co, hit.no);
- closest_to_plane_v3(pos_on_friction_plane, friction_plane, pos_world_space);
- sub_v3_v3v3(movement_disp, pos_on_friction_plane, hit.co);
-
- /* TODO(pablodp606): This can be exposed in a brush/filter property as friction. */
- mul_v3_fl(movement_disp, 0.35f);
-
- copy_v3_v3(cloth_sim->pos[i], hit.co);
- add_v3_v3(cloth_sim->pos[i], movement_disp);
- add_v3_v3(cloth_sim->pos[i], collision_disp);
- mul_v3_m4v3(cloth_sim->pos[i], obmat_inv, cloth_sim->pos[i]);
+ if (hit.index == -1) {
+ continue;
}
+
+ float collision_disp[3];
+ float movement_disp[3];
+ mul_v3_v3fl(collision_disp, hit.no, 0.005f);
+ sub_v3_v3v3(movement_disp, pos_world_space, prev_pos_world_space);
+ float friction_plane[4];
+ float pos_on_friction_plane[3];
+ plane_from_point_normal_v3(friction_plane, hit.co, hit.no);
+ closest_to_plane_v3(pos_on_friction_plane, friction_plane, pos_world_space);
+ sub_v3_v3v3(movement_disp, pos_on_friction_plane, hit.co);
+
+ /* TODO(pablodp606): This can be exposed in a brush/filter property as friction. */
+ mul_v3_fl(movement_disp, 0.35f);
+
+ copy_v3_v3(cloth_sim->pos[i], hit.co);
+ add_v3_v3(cloth_sim->pos[i], movement_disp);
+ add_v3_v3(cloth_sim->pos[i], collision_disp);
+ mul_v3_m4v3(cloth_sim->pos[i], obmat_inv, cloth_sim->pos[i]);
}
}
@@ -784,38 +791,40 @@ static void do_cloth_brush_solve_simulation_task_cb_ex(
ss->cache ? cloth_brush_simulation_falloff_get(
brush, ss->cache->radius, sim_location, cloth_sim->init_pos[vd.index]) :
1.0f;
- if (sim_factor > 0.0f) {
- int i = vd.index;
- float temp[3];
- copy_v3_v3(temp, cloth_sim->pos[i]);
+ if (sim_factor <= 0.0f) {
+ continue;
+ }
- mul_v3_fl(cloth_sim->acceleration[i], time_step);
+ int i = vd.index;
+ float temp[3];
+ copy_v3_v3(temp, cloth_sim->pos[i]);
- float pos_diff[3];
- sub_v3_v3v3(pos_diff, cloth_sim->pos[i], cloth_sim->prev_pos[i]);
- mul_v3_fl(pos_diff, (1.0f - cloth_sim->damping) * sim_factor);
+ mul_v3_fl(cloth_sim->acceleration[i], time_step);
- const float mask_v = (1.0f - (vd.mask ? *vd.mask : 0.0f)) *
- SCULPT_automasking_factor_get(automasking, ss, vd.index);
+ float pos_diff[3];
+ sub_v3_v3v3(pos_diff, cloth_sim->pos[i], cloth_sim->prev_pos[i]);
+ mul_v3_fl(pos_diff, (1.0f - cloth_sim->damping) * sim_factor);
- madd_v3_v3fl(cloth_sim->pos[i], pos_diff, mask_v);
- madd_v3_v3fl(cloth_sim->pos[i], cloth_sim->acceleration[i], mask_v);
+ const float mask_v = (1.0f - (vd.mask ? *vd.mask : 0.0f)) *
+ SCULPT_automasking_factor_get(automasking, ss, vd.index);
- if (cloth_sim->collider_list != NULL) {
- cloth_brush_solve_collision(data->ob, cloth_sim, i);
- }
+ madd_v3_v3fl(cloth_sim->pos[i], pos_diff, mask_v);
+ madd_v3_v3fl(cloth_sim->pos[i], cloth_sim->acceleration[i], mask_v);
- copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]);
+ if (cloth_sim->collider_list != NULL) {
+ cloth_brush_solve_collision(data->ob, cloth_sim, i);
+ }
- copy_v3_v3(cloth_sim->prev_pos[i], temp);
- copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]);
- copy_v3_fl(cloth_sim->acceleration[i], 0.0f);
+ copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]);
- copy_v3_v3(vd.co, cloth_sim->pos[vd.index]);
+ copy_v3_v3(cloth_sim->prev_pos[i], temp);
+ copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]);
+ copy_v3_fl(cloth_sim->acceleration[i], 0.0f);
- if (vd.mvert) {
- vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
- }
+ copy_v3_v3(vd.co, cloth_sim->pos[vd.index]);
+
+ if (vd.mvert) {
+ vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
}
}
BKE_pbvh_vertex_iter_end;