Fix T59152: dynamic topology constant detail should be in world space.
It seems more predictable, and makes more sense for future multi-object modes.
This commit is contained in:
parent
409443500b
commit
22bc6142c3
Notes:
blender-bot
2023-02-14 08:24:03 +01:00
Referenced by issue #61040, Object scale seems to be applied twice to Dyntopo Constant Detail Referenced by issue #59152, Dyntopo Constant Detail freezes Blender on scaled object
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in New Issue