diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-04-05 19:47:10 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-04-05 19:47:10 +0300 |
commit | 7748dd4ec735535f53f61d6aa4a2f6b9db9abdc1 (patch) | |
tree | 65f854f448a2503bef50781212355b74fa616839 /source/blender/blenkernel/intern | |
parent | 9e12a731db6f6647d5e6dfdaa32fc4d8117a523d (diff) | |
parent | b84255f590c07b129f726eadbfec72c73bfc2ee1 (diff) |
Merge remote-tracking branch 'origin/master' into temp-sculpt-colorstemp-sculpt-colors
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/camera.c | 106 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve.cc | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve_bezier.cc | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.cc | 21 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist_tangent.c | 269 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/geometry_component_curves.cc | 2 |
7 files changed, 76 insertions, 329 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 8acb6092697..b9cd9e1ee59 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -1558,6 +1558,7 @@ void BKE_brush_init_curves_sculpt_settings(Brush *brush) brush->curves_sculpt_settings = MEM_callocN(sizeof(BrushCurvesSculptSettings), __func__); } brush->curves_sculpt_settings->add_amount = 1; + brush->curves_sculpt_settings->minimum_length = 0.01f; } struct Brush *BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mode) diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index b840fb1e665..3897df9f05f 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -552,12 +552,11 @@ void BKE_camera_view_frame(const Scene *scene, const Camera *camera, float r_vec typedef struct CameraViewFrameData { float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4]; /* 4 planes normalized */ float dist_vals[CAMERA_VIEWFRAME_NUM_PLANES]; /* distance (signed) */ + float camera_no[3]; + float z_range[2]; unsigned int tot; - /* Ortho camera only. */ - bool is_ortho; - float camera_no[3]; - float dist_to_cam; + bool do_zrange; /* Not used by callbacks... */ float camera_rotmat[3][3]; @@ -572,9 +571,10 @@ static void camera_to_frame_view_cb(const float co[3], void *user_data) CLAMP_MAX(data->dist_vals[i], nd); } - if (data->is_ortho) { + if (data->do_zrange) { const float d = dot_v3v3(data->camera_no, co); - CLAMP_MAX(data->dist_to_cam, d); + CLAMP_MAX(data->z_range[0], d); + CLAMP_MIN(data->z_range[1], d); } data->tot++; @@ -582,6 +582,7 @@ static void camera_to_frame_view_cb(const float co[3], void *user_data) static void camera_frame_fit_data_init(const Scene *scene, const Object *ob, + const bool do_clip_dists, CameraParams *params, CameraViewFrameData *data) { @@ -626,22 +627,27 @@ static void camera_frame_fit_data_init(const Scene *scene, mul_m4_v4(camera_rotmat_transposed_inversed, data->plane_tx[i]); /* Normalize. */ data->plane_tx[i][3] /= normalize_v3(data->plane_tx[i]); + + data->dist_vals[i] = FLT_MAX; } - copy_v4_fl(data->dist_vals, FLT_MAX); data->tot = 0; - data->is_ortho = params->is_ortho; - if (params->is_ortho) { - /* we want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */ + data->do_zrange = params->is_ortho || do_clip_dists; + + if (data->do_zrange) { + /* We want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */ negate_v3_v3(data->camera_no, data->camera_rotmat[2]); - data->dist_to_cam = FLT_MAX; + data->z_range[0] = FLT_MAX; + data->z_range[1] = -FLT_MAX; } } static bool camera_frame_fit_calc_from_data(CameraParams *params, CameraViewFrameData *data, float r_co[3], - float *r_scale) + float *r_scale, + float *r_clip_start, + float *r_clip_end) { float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4]; @@ -669,37 +675,38 @@ static bool camera_frame_fit_calc_from_data(CameraParams *params, zero_v3(r_co); madd_v3_v3fl(r_co, cam_axis_x, (dists[2] - dists[0]) * 0.5f + params->shiftx * scale_diff); madd_v3_v3fl(r_co, cam_axis_y, (dists[1] - dists[3]) * 0.5f + params->shifty * scale_diff); - madd_v3_v3fl(r_co, cam_axis_z, -(data->dist_to_cam - 1.0f - params->clip_start)); - - return true; + madd_v3_v3fl(r_co, cam_axis_z, -(data->z_range[0] - 1.0f - params->clip_start)); } + else { + float plane_isect_1[3], plane_isect_1_no[3], plane_isect_1_other[3]; + float plane_isect_2[3], plane_isect_2_no[3], plane_isect_2_other[3]; - float plane_isect_1[3], plane_isect_1_no[3], plane_isect_1_other[3]; - float plane_isect_2[3], plane_isect_2_no[3], plane_isect_2_other[3]; + float plane_isect_pt_1[3], plane_isect_pt_2[3]; - float plane_isect_pt_1[3], plane_isect_pt_2[3]; + /* apply the dist-from-plane's to the transformed plane points */ + for (int i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { + float co[3]; + mul_v3_v3fl(co, data->plane_tx[i], data->dist_vals[i]); + plane_from_point_normal_v3(plane_tx[i], co, data->plane_tx[i]); + } - /* apply the dist-from-plane's to the transformed plane points */ - for (int i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { - float co[3]; - mul_v3_v3fl(co, data->plane_tx[i], data->dist_vals[i]); - plane_from_point_normal_v3(plane_tx[i], co, data->plane_tx[i]); - } + if ((!isect_plane_plane_v3(plane_tx[0], plane_tx[2], plane_isect_1, plane_isect_1_no)) || + (!isect_plane_plane_v3(plane_tx[1], plane_tx[3], plane_isect_2, plane_isect_2_no))) { + return false; + } - if ((!isect_plane_plane_v3(plane_tx[0], plane_tx[2], plane_isect_1, plane_isect_1_no)) || - (!isect_plane_plane_v3(plane_tx[1], plane_tx[3], plane_isect_2, plane_isect_2_no))) { - return false; - } + add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no); + add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no); - add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no); - add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no); + if (!isect_line_line_v3(plane_isect_1, + plane_isect_1_other, + plane_isect_2, + plane_isect_2_other, + plane_isect_pt_1, + plane_isect_pt_2) != 0) { + return false; + } - if (isect_line_line_v3(plane_isect_1, - plane_isect_1_other, - plane_isect_2, - plane_isect_2_other, - plane_isect_pt_1, - plane_isect_pt_2) != 0) { float cam_plane_no[3]; float plane_isect_delta[3]; float plane_isect_delta_len; @@ -728,15 +735,23 @@ static bool camera_frame_fit_calc_from_data(CameraParams *params, normalize_v3(plane_isect_2_no); madd_v3_v3fl(r_co, plane_isect_2_no, params->shiftx * plane_isect_delta_len * shift_fac); } - - return true; } - return false; + if (r_clip_start && r_clip_end) { + const float z_offs = dot_v3v3(r_co, data->camera_no); + *r_clip_start = data->z_range[0] - z_offs; + *r_clip_end = data->z_range[1] - z_offs; + } + return true; } -bool BKE_camera_view_frame_fit_to_scene( - Depsgraph *depsgraph, const Scene *scene, Object *camera_ob, float r_co[3], float *r_scale) +bool BKE_camera_view_frame_fit_to_scene(Depsgraph *depsgraph, + const Scene *scene, + Object *camera_ob, + float r_co[3], + float *r_scale, + float *r_clip_start, + float *r_clip_end) { CameraParams params; CameraViewFrameData data_cb; @@ -744,12 +759,13 @@ bool BKE_camera_view_frame_fit_to_scene( /* just in case */ *r_scale = 1.0f; - camera_frame_fit_data_init(scene, camera_ob, ¶ms, &data_cb); + camera_frame_fit_data_init(scene, camera_ob, r_clip_start && r_clip_end, ¶ms, &data_cb); /* run callback on all visible points */ BKE_scene_foreach_display_point(depsgraph, camera_to_frame_view_cb, &data_cb); - return camera_frame_fit_calc_from_data(¶ms, &data_cb, r_co, r_scale); + return camera_frame_fit_calc_from_data( + ¶ms, &data_cb, r_co, r_scale, r_clip_start, r_clip_end); } bool BKE_camera_view_frame_fit_to_coords(const Depsgraph *depsgraph, @@ -767,14 +783,14 @@ bool BKE_camera_view_frame_fit_to_coords(const Depsgraph *depsgraph, /* just in case */ *r_scale = 1.0f; - camera_frame_fit_data_init(scene_eval, camera_ob_eval, ¶ms, &data_cb); + camera_frame_fit_data_init(scene_eval, camera_ob_eval, false, ¶ms, &data_cb); /* run callback on all given coordinates */ while (num_cos--) { camera_to_frame_view_cb(cos[num_cos], &data_cb); } - return camera_frame_fit_calc_from_data(¶ms, &data_cb, r_co, r_scale); + return camera_frame_fit_calc_from_data(¶ms, &data_cb, r_co, r_scale, NULL, NULL); } /** \} */ diff --git a/source/blender/blenkernel/intern/curve.cc b/source/blender/blenkernel/intern/curve.cc index 26f5d7e9cb4..2d72ad28d18 100644 --- a/source/blender/blenkernel/intern/curve.cc +++ b/source/blender/blenkernel/intern/curve.cc @@ -123,8 +123,6 @@ static void curve_free_data(ID *id) MEM_SAFE_FREE(curve->str); MEM_SAFE_FREE(curve->strinfo); MEM_SAFE_FREE(curve->tb); - - delete curve->curve_eval; } static void curve_foreach_id(ID *id, LibraryForeachIDData *data) diff --git a/source/blender/blenkernel/intern/curve_bezier.cc b/source/blender/blenkernel/intern/curve_bezier.cc index 30a5869c976..dfe462d8566 100644 --- a/source/blender/blenkernel/intern/curve_bezier.cc +++ b/source/blender/blenkernel/intern/curve_bezier.cc @@ -218,6 +218,10 @@ void calculate_evaluated_positions(const Span<float3> positions, { BLI_assert(evaluated_offsets.last() == evaluated_positions.size()); BLI_assert(evaluated_offsets.size() == positions.size()); + if (evaluated_offsets.last() == 1) { + evaluated_positions.first() = positions.first(); + return; + } /* Evaluate the first segment. */ evaluate_segment(positions.first(), diff --git a/source/blender/blenkernel/intern/displist.cc b/source/blender/blenkernel/intern/displist.cc index 791e0faab3b..8c1161d6ff6 100644 --- a/source/blender/blenkernel/intern/displist.cc +++ b/source/blender/blenkernel/intern/displist.cc @@ -948,12 +948,11 @@ static void displist_surf_indices(DispList *dl) } } -static void evaluate_surface_object(Depsgraph *depsgraph, - const Scene *scene, - Object *ob, - const bool for_render, - ListBase *r_dispbase, - Mesh **r_final) +static GeometrySet evaluate_surface_object(Depsgraph *depsgraph, + const Scene *scene, + Object *ob, + const bool for_render, + ListBase *r_dispbase) { BLI_assert(ob->type == OB_SURF); const Curve *cu = (const Curve *)ob->data; @@ -1036,8 +1035,7 @@ static void evaluate_surface_object(Depsgraph *depsgraph, if (!geometry_set.has_mesh()) { geometry_set.replace_mesh(BKE_mesh_new_nomain(0, 0, 0, 0, 0)); } - MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>(); - *r_final = mesh_component.release(); + return geometry_set; } static void rotateBevelPiece(const Curve *cu, @@ -1483,9 +1481,8 @@ void BKE_displist_make_curveTypes(Depsgraph *depsgraph, ListBase *dispbase = &ob->runtime.curve_cache->disp; if (ob->type == OB_SURF) { - Mesh *mesh_eval; - evaluate_surface_object(depsgraph, scene, ob, for_render, dispbase, &mesh_eval); - BKE_object_eval_assign_data(ob, &mesh_eval->id, true); + GeometrySet geometry = evaluate_surface_object(depsgraph, scene, ob, for_render, dispbase); + ob->runtime.geometry_set_eval = new GeometrySet(std::move(geometry)); } else { GeometrySet geometry = evaluate_curve_type_object(depsgraph, scene, ob, for_render, dispbase); @@ -1497,7 +1494,7 @@ void BKE_displist_make_curveTypes(Depsgraph *depsgraph, * the CurveEval data type was introduced, when an evaluated object's curve data was just a * copy of the original curve and everything else ended up in #CurveCache. */ CurveComponent &curve_component = geometry.get_component_for_write<CurveComponent>(); - cow_curve.curve_eval = curves_to_curve_eval(*curve_component.get_for_read()).release(); + cow_curve.curve_eval = curve_component.get_for_read(); BKE_object_eval_assign_data(ob, &cow_curve.id, false); } diff --git a/source/blender/blenkernel/intern/displist_tangent.c b/source/blender/blenkernel/intern/displist_tangent.c deleted file mode 100644 index eb6bdd8d5e9..00000000000 --- a/source/blender/blenkernel/intern/displist_tangent.c +++ /dev/null @@ -1,269 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ - -/** \file - * \ingroup bke - */ - -#include "BLI_math.h" -#include "BLI_task.h" - -#include "BKE_displist.h" -#include "BKE_displist_tangent.h" - -#include "MEM_guardedalloc.h" - -/* interface */ -#include "mikktspace.h" - -/* -------------------------------------------------------------------- */ -/** \name Internal Types - * \{ */ - -typedef struct { - const DispList *dl; - float (*tangent)[4]; /* destination */ - /** Face normal for flat shading. */ - float (*fnormals)[3]; - /** Use by surfaces. Size of the surface in faces. */ - int u_len, v_len; -} SGLSLDisplistToTangent; - -/** \} */ - -/* ---------------------------------------------------------------------- */ -/** \name DL_INDEX3 tangents - * \{ */ - -static int dl3_ts_GetNumFaces(const SMikkTSpaceContext *pContext) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - - return dlt->dl->parts; -} - -static int dl3_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num) -{ - UNUSED_VARS(pContext, face_num); - - return 3; -} - -static void dl3_ts_GetPosition(const SMikkTSpaceContext *pContext, - float r_co[3], - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - const float(*verts)[3] = (float(*)[3])dlt->dl->verts; - const int(*idx)[3] = (int(*)[3])dlt->dl->index; - - copy_v3_v3(r_co, verts[idx[face_num][vert_index]]); -} - -static void dl3_ts_GetTextureCoordinate(const SMikkTSpaceContext *pContext, - float r_uv[2], - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - const int(*idx)[3] = (int(*)[3])dlt->dl->index; - - r_uv[0] = idx[face_num][vert_index] / (float)(dlt->dl->nr - 1); - r_uv[1] = 0.0f; -} - -static void dl3_ts_GetNormal(const SMikkTSpaceContext *pContext, - float r_no[3], - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - UNUSED_VARS(face_num, vert_index); - - copy_v3_v3(r_no, dlt->dl->nors); -} - -static void dl3_ts_SetTSpace(const SMikkTSpaceContext *pContext, - const float fvTangent[3], - const float fSign, - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - UNUSED_VARS(face_num, vert_index); - - copy_v3_v3(dlt->tangent[0], fvTangent); - dlt->tangent[0][3] = fSign; -} - -/** \} */ - -/* ---------------------------------------------------------------------- */ -/** \name DL_SURF tangents - * \{ */ - -static int dlsurf_ts_GetNumFaces(const SMikkTSpaceContext *pContext) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - - return dlt->v_len * dlt->u_len; -} - -static int dlsurf_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num) -{ - UNUSED_VARS(pContext, face_num); - - return 4; -} - -static int face_to_vert_index(SGLSLDisplistToTangent *dlt, - const int face_num, - const int vert_index) -{ - int u = face_num % dlt->u_len; - int v = face_num / dlt->u_len; - - if (vert_index == 0) { - u += 1; - } - else if (vert_index == 1) { - u += 1; - v += 1; - } - else if (vert_index == 2) { - v += 1; - } - - /* Cyclic correction. */ - u = u % dlt->dl->nr; - v = v % dlt->dl->parts; - - return v * dlt->dl->nr + u; -} - -static void dlsurf_ts_GetPosition(const SMikkTSpaceContext *pContext, - float r_co[3], - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - const float(*verts)[3] = (float(*)[3])dlt->dl->verts; - - copy_v3_v3(r_co, verts[face_to_vert_index(dlt, face_num, vert_index)]); -} - -static void dlsurf_ts_GetTextureCoordinate(const SMikkTSpaceContext *pContext, - float r_uv[2], - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - - int idx = face_to_vert_index(dlt, face_num, vert_index); - - /* NOTE: For some reason the shading U and V are swapped compared to the - * one described in the surface format. */ - r_uv[0] = (idx / dlt->dl->nr) / (float)(dlt->v_len); - r_uv[1] = (idx % dlt->dl->nr) / (float)(dlt->u_len); - - if (r_uv[0] == 0.0f && ELEM(vert_index, 1, 2)) { - r_uv[0] = 1.0f; - } - if (r_uv[1] == 0.0f && ELEM(vert_index, 0, 1)) { - r_uv[1] = 1.0f; - } -} - -static void dlsurf_ts_GetNormal(const SMikkTSpaceContext *pContext, - float r_no[3], - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - const float(*nors)[3] = (float(*)[3])dlt->dl->nors; - - if (dlt->fnormals) { - copy_v3_v3(r_no, dlt->fnormals[face_num]); - } - else { - copy_v3_v3(r_no, nors[face_to_vert_index(dlt, face_num, vert_index)]); - } -} - -static void dlsurf_ts_SetTSpace(const SMikkTSpaceContext *pContext, - const float fvTangent[3], - const float fSign, - const int face_num, - const int vert_index) -{ - SGLSLDisplistToTangent *dlt = pContext->m_pUserData; - UNUSED_VARS(face_num, vert_index); - - float *r_tan = dlt->tangent[face_num * 4 + vert_index]; - copy_v3_v3(r_tan, fvTangent); - r_tan[3] = fSign; -} - -/** \} */ - -/* ---------------------------------------------------------------------- */ -/** \name Entry point - * \{ */ - -void BKE_displist_tangent_calc(const DispList *dl, float (*fnormals)[3], float (**r_tangent)[4]) -{ - if (dl->type == DL_INDEX3) { - /* INDEX3 have only one tangent so we don't need actual allocation. */ - BLI_assert(*r_tangent != NULL); - - SGLSLDisplistToTangent mesh2tangent = { - .tangent = *r_tangent, - .dl = dl, - }; - SMikkTSpaceContext sContext = {NULL}; - SMikkTSpaceInterface sInterface = {NULL}; - sContext.m_pUserData = &mesh2tangent; - sContext.m_pInterface = &sInterface; - sInterface.m_getNumFaces = dl3_ts_GetNumFaces; - sInterface.m_getNumVerticesOfFace = dl3_ts_GetNumVertsOfFace; - sInterface.m_getPosition = dl3_ts_GetPosition; - sInterface.m_getTexCoord = dl3_ts_GetTextureCoordinate; - sInterface.m_getNormal = dl3_ts_GetNormal; - sInterface.m_setTSpaceBasic = dl3_ts_SetTSpace; - /* 0 if failed */ - genTangSpaceDefault(&sContext); - } - else if (dl->type == DL_SURF) { - SGLSLDisplistToTangent mesh2tangent = { - .dl = dl, - .u_len = dl->nr - ((dl->flag & DL_CYCL_U) ? 0 : 1), - .v_len = dl->parts - ((dl->flag & DL_CYCL_V) ? 0 : 1), - .fnormals = fnormals, - }; - - int loop_len = mesh2tangent.u_len * mesh2tangent.v_len * 4; - - if (*r_tangent == NULL) { - *r_tangent = MEM_mallocN(sizeof(float[4]) * loop_len, "displist tangents"); - } - mesh2tangent.tangent = *r_tangent; - SMikkTSpaceContext sContext = {NULL}; - SMikkTSpaceInterface sInterface = {NULL}; - sContext.m_pUserData = &mesh2tangent; - sContext.m_pInterface = &sInterface; - sInterface.m_getNumFaces = dlsurf_ts_GetNumFaces; - sInterface.m_getNumVerticesOfFace = dlsurf_ts_GetNumVertsOfFace; - sInterface.m_getPosition = dlsurf_ts_GetPosition; - sInterface.m_getTexCoord = dlsurf_ts_GetTextureCoordinate; - sInterface.m_getNormal = dlsurf_ts_GetNormal; - sInterface.m_setTSpaceBasic = dlsurf_ts_SetTSpace; - /* 0 if failed */ - genTangSpaceDefault(&sContext); - } - else { - /* Unsupported. */ - BLI_assert(0); - } -} - -/** \} */ diff --git a/source/blender/blenkernel/intern/geometry_component_curves.cc b/source/blender/blenkernel/intern/geometry_component_curves.cc index b5771cc063f..27c1a2f2f33 100644 --- a/source/blender/blenkernel/intern/geometry_component_curves.cc +++ b/source/blender/blenkernel/intern/geometry_component_curves.cc @@ -128,7 +128,7 @@ const Curve *CurveComponent::get_curve_for_render() const } curve_for_render_ = (Curve *)BKE_id_new_nomain(ID_CU_LEGACY, nullptr); - curve_for_render_->curve_eval = curves_to_curve_eval(*curves_).release(); + curve_for_render_->curve_eval = curves_; return curve_for_render_; } |