Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt.c
| Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | case PBVH_GRIDS: { | ||||
| const int vertex_index = index - grid_index * key->grid_area; | const int vertex_index = index - grid_index * key->grid_area; | ||||
| CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index]; | CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index]; | ||||
| copy_v3_v3(no, CCG_elem_no(key, CCG_elem_offset(key, elem, vertex_index))); | copy_v3_v3(no, CCG_elem_no(key, CCG_elem_offset(key, elem, vertex_index))); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index) | |||||
| { | |||||
| if (ss->persistent_base) { | |||||
| return ss->persistent_base[index].co; | |||||
| } | |||||
| return SCULPT_vertex_co_get(ss, index); | |||||
| } | |||||
| void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3]) | |||||
| { | |||||
| if (ss->persistent_base) { | |||||
| copy_v3_v3(no, ss->persistent_base[index].no); | |||||
| return; | |||||
| } | |||||
| SCULPT_vertex_normal_get(ss, index, no); | |||||
| } | |||||
| float SCULPT_vertex_mask_get(SculptSession *ss, int index) | float SCULPT_vertex_mask_get(SculptSession *ss, int index) | ||||
| { | { | ||||
| BMVert *v; | BMVert *v; | ||||
| float *mask; | float *mask; | ||||
| switch (BKE_pbvh_type(ss->pbvh)) { | switch (BKE_pbvh_type(ss->pbvh)) { | ||||
| case PBVH_FACES: | case PBVH_FACES: | ||||
| return ss->vmask[index]; | return ss->vmask[index]; | ||||
| case PBVH_BMESH: | case PBVH_BMESH: | ||||
| ▲ Show 20 Lines • Show All 3,897 Lines • ▼ Show 20 Lines | static void do_layer_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; | ||||
| Sculpt *sd = data->sd; | Sculpt *sd = data->sd; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const bool use_persistent_base = ss->layer_base && brush->flag & BRUSH_PERSISTENT; | const bool use_persistent_base = ss->persistent_base && brush->flag & BRUSH_PERSISTENT; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| 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( | ||||
| Show All 13 Lines | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| thread_id); | thread_id); | ||||
| const int vi = vd.index; | const int vi = vd.index; | ||||
| float *disp_factor; | float *disp_factor; | ||||
| if (use_persistent_base) { | if (use_persistent_base) { | ||||
| disp_factor = &ss->layer_base[vi].disp; | disp_factor = &ss->persistent_base[vi].disp; | ||||
| } | } | ||||
| else { | else { | ||||
| disp_factor = &ss->cache->layer_displacement_factor[vi]; | disp_factor = &ss->cache->layer_displacement_factor[vi]; | ||||
| } | } | ||||
| /* When using persistent base, the layer brush Ctrl invert mode resets the height of the | /* When using persistent base, the layer brush Ctrl invert mode resets the height of the | ||||
| * layer to 0. This makes possible to clean edges of previously added layers on top of the | * layer to 0. This makes possible to clean edges of previously added layers on top of the | ||||
| * base. */ | * base. */ | ||||
| Show All 13 Lines | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| else { | else { | ||||
| CLAMP(*disp_factor, -1.0f, 1.0f); | CLAMP(*disp_factor, -1.0f, 1.0f); | ||||
| } | } | ||||
| float final_co[3]; | float final_co[3]; | ||||
| float normal[3]; | float normal[3]; | ||||
| if (use_persistent_base) { | if (use_persistent_base) { | ||||
| copy_v3_v3(normal, ss->layer_base[vi].no); | SCULPT_vertex_persistent_normal_get(ss, vi, normal); | ||||
| mul_v3_fl(normal, brush->height); | mul_v3_fl(normal, brush->height); | ||||
| madd_v3_v3v3fl(final_co, ss->layer_base[vi].co, normal, *disp_factor); | madd_v3_v3v3fl(final_co, SCULPT_vertex_persistent_co_get(ss, vi), normal, *disp_factor); | ||||
| } | } | ||||
| else { | else { | ||||
| normal_short_to_float_v3(normal, orig_data.no); | normal_short_to_float_v3(normal, orig_data.no); | ||||
| mul_v3_fl(normal, brush->height); | mul_v3_fl(normal, brush->height); | ||||
| madd_v3_v3v3fl(final_co, orig_data.co, normal, *disp_factor); | madd_v3_v3v3fl(final_co, orig_data.co, normal, *disp_factor); | ||||
| } | } | ||||
| float vdisp[3]; | float vdisp[3]; | ||||
| ▲ Show 20 Lines • Show All 3,176 Lines • ▼ Show 20 Lines | static int sculpt_set_persistent_base_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| if (ss) { | if (ss) { | ||||
| SCULPT_vertex_random_access_init(ss); | SCULPT_vertex_random_access_init(ss); | ||||
| BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false); | BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false); | ||||
| MEM_SAFE_FREE(ss->layer_base); | MEM_SAFE_FREE(ss->persistent_base); | ||||
| const int totvert = SCULPT_vertex_count_get(ss); | const int totvert = SCULPT_vertex_count_get(ss); | ||||
| ss->layer_base = MEM_mallocN(sizeof(SculptLayerPersistentBase) * totvert, | ss->persistent_base = MEM_mallocN(sizeof(SculptPersistentBase) * totvert, | ||||
| "layer persistent base"); | "layer persistent base"); | ||||
| for (int i = 0; i < totvert; i++) { | for (int i = 0; i < totvert; i++) { | ||||
| copy_v3_v3(ss->layer_base[i].co, SCULPT_vertex_co_get(ss, i)); | copy_v3_v3(ss->persistent_base[i].co, SCULPT_vertex_co_get(ss, i)); | ||||
| SCULPT_vertex_normal_get(ss, i, ss->layer_base[i].no); | SCULPT_vertex_normal_get(ss, i, ss->persistent_base[i].no); | ||||
| ss->layer_base[i].disp = 0.0f; | ss->persistent_base[i].disp = 0.0f; | ||||
| } | } | ||||
| } | } | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static void SCULPT_OT_set_persistent_base(wmOperatorType *ot) | static void SCULPT_OT_set_persistent_base(wmOperatorType *ot) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 543 Lines • Show Last 20 Lines | |||||