[Bf-blender-cvs] [e20b31504a2] master: Fix T86347: Add Primitive Tool fails for 1x1x1 scale

Philipp Oeser noreply at git.blender.org
Mon Mar 8 15:20:46 CET 2021


Commit: e20b31504a2381011e60c5eadffb67f18918bc71
Author: Philipp Oeser
Date:   Sun Mar 7 13:05:34 2021 +0100
Branches: master
https://developer.blender.org/rBe20b31504a2381011e60c5eadffb67f18918bc71

Fix T86347: Add Primitive Tool fails for 1x1x1 scale

The Tool stores desired dimensions as `scale` and thus had to half the
scale again in `make_prim_init()` because by default all primitives are
created at a size of 2 in blender.

This worked, but:
- [1] it logged something like size=2, scale=2,2,2 for a 2x2x2 cube
[which does not sound right, it should be size=2 scale=1,1,1]
- [2] it had to make an exception for the case scale is exactly 1x1x1
[this happens when the property is not set specifically, e.g. adding
primitives from the menu]
-- this exception led to double sized primitives being created when the
tool asked for exact dimensions of 1x1x1

Now - instead of compensating in `make_prim_init()` - do this earlier in
the tool itself, see `view3d_interactive_add_modal`, this fixes the bug
and now also correctly logs size=2 scale 0.5,0.5,0.5 for a 1x1x1 cube.

Maniphest Tasks: T86347

Differential Revision: https://developer.blender.org/D10632

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

M	source/blender/editors/mesh/editmesh_add.c
M	source/blender/editors/space_view3d/view3d_placement.c

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

diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c
index d60d83850a5..582ff01173a 100644
--- a/source/blender/editors/mesh/editmesh_add.c
+++ b/source/blender/editors/mesh/editmesh_add.c
@@ -75,11 +75,8 @@ static Object *make_prim_init(bContext *C,
 
   ED_object_new_primitive_matrix(C, obedit, loc, rot, r_creation_data->mat);
 
-  if (scale && !equals_v3v3(scale, (const float[3]){1.0f, 1.0f, 1.0f})) {
-    float scale_half[3];
-    copy_v3_v3(scale_half, scale);
-    mul_v3_fl(scale_half, 0.5f);
-    rescale_m4(r_creation_data->mat, scale_half);
+  if (scale) {
+    rescale_m4(r_creation_data->mat, scale);
   }
 
   return obedit;
diff --git a/source/blender/editors/space_view3d/view3d_placement.c b/source/blender/editors/space_view3d/view3d_placement.c
index c75d9796265..48f274ca71b 100644
--- a/source/blender/editors/space_view3d/view3d_placement.c
+++ b/source/blender/editors/space_view3d/view3d_placement.c
@@ -1438,6 +1438,8 @@ static int view3d_interactive_add_modal(bContext *C, wmOperator *op, const wmEve
         const int cube_verts[3] = {3, 1, 4};
         for (int i = 0; i < 3; i++) {
           scale[i] = len_v3v3(bounds.vec[0], bounds.vec[cube_verts[i]]);
+          /* Primitives have size 2 by default, compensate for this here. */
+          scale[i] /= 2.0f;
         }
 
         wmOperatorType *ot = NULL;



More information about the Bf-blender-cvs mailing list