Merge branch 'master' into blender2.8

This commit is contained in:
Campbell Barton 2018-05-02 14:40:00 +02:00
commit 5659d8bc0a
14 changed files with 91 additions and 35 deletions

View File

@ -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_*.
*/

View File

@ -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;
}
/** \} */

View File

@ -3431,9 +3431,9 @@ static void shrinkwrap_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstrai
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;

View File

@ -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;

View File

@ -214,7 +214,8 @@ Paint *BKE_paint_get_active_from_context(const bContext *C)
}
}
else {
return BKE_paint_get_active(sce, view_layer);
/* default to image paint */
return &ts->imapaint.paint;
}
}

View File

@ -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;

View File

@ -2465,6 +2465,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 {

View File

@ -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"
@ -479,6 +480,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;
@ -608,6 +621,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;
}

View File

@ -699,11 +699,11 @@ static bool remap_hair_emitter(
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);

View File

@ -1694,10 +1694,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;
}
}

View File

@ -158,9 +158,9 @@ static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
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);
}
}

View File

@ -949,7 +949,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);

View File

@ -148,7 +148,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;
@ -156,7 +156,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;
@ -164,7 +164,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;

View File

@ -548,7 +548,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);