diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-31 20:04:03 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-31 20:04:03 +0400 |
commit | c3a7db28d31780329f8402f3f26c7bd575031474 (patch) | |
tree | f206c22ced73ce277560776a0e46da5be2eee180 /source/blender/editors | |
parent | b04cd3a76561f17ef0951837ae0ea169e563a571 (diff) |
Fix #31657: adding mesh objects did not take units into account for the grid
scale that sets the default size.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_add.c | 30 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 27 |
4 files changed, 24 insertions, 40 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index f9f59c9bdd9..55210080e01 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -310,6 +310,8 @@ struct BGpic *ED_view3D_background_image_new(struct View3D *v3d); void ED_view3D_background_image_remove(struct View3D *v3d, struct BGpic *bgpic); void ED_view3D_background_image_clear(struct View3D *v3d); +float ED_view3d_grid_scale(struct Scene *scene, struct View3D *v3d, const char **grid_unit); + /* view matrix properties utilities */ /* unused */ #if 0 diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index f9eb8770012..9cbd9e0b7da 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -53,34 +53,6 @@ #include "mesh_intern.h" -/* uses context to figure out transform for primitive */ -/* returns standard diameter */ -static float new_primitive_matrix(bContext *C, const float loc[3], const float rot[3], float primmat[][4]) -{ - Object *obedit = CTX_data_edit_object(C); - View3D *v3d = CTX_wm_view3d(C); - float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3]; - - unit_m4(primmat); - - eul_to_mat3(rmat, rot); - invert_m3(rmat); - - /* inverse transform for initial rotation and object */ - copy_m3_m4(mat, obedit->obmat); - mul_m3_m3m3(cmat, rmat, mat); - invert_m3_m3(imat, cmat); - copy_m4_m3(primmat, imat); - - /* center */ - copy_v3_v3(primmat[3], loc); - sub_v3_v3(primmat[3], obedit->obmat[3]); - invert_m3_m3(imat, mat); - mul_m3_v3(imat, primmat[3]); - - return v3d ? v3d->grid : 1.0f; -} - /* ********* add primitive operators ************* */ static void make_prim_init(bContext *C, const char *idname, @@ -101,7 +73,7 @@ static void make_prim_init(bContext *C, const char *idname, *state = 1; } - *dia = new_primitive_matrix(C, loc, rot, mat); + *dia = ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); } static void make_prim_finish(bContext *C, int *state, int enter_editmode) diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 699b731bc15..159f75b60e6 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -166,6 +166,7 @@ void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3], float ED_object_new_primitive_matrix(bContext *C, Object *obedit, const float loc[3], const float rot[3], float primmat[][4]) { + Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3]; @@ -186,7 +187,9 @@ float ED_object_new_primitive_matrix(bContext *C, Object *obedit, invert_m3_m3(imat, mat); mul_m3_v3(imat, primmat[3]); - if (v3d) return v3d->grid; + if (v3d) + return ED_view3d_grid_scale(scene, v3d, NULL); + return 1.0f; } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index ee02f99d5b7..14afcaa855f 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -437,16 +437,9 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char ** } #undef GRID_MIN_PX -static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) +float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit) { - float grid, grid_scale; - unsigned char col_grid[3]; - const int gridlines = v3d->gridlines / 2; - - if (v3d->gridlines < 3) return; - - grid_scale = v3d->grid; - /* use 'grid_scale' instead of 'v3d->grid' from now on */ + float grid_scale = v3d->grid; /* apply units */ if (scene->unit.system) { @@ -457,11 +450,25 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) if (usys) { int i = bUnit_GetBaseUnit(usys); - *grid_unit = bUnit_GetNameDisplay(usys, i); + if (grid_unit) + *grid_unit = bUnit_GetNameDisplay(usys, i); grid_scale = (grid_scale * (float)bUnit_GetScaler(usys, i)) / scene->unit.scale_length; } } + return grid_scale; +} + +static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) +{ + float grid, grid_scale; + unsigned char col_grid[3]; + const int gridlines = v3d->gridlines / 2; + + if (v3d->gridlines < 3) return; + + /* use 'grid_scale' instead of 'v3d->grid' from now on */ + grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit); grid = gridlines * grid_scale; if (v3d->zbuf && scene->obedit) glDepthMask(0); // for zbuffer-select |