diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint')
16 files changed, 129 insertions, 113 deletions
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc index e276bae6697..8172eb8a5d7 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc @@ -185,7 +185,7 @@ std::optional<CurvesBrush3D> sample_curves_3d_brush(const Depsgraph &depsgraph, /* Shorten ray when the surface object is hit. */ if (surface_object_eval != nullptr) { - const float4x4 surface_to_world_mat = surface_object->obmat; + const float4x4 surface_to_world_mat = surface_object->object_to_world; const float4x4 world_to_surface_mat = surface_to_world_mat.inverted(); Mesh *surface_eval = BKE_object_get_evaluated_mesh(surface_object_eval); @@ -218,7 +218,7 @@ std::optional<CurvesBrush3D> sample_curves_3d_brush(const Depsgraph &depsgraph, } } - const float4x4 curves_to_world_mat = curves_object.obmat; + const float4x4 curves_to_world_mat = curves_object.object_to_world; const float4x4 world_to_curves_mat = curves_to_world_mat.inverted(); const float3 center_ray_start_cu = world_to_curves_mat * center_ray_start_wo; diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc index 6366da310b6..df7dd871a94 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc @@ -220,8 +220,10 @@ static int sculpt_curves_stroke_invoke(bContext *C, wmOperator *op, const wmEven int return_value = op->type->modal(C, op, event); if (return_value == OPERATOR_FINISHED) { - paint_stroke_free(C, op, op_data->stroke); - MEM_delete(op_data); + if (op->customdata != nullptr) { + paint_stroke_free(C, op, op_data->stroke); + MEM_delete(op_data); + } return OPERATOR_FINISHED; } @@ -236,16 +238,19 @@ static int sculpt_curves_stroke_modal(bContext *C, wmOperator *op, const wmEvent int return_value = paint_stroke_modal(C, op, event, &op_data->stroke); if (ELEM(return_value, OPERATOR_FINISHED, OPERATOR_CANCELLED)) { MEM_delete(op_data); + op->customdata = nullptr; } return return_value; } static void sculpt_curves_stroke_cancel(bContext *C, wmOperator *op) { - SculptCurvesBrushStrokeData *op_data = static_cast<SculptCurvesBrushStrokeData *>( - op->customdata); - paint_stroke_cancel(C, op, op_data->stroke); - MEM_delete(op_data); + if (op->customdata != nullptr) { + SculptCurvesBrushStrokeData *op_data = static_cast<SculptCurvesBrushStrokeData *>( + op->customdata); + paint_stroke_cancel(C, op, op_data->stroke); + MEM_delete(op_data); + } } static void SCULPT_CURVES_OT_brush_stroke(struct wmOperatorType *ot) @@ -786,7 +791,7 @@ static void select_grow_invoke_per_curve(Curves &curves_id, }); }); - float4x4 curves_to_world_mat = curves_ob.obmat; + float4x4 curves_to_world_mat = curves_ob.object_to_world; float4x4 world_to_curves_mat = curves_to_world_mat.inverted(); float4x4 projection; diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 71ec444098e..b85b878af7d 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -1071,7 +1071,7 @@ static void cursor_draw_tiling_preview(const uint gpuattr, for (int dim = 0; dim < 3; dim++) { location[dim] = cur[dim] * step[dim] + orgLoc[dim]; } - cursor_draw_point_screen_space(gpuattr, region, location, ob->obmat, 3); + cursor_draw_point_screen_space(gpuattr, region, location, ob->object_to_world, 3); } } } @@ -1092,7 +1092,7 @@ static void cursor_draw_point_with_symmetry(const uint gpuattr, /* Axis Symmetry. */ flip_v3_v3(location, true_location, (char)i); - cursor_draw_point_screen_space(gpuattr, region, location, ob->obmat, 3); + cursor_draw_point_screen_space(gpuattr, region, location, ob->object_to_world, 3); /* Tiling. */ cursor_draw_tiling_preview(gpuattr, region, location, sd, ob, radius); @@ -1107,7 +1107,7 @@ static void cursor_draw_point_with_symmetry(const uint gpuattr, mul_m4_v3(symm_rot_mat, location); cursor_draw_tiling_preview(gpuattr, region, location, sd, ob, radius); - cursor_draw_point_screen_space(gpuattr, region, location, ob->obmat, 3); + cursor_draw_point_screen_space(gpuattr, region, location, ob->object_to_world, 3); } } } @@ -1334,7 +1334,7 @@ static void paint_cursor_update_pixel_radius(PaintCursorContext *pcontext) } copy_v3_v3(pcontext->scene_space_location, pcontext->location); - mul_m4_v3(pcontext->vc.obact->obmat, pcontext->scene_space_location); + mul_m4_v3(pcontext->vc.obact->object_to_world, pcontext->scene_space_location); } else { Sculpt *sd = CTX_data_tool_settings(pcontext->C)->sculpt; @@ -1464,7 +1464,7 @@ static void paint_cursor_drawing_setup_cursor_space(PaintCursorContext *pcontext float cursor_trans[4][4], cursor_rot[4][4]; const float z_axis[4] = {0.0f, 0.0f, 1.0f, 0.0f}; float quat[4]; - copy_m4_m4(cursor_trans, pcontext->vc.obact->obmat); + copy_m4_m4(cursor_trans, pcontext->vc.obact->object_to_world); translate_m4(cursor_trans, pcontext->location[0], pcontext->location[1], pcontext->location[2]); rotation_between_vecs_to_quat(quat, z_axis, pcontext->normal); quat_to_mat4(cursor_rot, quat); @@ -1508,7 +1508,7 @@ static void paint_cursor_pose_brush_origins_draw(PaintCursorContext *pcontext) cursor_draw_point_screen_space(pcontext->pos, pcontext->region, ss->pose_ik_chain_preview->segments[i].initial_orig, - pcontext->vc.obact->obmat, + pcontext->vc.obact->object_to_world, 3); } } @@ -1526,7 +1526,7 @@ static void paint_cursor_preview_boundary_data_pivot_draw(PaintCursorContext *pc pcontext->pos, pcontext->region, SCULPT_vertex_co_get(pcontext->ss, pcontext->ss->boundary_preview->pivot_vertex), - pcontext->vc.obact->obmat, + pcontext->vc.obact->object_to_world, 3); } @@ -1634,7 +1634,7 @@ static void paint_cursor_draw_3d_view_brush_cursor_inactive(PaintCursorContext * pcontext->pos, pcontext->region, SCULPT_vertex_co_get(pcontext->ss, pcontext->ss->expand_cache->initial_active_vertex), - pcontext->vc.obact->obmat, + pcontext->vc.obact->object_to_world, 2); } @@ -1656,7 +1656,7 @@ static void paint_cursor_draw_3d_view_brush_cursor_inactive(PaintCursorContext * NULL); GPU_matrix_push(); - GPU_matrix_mul(pcontext->vc.obact->obmat); + GPU_matrix_mul(pcontext->vc.obact->object_to_world); /* Drawing Cursor overlays in 3D object space. */ if (is_brush_tool && brush->sculpt_tool == SCULPT_TOOL_GRAB && @@ -1747,7 +1747,7 @@ static void paint_cursor_cursor_draw_3d_view_brush_cursor_active(PaintCursorCont NULL, NULL); GPU_matrix_push(); - GPU_matrix_mul(pcontext->vc.obact->obmat); + GPU_matrix_mul(pcontext->vc.obact->object_to_world); /* Draw the special active cursors different tools may have. */ diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index 22d6626ab16..26f76d46f85 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -44,7 +44,7 @@ bool paint_curve_poll(bContext *C) RegionView3D *rv3d = CTX_wm_region_view3d(C); SpaceImage *sima; - if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) { + if (rv3d && !(ob && ((ob->mode & (OB_MODE_ALL_PAINT | OB_MODE_SCULPT_CURVES)) != 0))) { return false; } @@ -676,6 +676,9 @@ static int paintcurve_draw_exec(bContext *C, wmOperator *UNUSED(op)) case PAINT_MODE_SCULPT: name = "SCULPT_OT_brush_stroke"; break; + case PAINT_MODE_SCULPT_CURVES: + name = "SCULPT_CURVES_OT_brush_stroke"; + break; default: return OPERATOR_PASS_THROUGH; } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index d9aa11a2847..ea33449f0dd 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -3684,7 +3684,7 @@ static void proj_paint_state_viewport_init(ProjPaintState *ps, const char symmet ps->viewDir[1] = 0.0f; ps->viewDir[2] = 1.0f; - copy_m4_m4(ps->obmat, ps->ob->obmat); + copy_m4_m4(ps->obmat, ps->ob->object_to_world); if (symmetry_flag) { int i; @@ -3742,7 +3742,7 @@ static void proj_paint_state_viewport_init(ProjPaintState *ps, const char symmet CameraParams params; /* viewmat & viewinv */ - copy_m4_m4(viewinv, cam_ob_eval->obmat); + copy_m4_m4(viewinv, cam_ob_eval->object_to_world); normalize_m4(viewinv); invert_m4_m4(viewmat, viewinv); @@ -4462,7 +4462,7 @@ static void project_paint_begin(const bContext *C, if (ps->source == PROJ_SRC_VIEW) { /* faster clipping lookups */ - ED_view3d_clipping_local(ps->rv3d, ps->ob->obmat); + ED_view3d_clipping_local(ps->rv3d, ps->ob->object_to_world); } ps->do_face_sel = ((((Mesh *)ps->ob->data)->editflag & ME_EDIT_PAINT_FACE_SEL) != 0); diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index 571ebd79764..ce7db91571c 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -348,7 +348,7 @@ static void sculpt_gesture_context_init_common(bContext *C, copy_m3_m4(mat, sgcontext->vc.rv3d->viewinv); mul_m3_v3(mat, view_dir); normalize_v3_v3(sgcontext->world_space_view_normal, view_dir); - copy_m3_m4(mat, ob->imat); + copy_m3_m4(mat, ob->world_to_object); mul_m3_v3(mat, view_dir); normalize_v3_v3(sgcontext->true_view_normal, view_dir); @@ -460,12 +460,12 @@ static void sculpt_gesture_line_plane_from_tri(float *r_plane, { float normal[3]; normal_tri_v3(normal, p1, p2, p3); - mul_v3_mat3_m4v3(normal, sgcontext->vc.obact->imat, normal); + mul_v3_mat3_m4v3(normal, sgcontext->vc.obact->world_to_object, normal); if (flip) { mul_v3_fl(normal, -1.0f); } float plane_point_object_space[3]; - mul_v3_m4v3(plane_point_object_space, sgcontext->vc.obact->imat, p1); + mul_v3_m4v3(plane_point_object_space, sgcontext->vc.obact->world_to_object, p1); plane_from_point_normal_v3(r_plane, plane_point_object_space, normal); } @@ -1009,11 +1009,12 @@ static void sculpt_gesture_trim_shape_origin_normal_get(SculptGestureContext *sg copy_v3_v3(r_normal, sgcontext->world_space_view_normal); break; case SCULPT_GESTURE_TRIM_ORIENTATION_SURFACE: - mul_v3_m4v3(r_origin, sgcontext->vc.obact->obmat, sgcontext->ss->gesture_initial_location); + mul_v3_m4v3( + r_origin, sgcontext->vc.obact->object_to_world, sgcontext->ss->gesture_initial_location); /* Transforming the normal does not take non uniform scaling into account. Sculpt mode is not * expected to work on object with non uniform scaling. */ copy_v3_v3(r_normal, sgcontext->ss->gesture_initial_normal); - mul_mat3_m4_v3(sgcontext->vc.obact->obmat, r_normal); + mul_mat3_m4_v3(sgcontext->vc.obact->object_to_world, r_normal); break; } } @@ -1044,7 +1045,7 @@ static void sculpt_gesture_trim_calculate_depth(SculptGestureContext *sgcontext) * mesh, coordinates are first calculated in world space, then converted to object space to * store them. */ float world_space_vco[3]; - mul_v3_m4v3(world_space_vco, vc->obact->obmat, vco); + mul_v3_m4v3(world_space_vco, vc->obact->object_to_world, vco); const float dist = dist_signed_to_plane_v3(world_space_vco, shape_plane); trim_operation->depth_front = min_ff(dist, trim_operation->depth_front); trim_operation->depth_back = max_ff(dist, trim_operation->depth_back); @@ -1052,8 +1053,9 @@ static void sculpt_gesture_trim_calculate_depth(SculptGestureContext *sgcontext) if (trim_operation->use_cursor_depth) { float world_space_gesture_initial_location[3]; - mul_v3_m4v3( - world_space_gesture_initial_location, vc->obact->obmat, ss->gesture_initial_location); + mul_v3_m4v3(world_space_gesture_initial_location, + vc->obact->object_to_world, + ss->gesture_initial_location); float mid_point_depth; if (trim_operation->orientation == SCULPT_GESTURE_TRIM_ORIENTATION_VIEW) { @@ -1132,7 +1134,7 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex sculpt_gesture_trim_shape_origin_normal_get(sgcontext, shape_origin, shape_normal); plane_from_point_normal_v3(shape_plane, shape_origin, shape_normal); - const float(*ob_imat)[4] = vc->obact->imat; + const float(*ob_imat)[4] = vc->obact->world_to_object; /* Write vertices coordinates for the front face. */ MVert *verts = BKE_mesh_verts_for_write(trim_operation->mesh); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index bc4c6dc4148..97f5bd77d47 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -564,7 +564,7 @@ static void paint_brush_stroke_add_step( if (SCULPT_stroke_get_location( C, world_space_position, stroke->last_mouse_position, stroke->original)) { copy_v3_v3(stroke->last_world_space_position, world_space_position); - mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); + mul_m4_v3(stroke->vc.obact->object_to_world, stroke->last_world_space_position); } else { add_v3_v3(stroke->last_world_space_position, stroke->last_scene_spacing_delta); @@ -681,8 +681,9 @@ static float paint_space_stroke_spacing(bContext *C, if (paint_stroke_use_scene_spacing(brush, mode)) { if (!BKE_brush_use_locked_size(scene, brush)) { float last_object_space_position[3]; - mul_v3_m4v3( - last_object_space_position, stroke->vc.obact->imat, stroke->last_world_space_position); + mul_v3_m4v3(last_object_space_position, + stroke->vc.obact->world_to_object, + stroke->last_world_space_position); size_clamp = paint_calc_object_space_radius(&stroke->vc, last_object_space_position, size); } else { @@ -825,7 +826,7 @@ static int paint_space_stroke(bContext *C, if (use_scene_spacing) { float world_space_position[3]; bool hit = SCULPT_stroke_get_location(C, world_space_position, final_mouse, stroke->original); - mul_m4_v3(stroke->vc.obact->obmat, world_space_position); + mul_m4_v3(stroke->vc.obact->object_to_world, world_space_position); if (hit && stroke->stroke_over_mesh) { sub_v3_v3v3(d_world_space_position, world_space_position, stroke->last_world_space_position); length = len_v3(d_world_space_position); @@ -1216,8 +1217,8 @@ static void paint_line_strokes_spacing(bContext *C, C, world_space_position_old, old_pos, stroke->original); bool hit_new = SCULPT_stroke_get_location( C, world_space_position_new, new_pos, stroke->original); - mul_m4_v3(stroke->vc.obact->obmat, world_space_position_old); - mul_m4_v3(stroke->vc.obact->obmat, world_space_position_new); + mul_m4_v3(stroke->vc.obact->object_to_world, world_space_position_old); + mul_m4_v3(stroke->vc.obact->object_to_world, world_space_position_new); if (hit_old && hit_new && stroke->stroke_over_mesh) { sub_v3_v3v3(d_world_space_position, world_space_position_new, world_space_position_old); length = len_v3(d_world_space_position); @@ -1360,7 +1361,7 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str if (paint_stroke_use_scene_spacing(br, BKE_paintmode_get_active_from_context(C))) { stroke->stroke_over_mesh = SCULPT_stroke_get_location( C, stroke->last_world_space_position, data + 2 * j, stroke->original); - mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); + mul_m4_v3(stroke->vc.obact->object_to_world, stroke->last_world_space_position); } stroke->stroke_started = stroke->test_start(C, op, stroke->last_mouse_position); @@ -1492,7 +1493,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintS if (paint_stroke_use_scene_spacing(br, mode)) { stroke->stroke_over_mesh = SCULPT_stroke_get_location( C, stroke->last_world_space_position, sample_average.mouse, stroke->original); - mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position); + mul_m4_v3(stroke->vc.obact->object_to_world, stroke->last_world_space_position); } stroke->stroke_started = stroke->test_start(C, op, sample_average.mouse); BLI_assert((stroke->stroke_started & ~1) == 0); /* 0/1 */ diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index ce4a5151a20..f87ca073c82 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -135,12 +135,12 @@ float paint_calc_object_space_radius(ViewContext *vc, const float center[3], flo float delta[3], scale, loc[3]; const float xy_delta[2] = {pixel_radius, 0.0f}; - mul_v3_m4v3(loc, ob->obmat, center); + mul_v3_m4v3(loc, ob->object_to_world, center); const float zfac = ED_view3d_calc_zfac(vc->rv3d, loc); ED_view3d_win_to_delta(vc->region, xy_delta, zfac, delta); - scale = fabsf(mat4_to_scale(ob->obmat)); + scale = fabsf(mat4_to_scale(ob->object_to_world)); scale = (scale == 0.0f) ? 1.0f : scale; return len_v3(delta) / scale; @@ -297,7 +297,7 @@ static void imapaint_pick_uv( GPU_matrix_model_view_get(matrix); GPU_matrix_projection_get(proj); view[0] = view[1] = 0; - mul_m4_m4m4(matrix, matrix, ob_eval->obmat); + mul_m4_m4m4(matrix, matrix, ob_eval->object_to_world); mul_m4_m4m4(matrix, proj, matrix); minabsw = 1e10; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index acd8b1a6bb1..8e790ac435e 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -1647,10 +1647,10 @@ static void vwpaint_update_cache_invariants( /* cache projection matrix */ ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat); - invert_m4_m4(ob->imat, ob->obmat); + invert_m4_m4(ob->world_to_object, ob->object_to_world); copy_m3_m4(mat, cache->vc->rv3d->viewinv); mul_m3_v3(mat, view_dir); - copy_m3_m4(mat, ob->imat); + copy_m3_m4(mat, ob->world_to_object); mul_m3_v3(mat, view_dir); normalize_v3_v3(cache->true_view_normal, view_dir); @@ -2518,7 +2518,7 @@ static void wpaint_stroke_update_step(bContext *C, ED_view3d_init_mats_rv3d(ob, vc->rv3d); /* load projection matrix */ - mul_m4_m4m4(mat, vc->rv3d->persmat, ob->obmat); + mul_m4_m4m4(mat, vc->rv3d->persmat, ob->object_to_world); Mesh *mesh = static_cast<Mesh *>(ob->data); @@ -2556,7 +2556,7 @@ static void wpaint_stroke_update_step(bContext *C, /* Calculate pivot for rotation around selection if needed. * also needed for "Frame Selected" on last stroke. */ float loc_world[3]; - mul_v3_m4v3(loc_world, ob->obmat, ss->cache->true_location); + mul_v3_m4v3(loc_world, ob->object_to_world, ss->cache->true_location); paint_last_stroke_update(scene, loc_world); BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL); @@ -3847,7 +3847,7 @@ static void vpaint_stroke_update_step_intern(bContext *C, PaintStroke *stroke, P ED_view3d_init_mats_rv3d(ob, vc->rv3d); /* load projection matrix */ - mul_m4_m4m4(mat, vc->rv3d->persmat, ob->obmat); + mul_m4_m4m4(mat, vc->rv3d->persmat, ob->object_to_world); swap_m4m4(vc->rv3d->persmat, mat); @@ -3870,7 +3870,7 @@ static void vpaint_stroke_update_step_intern(bContext *C, PaintStroke *stroke, P /* Calculate pivot for rotation around selection if needed. * also needed for "Frame Selected" on last stroke. */ float loc_world[3]; - mul_v3_m4v3(loc_world, ob->obmat, ss->cache->true_location); + mul_v3_m4v3(loc_world, ob->object_to_world, ss->cache->true_location); paint_last_stroke_update(scene, loc_world); ED_region_tag_redraw(vc->region); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 95192114429..3477285814e 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1121,8 +1121,8 @@ void SCULPT_tag_update_overlays(bContext *C) DEG_id_tag_update(&ob->id, ID_RECALC_SHADING); - View3D *v3d = CTX_wm_view3d(C); - if (!BKE_sculptsession_use_pbvh_draw(ob, v3d)) { + RegionView3D *rv3d = CTX_wm_region_view3d(C); + if (!BKE_sculptsession_use_pbvh_draw(ob, rv3d)) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } } @@ -2773,14 +2773,14 @@ static void calc_local_y(ViewContext *vc, const float center[3], float y[3]) float loc[3]; const float xy_delta[2] = {0.0f, 1.0f}; - mul_v3_m4v3(loc, ob->imat, center); + mul_v3_m4v3(loc, ob->world_to_object, center); const float zfac = ED_view3d_calc_zfac(vc->rv3d, loc); ED_view3d_win_to_delta(vc->region, xy_delta, zfac, y); normalize_v3(y); add_v3_v3(y, ob->loc); - mul_m4_v3(ob->imat, y); + mul_m4_v3(ob->world_to_object, y); } static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat[4][4]) @@ -2792,8 +2792,8 @@ static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat float angle, v[3]; float up[3]; - /* Ensure `ob->imat` is up to date. */ - invert_m4_m4(ob->imat, ob->obmat); + /* Ensure `ob->world_to_object` is up to date. */ + invert_m4_m4(ob->world_to_object, ob->object_to_world); /* Initialize last column of matrix. */ mat[0][3] = 0.0f; @@ -2833,13 +2833,13 @@ void SCULPT_tilt_apply_to_normal(float r_normal[3], StrokeCache *cache, const fl return; } const float rot_max = M_PI_2 * tilt_strength * SCULPT_TILT_SENSITIVITY; - mul_v3_mat3_m4v3(r_normal, cache->vc->obact->obmat, r_normal); + mul_v3_mat3_m4v3(r_normal, cache->vc->obact->object_to_world, r_normal); float normal_tilt_y[3]; rotate_v3_v3v3fl(normal_tilt_y, r_normal, cache->vc->rv3d->viewinv[0], cache->y_tilt * rot_max); float normal_tilt_xy[3]; rotate_v3_v3v3fl( normal_tilt_xy, normal_tilt_y, cache->vc->rv3d->viewinv[1], cache->x_tilt * rot_max); - mul_v3_mat3_m4v3(r_normal, cache->vc->obact->imat, normal_tilt_xy); + mul_v3_mat3_m4v3(r_normal, cache->vc->obact->world_to_object, normal_tilt_xy); normalize_v3(r_normal); } @@ -3284,7 +3284,7 @@ static void sculpt_topology_update(Sculpt *sd, /* Update average stroke position. */ copy_v3_v3(location, ss->cache->true_location); - mul_m4_v3(ob->obmat, location); + mul_m4_v3(ob->object_to_world, location); } static void do_brush_action_task_cb(void *__restrict userdata, @@ -3615,7 +3615,7 @@ static void do_brush_action(Sculpt *sd, /* Update average stroke position. */ copy_v3_v3(location, ss->cache->true_location); - mul_m4_v3(ob->obmat, location); + mul_m4_v3(ob->object_to_world, location); add_v3_v3(ups->average_stroke_accum, location); ups->average_stroke_counter++; @@ -4201,8 +4201,8 @@ static void sculpt_init_mirror_clipping(Object *ob, SculptSession *ss) /* Store matrix for mirror object clipping. */ if (mmd->mirror_ob) { float imtx_mirror_ob[4][4]; - invert_m4_m4(imtx_mirror_ob, mmd->mirror_ob->obmat); - mul_m4_m4m4(ss->cache->clip_mirror_mtx, imtx_mirror_ob, ob->obmat); + invert_m4_m4(imtx_mirror_ob, mmd->mirror_ob->object_to_world); + mul_m4_m4m4(ss->cache->clip_mirror_mtx, imtx_mirror_ob, ob->object_to_world); } } } @@ -4354,10 +4354,10 @@ static void sculpt_update_cache_invariants( /* Cache projection matrix. */ ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat); - invert_m4_m4(ob->imat, ob->obmat); + invert_m4_m4(ob->world_to_object, ob->object_to_world); copy_m3_m4(mat, cache->vc->rv3d->viewinv); mul_m3_v3(mat, viewDir); - copy_m3_m4(mat, ob->imat); + copy_m3_m4(mat, ob->world_to_object); mul_m3_v3(mat, viewDir); normalize_v3_v3(cache->true_view_normal, viewDir); @@ -4373,7 +4373,7 @@ static void sculpt_update_cache_invariants( if (sd->gravity_object) { Object *gravity_object = sd->gravity_object; - copy_v3_v3(cache->true_gravity_direction, gravity_object->obmat[2]); + copy_v3_v3(cache->true_gravity_direction, gravity_object->object_to_world[2]); } else { cache->true_gravity_direction[0] = cache->true_gravity_direction[1] = 0.0f; @@ -4527,27 +4527,27 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru } /* Compute 3d coordinate at same z from original location + mval. */ - mul_v3_m4v3(loc, ob->obmat, cache->orig_grab_location); + mul_v3_m4v3(loc, ob->object_to_world, cache->orig_grab_location); ED_view3d_win_to_3d(cache->vc->v3d, cache->vc->region, loc, mval, grab_location); /* Compute delta to move verts by. */ if (!SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache)) { if (sculpt_needs_delta_from_anchored_origin(brush)) { sub_v3_v3v3(delta, grab_location, cache->old_grab_location); - invert_m4_m4(imat, ob->obmat); + invert_m4_m4(imat, ob->object_to_world); mul_mat3_m4_v3(imat, delta); add_v3_v3(cache->grab_delta, delta); } else if (sculpt_needs_delta_for_tip_orientation(brush)) { if (brush->flag & BRUSH_ANCHORED) { float orig[3]; - mul_v3_m4v3(orig, ob->obmat, cache->orig_grab_location); + mul_v3_m4v3(orig, ob->object_to_world, cache->orig_grab_location); sub_v3_v3v3(cache->grab_delta, grab_location, orig); } else { sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location); } - invert_m4_m4(imat, ob->obmat); + invert_m4_m4(imat, ob->object_to_world); mul_mat3_m4_v3(imat, cache->grab_delta); } else { @@ -4592,7 +4592,7 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru /* Handle 'rake' */ cache->is_rake_rotation_valid = false; - invert_m4_m4(imat, ob->obmat); + invert_m4_m4(imat, ob->object_to_world); mul_mat3_m4_v3(imat, grab_location); if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache)) { @@ -4813,12 +4813,12 @@ static bool sculpt_needs_connectivity_info(const Sculpt *sd, void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush) { SculptSession *ss = ob->sculpt; - View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; bool need_pmap = sculpt_needs_connectivity_info(sd, brush, ss, 0); if (ss->shapekey_active || ss->deform_modifiers_active || - (!BKE_sculptsession_use_pbvh_draw(ob, v3d) && need_pmap)) { + (!BKE_sculptsession_use_pbvh_draw(ob, rv3d) && need_pmap)) { Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); BKE_sculpt_update_object_for_edit( depsgraph, ob, need_pmap, false, SCULPT_tool_is_paint(brush->sculpt_tool)); @@ -4913,7 +4913,7 @@ float SCULPT_raycast_init(ViewContext *vc, ED_view3d_win_to_segment_clipped( vc->depsgraph, vc->region, vc->v3d, mval, ray_start, ray_end, true); - invert_m4_m4(obimat, ob->obmat); + invert_m4_m4(obimat, ob->object_to_world); mul_m4_v3(obimat, ray_start); mul_m4_v3(obimat, ray_end); @@ -5021,10 +5021,10 @@ bool SCULPT_cursor_geometry_info_update(bContext *C, float radius; /* Update cursor data in SculptSession. */ - invert_m4_m4(ob->imat, ob->obmat); + invert_m4_m4(ob->world_to_object, ob->object_to_world); copy_m3_m4(mat, vc.rv3d->viewinv); mul_m3_v3(mat, viewDir); - copy_m3_m4(mat, ob->imat); + copy_m3_m4(mat, ob->world_to_object); mul_m3_v3(mat, viewDir); normalize_v3_v3(ss->cursor_view_normal, viewDir); copy_v3_v3(ss->cursor_normal, srd.face_normal); @@ -5249,7 +5249,6 @@ void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags) SculptSession *ss = ob->sculpt; ARegion *region = CTX_wm_region(C); MultiresModifierData *mmd = ss->multires.modifier; - View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); if (rv3d) { @@ -5274,7 +5273,7 @@ void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags) /* Only current viewport matters, slower update for all viewports will * be done in sculpt_flush_update_done. */ - if (!BKE_sculptsession_use_pbvh_draw(ob, v3d)) { + if (!BKE_sculptsession_use_pbvh_draw(ob, rv3d)) { /* Slow update with full dependency graph update and all that comes with it. * Needed when there are modifiers or full shading in the 3D viewport. */ DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -5316,16 +5315,15 @@ void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType up /* After we are done drawing the stroke, check if we need to do a more * expensive depsgraph tag to update geometry. */ wmWindowManager *wm = CTX_wm_manager(C); - View3D *current_v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); + RegionView3D *current_rv3d = CTX_wm_region_view3d(C); SculptSession *ss = ob->sculpt; Mesh *mesh = ob->data; /* Always needed for linked duplicates. */ bool need_tag = (ID_REAL_USERS(&mesh->id) > 1); - if (rv3d) { - rv3d->rflag &= ~RV3D_PAINTING; + if (current_rv3d) { + current_rv3d->rflag &= ~RV3D_PAINTING; } LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { @@ -5335,16 +5333,17 @@ void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType up if (sl->spacetype != SPACE_VIEW3D) { continue; } - View3D *v3d = (View3D *)sl; - if (v3d != current_v3d) { - need_tag |= !BKE_sculptsession_use_pbvh_draw(ob, v3d); - } /* Tag all 3D viewports for redraw now that we are done. Others * viewports did not get a full redraw, and anti-aliasing for the * current viewport was deactivated. */ LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype == RGN_TYPE_WINDOW) { + RegionView3D *rv3d = region->regiondata; + if (rv3d != current_rv3d) { + need_tag |= !BKE_sculptsession_use_pbvh_draw(ob, rv3d); + } + ED_region_tag_redraw(region); } } @@ -5378,15 +5377,17 @@ void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType up BKE_sculpt_attributes_destroy_temporary_stroke(ob); - if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { - BKE_pbvh_bmesh_after_stroke(ss->pbvh); - } + if (update_flags & SCULPT_UPDATE_COORDS) { + if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { + BKE_pbvh_bmesh_after_stroke(ss->pbvh); + } - /* Optimization: if there is locked key and active modifiers present in */ - /* the stack, keyblock is updating at each step. otherwise we could update */ - /* keyblock only when stroke is finished. */ - if (ss->shapekey_active && !ss->deform_modifiers_active) { - sculpt_update_keyblock(ob); + /* Optimization: if there is locked key and active modifiers present in */ + /* the stack, keyblock is updating at each step. otherwise we could update */ + /* keyblock only when stroke is finished. */ + if (ss->shapekey_active && !ss->deform_modifiers_active) { + sculpt_update_keyblock(ob); + } } if (need_tag) { @@ -5511,7 +5512,8 @@ static void sculpt_stroke_update_step(bContext *C, sculpt_restore_mesh(sd, ob); if (sd->flags & (SCULPT_DYNTOPO_DETAIL_CONSTANT | SCULPT_DYNTOPO_DETAIL_MANUAL)) { - float object_space_constant_detail = 1.0f / (sd->constant_detail * mat4_to_scale(ob->obmat)); + float object_space_constant_detail = 1.0f / (sd->constant_detail * + mat4_to_scale(ob->object_to_world)); BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail); } else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) { @@ -5625,6 +5627,7 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str } else { BKE_sculpt_attributes_destroy_temporary_stroke(ob); + SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COLOR); } } else { diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c index b6bb4c185f9..cf7e1d027f7 100644 --- a/source/blender/editors/sculpt_paint/sculpt_cloth.c +++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c @@ -667,15 +667,15 @@ static void cloth_brush_solve_collision(Object *object, BVHTreeRayHit hit; float obmat_inv[4][4]; - invert_m4_m4(obmat_inv, object->obmat); + invert_m4_m4(obmat_inv, object->object_to_world); for (collider_cache = cloth_sim->collider_list->first; collider_cache; collider_cache = collider_cache->next) { float ray_start[3], ray_normal[3]; float pos_world_space[3], prev_pos_world_space[3]; - mul_v3_m4v3(pos_world_space, object->obmat, cloth_sim->pos[i]); - mul_v3_m4v3(prev_pos_world_space, object->obmat, cloth_sim->last_iteration_pos[i]); + mul_v3_m4v3(pos_world_space, object->object_to_world, cloth_sim->pos[i]); + mul_v3_m4v3(prev_pos_world_space, object->object_to_world, cloth_sim->last_iteration_pos[i]); sub_v3_v3v3(ray_normal, pos_world_space, prev_pos_world_space); copy_v3_v3(ray_start, prev_pos_world_space); hit.index = -1; @@ -1419,7 +1419,7 @@ static void cloth_filter_apply_forces_task_cb(void *__restrict userdata, float sculpt_gravity[3] = {0.0f}; if (sd->gravity_object) { - copy_v3_v3(sculpt_gravity, sd->gravity_object->obmat[2]); + copy_v3_v3(sculpt_gravity, sd->gravity_object->object_to_world[2]); } else { sculpt_gravity[2] = -1.0f; diff --git a/source/blender/editors/sculpt_paint/sculpt_detail.c b/source/blender/editors/sculpt_paint/sculpt_detail.c index 6dd718d6a0c..0e46fd50f3b 100644 --- a/source/blender/editors/sculpt_paint/sculpt_detail.c +++ b/source/blender/editors/sculpt_paint/sculpt_detail.c @@ -102,7 +102,8 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op) size = max_fff(dim[0], dim[1], dim[2]); /* Update topology size. */ - float object_space_constant_detail = 1.0f / (sd->constant_detail * mat4_to_scale(ob->obmat)); + float object_space_constant_detail = 1.0f / + (sd->constant_detail * mat4_to_scale(ob->object_to_world)); BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail); SCULPT_undo_push_begin(ob, op); @@ -223,7 +224,7 @@ static void sample_detail_dyntopo(bContext *C, ViewContext *vc, const int mval[2 if (srd.hit && srd.edge_length > 0.0f) { /* Convert edge length to world space detail resolution. */ - sd->constant_detail = 1 / (srd.edge_length * mat4_to_scale(ob->obmat)); + sd->constant_detail = 1 / (srd.edge_length * mat4_to_scale(ob->object_to_world)); } } @@ -473,8 +474,8 @@ static void dyntopo_detail_size_parallel_lines_draw(uint pos3d, bool flip, const float angle) { - float object_space_constant_detail = 1.0f / - (cd->detail_size * mat4_to_scale(cd->active_object->obmat)); + float object_space_constant_detail = 1.0f / (cd->detail_size * + mat4_to_scale(cd->active_object->object_to_world)); /* The constant detail represents the maximum edge length allowed before subdividing it. If the * triangle grid preview is created with this value it will represent an ideal mesh density where @@ -592,7 +593,8 @@ static void dyntopo_detail_size_sample_from_surface(Object *ob, if (num_neighbors > 0) { const float avg_edge_len = len_accum / num_neighbors; /* Use 0.7 as the average of min and max dyntopo edge length. */ - const float detail_size = 0.7f / (avg_edge_len * mat4_to_scale(cd->active_object->obmat)); + const float detail_size = 0.7f / + (avg_edge_len * mat4_to_scale(cd->active_object->object_to_world)); cd->detail_size = clamp_f(detail_size, 1.0f, 500.0f); } } @@ -716,7 +718,7 @@ static int dyntopo_detail_size_edit_invoke(bContext *C, wmOperator *op, const wm float cursor_trans[4][4], cursor_rot[4][4]; const float z_axis[4] = {0.0f, 0.0f, 1.0f, 0.0f}; float quat[4]; - copy_m4_m4(cursor_trans, active_object->obmat); + copy_m4_m4(cursor_trans, active_object->object_to_world); translate_m4( cursor_trans, ss->cursor_location[0], ss->cursor_location[1], ss->cursor_location[2]); diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc index 8fb4dea668e..40835172be9 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc @@ -917,7 +917,7 @@ static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op) UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; float location[3]; copy_v3_v3(location, SCULPT_active_vertex_co_get(ss)); - mul_m4_v3(ob->obmat, location); + mul_m4_v3(ob->object_to_world, location); copy_v3_v3(ups->average_stroke_accum, location); ups->average_stroke_counter = 1; ups->last_stroke_valid = true; diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c index 1fa53eaa006..c158cf33f6d 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c @@ -146,8 +146,8 @@ void SCULPT_filter_cache_init(bContext *C, 0, ss->filter_cache->totnode, &data, filter_cache_init_task_cb, &settings); /* Setup orientation matrices. */ - copy_m4_m4(ss->filter_cache->obmat, ob->obmat); - invert_m4_m4(ss->filter_cache->obmat_inv, ob->obmat); + copy_m4_m4(ss->filter_cache->obmat, ob->object_to_world); + invert_m4_m4(ss->filter_cache->obmat_inv, ob->object_to_world); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewContext vc; @@ -203,7 +203,7 @@ void SCULPT_filter_cache_init(bContext *C, /* Update last stroke location */ - mul_m4_v3(ob->obmat, co); + mul_m4_v3(ob->object_to_world, co); add_v3_v3(ups->average_stroke_accum, co); ups->average_stroke_counter++; @@ -221,10 +221,10 @@ void SCULPT_filter_cache_init(bContext *C, ED_view3d_ob_project_mat_get(vc.rv3d, ob, projection_mat); - invert_m4_m4(ob->imat, ob->obmat); + invert_m4_m4(ob->world_to_object, ob->object_to_world); copy_m3_m4(mat, vc.rv3d->viewinv); mul_m3_v3(mat, viewDir); - copy_m3_m4(mat, ob->imat); + copy_m3_m4(mat, ob->world_to_object); mul_m3_v3(mat, viewDir); normalize_v3_v3(ss->filter_cache->view_normal, viewDir); } diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.c b/source/blender/editors/sculpt_paint/sculpt_ops.c index a740ec2773b..8affb0e9d53 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.c +++ b/source/blender/editors/sculpt_paint/sculpt_ops.c @@ -323,7 +323,7 @@ void ED_object_sculptmode_enter_ex(Main *bmain, BKE_report( reports, RPT_WARNING, "Object has non-uniform scale, sculpting may be unpredictable"); } - else if (is_negative_m4(ob->obmat)) { + else if (is_negative_m4(ob->object_to_world)) { BKE_report(reports, RPT_WARNING, "Object has negative scale, sculpting may be unpredictable"); } diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 13e3dd64521..eb92c865f18 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -857,7 +857,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); SculptSession *ss = ob->sculpt; @@ -911,7 +911,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase } DEG_id_tag_update(&ob->id, ID_RECALC_SHADING); - if (!BKE_sculptsession_use_pbvh_draw(ob, v3d)) { + if (!BKE_sculptsession_use_pbvh_draw(ob, rv3d)) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } @@ -1070,7 +1070,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase } } - tag_update |= ID_REAL_USERS(ob->data) > 1 || !BKE_sculptsession_use_pbvh_draw(ob, v3d) || + tag_update |= ID_REAL_USERS(ob->data) > 1 || !BKE_sculptsession_use_pbvh_draw(ob, rv3d) || ss->shapekey_active || ss->deform_modifiers_active; if (tag_update) { |