[Bf-blender-cvs] [59c3194f8e8] master: Cleanup: Use float3 type

Hans Goudey noreply at git.blender.org
Fri Apr 1 21:48:59 CEST 2022


Commit: 59c3194f8e88509a44384c4c48a9a466f8aeffde
Author: Hans Goudey
Date:   Fri Apr 1 14:48:48 2022 -0500
Branches: master
https://developer.blender.org/rB59c3194f8e88509a44384c4c48a9a466f8aeffde

Cleanup: Use float3 type

This can help make some refactoring to bounding boxes slightly easier.

===================================================================

M	source/blender/blenkernel/intern/object.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index b37cf7db739..4679e643b01 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -54,6 +54,7 @@
 #include "BLI_linklist.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_math_vec_types.hh"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
@@ -143,6 +144,8 @@
 #include "CCGSubSurf.h"
 #include "atomic_ops.h"
 
+using blender::float3;
+
 static CLG_LogRef LOG = {"bke.object"};
 
 /**
@@ -1172,7 +1175,7 @@ static void object_lib_override_apply_post(ID *id_dst, ID *id_src)
 
 static IDProperty *object_asset_dimensions_property(Object *ob)
 {
-  float dimensions[3];
+  float3 dimensions;
   BKE_object_dimensions_get(ob, dimensions);
   if (is_zero_v3(dimensions)) {
     return nullptr;
@@ -2837,7 +2840,7 @@ void BKE_object_obdata_size_init(struct Object *ob, const float size)
 
 void BKE_object_scale_to_mat3(Object *ob, float mat[3][3])
 {
-  float vec[3];
+  float3 vec;
   mul_v3_v3v3(vec, ob->scale, ob->dscale);
   size_to_mat3(mat, vec);
 }
@@ -3119,7 +3122,7 @@ static bool ob_parcurve(Object *ob, Object *par, float r_mat[4][4])
 
 static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
 {
-  float vec[3];
+  float3 vec;
 
   if (par->type != OB_ARMATURE) {
     unit_m4(r_mat);
@@ -3540,11 +3543,8 @@ void BKE_object_apply_mat4(Object *ob,
 
 BoundBox *BKE_boundbox_alloc_unit()
 {
-  const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {1.0f, 1.0f, 1.0f};
-
-  BoundBox *bb = MEM_cnew<BoundBox>("OB-BoundBox");
-  BKE_boundbox_init_from_minmax(bb, min, max);
-
+  BoundBox *bb = MEM_cnew<BoundBox>(__func__);
+  BKE_boundbox_init_from_minmax(bb, float3(-1), float3(1));
   return bb;
 }
 
@@ -3642,13 +3642,12 @@ void BKE_object_boundbox_flag(Object *ob, int flag, const bool set)
 
 void BKE_object_boundbox_calc_from_mesh(Object *ob, const Mesh *me_eval)
 {
-  float min[3], max[3];
-
-  INIT_MINMAX(min, max);
+  float3 min(FLT_MAX);
+  float3 max(-FLT_MAX);
 
   if (!BKE_mesh_wrapper_minmax(me_eval, min, max)) {
-    zero_v3(min);
-    zero_v3(max);
+    min = float3(0);
+    max = float3(0);
   }
 
   if (ob->runtime.bb == nullptr) {
@@ -3662,19 +3661,19 @@ void BKE_object_boundbox_calc_from_mesh(Object *ob, const Mesh *me_eval)
 
 bool BKE_object_boundbox_calc_from_evaluated_geometry(Object *ob)
 {
-  blender::float3 min, max;
-  INIT_MINMAX(min, max);
+  float3 min(FLT_MAX);
+  float3 max(-FLT_MAX);
 
   if (ob->runtime.geometry_set_eval) {
     if (!ob->runtime.geometry_set_eval->compute_boundbox_without_instances(&min, &max)) {
-      zero_v3(min);
-      zero_v3(max);
+      min = float3(0);
+      max = float3(0);
     }
   }
   else if (const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob)) {
     if (!BKE_mesh_wrapper_minmax(mesh_eval, min, max)) {
-      zero_v3(min);
-      zero_v3(max);
+      min = float3(0);
+      max = float3(0);
     }
   }
   else if (ob->runtime.curve_cache) {
@@ -3707,8 +3706,7 @@ void BKE_object_dimensions_get(Object *ob, float r_vec[3])
 {
   const BoundBox *bb = BKE_object_boundbox_get(ob);
   if (bb) {
-    float scale[3];
-
+    float3 scale;
     mat4_to_size(scale, ob->obmat);
 
     r_vec[0] = fabsf(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
@@ -3728,11 +3726,10 @@ void BKE_object_dimensions_set_ex(Object *ob,
 {
   const BoundBox *bb = BKE_object_boundbox_get(ob);
   if (bb) {
-    float len[3];
-
-    len[0] = bb->vec[4][0] - bb->vec[0][0];
-    len[1] = bb->vec[2][1] - bb->vec[0][1];
-    len[2] = bb->vec[1][2] - bb->vec[0][2];
+    float3 len;
+    len.x = bb->vec[4][0] - bb->vec[0][0];
+    len.y = bb->vec[2][1] - bb->vec[0][1];
+    len.z = bb->vec[1][2] - bb->vec[0][2];
 
     for (int i = 0; i < 3; i++) {
       if (((1 << i) & axis_mask) == 0) {
@@ -3760,7 +3757,6 @@ void BKE_object_dimensions_set(Object *ob, const float value[3], int axis_mask)
 
 void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
 {
-  float vec[3];
   bool changed = false;
 
   switch (ob->type) {
@@ -3792,6 +3788,7 @@ void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool us
       for (w = 0; w < lt->pntsw; w++) {
         for (v = 0; v < lt->pntsv; v++) {
           for (u = 0; u < lt->pntsu; u++, bp++) {
+            float3 vec;
             mul_v3_m4v3(vec, ob->obmat, bp->vec);
             minmax_v3v3_v3(r_min, r_max, vec);
           }
@@ -3836,15 +3833,16 @@ void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool us
   }
 
   if (changed == false) {
-    float size[3];
+    float3 size = ob->scale;
 
     copy_v3_v3(size, ob->scale);
     if (ob->type == OB_EMPTY) {
-      mul_v3_fl(size, ob->empty_drawsize);
+      size *= ob->empty_drawsize;
     }
 
     minmax_v3v3_v3(r_min, r_max, ob->obmat[3]);
 
+    float3 vec;
     copy_v3_v3(vec, ob->obmat[3]);
     add_v3_v3(vec, size);
     minmax_v3v3_v3(r_min, r_max, vec);
@@ -3895,7 +3893,7 @@ bool BKE_object_empty_image_data_is_visible_in_view3d(const Object *ob, const Re
       /* NOTE: we could normalize the 'view_dir' then use 'eps'
        * however the issue with empty objects being visible when viewed from the side
        * is only noticeable in orthographic views. */
