[Bf-blender-cvs] [7b8ac04d86e] master: Fix T74601: Cut Particles to Shape fails for transformed object

Campbell Barton noreply at git.blender.org
Tue Mar 10 06:58:58 CET 2020


Commit: 7b8ac04d86e28ab47fd0863958201079a9c43501
Author: Campbell Barton
Date:   Tue Mar 10 16:55:41 2020 +1100
Branches: master
https://developer.blender.org/rB7b8ac04d86e28ab47fd0863958201079a9c43501

Fix T74601: Cut Particles to Shape fails for transformed object

===================================================================

M	source/blender/editors/physics/particle_edit.c

===================================================================

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



More information about the Bf-blender-cvs mailing list