diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-03-10 08:55:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-03-10 08:55:41 +0300 |
commit | 7b8ac04d86e28ab47fd0863958201079a9c43501 (patch) | |
tree | 9dfecc74838b380ebc43b3929e58c6c9f778ea40 /source/blender/editors/physics | |
parent | 5aa54207e11626392c093c72367174f984aefa0f (diff) |
Fix T74601: Cut Particles to Shape fails for transformed object
Diffstat (limited to 'source/blender/editors/physics')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index d7ae1a15e1b..17875688c61 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -4890,7 +4890,7 @@ static void point_inside_bvh_cb(void *userdata, } /* true if the point is inside the shape mesh */ -static bool shape_cut_test_point(PEData *data, ParticleCacheKey *key) +static bool shape_cut_test_point(PEData *data, ParticleEditSettings *pset, ParticleCacheKey *key) { BVHTreeFromMesh *shape_bvh = &data->shape_bvh; const float dir[3] = {1.0f, 0.0f, 0.0f}; @@ -4899,8 +4899,11 @@ static bool shape_cut_test_point(PEData *data, ParticleCacheKey *key) userdata.bvhdata = data->shape_bvh; userdata.num_hits = 0; + float co_shape[3]; + mul_v3_m4v3(co_shape, pset->shape_object->imat, key->co); + BLI_bvhtree_ray_cast_all( - shape_bvh->tree, key->co, dir, 0.0f, BVH_RAYCAST_DIST_MAX, point_inside_bvh_cb, &userdata); + shape_bvh->tree, co_shape, dir, 0.0f, BVH_RAYCAST_DIST_MAX, point_inside_bvh_cb, &userdata); /* for any point inside a watertight mesh the number of hits is uneven */ return (userdata.num_hits % 2) == 1; @@ -4926,32 +4929,37 @@ static void shape_cut(PEData *data, int pa_index) /* check if root is inside the cut shape */ key = edit->pathcache[pa_index]; - if (!shape_cut_test_point(data, key)) { + if (!shape_cut_test_point(data, pset, key)) { cut_time = -1.0f; cut = true; } else { for (k = 0; k < totkeys; k++, key++) { BVHTreeRayHit hit; - float dir[3]; - float len; - sub_v3_v3v3(dir, (key + 1)->co, key->co); - len = normalize_v3(dir); + float co_curr_shape[3], co_next_shape[3]; + float dir_shape[3]; + float len_shape; + + mul_v3_m4v3(co_curr_shape, pset->shape_object->imat, key->co); + mul_v3_m4v3(co_next_shape, pset->shape_object->imat, (key + 1)->co); + + sub_v3_v3v3(dir_shape, co_next_shape, co_curr_shape); + len_shape = normalize_v3(dir_shape); memset(&hit, 0, sizeof(hit)); hit.index = -1; - hit.dist = len; + hit.dist = len_shape; BLI_bvhtree_ray_cast(data->shape_bvh.tree, - key->co, - dir, + co_curr_shape, + dir_shape, 0.0f, &hit, data->shape_bvh.raycast_callback, &data->shape_bvh); if (hit.index >= 0) { - if (hit.dist < len) { - cut_time = (hit.dist / len + (float)k) / (float)totkeys; + if (hit.dist < len_shape) { + cut_time = ((hit.dist / len_shape) + (float)k) / (float)totkeys; cut = true; break; } |