diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-05-13 14:03:55 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-05-13 14:03:55 +0300 |
commit | 498bd0772ec54601241911b6a98f4fedf97d9166 (patch) | |
tree | 0a85b6e6a78603245d61958a5add2482a9bcb4cc /source | |
parent | b55c78a289c600696282f97191d6e800a1c1ac34 (diff) | |
parent | cbcc15bdaf98cf76ec42fb09e898c95407905f32 (diff) |
Merge branch 'blender-v2.83-release'
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 9 | ||||
-rw-r--r-- | source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c | 75 |
4 files changed, 68 insertions, 25 deletions
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 3d91a9e98cf..c456ab0ecef 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -33,6 +33,7 @@ #include "BLI_assert.h" #include "BLI_math_inline.h" +#include "BLI_sys_types.h" #include <math.h> #ifndef M_PI diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index d5105a7cefc..2ad9b53ba3d 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -360,6 +360,14 @@ MINLINE int divide_floor_i(int a, int b) } /** + * Integer division that ceils the result, instead of flooring like normal C division. + */ +MINLINE uint divide_ceil_u(uint a, uint b) +{ + return (a + b - 1) / b; +} + +/** * modulo that handles negative numbers, works the same as Python's. */ MINLINE int mod_i(int i, int n) diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 6b594c02c15..3b62941af83 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -47,6 +47,7 @@ #include "BLI_blenlib.h" #include "BLI_fnmatch.h" +#include "BLI_math_base.h" #include "BLI_utildefines.h" #include "BLO_readfile.h" @@ -758,11 +759,11 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *region) layout->attribute_column_header_h = 0; layout->offset_top = 0; if (layout->flow_columns > 0) { - layout->rows = numfiles / layout->flow_columns + 1; // XXX dirty, modulo is zero + layout->rows = divide_ceil_u(numfiles, layout->flow_columns); } else { layout->flow_columns = 1; - layout->rows = numfiles + 1; // XXX dirty, modulo is zero + layout->rows = numfiles; } layout->height = sfile->layout->rows * (layout->tile_h + 2 * layout->tile_border_y) + layout->tile_border_y * 2 - layout->offset_top; @@ -807,11 +808,11 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *region) file_attribute_columns_init(params, layout); if (layout->rows > 0) { - layout->flow_columns = numfiles / layout->rows + 1; // XXX dirty, modulo is zero + layout->flow_columns = divide_ceil_u(numfiles, layout->rows); } else { layout->rows = 1; - layout->flow_columns = numfiles + 1; // XXX dirty, modulo is zero + layout->flow_columns = numfiles; } layout->width = sfile->layout->flow_columns * (layout->tile_w + 2 * layout->tile_border_x) + layout->tile_border_x * 2; diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c index 542e68a7903..d750853fc94 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c @@ -41,6 +41,7 @@ #include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_modifier.h" +#include "BKE_object.h" #include "BKE_scene.h" #include "MEM_guardedalloc.h" @@ -66,13 +67,35 @@ static void copyData(const GpencilModifierData *md, GpencilModifierData *target) BKE_gpencil_modifier_copydata_generic(md, target); } -static void update_position(Object *ob, MirrorGpencilModifierData *mmd, bGPDstroke *gps, int axis) +/* Mirror is using current object as origin. */ +static void update_mirror_local(Object *ob, bGPDstroke *gps, int axis) { int i; bGPDspoint *pt; float factor[3] = {1.0f, 1.0f, 1.0f}; factor[axis] = -1.0f; + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + mul_v3_v3(&pt->x, factor); + } +} + +/* Mirror is using other object as origin. */ +static void update_mirror_object(Object *ob, + MirrorGpencilModifierData *mmd, + bGPDstroke *gps, + int axis) +{ + /* Calculate local matrix transformation. */ + float mat[3][3], inv_mat[3][3]; + BKE_object_to_mat3(ob, mat); + invert_m3_m3(inv_mat, mat); + + int i; + bGPDspoint *pt; + float factor[3] = {1.0f, 1.0f, 1.0f}; + factor[axis] = -1.0f; + float clear[3] = {0.0f, 0.0f, 0.0f}; clear[axis] = 1.0f; @@ -81,34 +104,44 @@ static void update_position(Object *ob, MirrorGpencilModifierData *mmd, bGPDstro float half_origin[3]; float rot_mat[3][3]; - if (mmd->object) { - float eul[3]; - mat4_to_eul(eul, mmd->object->obmat); - mul_v3_fl(eul, 2.0f); - eul_to_mat3(rot_mat, eul); - sub_v3_v3v3(ob_origin, ob->obmat[3], mmd->object->obmat[3]); - } - else { - copy_v3_v3(ob_origin, ob->obmat[3]); - } + float eul[3]; + mat4_to_eul(eul, mmd->object->obmat); + mul_v3_fl(eul, 2.0f); + eul_to_mat3(rot_mat, eul); + sub_v3_v3v3(ob_origin, ob->obmat[3], mmd->object->obmat[3]); - /* only works with current axis */ + /* Only works with current axis. */ mul_v3_v3(ob_origin, clear); + /* Invert the origin. */ mul_v3_v3fl(pt_origin, ob_origin, -2.0f); mul_v3_v3fl(half_origin, pt_origin, 0.5f); for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + /* Apply any local transformation. */ + mul_m3_v3(mat, &pt->x); + + /* Apply mirror effect. */ mul_v3_v3(&pt->x, factor); - if (mmd->object) { - /* apply location */ - add_v3_v3(&pt->x, pt_origin); - - /* apply rotation (around new center) */ - sub_v3_v3(&pt->x, half_origin); - mul_m3_v3(rot_mat, &pt->x); - add_v3_v3(&pt->x, half_origin); - } + /* Apply location. */ + add_v3_v3(&pt->x, pt_origin); + /* Apply rotation (around new center). */ + sub_v3_v3(&pt->x, half_origin); + mul_m3_v3(rot_mat, &pt->x); + add_v3_v3(&pt->x, half_origin); + + /* Undo local transformation to avoid double transform in drawing. */ + mul_m3_v3(inv_mat, &pt->x); + } +} + +static void update_position(Object *ob, MirrorGpencilModifierData *mmd, bGPDstroke *gps, int axis) +{ + if (mmd->object == NULL) { + update_mirror_local(ob, gps, axis); + } + else { + update_mirror_object(ob, mmd, gps, axis); } } |