-      float view_dir[3];
+      float3 view_dir;
       sub_v3_v3v3(view_dir, rv3d->viewinv[3], ob->obmat[3]);
       dot = dot_v3v3(ob->obmat[2], view_dir);
       eps = 0.0f;
@@ -3917,7 +3915,7 @@ bool BKE_object_empty_image_data_is_visible_in_view3d(const Object *ob, const Re
   }
 
   if (visibility_flag & OB_EMPTY_IMAGE_HIDE_NON_AXIS_ALIGNED) {
-    float proj[3];
+    float3 proj;
     project_plane_v3_v3v3(proj, ob->obmat[2], rv3d->viewinv[2]);
     const float proj_length_sq = len_squared_v3(proj);
     if (proj_length_sq > 1e-5f) {
@@ -3955,7 +3953,7 @@ bool BKE_object_minmax_dupli(Depsgraph *depsgraph,
       if (bb) {
         int i;
         for (i = 0; i < 8; i++) {
-          float vec[3];
+          float3 vec;
           mul_v3_m4v3(vec, dob->mat, bb->vec[i]);
           minmax_v3v3_v3(r_min, r_max, vec);
         }
@@ -3988,7 +3986,7 @@ static void foreach_display_point_gpencil_stroke_fn(bGPDlayer *UNUSED(layer),
     bGPDspoint *pt;
     int i;
     for (i = 0, pt = stroke->points; i < stroke->totpoints; i++, pt++) {
-      float co[3];
+      float3 co;
       mul_v3_m4v3(co, iter_data->obmat, &pt->x);
       iter_data->point_func_cb(co, iter_data->user_data);
     }
@@ -4002,7 +4000,7 @@ void BKE_object_foreach_display_point(Object *ob,
 {
   /* TODO: pointcloud and curves object support */
   const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob);
-  float co[3];
+  float3 co;
 
   if (mesh_eval != nullptr) {
     const MVert *mv = mesh_eval->mvert;



More information about the Bf-blender-cvs mailing list