Commit: 22bc6142c3c505de2f2a9a85941c43236f53b941
Author: Brecht Van Lommel
Date:   Wed Jan 23 16:48:02 2019 +0100
Branches: master
https://developer.blender.org/rB22bc6142c3c505de2f2a9a85941c43236f53b941

Fix T59152: dynamic topology constant detail should be in world space.

It seems more predictable, and makes more sense for future multi-object modes.

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

M       source/blender/blenkernel/BKE_pbvh.h
M       source/blender/blenkernel/intern/pbvh_bmesh.c
M       source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h 
b/source/blender/blenkernel/BKE_pbvh.h
index 47fedb565fc..0067f63ded0 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -108,7 +108,7 @@ bool BKE_pbvh_node_raycast(
 bool BKE_pbvh_bmesh_node_raycast_detail(
         PBVHNode *node,
         const float ray_start[3], const float ray_normal[3],
-        float *depth, float *r_detail);
+        float *depth, float *r_edge_length);
 
 /* for orthographic cameras, project the far away ray segment points to the 
root node so
  * we can have better precision. */
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c 
b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 3369b05ea60..53dafdc9787 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1549,7 +1549,7 @@ bool pbvh_bmesh_node_raycast(
 bool BKE_pbvh_bmesh_node_raycast_detail(
         PBVHNode *node,
         const float ray_start[3], const float ray_normal[3],
-        float *depth, float *r_detail)
+        float *depth, float *r_edge_length)
 {
        if (node->flag & PBVH_FullyHidden)
                return 0;
@@ -1588,7 +1588,7 @@ bool BKE_pbvh_bmesh_node_raycast_detail(
                float len3 = len_squared_v3v3(v_tri[2]->co, v_tri[0]->co);
 
                /* detail returned will be set to the maximum allowed size, so 
take max here */
-               *r_detail = sqrtf(max_fff(len1, len2, len3));
+               *r_edge_length = sqrtf(max_fff(len1, len2, len3));
        }
 
        return hit;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index e72b5490f8a..b2df942b2fa 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1644,7 +1644,7 @@ typedef struct {
        const float *ray_start, *ray_normal;
        bool hit;
        float depth;
-       float detail;
+       float edge_length;
 } SculptDetailRaycastData;
 
 typedef struct {
@@ -4684,7 +4684,7 @@ static void sculpt_raycast_detail_cb(PBVHNode *node, void 
*data_v, float *tmin)
        if (BKE_pbvh_node_get_tmin(node) < *tmin) {
                SculptDetailRaycastData *srd = data_v;
                if (BKE_pbvh_bmesh_node_raycast_detail(node, srd->ray_start, 
srd->ray_normal,
-                                                      &srd->depth, 
&srd->detail))
+                                                      &srd->depth, 
&srd->edge_length))
                {
                        srd->hit = 1;
                        *tmin = srd->depth;
@@ -4972,7 +4972,8 @@ static void sculpt_stroke_update_step(bContext *C, struct 
PaintStroke *UNUSED(st
        sculpt_restore_mesh(sd, ob);
 
        if (sd->flags & (SCULPT_DYNTOPO_DETAIL_CONSTANT | 
SCULPT_DYNTOPO_DETAIL_MANUAL)) {
-               BKE_pbvh_bmesh_detail_size_set(ss->pbvh, 1.0f / 
sd->constant_detail);
+               float object_space_constant_detail = sd->constant_detail * 
mat4_to_scale(ob->imat);
+               BKE_pbvh_bmesh_detail_size_set(ss->pbvh, 1.0f / 
object_space_constant_detail);
        }
        else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) {
                BKE_pbvh_bmesh_detail_size_set(ss->pbvh, ss->cache->radius * 
sd->detail_percent / 100.0f);
@@ -5915,7 +5916,8 @@ static int sculpt_detail_flood_fill_exec(bContext *C, 
wmOperator *UNUSED(op))
        size = max_fff(dim[0], dim[1], dim[2]);
 
        /* update topology size */
-       BKE_pbvh_bmesh_detail_size_set(ss->pbvh, 1.0f / sd->constant_detail);
+       float object_space_constant_detail = sd->constant_detail * 
mat4_to_scale(ob->imat);
+       BKE_pbvh_bmesh_detail_size_set(ss->pbvh, 1.0f / 
object_space_constant_detail);
 
        sculpt_undo_push_begin("Dynamic topology flood fill");
        sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_COORDS);
@@ -5988,14 +5990,14 @@ static void sample_detail(bContext *C, int mx, int my)
        srd.ray_start = ray_start;
        srd.ray_normal = ray_normal;
        srd.depth = depth;
-       srd.detail = sd->constant_detail;
+       srd.edge_length = 0.0f;
 
        BKE_pbvh_raycast(ob->sculpt->pbvh, sculpt_raycast_detail_cb, &srd,
                         ray_start, ray_normal, false);
 
-       if (srd.hit) {
-               /* convert edge length to detail resolution */
-               sd->constant_detail = 1.0f / srd.detail;
+       if (srd.hit && srd.edge_length > 0.0f) {
+               /* Convert edge length to world space detail resolution. */
+               sd->constant_detail = mat4_to_scale(ob->obmat) / 
srd.edge_length;
        }
 
        /* Restore context. */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to