Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 2,838 Lines • ▼ Show 20 Lines | case BRUSH_MASK_DRAW: | ||||
| do_mask_brush_draw(sd, ob, nodes, totnode); | do_mask_brush_draw(sd, ob, nodes, totnode); | ||||
| break; | break; | ||||
| case BRUSH_MASK_SMOOTH: | case BRUSH_MASK_SMOOTH: | ||||
| smooth(sd, ob, nodes, totnode, ss->cache->bstrength, true); | smooth(sd, ob, nodes, totnode, ss->cache->bstrength, true); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| static void calc_sculpt_plane( | |||||
jbakker: This seems like that this functions has been moved. I didn't see any code differences. Is this… | |||||
| Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3]) | |||||
| { | |||||
| SculptSession *ss = ob->sculpt; | |||||
| Brush *brush = BKE_paint_brush(&sd->paint); | |||||
| if (ss->cache->mirror_symmetry_pass == 0 && ss->cache->radial_symmetry_pass == 0 && | |||||
| ss->cache->tile_pass == 0 && | |||||
| (ss->cache->first_time || !(brush->flag & BRUSH_ORIGINAL_PLANE) || | |||||
| !(brush->flag & BRUSH_ORIGINAL_NORMAL))) { | |||||
| switch (brush->sculpt_plane) { | |||||
| case SCULPT_DISP_DIR_VIEW: | |||||
| copy_v3_v3(r_area_no, ss->cache->true_view_normal); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_X: | |||||
| ARRAY_SET_ITEMS(r_area_no, 1, 0, 0); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_Y: | |||||
| ARRAY_SET_ITEMS(r_area_no, 0, 1, 0); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_Z: | |||||
| ARRAY_SET_ITEMS(r_area_no, 0, 0, 1); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_AREA: | |||||
| calc_area_normal_and_center(sd, ob, nodes, totnode, r_area_no, r_area_co); | |||||
| if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | |||||
| project_plane_v3_v3v3(r_area_no, r_area_no, ss->cache->view_normal); | |||||
| normalize_v3(r_area_no); | |||||
| } | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| /* for flatten center */ | |||||
| /* flatten center has not been calculated yet if we are not using the area normal */ | |||||
| if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) { | |||||
| calc_area_center(sd, ob, nodes, totnode, r_area_co); | |||||
| } | |||||
| /* for area normal */ | |||||
| if ((!ss->cache->first_time) && (brush->flag & BRUSH_ORIGINAL_NORMAL)) { | |||||
| copy_v3_v3(r_area_no, ss->cache->sculpt_normal); | |||||
| } | |||||
| else { | |||||
| copy_v3_v3(ss->cache->sculpt_normal, r_area_no); | |||||
| } | |||||
| /* for flatten center */ | |||||
| if ((!ss->cache->first_time) && (brush->flag & BRUSH_ORIGINAL_PLANE)) { | |||||
| copy_v3_v3(r_area_co, ss->cache->last_center); | |||||
| } | |||||
| else { | |||||
| copy_v3_v3(ss->cache->last_center, r_area_co); | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* for area normal */ | |||||
| copy_v3_v3(r_area_no, ss->cache->sculpt_normal); | |||||
| /* for flatten center */ | |||||
| copy_v3_v3(r_area_co, ss->cache->last_center); | |||||
| /* for area normal */ | |||||
| flip_v3(r_area_no, ss->cache->mirror_symmetry_pass); | |||||
| /* for flatten center */ | |||||
| flip_v3(r_area_co, ss->cache->mirror_symmetry_pass); | |||||
| /* for area normal */ | |||||
| mul_m4_v3(ss->cache->symm_rot_mat, r_area_no); | |||||
| /* for flatten center */ | |||||
| mul_m4_v3(ss->cache->symm_rot_mat, r_area_co); | |||||
| /* shift the plane for the current tile */ | |||||
| add_v3_v3(r_area_co, ss->cache->plane_offset); | |||||
| } | |||||
| } | |||||
| static void do_draw_brush_task_cb_ex(void *__restrict userdata, | static void do_draw_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float *offset = data->offset; | const float *offset = data->offset; | ||||
| ▲ Show 20 Lines • Show All 327 Lines • ▼ Show 20 Lines | static void do_crease_brush_task_cb_ex(void *__restrict userdata, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| SculptProjectVector *spvc = data->spvc; | SculptProjectVector *spvc = data->spvc; | ||||
| const float flippedbstrength = data->flippedbstrength; | const float flippedbstrength = data->flippedbstrength; | ||||
| const float *offset = data->offset; | const float *offset = data->offset; | ||||
| float(*mat)[4] = data->mat; | |||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| 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); | ||||
| float x_object_space[3]; | |||||
| float z_object_space[3]; | |||||
| normalize_v3_v3(x_object_space, mat[0]); | |||||
| normalize_v3_v3(z_object_space, mat[2]); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| /* offset vertex */ | /* offset vertex */ | ||||
| const float fade = tex_strength(ss, | const float fade = tex_strength(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.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); | tls->thread_id); | ||||
| float val1[3]; | float val1[3]; | ||||
| float val2[3]; | float val2[3]; | ||||
| /* first we pinch */ | /* first we pinch */ | ||||
| sub_v3_v3v3(val1, test.location, vd.co); | float disp_center[3]; | ||||
| float x_disp[3]; | |||||
| float z_disp[3]; | |||||
| sub_v3_v3v3(disp_center, test.location, vd.co); | |||||
| 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(val1, x_disp, z_disp); | |||||
| //sub_v3_v3v3(val1, test.location, vd.co); | |||||
| if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | ||||
| project_plane_v3_v3v3(val1, val1, ss->cache->view_normal); | project_plane_v3_v3v3(val1, val1, ss->cache->view_normal); | ||||
| } | } | ||||
| mul_v3_fl(val1, fade * flippedbstrength); | mul_v3_fl(val1, fade * flippedbstrength); | ||||
| sculpt_project_v3(spvc, val1, val1); | sculpt_project_v3(spvc, val1, val1); | ||||
| Show All 24 Lines | static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| /* offset with as much as possible factored in already */ | /* offset with as much as possible factored in already */ | ||||
| mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); | mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); | ||||
| mul_v3_v3(offset, ss->cache->scale); | mul_v3_v3(offset, ss->cache->scale); | ||||
| mul_v3_fl(offset, bstrength); | mul_v3_fl(offset, bstrength); | ||||
| /* We divide out the squared alpha and multiply by the squared crease | /* We divide out the squared alpha and multiply by the squared crease | ||||
| * to give us the pinch strength. */ | * to give us the pinch strength. */ | ||||
| crease_correction = brush->crease_pinch_factor * brush->crease_pinch_factor; | crease_correction = brush->crease_pinch_factor; | ||||
| brush_alpha = BKE_brush_alpha_get(scene, brush); | brush_alpha = BKE_brush_alpha_get(scene, brush); | ||||
| if (brush_alpha > 0.0f) { | if (brush_alpha > 0.0f) { | ||||
| crease_correction /= brush_alpha * brush_alpha; | crease_correction /= brush_alpha * brush_alpha; | ||||
| } | } | ||||
| /* we always want crease to pinch or blob to relax even when draw is negative */ | /* we always want crease to pinch or blob to relax even when draw is negative */ | ||||
| flippedbstrength = (bstrength < 0) ? -crease_correction * bstrength : | flippedbstrength = (bstrength < 0) ? -crease_correction * bstrength : | ||||
| crease_correction * bstrength; | crease_correction * bstrength; | ||||
| if (brush->sculpt_tool == SCULPT_TOOL_BLOB) { | if (brush->sculpt_tool == SCULPT_TOOL_BLOB) { | ||||
| flippedbstrength *= -1.0f; | flippedbstrength *= -1.0f; | ||||
| } | } | ||||
| /* Use surface normal for 'spvc', | /* Use surface normal for 'spvc', | ||||
| * so the vertices are pinched towards a line instead of a single point. | * so the vertices are pinched towards a line instead of a single point. | ||||
| * Without this we get a 'flat' surface surrounding the pinch */ | * Without this we get a 'flat' surface surrounding the pinch */ | ||||
| sculpt_project_v3_cache_init(&spvc, ss->cache->sculpt_normal_symm); | sculpt_project_v3_cache_init(&spvc, ss->cache->sculpt_normal_symm); | ||||
| float area_no[3]; | |||||
| float area_co[3]; | |||||
| float mat[4][4]; | |||||
| calc_sculpt_plane(sd, ob, nodes, totnode, area_no, area_co); | |||||
| /* delay the first daub because grab delta is not setup */ | |||||
| if (ss->cache->first_time) { | |||||
| return; | |||||
| } | |||||
| if (is_zero_v3(ss->cache->grab_delta_symmetry)) { | |||||
| return; | |||||
| } | |||||
Not Done Inline ActionsBit of a code style question. Is it useful to duplicate this code. I can imagine it is. jbakker: Bit of a code style question. Is it useful to duplicate this code. I can imagine it is. | |||||
| /* Init mat */ | |||||
| cross_v3_v3v3(mat[0], area_no, ss->cache->grab_delta_symmetry); | |||||
| mat[0][3] = 0; | |||||
| cross_v3_v3v3(mat[1], area_no, mat[0]); | |||||
| mat[1][3] = 0; | |||||
| copy_v3_v3(mat[2], area_no); | |||||
| mat[2][3] = 0; | |||||
| copy_v3_v3(mat[3], ss->cache->location); | |||||
| mat[3][3] = 1; | |||||
| normalize_m4(mat); | |||||
| /* threaded loop over nodes */ | /* threaded loop over nodes */ | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .spvc = &spvc, | .spvc = &spvc, | ||||
| .offset = offset, | .offset = offset, | ||||
| .mat = mat, | |||||
| .flippedbstrength = flippedbstrength, | .flippedbstrength = flippedbstrength, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | PBVHParallelSettings 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(0, totnode, &data, do_crease_brush_task_cb_ex, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,414 Lines • ▼ Show 20 Lines | SculptThreadedTaskData data = { | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | PBVHParallelSettings 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(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void calc_sculpt_plane( | |||||
| Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3]) | |||||
| { | |||||
| SculptSession *ss = ob->sculpt; | |||||
| Brush *brush = BKE_paint_brush(&sd->paint); | |||||
| if (ss->cache->mirror_symmetry_pass == 0 && ss->cache->radial_symmetry_pass == 0 && | |||||
| ss->cache->tile_pass == 0 && | |||||
| (ss->cache->first_time || !(brush->flag & BRUSH_ORIGINAL_PLANE) || | |||||
| !(brush->flag & BRUSH_ORIGINAL_NORMAL))) { | |||||
| switch (brush->sculpt_plane) { | |||||
| case SCULPT_DISP_DIR_VIEW: | |||||
| copy_v3_v3(r_area_no, ss->cache->true_view_normal); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_X: | |||||
| ARRAY_SET_ITEMS(r_area_no, 1, 0, 0); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_Y: | |||||
| ARRAY_SET_ITEMS(r_area_no, 0, 1, 0); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_Z: | |||||
| ARRAY_SET_ITEMS(r_area_no, 0, 0, 1); | |||||
| break; | |||||
| case SCULPT_DISP_DIR_AREA: | |||||
| calc_area_normal_and_center(sd, ob, nodes, totnode, r_area_no, r_area_co); | |||||
| if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | |||||
| project_plane_v3_v3v3(r_area_no, r_area_no, ss->cache->view_normal); | |||||
| normalize_v3(r_area_no); | |||||
| } | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| /* for flatten center */ | |||||
| /* flatten center has not been calculated yet if we are not using the area normal */ | |||||
| if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) { | |||||
| calc_area_center(sd, ob, nodes, totnode, r_area_co); | |||||
| } | |||||
| /* for area normal */ | |||||
| if ((!ss->cache->first_time) && (brush->flag & BRUSH_ORIGINAL_NORMAL)) { | |||||
| copy_v3_v3(r_area_no, ss->cache->sculpt_normal); | |||||
| } | |||||
| else { | |||||
| copy_v3_v3(ss->cache->sculpt_normal, r_area_no); | |||||
| } | |||||
| /* for flatten center */ | |||||
| if ((!ss->cache->first_time) && (brush->flag & BRUSH_ORIGINAL_PLANE)) { | |||||
| copy_v3_v3(r_area_co, ss->cache->last_center); | |||||
| } | |||||
| else { | |||||
| copy_v3_v3(ss->cache->last_center, r_area_co); | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* for area normal */ | |||||
| copy_v3_v3(r_area_no, ss->cache->sculpt_normal); | |||||
| /* for flatten center */ | |||||
| copy_v3_v3(r_area_co, ss->cache->last_center); | |||||
| /* for area normal */ | |||||
| flip_v3(r_area_no, ss->cache->mirror_symmetry_pass); | |||||
| /* for flatten center */ | |||||
| flip_v3(r_area_co, ss->cache->mirror_symmetry_pass); | |||||
| /* for area normal */ | |||||
| mul_m4_v3(ss->cache->symm_rot_mat, r_area_no); | |||||
| /* for flatten center */ | |||||
| mul_m4_v3(ss->cache->symm_rot_mat, r_area_co); | |||||
| /* shift the plane for the current tile */ | |||||
| add_v3_v3(r_area_co, ss->cache->plane_offset); | |||||
| } | |||||
| } | |||||
| static int plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3]) | static int plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3]) | ||||
| { | { | ||||
| return (!(brush->flag & BRUSH_PLANE_TRIM) || | return (!(brush->flag & BRUSH_PLANE_TRIM) || | ||||
| ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_trim_squared))); | ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_trim_squared))); | ||||
| } | } | ||||
| static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip) | static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip) | ||||
| ▲ Show 20 Lines • Show All 2,070 Lines • ▼ Show 20 Lines | static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Brush *brush) | ||||
| }; | }; | ||||
| int tool = brush->sculpt_tool; | int tool = brush->sculpt_tool; | ||||
| if (ELEM(tool, | if (ELEM(tool, | ||||
| SCULPT_TOOL_GRAB, | SCULPT_TOOL_GRAB, | ||||
| SCULPT_TOOL_ELASTIC_DEFORM, | SCULPT_TOOL_ELASTIC_DEFORM, | ||||
| SCULPT_TOOL_NUDGE, | SCULPT_TOOL_NUDGE, | ||||
| SCULPT_TOOL_CLAY_STRIPS, | SCULPT_TOOL_CLAY_STRIPS, | ||||
| SCULPT_TOOL_CREASE, | |||||
| SCULPT_TOOL_MULTIPLANE_SCRAPE, | SCULPT_TOOL_MULTIPLANE_SCRAPE, | ||||
| SCULPT_TOOL_SNAKE_HOOK, | SCULPT_TOOL_SNAKE_HOOK, | ||||
| SCULPT_TOOL_POSE, | SCULPT_TOOL_POSE, | ||||
| SCULPT_TOOL_THUMB) || | SCULPT_TOOL_THUMB) || | ||||
| sculpt_brush_use_topology_rake(ss, brush)) { | sculpt_brush_use_topology_rake(ss, brush)) { | ||||
| float grab_location[3], imat[4][4], delta[3], loc[3]; | float grab_location[3], imat[4][4], delta[3], loc[3]; | ||||
| if (cache->first_time) { | if (cache->first_time) { | ||||
| Show All 20 Lines | if (!cache->first_time) { | ||||
| case SCULPT_TOOL_THUMB: | case SCULPT_TOOL_THUMB: | ||||
| case SCULPT_TOOL_ELASTIC_DEFORM: | case SCULPT_TOOL_ELASTIC_DEFORM: | ||||
| sub_v3_v3v3(delta, grab_location, cache->old_grab_location); | sub_v3_v3v3(delta, grab_location, cache->old_grab_location); | ||||
| invert_m4_m4(imat, ob->obmat); | invert_m4_m4(imat, ob->obmat); | ||||
| mul_mat3_m4_v3(imat, delta); | mul_mat3_m4_v3(imat, delta); | ||||
| add_v3_v3(cache->grab_delta, delta); | add_v3_v3(cache->grab_delta, delta); | ||||
| break; | break; | ||||
| case SCULPT_TOOL_CLAY_STRIPS: | case SCULPT_TOOL_CLAY_STRIPS: | ||||
| case SCULPT_TOOL_CREASE: | |||||
| case SCULPT_TOOL_MULTIPLANE_SCRAPE: | case SCULPT_TOOL_MULTIPLANE_SCRAPE: | ||||
| case SCULPT_TOOL_NUDGE: | case SCULPT_TOOL_NUDGE: | ||||
| case SCULPT_TOOL_SNAKE_HOOK: | case SCULPT_TOOL_SNAKE_HOOK: | ||||
| if (brush->flag & BRUSH_ANCHORED) { | if (brush->flag & BRUSH_ANCHORED) { | ||||
| float orig[3]; | float orig[3]; | ||||
| mul_v3_m4v3(orig, ob->obmat, cache->orig_grab_location); | mul_v3_m4v3(orig, ob->obmat, cache->orig_grab_location); | ||||
| sub_v3_v3v3(cache->grab_delta, grab_location, orig); | sub_v3_v3v3(cache->grab_delta, grab_location, orig); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 3,675 Lines • Show Last 20 Lines | |||||
This seems like that this functions has been moved. I didn't see any code differences. Is this OK?