Cleanup: Change some view3d projection functions to use C++ types

These two have been used a lot in C++ code so the benefits are clear.
This commit is contained in:
Hans Goudey
2023-12-07 22:55:07 -05:00
parent 1abdf9d624
commit d742f08cc6
29 changed files with 182 additions and 260 deletions

View File

@@ -6,6 +6,7 @@
* \ingroup draw_engine
*/
#include "BKE_attribute.h"
#include "BKE_curves.h"
#include "DRW_render.h"

View File

@@ -520,8 +520,7 @@ static std::optional<FindClosestData> find_closest_point_to_screen_co(
float radius,
const FindClosestData &initial_closest)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(rv3d, &object, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(rv3d, &object);
const float radius_sq = pow2f(radius);
const FindClosestData new_closest_data = threading::parallel_reduce(
@@ -535,8 +534,7 @@ static std::optional<FindClosestData> find_closest_point_to_screen_co(
const float3 pos = deformed_positions[point_i];
/* Find the position of the point in screen space. */
float2 pos_proj;
ED_view3d_project_float_v2_m4(region, pos, pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(region, pos, projection);
const float distance_proj_sq = math::distance_squared(pos_proj, mouse_pos);
if (distance_proj_sq > radius_sq ||
@@ -578,8 +576,7 @@ static std::optional<FindClosestData> find_closest_curve_to_screen_co(
float radius,
const FindClosestData &initial_closest)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(rv3d, &object, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(rv3d, &object);
const float radius_sq = pow2f(radius);
@@ -596,8 +593,7 @@ static std::optional<FindClosestData> find_closest_curve_to_screen_co(
const float3 pos = deformed_positions[points.first()];
/* Find the position of the point in screen space. */
float2 pos_proj;
ED_view3d_project_float_v2_m4(region, pos, pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(region, pos, projection);
const float distance_proj_sq = math::distance_squared(pos_proj, mouse_pos);
if (distance_proj_sq > radius_sq ||
@@ -618,10 +614,8 @@ static std::optional<FindClosestData> find_closest_curve_to_screen_co(
for (const int segment_i : points.drop_back(1)) {
const float3 pos1 = deformed_positions[segment_i];
const float3 pos2 = deformed_positions[segment_i + 1];
float2 pos1_proj, pos2_proj;
ED_view3d_project_float_v2_m4(region, pos1, pos1_proj, projection.ptr());
ED_view3d_project_float_v2_m4(region, pos2, pos2_proj, projection.ptr());
const float2 pos1_proj = ED_view3d_project_float_v2_m4(region, pos1, projection);
const float2 pos2_proj = ED_view3d_project_float_v2_m4(region, pos2, projection);
const float distance_proj_sq = dist_squared_to_line_segment_v2(
mouse_pos, pos1_proj, pos2_proj);
@@ -708,15 +702,13 @@ bool select_box(const ViewContext &vc,
changed = true;
}
float4x4 projection;
ED_view3d_ob_project_mat_get(vc.rv3d, vc.obact, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, vc.obact);
const OffsetIndices points_by_curve = curves.points_by_curve();
if (selection_domain == ATTR_DOMAIN_POINT) {
mask.foreach_index_optimized<int64_t>(GrainSize(1024), [&](const int64_t point_i) {
float2 pos_proj;
ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[point_i], pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[point_i], projection);
if (BLI_rcti_isect_pt_v(&rect, int2(pos_proj))) {
apply_selection_operation_at_index(selection.span, point_i, sel_op);
changed = true;
@@ -727,9 +719,8 @@ bool select_box(const ViewContext &vc,
mask.foreach_index_optimized<int64_t>(GrainSize(512), [&](const int64_t curve_i) {
const IndexRange points = points_by_curve[curve_i];
if (points.size() == 1) {
float2 pos_proj;
ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[points.first()], pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[points.first()], projection);
if (BLI_rcti_isect_pt_v(&rect, int2(pos_proj))) {
apply_selection_operation_at_index(selection.span, curve_i, sel_op);
changed = true;
@@ -740,9 +731,8 @@ bool select_box(const ViewContext &vc,
const float3 pos1 = deformed_positions[segment_i];
const float3 pos2 = deformed_positions[segment_i + 1];
float2 pos1_proj, pos2_proj;
ED_view3d_project_float_v2_m4(vc.region, pos1, pos1_proj, projection.ptr());
ED_view3d_project_float_v2_m4(vc.region, pos2, pos2_proj, projection.ptr());
const float2 pos1_proj = ED_view3d_project_float_v2_m4(vc.region, pos1, projection);
const float2 pos2_proj = ED_view3d_project_float_v2_m4(vc.region, pos2, projection);
if (BLI_rcti_isect_segment(&rect, int2(pos1_proj), int2(pos2_proj))) {
apply_selection_operation_at_index(selection.span, curve_i, sel_op);
@@ -778,15 +768,13 @@ bool select_lasso(const ViewContext &vc,
changed = true;
}
float4x4 projection;
ED_view3d_ob_project_mat_get(vc.rv3d, vc.obact, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, vc.obact);
const OffsetIndices points_by_curve = curves.points_by_curve();
if (selection_domain == ATTR_DOMAIN_POINT) {
mask.foreach_index_optimized<int64_t>(GrainSize(1024), [&](const int64_t point_i) {
float2 pos_proj;
ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[point_i], pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[point_i], projection);
/* Check the lasso bounding box first as an optimization. */
if (BLI_rcti_isect_pt_v(&bbox, int2(pos_proj)) &&
BLI_lasso_is_point_inside(
@@ -801,9 +789,8 @@ bool select_lasso(const ViewContext &vc,
mask.foreach_index_optimized<int64_t>(GrainSize(512), [&](const int64_t curve_i) {
const IndexRange points = points_by_curve[curve_i];
if (points.size() == 1) {
float2 pos_proj;
ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[points.first()], pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[points.first()], projection);
/* Check the lasso bounding box first as an optimization. */
if (BLI_rcti_isect_pt_v(&bbox, int2(pos_proj)) &&
BLI_lasso_is_point_inside(
@@ -818,9 +805,8 @@ bool select_lasso(const ViewContext &vc,
const float3 pos1 = deformed_positions[segment_i];
const float3 pos2 = deformed_positions[segment_i + 1];
float2 pos1_proj, pos2_proj;
ED_view3d_project_float_v2_m4(vc.region, pos1, pos1_proj, projection.ptr());
ED_view3d_project_float_v2_m4(vc.region, pos2, pos2_proj, projection.ptr());
const float2 pos1_proj = ED_view3d_project_float_v2_m4(vc.region, pos1, projection);
const float2 pos2_proj = ED_view3d_project_float_v2_m4(vc.region, pos2, projection);
/* Check the lasso bounding box first as an optimization. */
if (BLI_rcti_isect_segment(&bbox, int2(pos1_proj), int2(pos2_proj)) &&
@@ -863,15 +849,13 @@ bool select_circle(const ViewContext &vc,
changed = true;
}
float4x4 projection;
ED_view3d_ob_project_mat_get(vc.rv3d, vc.obact, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, vc.obact);
const OffsetIndices points_by_curve = curves.points_by_curve();
if (selection_domain == ATTR_DOMAIN_POINT) {
mask.foreach_index_optimized<int64_t>(GrainSize(1024), [&](const int64_t point_i) {
float2 pos_proj;
ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[point_i], pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[point_i], projection);
if (math::distance_squared(pos_proj, float2(coord)) <= radius_sq) {
apply_selection_operation_at_index(selection.span, point_i, sel_op);
changed = true;
@@ -882,9 +866,8 @@ bool select_circle(const ViewContext &vc,
mask.foreach_index_optimized<int64_t>(GrainSize(512), [&](const int64_t curve_i) {
const IndexRange points = points_by_curve[curve_i];
if (points.size() == 1) {
float2 pos_proj;
ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[points.first()], pos_proj, projection.ptr());
const float2 pos_proj = ED_view3d_project_float_v2_m4(
vc.region, deformed_positions[points.first()], projection);
if (math::distance_squared(pos_proj, float2(coord)) <= radius_sq) {
apply_selection_operation_at_index(selection.span, curve_i, sel_op);
changed = true;
@@ -895,9 +878,8 @@ bool select_circle(const ViewContext &vc,
const float3 pos1 = deformed_positions[segment_i];
const float3 pos2 = deformed_positions[segment_i + 1];
float2 pos1_proj, pos2_proj;
ED_view3d_project_float_v2_m4(vc.region, pos1, pos1_proj, projection.ptr());
ED_view3d_project_float_v2_m4(vc.region, pos2, pos2_proj, projection.ptr());
const float2 pos1_proj = ED_view3d_project_float_v2_m4(vc.region, pos1, projection);
const float2 pos2_proj = ED_view3d_project_float_v2_m4(vc.region, pos2, projection);
const float distance_proj_sq = dist_squared_to_line_segment_v2(
float2(coord), pos1_proj, pos2_proj);

View File

@@ -8,8 +8,10 @@
#pragma once
#include "BKE_attribute.h"
#include "BLI_math_matrix_types.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_utildefines.h"
#include "DNA_scene_types.h"
/* ********* exports for space_view3d/ module ********** */
@@ -440,10 +442,9 @@ void pose_foreachScreenBone(ViewContext *vc,
/**
* \note use #ED_view3d_ob_project_mat_get to get the projection matrix
*/
void ED_view3d_project_float_v2_m4(const ARegion *region,
const float co[3],
float r_co[2],
const float mat[4][4]);
blender::float2 ED_view3d_project_float_v2_m4(const ARegion *region,
const float co[3],
const blender::float4x4 &mat);
/**
* \note use #ED_view3d_ob_project_mat_get to get projecting mat
*/
@@ -704,7 +705,7 @@ bool ED_view3d_win_to_segment_clipped(const Depsgraph *depsgraph,
float r_ray_start[3],
float r_ray_end[3],
bool do_clip_planes);
void ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob, float r_pmat[4][4]);
blender::float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob);
void ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d,
const float obmat[4][4],
float r_pmat[4][4]);

View File

@@ -64,12 +64,12 @@ static LinkNode *knifeproject_poly_from_object(const bContext *C, Object *ob, Li
if (me_eval) {
ListBase nurbslist = {nullptr, nullptr};
float projmat[4][4];
BKE_mesh_to_curve_nurblist(me_eval, &nurbslist, 0); /* wire */
BKE_mesh_to_curve_nurblist(me_eval, &nurbslist, 1); /* boundary */
ED_view3d_ob_project_mat_get(static_cast<RegionView3D *>(region->regiondata), ob, projmat);
const blender::float4x4 projmat = ED_view3d_ob_project_mat_get(
static_cast<RegionView3D *>(region->regiondata), ob);
if (nurbslist.first) {
LISTBASE_FOREACH (Nurb *, nu, &nurbslist) {
@@ -81,7 +81,7 @@ static LinkNode *knifeproject_poly_from_object(const bContext *C, Object *ob, Li
MEM_mallocN(sizeof(*mval) * (nu->pntsu + is_cyclic), __func__));
for (bp = nu->bp, a = 0; a < nu->pntsu; a++, bp++) {
ED_view3d_project_float_v2_m4(region, bp->vec, mval[a], projmat);
copy_v2_v2(mval[a], ED_view3d_project_float_v2_m4(region, bp->vec, projmat));
}
if (is_cyclic) {
copy_v2_v2(mval[a], mval[0]);

View File

@@ -12,6 +12,7 @@
#include "BLI_math_geom.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_span.hh"
#include "BLI_vector.hh"
@@ -37,6 +38,8 @@
#include "mesh_intern.h" /* own include */
using blender::float2;
using blender::float3;
using blender::Span;
using blender::Vector;
@@ -53,16 +56,15 @@ using blender::Vector;
*/
#define INSET_DEFAULT 0.00001f
static float edbm_rip_edgedist_squared(ARegion *region,
float mat[4][4],
const blender::float4x4 &mat,
const float co1[3],
const float co2[3],
const float mvalf[2],
const float inset)
{
float vec1[2], vec2[2], dist_sq;
ED_view3d_project_float_v2_m4(region, co1, vec1, mat);
ED_view3d_project_float_v2_m4(region, co2, vec2, mat);
float2 vec1 = ED_view3d_project_float_v2_m4(region, co1, mat);
float2 vec2 = ED_view3d_project_float_v2_m4(region, co2, mat);
if (inset != 0.0f) {
const float dist_2d = len_v2v2(vec1, vec2);
@@ -74,7 +76,7 @@ static float edbm_rip_edgedist_squared(ARegion *region,
}
}
dist_sq = dist_squared_to_line_segment_v2(mvalf, vec1, vec2);
const float dist_sq = dist_squared_to_line_segment_v2(mvalf, vec1, vec2);
BLI_assert(isfinite(dist_sq));
return dist_sq;
@@ -107,14 +109,14 @@ static void edbm_calc_loop_co(BMLoop *l, float l_mid_co[3])
add_v3_v3(l_mid_co, l->v->co);
}
static float edbm_rip_edge_side_measure(
BMEdge *e, BMLoop *e_l, ARegion *region, float projectMat[4][4], const float fmval[2])
static float edbm_rip_edge_side_measure(BMEdge *e,
BMLoop *e_l,
ARegion *region,
const blender::float4x4 &projectMat,
const float fmval[2])
{
float cent[3] = {0, 0, 0}, mid[3];
float vec[2];
float fmval_tweak[2];
float e_v1_co[2], e_v2_co[2];
float score;
BMVert *v1_other;
@@ -132,14 +134,14 @@ static float edbm_rip_edge_side_measure(
* both edge verts connected to this one */
v1_other = BM_face_other_vert_loop(e_l->f, e->v2, e->v1)->v;
v2_other = BM_face_other_vert_loop(e_l->f, e->v1, e->v2)->v;
mid_v3_v3v3(cent, v1_other->co, v2_other->co);
mid_v3_v3v3(mid, e->v1->co, e->v2->co);
ED_view3d_project_float_v2_m4(region, cent, cent, projectMat);
ED_view3d_project_float_v2_m4(region, mid, mid, projectMat);
float2 cent = ED_view3d_project_float_v2_m4(
region, blender::math::midpoint(float3(v1_other->co), float3(v2_other->co)), projectMat);
float2 mid = ED_view3d_project_float_v2_m4(
region, blender::math::midpoint(float3(e->v1->co), float3(e->v2->co)), projectMat);
ED_view3d_project_float_v2_m4(region, e->v1->co, e_v1_co, projectMat);
ED_view3d_project_float_v2_m4(region, e->v2->co, e_v2_co, projectMat);
float2 e_v1_co = ED_view3d_project_float_v2_m4(region, e->v1->co, projectMat);
float2 e_v2_co = ED_view3d_project_float_v2_m4(region, e->v2->co, projectMat);
sub_v2_v2v2(vec, cent, mid);
normalize_v2_length(vec, 0.01f);
@@ -349,7 +351,7 @@ static BMVert *edbm_ripsel_edloop_pair_start_vert(BMEdge *e)
static void edbm_ripsel_deselect_helper(BMesh *bm,
const Span<EdgeLoopPair> eloop_pairs,
ARegion *region,
float projectMat[4][4],
const blender::float4x4 &projectMat,
const float fmval[2])
{
for (const EdgeLoopPair &lp : eloop_pairs) {
@@ -533,7 +535,7 @@ static int edbm_rip_invoke__vert(bContext *C, const wmEvent *event, Object *obed
BMVert *v;
const int totvert_orig = bm->totvert;
int i;
float projectMat[4][4], fmval[3] = {float(event->mval[0]), float(event->mval[1])};
float fmval[3] = {float(event->mval[0]), float(event->mval[1])};
float dist_sq = FLT_MAX;
float d;
bool is_wire, is_manifold_region;
@@ -541,7 +543,7 @@ static int edbm_rip_invoke__vert(bContext *C, const wmEvent *event, Object *obed
BMEditSelection ese;
int totboundary_edge = 0;
ED_view3d_ob_project_mat_get(rv3d, obedit, projectMat);
const blender::float4x4 projectMat = ED_view3d_ob_project_mat_get(rv3d, obedit);
/* find selected vert - same some time and check history first */
if (BM_select_history_active_get(bm, &ese) && ese.htype == BM_VERT) {
@@ -898,9 +900,9 @@ static int edbm_rip_invoke__edge(bContext *C, const wmEvent *event, Object *obed
BMVert *v;
const int totvert_orig = bm->totvert;
const int totedge_orig = bm->totedge;
float projectMat[4][4], fmval[3] = {float(event->mval[0]), float(event->mval[1])};
float fmval[3] = {float(event->mval[0]), float(event->mval[1])};
ED_view3d_ob_project_mat_get(rv3d, obedit, projectMat);
const blender::float4x4 projectMat = ED_view3d_ob_project_mat_get(rv3d, obedit);
/* important this runs on the original selection, before tampering with tagging */
Vector<EdgeLoopPair> eloop_pairs = edbm_ripsel_looptag_helper(bm);

View File

@@ -19,6 +19,7 @@
#include "BLI_math_geom.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "WM_types.hh"
@@ -31,6 +32,8 @@
#include "mesh_intern.h" /* own include */
using blender::float2;
/* uses total number of selected edges around a vertex to choose how to extend */
#define USE_TRICKY_EXTEND
@@ -59,13 +62,11 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
/* mouse direction to view center */
float mval_dir[2];
float projectMat[4][4];
if (bm->totvertsel == 0) {
continue;
}
ED_view3d_ob_project_mat_get(rv3d, obedit, projectMat);
const blender::float4x4 projectMat = ED_view3d_ob_project_mat_get(rv3d, obedit);
zero_v2(cent_sco);
cent_tot = 0;
@@ -75,8 +76,7 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
BM_elem_flag_disable(v, BM_ELEM_TAG);
if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
float v_sco[2];
ED_view3d_project_float_v2_m4(region, v->co, v_sco, projectMat);
const float2 v_sco = ED_view3d_project_float_v2_m4(region, v->co, projectMat);
add_v2_v2(cent_sco, v_sco);
cent_tot += 1;
@@ -94,14 +94,13 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
float e_sco[2][2];
float cent_sco_test[2];
float dist_sq_test;
ED_view3d_project_float_v2_m4(region, e->v1->co, e_sco[0], projectMat);
ED_view3d_project_float_v2_m4(region, e->v2->co, e_sco[1], projectMat);
const float2 e_sco_0 = ED_view3d_project_float_v2_m4(region, e->v1->co, projectMat);
const float2 e_sco_1 = ED_view3d_project_float_v2_m4(region, e->v2->co, projectMat);
closest_to_line_segment_v2(cent_sco_test, mval_fl, e_sco[0], e_sco[1]);
closest_to_line_segment_v2(cent_sco_test, mval_fl, e_sco_0, e_sco_1);
dist_sq_test = len_squared_v2v2(cent_sco_test, mval_fl);
if (dist_sq_test < dist_sq_best) {
dist_sq_best = dist_sq_test;
@@ -120,7 +119,7 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
BMIter eiter;
BMEdge *e;
float v_sco[2];
float2 v_sco;
if (BM_elem_flag_test(v, BM_ELEM_SELECT) && BM_elem_flag_test(v, BM_ELEM_TAG) == false) {
/* Rules for */
@@ -156,15 +155,14 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
goto found_edge;
}
#endif
ED_view3d_project_float_v2_m4(region, v->co, v_sco, projectMat);
v_sco = ED_view3d_project_float_v2_m4(region, v->co, projectMat);
BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) {
if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN)) {
BMVert *v_other = BM_edge_other_vert(e, v);
float v_other_sco[2];
float angle_test;
ED_view3d_project_float_v2_m4(region, v_other->co, v_other_sco, projectMat);
float2 v_other_sco = ED_view3d_project_float_v2_m4(region, v_other->co, projectMat);
/* avoid comparing with view-axis aligned edges (less than a pixel) */
if (len_squared_v2v2(v_sco, v_other_sco) > 1.0f) {

View File

@@ -24,6 +24,7 @@
#include "BLI_utildefines_stack.h"
#include "BLI_vector.hh"
#include "BKE_attribute.h"
#include "BKE_context.hh"
#include "BKE_customdata.hh"
#include "BKE_deform.h"

View File

@@ -63,11 +63,8 @@ static std::optional<float3> find_curves_brush_position(const CurvesGeometry &cu
const float brush_inner_radius_re = std::min<float>(brush_radius_re, float(UI_UNIT_X) / 3.0f);
const float brush_inner_radius_sq_re = pow2f(brush_inner_radius_re);
float4x4 projection;
ED_view3d_ob_project_mat_get(&rv3d, &object, projection.ptr());
float2 brush_pos_re;
ED_view3d_project_float_v2_m4(&region, ray_start_cu, brush_pos_re, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(&rv3d, &object);
const float2 brush_pos_re = ED_view3d_project_float_v2_m4(&region, ray_start_cu, projection);
const float max_depth_sq_cu = math::distance_squared(ray_start_cu, ray_end_cu);
@@ -117,8 +114,7 @@ static std::optional<float3> find_curves_brush_position(const CurvesGeometry &cu
continue;
}
float2 pos_re;
ED_view3d_project_float_v2_m4(&region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(&region, pos_cu, projection);
BrushPositionCandidate candidate;
candidate.position_cu = pos_cu;
@@ -133,9 +129,8 @@ static std::optional<float3> find_curves_brush_position(const CurvesGeometry &cu
const float3 &p1_cu = positions[segment_i];
const float3 &p2_cu = positions[segment_i + 1];
float2 p1_re, p2_re;
ED_view3d_project_float_v2_m4(&region, p1_cu, p1_re, projection.ptr());
ED_view3d_project_float_v2_m4(&region, p2_cu, p2_re, projection.ptr());
const float2 p1_re = ED_view3d_project_float_v2_m4(&region, p1_cu, projection);
const float2 p2_re = ED_view3d_project_float_v2_m4(&region, p2_cu, projection);
float2 closest_re;
const float lambda = closest_to_line_segment_v2(

View File

@@ -210,8 +210,7 @@ struct CombOperationExecutor {
bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *curves_ob_orig_);
const OffsetIndices points_by_curve = curves_orig_->points_by_curve();
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_);
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
@@ -237,9 +236,8 @@ struct CombOperationExecutor {
const float3 old_symm_pos_cu = math::transform_point(brush_transform_inv, old_pos_cu);
/* Find the position of the point in screen space. */
float2 old_symm_pos_re;
ED_view3d_project_float_v2_m4(
ctx_.region, old_symm_pos_cu, old_symm_pos_re, projection.ptr());
const float2 old_symm_pos_re = ED_view3d_project_float_v2_m4(
ctx_.region, old_symm_pos_cu, projection);
const float distance_to_brush_sq_re = dist_squared_to_line_segment_v2(
old_symm_pos_re, brush_pos_prev_re_, brush_pos_re_);
@@ -291,8 +289,7 @@ struct CombOperationExecutor {
*/
void comb_spherical_with_symmetry(MutableSpan<bool> r_changed_curves)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_);
float3 brush_start_wo, brush_end_wo;
ED_view3d_win_to_3d(

View File

@@ -162,8 +162,7 @@ struct DeleteOperationExecutor {
{
const float4x4 brush_transform_inv = math::invert(brush_transform);
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
@@ -175,8 +174,7 @@ struct DeleteOperationExecutor {
if (points.size() == 1) {
const float3 pos_cu = math::transform_point(brush_transform_inv,
self_->deformed_positions_[points.first()]);
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
if (math::distance_squared(brush_pos_re_, pos_re) <= brush_radius_sq_re) {
curves_to_keep[curve_i] = false;
@@ -190,9 +188,8 @@ struct DeleteOperationExecutor {
const float3 pos2_cu = math::transform_point(brush_transform_inv,
self_->deformed_positions_[segment_i + 1]);
float2 pos1_re, pos2_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos1_cu, pos1_re, projection.ptr());
ED_view3d_project_float_v2_m4(ctx_.region, pos2_cu, pos2_re, projection.ptr());
const float2 pos1_re = ED_view3d_project_float_v2_m4(ctx_.region, pos1_cu, projection);
const float2 pos2_re = ED_view3d_project_float_v2_m4(ctx_.region, pos2_cu, projection);
const float dist_sq_re = dist_squared_to_line_segment_v2(
brush_pos_re_, pos1_re, pos2_re);
@@ -207,8 +204,7 @@ struct DeleteOperationExecutor {
void delete_spherical_with_symmetry(MutableSpan<bool> curves_to_keep)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
float3 brush_wo;
ED_view3d_win_to_3d(

View File

@@ -331,8 +331,7 @@ struct DensityAddOperationExecutor {
Vector<float2> &r_uvs,
Vector<float3> &r_positions_su)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_);
const Vector<float4x4> symmetry_brush_transforms = get_symmetry_brush_transforms(
eCurvesSymmetryType(curves_id_orig_->symmetry));
@@ -368,8 +367,7 @@ struct DensityAddOperationExecutor {
const float3 pos_su = positions_su[i];
const float3 pos_cu = math::transform_point(
brush_transform_inv, math::transform_point(transforms_.surface_to_curves, pos_su));
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
const float dist_to_brush_re = math::distance(brush_pos_re_, pos_re);
const float radius_falloff = BKE_brush_curve_strength(
brush_, dist_to_brush_re, brush_radius_re_);
@@ -632,8 +630,7 @@ struct DensitySubtractOperationExecutor {
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
/* Randomly select the curves that are allowed to be removed, based on the brush radius and
* strength. */
@@ -649,8 +646,7 @@ struct DensitySubtractOperationExecutor {
const float3 pos_cu = math::transform_point(brush_transform,
self_->deformed_root_positions_[curve_i]);
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
const float dist_to_brush_sq_re = math::distance_squared(brush_pos_re_, pos_re);
if (dist_to_brush_sq_re > brush_radius_sq_re) {
continue;
@@ -676,8 +672,7 @@ struct DensitySubtractOperationExecutor {
}
const float3 orig_pos_cu = self_->deformed_root_positions_[curve_i];
const float3 pos_cu = math::transform_point(brush_transform, orig_pos_cu);
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
const float dist_to_brush_sq_re = math::distance_squared(brush_pos_re_, pos_re);
if (dist_to_brush_sq_re > brush_radius_sq_re) {
continue;

View File

@@ -341,8 +341,7 @@ struct CurvesEffectOperationExecutor {
bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *object_);
const OffsetIndices points_by_curve = curves_->points_by_curve();
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
const Vector<float4x4> symmetry_brush_transforms = get_symmetry_brush_transforms(
eCurvesSymmetryType(curves_id_->symmetry));
@@ -367,9 +366,8 @@ struct CurvesEffectOperationExecutor {
const float3 p2_cu = math::transform_point(brush_transform_inv,
deformation.positions[segment_i + 1]);
float2 p1_re, p2_re;
ED_view3d_project_float_v2_m4(ctx_.region, p1_cu, p1_re, projection.ptr());
ED_view3d_project_float_v2_m4(ctx_.region, p2_cu, p2_re, projection.ptr());
const float2 p1_re = ED_view3d_project_float_v2_m4(ctx_.region, p1_cu, projection);
const float2 p2_re = ED_view3d_project_float_v2_m4(ctx_.region, p2_cu, projection);
float2 closest_on_brush_re;
float2 closest_on_segment_re;

View File

@@ -692,8 +692,7 @@ static void select_grow_invoke_per_curve(const Curves &curves_id,
float4x4 curves_to_world_mat = float4x4(curves_ob.object_to_world);
float4x4 world_to_curves_mat = math::invert(curves_to_world_mat);
float4x4 projection;
ED_view3d_ob_project_mat_get(&rv3d, &curves_ob, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(&rv3d, &curves_ob);
/* Compute how mouse movements in screen space are converted into grow/shrink distances in
* object space. */
@@ -706,8 +705,7 @@ static void select_grow_invoke_per_curve(const Curves &curves_id,
const int point_i = curve_op_data.selected_points[i];
const float3 &pos_cu = positions[point_i];
float2 pos_re;
ED_view3d_project_float_v2_m4(&region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(&region, pos_cu, projection);
if (pos_re.x < 0 || pos_re.y < 0 || pos_re.x > region.winx || pos_re.y > region.winy) {
continue;
}

View File

@@ -170,8 +170,7 @@ struct PinchOperationExecutor {
bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *object_);
const OffsetIndices points_by_curve = curves_->points_by_curve();
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
MutableSpan<float3> positions_cu = curves_->positions_for_write();
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
@@ -182,9 +181,8 @@ struct PinchOperationExecutor {
for (const int point_i : points.drop_front(1)) {
const float3 old_pos_cu = deformation.positions[point_i];
const float3 old_symm_pos_cu = math::transform_point(brush_transform_inv, old_pos_cu);
float2 old_symm_pos_re;
ED_view3d_project_float_v2_m4(
ctx_.region, old_symm_pos_cu, old_symm_pos_re, projection.ptr());
const float2 old_symm_pos_re = ED_view3d_project_float_v2_m4(
ctx_.region, old_symm_pos_cu, projection);
const float dist_to_brush_sq_re = math::distance_squared(old_symm_pos_re, brush_pos_re_);
if (dist_to_brush_sq_re > brush_radius_sq_re) {

View File

@@ -181,8 +181,7 @@ struct PuffOperationExecutor {
{
const float4x4 brush_transform_inv = math::invert(brush_transform);
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
@@ -195,14 +194,12 @@ struct PuffOperationExecutor {
const IndexRange points = points_by_curve[curve_i];
const float3 first_pos_cu = math::transform_point(brush_transform_inv,
deformation.positions[points[0]]);
float2 prev_pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, first_pos_cu, prev_pos_re, projection.ptr());
float2 prev_pos_re = ED_view3d_project_float_v2_m4(ctx_.region, first_pos_cu, projection);
float max_weight = 0.0f;
for (const int point_i : points.drop_front(1)) {
const float3 pos_cu = math::transform_point(brush_transform_inv,
deformation.positions[point_i]);
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
BLI_SCOPED_DEFER([&]() { prev_pos_re = pos_re; });
const float dist_to_brush_sq_re = dist_squared_to_line_segment_v2(
@@ -222,8 +219,7 @@ struct PuffOperationExecutor {
void find_curves_weights_spherical_with_symmetry(MutableSpan<float> r_curve_weights)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
float3 brush_pos_wo;
ED_view3d_win_to_3d(

View File

@@ -161,8 +161,7 @@ struct SelectionPaintOperationExecutor {
{
const float4x4 brush_transform_inv = math::invert(brush_transform);
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
const bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *object_);
@@ -176,8 +175,7 @@ struct SelectionPaintOperationExecutor {
deformation.positions[point_i]);
/* Find the position of the point in screen space. */
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
const float distance_to_brush_sq_re = math::distance_squared(pos_re, brush_pos_re_);
if (distance_to_brush_sq_re > brush_radius_sq_re) {
@@ -199,9 +197,6 @@ struct SelectionPaintOperationExecutor {
void paint_point_selection_spherical_with_symmetry(MutableSpan<float> selection)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
float3 brush_wo;
ED_view3d_win_to_3d(
ctx_.v3d,
@@ -270,8 +265,7 @@ struct SelectionPaintOperationExecutor {
bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *object_);
const OffsetIndices points_by_curve = curves_->points_by_curve();
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
@@ -290,10 +284,10 @@ struct SelectionPaintOperationExecutor {
const float3 pos2_cu = math::transform_point(brush_transform_inv,
deformation.positions[segment_i + 1]);
float2 pos1_re;
float2 pos2_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos1_cu, pos1_re, projection.ptr());
ED_view3d_project_float_v2_m4(ctx_.region, pos2_cu, pos2_re, projection.ptr());
const float2 pos1_re = ED_view3d_project_float_v2_m4(
ctx_.region, pos1_cu, projection);
const float2 pos2_re = ED_view3d_project_float_v2_m4(
ctx_.region, pos2_cu, projection);
const float distance_sq_re = dist_squared_to_line_segment_v2(
brush_pos_re_, pos1_re, pos2_re);
@@ -315,9 +309,6 @@ struct SelectionPaintOperationExecutor {
void paint_curve_selection_spherical_with_symmetry(MutableSpan<float> selection)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
float3 brush_wo;
ED_view3d_win_to_3d(
ctx_.v3d,

View File

@@ -319,8 +319,7 @@ struct SlideOperationExecutor {
MutableSpan<float3> positions_orig_cu = curves_orig_->positions_for_write();
MutableSpan<float2> surface_uv_coords = curves_orig_->surface_uv_coords_for_write();
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, curves_ob_orig_);
const float2 brush_pos_diff_re = brush_pos_re_ - self_->initial_brush_pos_re_;
@@ -341,9 +340,8 @@ struct SlideOperationExecutor {
const float3 old_first_pos_eval_su = math::transform_point(transforms_.curves_to_surface,
old_first_pos_eval_cu);
float2 old_first_symm_pos_eval_re;
ED_view3d_project_float_v2_m4(
ctx_.region, old_first_symm_pos_eval_cu, old_first_symm_pos_eval_re, projection.ptr());
const float2 old_first_symm_pos_eval_re = ED_view3d_project_float_v2_m4(
ctx_.region, old_first_symm_pos_eval_cu, projection);
const float radius_falloff = slide_curve_info.radius_falloff;
const float curve_weight = brush_strength_ * radius_falloff * curve_factors_[curve_i];

View File

@@ -134,8 +134,7 @@ struct SmoothOperationExecutor {
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
const bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *object_);
@@ -146,8 +145,7 @@ struct SmoothOperationExecutor {
for (const int point_i : points) {
const float3 &pos_cu = math::transform_point(brush_transform_inv,
deformation.positions[point_i]);
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.ptr());
const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
const float dist_to_brush_sq_re = math::distance_squared(pos_re, brush_pos_re_);
if (dist_to_brush_sq_re > brush_radius_sq_re) {
continue;
@@ -168,9 +166,6 @@ struct SmoothOperationExecutor {
void find_spherical_smooth_factors_with_symmetry(MutableSpan<float> r_point_smooth_factors)
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
float3 brush_pos_wo;
ED_view3d_win_to_3d(
ctx_.v3d,

View File

@@ -183,8 +183,7 @@ struct SnakeHookOperatorExecutor {
MutableSpan<float3> positions_cu = curves_->positions_for_write();
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
const float4x4 projection = ED_view3d_ob_project_mat_get(ctx_.rv3d, object_);
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
@@ -197,9 +196,8 @@ struct SnakeHookOperatorExecutor {
const float3 old_pos_cu = deformation.positions[last_point_i];
const float3 old_symm_pos_cu = math::transform_point(brush_transform_inv, old_pos_cu);
float2 old_symm_pos_re;
ED_view3d_project_float_v2_m4(
ctx_.region, old_symm_pos_cu, old_symm_pos_re, projection.ptr());
const float2 old_symm_pos_re = ED_view3d_project_float_v2_m4(
ctx_.region, old_symm_pos_cu, projection);
const float distance_to_brush_sq_re = math::distance_squared(old_symm_pos_re,
brush_pos_prev_re_);
@@ -232,9 +230,6 @@ struct SnakeHookOperatorExecutor {
void spherical_snake_hook_with_symmetry()
{
float4x4 projection;
ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.ptr());
float3 brush_start_wo, brush_end_wo;
ED_view3d_win_to_3d(
ctx_.v3d,

View File

@@ -530,7 +530,7 @@ enum eSculptGestureShapeType {
};
struct LassoGestureData {
float projviewobjmat[4][4];
float4x4 projviewobjmat;
rcti boundbox;
int width;
@@ -688,8 +688,8 @@ static SculptGestureContext *sculpt_gesture_init_from_lasso(bContext *C, wmOpera
return nullptr;
}
ED_view3d_ob_project_mat_get(
sgcontext->vc.rv3d, sgcontext->vc.obact, sgcontext->lasso.projviewobjmat);
sgcontext->lasso.projviewobjmat = ED_view3d_ob_project_mat_get(sgcontext->vc.rv3d,
sgcontext->vc.obact);
BLI_lasso_boundbox(&sgcontext->lasso.boundbox, mcoords, mcoords_len);
const int lasso_width = 1 + sgcontext->lasso.boundbox.xmax - sgcontext->lasso.boundbox.xmin;
const int lasso_height = 1 + sgcontext->lasso.boundbox.ymax - sgcontext->lasso.boundbox.ymin;
@@ -945,15 +945,14 @@ static void sculpt_gesture_update_effected_nodes(SculptGestureContext *sgcontext
static bool sculpt_gesture_is_effected_lasso(SculptGestureContext *sgcontext, const float co[3])
{
float scr_co_f[2];
int scr_co_s[2];
float co_final[3];
flip_v3_v3(co_final, co, sgcontext->symmpass);
/* First project point to 2d space. */
ED_view3d_project_float_v2_m4(
sgcontext->vc.region, co_final, scr_co_f, sgcontext->lasso.projviewobjmat);
const float2 scr_co_f = ED_view3d_project_float_v2_m4(
sgcontext->vc.region, co_final, sgcontext->lasso.projviewobjmat);
scr_co_s[0] = scr_co_f[0];
scr_co_s[1] = scr_co_f[1];

View File

@@ -76,7 +76,6 @@ bool paint_convert_bb_to_rect(rcti *rect,
RegionView3D *rv3d,
Object *ob)
{
float projection_mat[4][4];
int i, j, k;
BLI_rcti_init_minmax(rect);
@@ -86,18 +85,18 @@ bool paint_convert_bb_to_rect(rcti *rect,
return false;
}
ED_view3d_ob_project_mat_get(rv3d, ob, projection_mat);
const blender::float4x4 projection = ED_view3d_ob_project_mat_get(rv3d, ob);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 2; k++) {
float vec[3], proj[2];
float vec[3];
int proj_i[2];
vec[0] = i ? bb_min[0] : bb_max[0];
vec[1] = j ? bb_min[1] : bb_max[1];
vec[2] = k ? bb_min[2] : bb_max[2];
/* convert corner to screen space */
ED_view3d_project_float_v2_m4(region, vec, proj, projection_mat);
const blender::float2 proj = ED_view3d_project_float_v2_m4(region, vec, projection);
/* expand 2D rectangle */
/* we could project directly to int? */

View File

@@ -503,7 +503,7 @@ void update_cache_invariants(
cache->first_time = true;
/* cache projection matrix */
ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat);
cache->projection_mat = ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob);
invert_m4_m4(ob->world_to_object, ob->object_to_world);
copy_m3_m4(mat, cache->vc->rv3d->viewinv);

View File

@@ -2370,9 +2370,8 @@ static void sculpt_apply_texture(const SculptSession *ss,
*r_value -= brush->texture_sample_bias;
}
else {
float point_2d[2];
ED_view3d_project_float_v2_m4(
cache->vc->region, symm_point, point_2d, cache->projection_mat);
const blender::float2 point_2d = ED_view3d_project_float_v2_m4(
cache->vc->region, symm_point, cache->projection_mat);
const float point_3d[3] = {point_2d[0], point_2d[1], 0.0f};
*r_value = BKE_brush_sample_tex_3d(scene, brush, mtex, point_3d, r_rgba, 0, ss->tex_pool);
}
@@ -4228,7 +4227,7 @@ static void sculpt_update_cache_invariants(
cache->brush = brush;
/* Cache projection matrix. */
ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat);
cache->projection_mat = ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob);
invert_m4_m4(ob->world_to_object, ob->object_to_world);
copy_m3_m4(mat, cache->vc->rv3d->viewinv);
@@ -5951,12 +5950,11 @@ bool SCULPT_vertex_is_occluded(SculptSession *ss, PBVHVertRef vertex, bool origi
float co[3];
copy_v3_v3(co, SCULPT_vertex_co_get(ss, vertex));
float mouse[2];
ViewContext *vc = ss->cache ? ss->cache->vc : &ss->filter_cache->vc;
ED_view3d_project_float_v2_m4(
vc->region, co, mouse, ss->cache ? ss->cache->projection_mat : ss->filter_cache->viewmat);
const blender::float2 mouse = ED_view3d_project_float_v2_m4(
vc->region, co, ss->cache ? ss->cache->projection_mat : ss->filter_cache->viewmat);
int depth = SCULPT_raycast_init(vc, mouse, ray_end, ray_start, ray_normal, original);

View File

@@ -63,11 +63,11 @@ void SCULPT_filter_to_orientation_space(float r_v[3], FilterCache *filter_cache)
/* Do nothing, Sculpt Mode already works in object space. */
break;
case SCULPT_FILTER_ORIENTATION_WORLD:
mul_mat3_m4_v3(filter_cache->obmat, r_v);
mul_mat3_m4_v3(filter_cache->obmat.ptr(), r_v);
break;
case SCULPT_FILTER_ORIENTATION_VIEW:
mul_mat3_m4_v3(filter_cache->obmat, r_v);
mul_mat3_m4_v3(filter_cache->viewmat, r_v);
mul_mat3_m4_v3(filter_cache->obmat.ptr(), r_v);
mul_mat3_m4_v3(filter_cache->viewmat.ptr(), r_v);
break;
}
}
@@ -79,11 +79,11 @@ void SCULPT_filter_to_object_space(float r_v[3], FilterCache *filter_cache)
/* Do nothing, Sculpt Mode already works in object space. */
break;
case SCULPT_FILTER_ORIENTATION_WORLD:
mul_mat3_m4_v3(filter_cache->obmat_inv, r_v);
mul_mat3_m4_v3(filter_cache->obmat_inv.ptr(), r_v);
break;
case SCULPT_FILTER_ORIENTATION_VIEW:
mul_mat3_m4_v3(filter_cache->viewmat_inv, r_v);
mul_mat3_m4_v3(filter_cache->obmat_inv, r_v);
mul_mat3_m4_v3(filter_cache->viewmat_inv.ptr(), r_v);
mul_mat3_m4_v3(filter_cache->obmat_inv.ptr(), r_v);
break;
}
}
@@ -144,16 +144,16 @@ void SCULPT_filter_cache_init(bContext *C,
}
/* Setup orientation matrices. */
copy_m4_m4(ss->filter_cache->obmat, ob->object_to_world);
invert_m4_m4(ss->filter_cache->obmat_inv, ob->object_to_world);
copy_m4_m4(ss->filter_cache->obmat.ptr(), ob->object_to_world);
invert_m4_m4(ss->filter_cache->obmat_inv.ptr(), ob->object_to_world);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
ss->filter_cache->vc = vc;
if (vc.rv3d) {
copy_m4_m4(ss->filter_cache->viewmat, vc.rv3d->viewmat);
copy_m4_m4(ss->filter_cache->viewmat_inv, vc.rv3d->viewinv);
copy_m4_m4(ss->filter_cache->viewmat.ptr(), vc.rv3d->viewmat);
copy_m4_m4(ss->filter_cache->viewmat_inv.ptr(), vc.rv3d->viewinv);
}
Scene *scene = CTX_data_scene(C);
@@ -213,13 +213,9 @@ void SCULPT_filter_cache_init(bContext *C,
}
/* Update view normal */
float projection_mat[4][4];
float mat[3][3];
float viewDir[3] = {0.0f, 0.0f, 1.0f};
if (vc.rv3d) {
ED_view3d_ob_project_mat_get(vc.rv3d, ob, projection_mat);
invert_m4_m4(ob->world_to_object, ob->object_to_world);
copy_m3_m4(mat, vc.rv3d->viewinv);
mul_m3_v3(mat, viewDir);

View File

@@ -29,6 +29,7 @@
#include "BLI_generic_array.hh"
#include "BLI_gsqueue.h"
#include "BLI_implicit_sharing.hh"
#include "BLI_math_matrix_types.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_set.hh"
#include "BLI_span.hh"
@@ -352,10 +353,10 @@ struct FilterCache {
/* Filter orientation. */
SculptFilterOrientation orientation;
float obmat[4][4];
float obmat_inv[4][4];
float viewmat[4][4];
float viewmat_inv[4][4];
blender::float4x4 obmat;
blender::float4x4 obmat_inv;
blender::float4x4 viewmat;
blender::float4x4 viewmat_inv;
/* Displacement eraser. */
float (*limit_surface_co)[3];
@@ -453,7 +454,7 @@ struct StrokeCache {
bool first_time; /* Beginning of stroke may do some things special */
/* from ED_view3d_ob_project_mat_get() */
float projection_mat[4][4];
blender::float4x4 projection_mat;
/* Clean this up! */
ViewContext *vc;

View File

@@ -91,9 +91,9 @@ static int content_planes_from_clip_flag(const ARegion *region,
BLI_assert(planes_len <= 6);
if (planes_len != 0) {
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
float projmat[4][4];
ED_view3d_ob_project_mat_get(rv3d, ob, projmat);
planes_from_projmat(projmat, clip_xmin, clip_xmax, clip_ymin, clip_ymax, clip_zmin, clip_zmax);
const blender::float4x4 projection = ED_view3d_ob_project_mat_get(rv3d, ob);
planes_from_projmat(
projection.ptr(), clip_xmin, clip_xmax, clip_ymin, clip_ymax, clip_zmin, clip_zmax);
}
return planes_len;
}

View File

@@ -18,6 +18,7 @@
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BKE_camera.h"
#include "BKE_screen.hh"
@@ -31,10 +32,9 @@
/* Non Clipping Projection Functions
* ********************************* */
void ED_view3d_project_float_v2_m4(const ARegion *region,
const float co[3],
float r_co[2],
const float mat[4][4])
blender::float2 ED_view3d_project_float_v2_m4(const ARegion *region,
const float co[3],
const blender::float4x4 &mat)
{
float vec4[4];
@@ -42,8 +42,9 @@ void ED_view3d_project_float_v2_m4(const ARegion *region,
vec4[3] = 1.0;
// r_co[0] = IS_CLIPPED; /* Always overwritten. */
mul_m4_v4(mat, vec4);
mul_m4_v4(mat.ptr(), vec4);
blender::float2 r_co;
if (vec4[3] > FLT_EPSILON) {
r_co[0] = float(region->winx / 2.0f) + (region->winx / 2.0f) * vec4[0] / vec4[3];
r_co[1] = float(region->winy / 2.0f) + (region->winy / 2.0f) * vec4[1] / vec4[3];
@@ -51,6 +52,7 @@ void ED_view3d_project_float_v2_m4(const ARegion *region,
else {
zero_v2(r_co);
}
return r_co;
}
void ED_view3d_project_float_v3_m4(const ARegion *region,
@@ -698,12 +700,14 @@ bool ED_view3d_win_to_segment_clipped(const Depsgraph *depsgraph,
/** \name Utility functions for projection
* \{ */
void ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob, float r_pmat[4][4])
blender::float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
{
float vmat[4][4];
blender::float4x4 r_pmat;
mul_m4_m4m4(vmat, rv3d->viewmat, ob->object_to_world);
mul_m4_m4m4(r_pmat, rv3d->winmat, vmat);
mul_m4_m4m4(r_pmat.ptr(), rv3d->winmat, vmat);
return r_pmat;
}
void ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d,

View File

@@ -296,7 +296,7 @@ static BMLoop *get_next_loop(
return nullptr;
}
static void edge_slide_projmat_get(TransInfo *t, TransDataContainer *tc, float r_projectMat[4][4])
static blender::float4x4 edge_slide_projmat_get(TransInfo *t, TransDataContainer *tc)
{
RegionView3D *rv3d = nullptr;
@@ -307,16 +307,14 @@ static void edge_slide_projmat_get(TransInfo *t, TransDataContainer *tc, float r
if (!rv3d) {
/* Ok, let's try to survive this. */
unit_m4(r_projectMat);
}
else {
ED_view3d_ob_project_mat_get(rv3d, tc->obedit, r_projectMat);
return blender::float4x4::identity();
}
return ED_view3d_ob_project_mat_get(rv3d, tc->obedit);
}
static void edge_slide_pair_project(TransDataEdgeSlideVert *sv,
ARegion *region,
float projectMat[4][4],
const float projectMat[4][4],
float r_sco_a[3],
float r_sco_b[3])
{
@@ -379,7 +377,6 @@ static void calcEdgeSlide_mval_range(TransInfo *t,
BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
ARegion *region = t->region;
View3D *v3d = nullptr;
float projectMat[4][4];
BMBVHTree *bmbvh;
/* only for use_calc_direction */
@@ -392,7 +389,7 @@ static void calcEdgeSlide_mval_range(TransInfo *t,
v3d = static_cast<View3D *>(t->area ? t->area->spacedata.first : nullptr);
}
edge_slide_projmat_get(t, tc, projectMat);
const blender::float4x4 projection = edge_slide_projmat_get(t, tc);
if (use_occlude_geometry) {
bmbvh = BKE_bmbvh_new_from_editmesh(em, BMBVH_RESPECT_HIDDEN, nullptr, false);
@@ -441,7 +438,7 @@ static void calcEdgeSlide_mval_range(TransInfo *t,
continue;
}
edge_slide_pair_project(sv, region, projectMat, sco_a, sco_b);
edge_slide_pair_project(sv, region, projection.ptr(), sco_a, sco_b);
/* global direction */
dist_sq = dist_squared_to_line_segment_v2(mval, sco_b, sco_a);
@@ -498,22 +495,19 @@ static void calcEdgeSlide_even(TransInfo *t,
if (sld->totsv > 0) {
ARegion *region = t->region;
float projectMat[4][4];
int i = 0;
float v_proj[2];
float dist_sq = 0;
float dist_min_sq = FLT_MAX;
edge_slide_projmat_get(t, tc, projectMat);
const blender::float4x4 projection = edge_slide_projmat_get(t, tc);
for (i = 0; i < sld->totsv; i++, sv++) {
/* Set length */
sv->edge_len = len_v3v3(sv->dir_side[0], sv->dir_side[1]);
ED_view3d_project_float_v2_m4(region, sv->v->co, v_proj, projectMat);
dist_sq = len_squared_v2v2(mval, v_proj);
const blender::float2 v_proj = ED_view3d_project_float_v2_m4(region, sv->v->co, projection);
const float dist_sq = len_squared_v2v2(mval, v_proj);
if (dist_sq < dist_min_sq) {
dist_min_sq = dist_sq;
sld->curr_sv_index = i;
@@ -1604,13 +1598,12 @@ void transform_mode_edge_slide_reproject_input(TransInfo *t)
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
EdgeSlideData *sld = static_cast<EdgeSlideData *>(tc->custom.mode.data);
if (sld) {
float projectMat[4][4];
edge_slide_projmat_get(t, tc, projectMat);
const blender::float4x4 projection = edge_slide_projmat_get(t, tc);
TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
float mval_dir[3], sco_a[3], sco_b[3];
edge_slide_pair_project(curr_sv, region, projectMat, sco_a, sco_b);
edge_slide_pair_project(curr_sv, region, projection.ptr(), sco_a, sco_b);
sub_v3_v3v3(mval_dir, sco_b, sco_a);
edge_slide_data_init_mval(&t->mouse, sld, mval_dir);
}

View File

@@ -63,7 +63,7 @@ struct VertSlideData {
int curr_sv_index;
/* result of ED_view3d_ob_project_mat_get */
float proj_mat[4][4];
float4x4 proj_mat;
};
struct VertSlideParams {
@@ -83,12 +83,10 @@ static void vert_slide_update_input(TransInfo *t)
const float *co_orig_3d = sv->co_orig_3d;
const float *co_curr_3d = sv->co_link_orig_3d[sv->co_link_curr];
float co_curr_2d[2], co_orig_2d[2];
int mval_ofs[2], mval_start[2], mval_end[2];
ED_view3d_project_float_v2_m4(t->region, co_orig_3d, co_orig_2d, sld->proj_mat);
ED_view3d_project_float_v2_m4(t->region, co_curr_3d, co_curr_2d, sld->proj_mat);
const float2 co_orig_2d = ED_view3d_project_float_v2_m4(t->region, co_orig_3d, sld->proj_mat);
const float2 co_curr_2d = ED_view3d_project_float_v2_m4(t->region, co_curr_3d, sld->proj_mat);
ARRAY_SET_ITEMS(mval_ofs, t->mouse.imval[0] - co_orig_2d[0], t->mouse.imval[1] - co_orig_2d[1]);
ARRAY_SET_ITEMS(mval_start, co_orig_2d[0] + mval_ofs[0], co_orig_2d[1] + mval_ofs[1]);
@@ -123,16 +121,13 @@ static void calcVertSlideMouseActiveVert(TransInfo *t, const float2 &mval_fl)
TransDataVertSlideVert *sv;
/* set the vertex to use as a reference for the mouse direction 'curr_sv_index' */
float dist_sq = 0.0f;
float dist_min_sq = FLT_MAX;
int i;
for (i = 0, sv = sld->sv; i < sld->totsv; i++, sv++) {
float co_2d[2];
const float2 co_2d = ED_view3d_project_float_v2_m4(t->region, sv->co_orig_3d, sld->proj_mat);
ED_view3d_project_float_v2_m4(t->region, sv->co_orig_3d, co_2d, sld->proj_mat);
dist_sq = len_squared_v2v2(mval_fl, co_2d);
const float dist_sq = len_squared_v2v2(mval_fl, co_2d);
if (dist_sq < dist_min_sq) {
dist_min_sq = dist_sq;
sld->curr_sv_index = i;
@@ -267,7 +262,7 @@ static VertSlideData *createVertSlideVerts(TransInfo *t, const TransDataContaine
sld->totsv = j;
/* most likely will be set below */
unit_m4(sld->proj_mat);
sld->proj_mat = blender::float4x4::identity();
if (t->spacetype == SPACE_VIEW3D) {
/* view vars */
@@ -276,7 +271,7 @@ static VertSlideData *createVertSlideVerts(TransInfo *t, const TransDataContaine
rv3d = static_cast<RegionView3D *>(region ? region->regiondata : nullptr);
if (rv3d) {
ED_view3d_ob_project_mat_get(rv3d, tc->obedit, sld->proj_mat);
sld->proj_mat = ED_view3d_ob_project_mat_get(rv3d, tc->obedit);
}
}
@@ -718,7 +713,7 @@ void transform_mode_vert_slide_reproject_input(TransInfo *t)
RegionView3D *rv3d = static_cast<RegionView3D *>(t->region->regiondata);
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
VertSlideData *sld = static_cast<VertSlideData *>(tc->custom.mode.data);
ED_view3d_ob_project_mat_get(rv3d, tc->obedit, sld->proj_mat);
sld->proj_mat = ED_view3d_ob_project_mat_get(rv3d, tc->obedit);
}
}