Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_cloth.c
| Show First 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | const bool use_falloff_plane = brush->cloth_force_falloff_type == | ||||
| BRUSH_CLOTH_FORCE_FALLOFF_PLANE; | BRUSH_CLOTH_FORCE_FALLOFF_PLANE; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| /* For Pich Perpendicular Deform Type. */ | /* For Pich Perpendicular Deform Type. */ | ||||
| float x_object_space[3]; | float x_object_space[3]; | ||||
| float z_object_space[3]; | float z_object_space[3]; | ||||
| if (brush->cloth_deform_type == BRUSH_CLOTH_DEFORM_PINCH_PERPENDICULAR) { | if (brush->cloth_deform_type == BRUSH_CLOTH_DEFORM_PINCH_PERPENDICULAR) { | ||||
| normalize_v3_v3(x_object_space, imat[0]); | normalize_v3_v3(x_object_space, imat[0]); | ||||
| normalize_v3_v3(z_object_space, imat[2]); | normalize_v3_v3(z_object_space, imat[2]); | ||||
| } | } | ||||
| Show All 32 Lines | if (sculpt_brush_test_sq_fn(&test, vd.co) || use_falloff_plane) { | ||||
| SCULPT_brush_strength_factor(ss, | SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| dist, | dist, | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| float brush_disp[3]; | float brush_disp[3]; | ||||
| float normal[3]; | float normal[3]; | ||||
| if (vd.no) { | if (vd.no) { | ||||
| normal_short_to_float_v3(normal, vd.no); | normal_short_to_float_v3(normal, vd.no); | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | static void cloth_brush_build_nodes_constraints(Sculpt *sd, | ||||
| int totnode) | int totnode) | ||||
| { | { | ||||
| Brush *brush = BKE_paint_brush(&sd->paint); | Brush *brush = BKE_paint_brush(&sd->paint); | ||||
| /* TODO: Multi-threaded needs to be disabled for this task until implementing the optimization of | /* TODO: Multi-threaded needs to be disabled for this task until implementing the optimization of | ||||
| * storing the constraints per node. */ | * storing the constraints per node. */ | ||||
| /* Currently all constrains are added to the same global array which can't be accessed from | /* Currently all constrains are added to the same global array which can't be accessed from | ||||
| * different threads. */ | * different threads. */ | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, false, totnode); | BKE_pbvh_parallel_range_settings(&settings, false, totnode); | ||||
| SculptThreadedTaskData build_constraints_data = { | SculptThreadedTaskData build_constraints_data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| BKE_pbvh_parallel_range( | BLI_task_parallel_range( | ||||
| 0, totnode, &build_constraints_data, do_cloth_brush_build_constraints_task_cb_ex, &settings); | 0, totnode, &build_constraints_data, do_cloth_brush_build_constraints_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void cloth_brush_satisfy_constraints(SculptSession *ss, | static void cloth_brush_satisfy_constraints(SculptSession *ss, | ||||
| Brush *brush, | Brush *brush, | ||||
| SculptClothSimulation *cloth_sim) | SculptClothSimulation *cloth_sim) | ||||
| { | { | ||||
| for (int constraint_it = 0; constraint_it < CLOTH_SIMULATION_ITERATIONS; constraint_it++) { | for (int constraint_it = 0; constraint_it < CLOTH_SIMULATION_ITERATIONS; constraint_it++) { | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | static void cloth_brush_do_simulation_step(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData solve_simulation_data = { | SculptThreadedTaskData solve_simulation_data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .cloth_time_step = CLOTH_SIMULATION_TIME_STEP, | .cloth_time_step = CLOTH_SIMULATION_TIME_STEP, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range( | BLI_task_parallel_range( | ||||
| 0, totnode, &solve_simulation_data, do_cloth_brush_solve_simulation_task_cb_ex, &settings); | 0, totnode, &solve_simulation_data, do_cloth_brush_solve_simulation_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void cloth_brush_apply_brush_foces(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | static void cloth_brush_apply_brush_foces(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| { | { | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| Brush *brush = BKE_paint_brush(&sd->paint); | Brush *brush = BKE_paint_brush(&sd->paint); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (brush->cloth_deform_type == BRUSH_CLOTH_DEFORM_PINCH_PERPENDICULAR || | ||||
| apply_forces_data.mat = mat; | apply_forces_data.mat = mat; | ||||
| /* Update matrix for the cursor preview. */ | /* Update matrix for the cursor preview. */ | ||||
| if (ss->cache->mirror_symmetry_pass == 0) { | if (ss->cache->mirror_symmetry_pass == 0) { | ||||
| copy_m4_m4(ss->cache->stroke_local_mat, mat); | copy_m4_m4(ss->cache->stroke_local_mat, mat); | ||||
| } | } | ||||
| } | } | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range( | BLI_task_parallel_range( | ||||
| 0, totnode, &apply_forces_data, do_cloth_brush_apply_forces_task_cb_ex, &settings); | 0, totnode, &apply_forces_data, do_cloth_brush_apply_forces_task_cb_ex, &settings); | ||||
| } | } | ||||
| /* Public functions. */ | /* Public functions. */ | ||||
| /* Main Brush Function. */ | /* Main Brush Function. */ | ||||
| void SCULPT_do_cloth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | void SCULPT_do_cloth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines | |||||