From 188c4a22c98fb68377b881e5e20ac759ff329d85 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 30 Apr 2018 18:58:43 +0200 Subject: Cleanup: de-duplicate paint access from object --- source/blender/blenkernel/intern/paint.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index bee6e7d3df0..144ec029db1 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -208,27 +208,8 @@ Paint *BKE_paint_get_active_from_context(const bContext *C) return &ts->imapaint.paint; } } - else if (obact) { - switch (obact->mode) { - case OB_MODE_SCULPT: - return &ts->sculpt->paint; - case OB_MODE_VERTEX_PAINT: - return &ts->vpaint->paint; - case OB_MODE_WEIGHT_PAINT: - return &ts->wpaint->paint; - case OB_MODE_TEXTURE_PAINT: - return &ts->imapaint.paint; - case OB_MODE_EDIT: - if (ts->use_uv_sculpt) - return &ts->uvsculpt->paint; - return &ts->imapaint.paint; - default: - return &ts->imapaint.paint; - } - } else { - /* default to image paint */ - return &ts->imapaint.paint; + return BKE_paint_get_active(sce); } } -- cgit v1.2.3 From 32c415804734055c4a48bbde3574d43477379f51 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Mon, 30 Apr 2018 21:34:13 +0200 Subject: Fix Merge > To Cursor In master this is working fine, but in 2.8 ob->imat was identity matrix. Committing this in master to simplify merging. --- source/blender/editors/mesh/editmesh_tools.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source') diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 350d43e2c51..683e69a4ff6 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -2328,6 +2328,7 @@ static bool merge_target( if (use_cursor) { vco = ED_view3d_cursor3d_get(scene, v3d); copy_v3_v3(co, vco); + invert_m4_m4(ob->imat, ob->obmat); mul_m4_v3(ob->imat, co); } else { -- cgit v1.2.3 From 2e98524b58a53f0d546e5f1e7d549d2f45815055 Mon Sep 17 00:00:00 2001 From: Lukas Stockner Date: Mon, 30 Apr 2018 22:05:03 +0200 Subject: Add support for area lights to the Apply Transform operator Since area lights are affected by scaling them, it only makes sense to support applying the scale to the lamp size. Of course, applying location or rotation does not work. If a scaling that changes the aspect ratio is applied to a square lamp, the mode is automatically changed to Rectangle. --- source/blender/editors/object/object_transform.c | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source') diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 05f98026e18..e29d49d00cb 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -35,6 +35,7 @@ #include "DNA_armature_types.h" #include "DNA_mesh_types.h" #include "DNA_meta_types.h" +#include "DNA_lamp_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_group_types.h" @@ -472,6 +473,18 @@ static int apply_objects_internal( changed = false; } } + + if (ob->type == OB_LAMP) { + Lamp *la = ob->data; + if (la->type == LA_AREA) { + if (apply_rot || apply_loc) { + BKE_reportf(reports, RPT_ERROR, + "Area Lamps can only have scale applied: \"%s\"", + ob->id.name + 2); + changed = false; + } + } + } } CTX_DATA_END; @@ -601,6 +614,22 @@ static int apply_objects_internal( ob->empty_drawsize *= max_scale; } } + else if (ob->type == OB_LAMP) { + Lamp *la = ob->data; + if (la->type != LA_AREA) { + continue; + } + + bool keeps_aspect_ratio = compare_ff_relative(rsmat[0][0], rsmat[1][1], FLT_EPSILON, 64); + if ((la->area_shape == LA_AREA_SQUARE) && !keeps_aspect_ratio) { + la->area_shape = LA_AREA_RECT; + la->area_sizey = la->area_size; + } + + la->area_size *= rsmat[0][0]; + la->area_sizey *= rsmat[1][1]; + la->area_sizez *= rsmat[2][2]; + } else { continue; } -- cgit v1.2.3 From 522bee3fc838c83b377d0e05fef8299a29ae5a16 Mon Sep 17 00:00:00 2001 From: Germano Date: Tue, 1 May 2018 10:03:28 -0300 Subject: Refactoring: bvhutils: Use a function that gets the bvhtree through an identifier type. Reviewed By: @campbellbarton Differential Revision: https://developer.blender.org/D3192 --- source/blender/blenkernel/BKE_bvhutils.h | 7 ++--- source/blender/blenkernel/intern/bvhutils.c | 23 +++++++++++++-- source/blender/blenkernel/intern/constraint.c | 4 +-- source/blender/blenkernel/intern/mesh_remap.c | 33 ++++++++++++++-------- source/blender/blenkernel/intern/shrinkwrap.c | 4 +-- source/blender/editors/physics/particle_object.c | 4 +-- .../editors/transform/transform_snap_object.c | 4 +-- source/blender/modifiers/intern/MOD_surface.c | 4 +-- .../blender/modifiers/intern/MOD_surfacedeform.c | 2 +- .../modifiers/intern/MOD_weightvgproximity.c | 6 ++-- source/blender/render/intern/source/bake_api.c | 2 +- 11 files changed, 59 insertions(+), 34 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index b3122f8adb9..33e88a6b8f8 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -113,8 +113,6 @@ BVHTree *bvhtree_from_editmesh_verts_ex( const BLI_bitmap *mask, int verts_num_active, float epsilon, int tree_type, int axis); -BVHTree *bvhtree_from_mesh_verts( - struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis); BVHTree *bvhtree_from_mesh_verts_ex( struct BVHTreeFromMesh *data, const struct MVert *vert, const int numVerts, const bool vert_allocated, const BLI_bitmap *mask, int verts_num_active, @@ -138,9 +136,6 @@ BVHTree *bvhtree_from_mesh_edges_ex( const BLI_bitmap *edges_mask, int edges_num_active, float epsilon, int tree_type, int axis); -BVHTree *bvhtree_from_mesh_faces( - struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, - int tree_type, int axis); BVHTree *bvhtree_from_mesh_faces_ex( struct BVHTreeFromMesh *data, const struct MVert *vert, const bool vert_allocated, @@ -166,6 +161,8 @@ BVHTree *bvhtree_from_mesh_looptri_ex( const BLI_bitmap *mask, int looptri_num_active, float epsilon, int tree_type, int axis); +BVHTree *bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type); + /** * Frees data allocated by a call to bvhtree_from_mesh_*. */ diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index cd2c7194237..90a75b8d3cc 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -501,7 +501,7 @@ BVHTree *bvhtree_from_editmesh_verts( /* Builds a bvh tree where nodes are the vertices of the given dm * and stores the BVHTree in dm->bvhCache */ -BVHTree *bvhtree_from_mesh_verts( +static BVHTree *bvhtree_from_mesh_verts( BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis) { @@ -859,7 +859,7 @@ static void bvhtree_from_mesh_faces_setup_data( } /* Builds a bvh tree where nodes are the tesselated faces of the given dm */ -BVHTree *bvhtree_from_mesh_faces( +static BVHTree *bvhtree_from_mesh_faces( BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis) { @@ -1225,6 +1225,25 @@ BVHTree *bvhtree_from_mesh_looptri_ex( return tree; } +/** + * Builds or queries a bvhcache for the cache bvhtree of the request type. + */ +BVHTree *bvhtree_from_mesh_get( + struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type) +{ + switch (type) { + case BVHTREE_FROM_VERTS: + return bvhtree_from_mesh_verts(data, mesh, 0.0f, 2, 6); + case BVHTREE_FROM_EDGES: + return bvhtree_from_mesh_edges(data, mesh, 0.0f, 2, 6); + case BVHTREE_FROM_FACES: + return bvhtree_from_mesh_faces(data, mesh, 0.0f, 2, 6); + case BVHTREE_FROM_LOOPTRI: + return bvhtree_from_mesh_looptri(data, mesh, 0.0f, 2, 6); + } + return NULL; +} + /** \} */ diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 28e4af32a71..934cfbe9374 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3508,9 +3508,9 @@ static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra nearest.dist_sq = FLT_MAX; if (scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) - bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_VERTS); else - bvhtree_from_mesh_looptri(&treeData, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_LOOPTRI); if (treeData.tree == NULL) { fail = true; diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c index 0af4dae4506..f99dd5574b2 100644 --- a/source/blender/blenkernel/intern/mesh_remap.c +++ b/source/blender/blenkernel/intern/mesh_remap.c @@ -131,7 +131,7 @@ float BKE_mesh_remap_calc_difference_from_dm( float result = 0.0f; int i; - bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS); nearest.index = -1; for (i = 0; i < numverts_dst; i++) { @@ -460,7 +460,7 @@ void BKE_mesh_remap_calc_verts_from_dm( float tmp_co[3], tmp_no[3]; if (mode == MREMAP_MODE_VERT_NEAREST) { - bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS); nearest.index = -1; for (i = 0; i < numverts_dst; i++) { @@ -485,7 +485,7 @@ void BKE_mesh_remap_calc_verts_from_dm( float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__); dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_edges(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES); nearest.index = -1; for (i = 0; i < numverts_dst; i++) { @@ -543,7 +543,13 @@ void BKE_mesh_remap_calc_verts_from_dm( float *weights = MEM_mallocN(sizeof(*weights) * tmp_buff_size, __func__); dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_looptri(&treedata, dm_src, (mode & MREMAP_USE_NORPROJ) ? ray_radius : 0.0f, 2, 6); + if (mode & MREMAP_USE_NORPROJ) { + bvhtree_from_mesh_looptri( + &treedata, dm_src, ray_radius, 2, 6); + } + else { + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI); + } if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) { for (i = 0; i < numverts_dst; i++) { @@ -676,7 +682,7 @@ void BKE_mesh_remap_calc_edges_from_dm( dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS); nearest.index = -1; for (i = 0; i < numedges_dst; i++) { @@ -776,7 +782,7 @@ void BKE_mesh_remap_calc_edges_from_dm( MEM_freeN(vert_to_edge_src_map_mem); } else if (mode == MREMAP_MODE_EDGE_NEAREST) { - bvhtree_from_mesh_edges(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES); nearest.index = -1; for (i = 0; i < numedges_dst; i++) { @@ -803,7 +809,7 @@ void BKE_mesh_remap_calc_edges_from_dm( float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__); dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_looptri(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI); for (i = 0; i < numedges_dst; i++) { interp_v3_v3v3(tmp_co, verts_dst[edges_dst[i].v1].co, verts_dst[edges_dst[i].v2].co, 0.5f); @@ -1360,7 +1366,7 @@ void BKE_mesh_remap_calc_loops_from_dm( } else { BLI_assert(num_trees == 1); - bvhtree_from_mesh_verts(&treedata[0], dm_src, bvh_epsilon, 2, 6); + bvhtree_from_mesh_get(&treedata[0], dm_src, BVHTREE_FROM_VERTS); } } else { /* We use polygons. */ @@ -2007,10 +2013,13 @@ void BKE_mesh_remap_calc_polys_from_dm( BVHTreeRayHit rayhit = {0}; float hit_dist; - bvhtree_from_mesh_looptri( - &treedata, dm_src, - (mode & MREMAP_USE_NORPROJ) ? MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius) : 0.0f, - 2, 6); + if (mode & MREMAP_USE_NORPROJ) { + bvhtree_from_mesh_looptri( + &treedata, dm_src, MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius), 2, 6); + } + else { + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI); + } if (mode == MREMAP_MODE_POLY_NEAREST) { nearest.index = -1; diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 618f495dbf1..0d381248ef2 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -158,7 +158,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) return; } - TIMEIT_BENCH(bvhtree_from_mesh_verts(&treeData, calc->target, 0.0, 2, 6), bvhtree_verts); + TIMEIT_BENCH(bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_VERTS), bvhtree_verts); if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; @@ -588,7 +588,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) } /* Create a bvh-tree of the given target */ - bvhtree_from_mesh_looptri(&treeData, calc->target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_LOOPTRI); if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 546fac6b7a3..f4334a2e872 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -692,11 +692,11 @@ static bool remap_hair_emitter(Scene *scene, Object *ob, ParticleSystem *psys, if (dm->getNumTessFaces(dm) != 0) { mface = dm->getTessFaceArray(dm); - bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6); + bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_FACES); } else if (dm->getNumEdges(dm) != 0) { medge = dm->getEdgeArray(dm); - bvhtree_from_mesh_edges(&bvhtree, dm, 0.0, 2, 6); + bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_EDGES); } else { dm->release(dm); diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index d248d0df4e3..569c662d31c 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -1687,10 +1687,10 @@ static bool snapDerivedMesh( if (treedata->tree == NULL) { switch (snapdata->snap_to) { case SCE_SNAP_MODE_EDGE: - bvhtree_from_mesh_edges(treedata, dm, 0.0f, 2, 6); + bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_EDGES); break; case SCE_SNAP_MODE_VERTEX: - bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6); + bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_VERTS); break; } } diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index 7bb4c0b2fd1..389cffe85e7 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -159,9 +159,9 @@ static void deformVerts(ModifierData *md, Object *ob, surmd->bvhtree = MEM_callocN(sizeof(BVHTreeFromMesh), "BVHTreeFromMesh"); if (surmd->dm->getNumPolys(surmd->dm)) - bvhtree_from_mesh_looptri(surmd->bvhtree, surmd->dm, 0.0, 2, 6); + bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_LOOPTRI); else - bvhtree_from_mesh_edges(surmd->bvhtree, surmd->dm, 0.0, 2, 6); + bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_EDGES); } } diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index fc605dd48e1..5006fe4a6e0 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -960,7 +960,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos) return false; } - bvhtree_from_mesh_looptri(&treeData, tdm, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, tdm, BVHTREE_FROM_LOOPTRI); if (treeData.tree == NULL) { modifier_setError((ModifierData *)smd, "Out of memory"); freeAdjacencyMap(vert_edges, adj_array, edge_polys); diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 09991887f69..c60c9690ac3 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -149,7 +149,7 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3], if (dist_v) { /* Create a bvh-tree of the given target's verts. */ - bvhtree_from_mesh_verts(&treeData_v, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData_v, target, BVHTREE_FROM_VERTS); if (treeData_v.tree == NULL) { OUT_OF_MEMORY(); return; @@ -157,7 +157,7 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3], } if (dist_e) { /* Create a bvh-tree of the given target's edges. */ - bvhtree_from_mesh_edges(&treeData_e, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData_e, target, BVHTREE_FROM_EDGES); if (treeData_e.tree == NULL) { OUT_OF_MEMORY(); return; @@ -165,7 +165,7 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3], } if (dist_f) { /* Create a bvh-tree of the given target's faces. */ - bvhtree_from_mesh_looptri(&treeData_f, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData_f, target, BVHTREE_FROM_LOOPTRI); if (treeData_f.tree == NULL) { OUT_OF_MEMORY(); return; diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c index 505af3c2fa8..7f7acceb5dd 100644 --- a/source/blender/render/intern/source/bake_api.c +++ b/source/blender/render/intern/source/bake_api.c @@ -526,7 +526,7 @@ bool RE_bake_pixels_populate_from_objects( if (dm_highpoly[i]->getNumTessFaces(dm_highpoly[i]) != 0) { /* Create a bvh-tree for each highpoly object */ - bvhtree_from_mesh_faces(&treeData[i], dm_highpoly[i], 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData[i], dm_highpoly[i], BVHTREE_FROM_FACES); if (treeData[i].tree == NULL) { printf("Baking: out of memory while creating BHVTree for object \"%s\"\n", highpoly[i].ob->id.name + 2); -- cgit v1.2.3