Page MenuHome
Paste P1764

Transform cloth deform target
ActivePublic

Authored by Pablo Dobarro (pablodp606) on Nov 13 2020, 5:44 PM.
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index c7edcd30873..f88f9e3b14f 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -6053,7 +6053,12 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata,
add_v3_v3(val, proxies[p].co[vd.i]);
}
- SCULPT_clip(sd, ss, vd.co, val);
+ if (ss->filter_cache->cloth_sim) {
+ SCULPT_clip(sd, ss, ss->filter_cache->cloth_sim->pos[vd.index], val);
+ }
+ else {
+ SCULPT_clip(sd, ss, vd.co, val);
+ }
if (ss->deform_modifiers_active) {
sculpt_flush_pbvhvert_deform(ob, &vd);
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index f8165890cc4..48fb46deea4 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -750,6 +750,7 @@ static void do_cloth_brush_solve_simulation_task_cb_ex(
if (sim_factor > 0.0f) {
int i = vd.index;
float temp[3];
+ /*
copy_v3_v3(temp, cloth_sim->pos[i]);
mul_v3_fl(cloth_sim->acceleration[i], time_step);
@@ -763,6 +764,7 @@ static void do_cloth_brush_solve_simulation_task_cb_ex(
madd_v3_v3fl(cloth_sim->pos[i], pos_diff, mask_v);
madd_v3_v3fl(cloth_sim->pos[i], cloth_sim->acceleration[i], mask_v);
+ */
if (cloth_sim->collider_list != NULL) {
cloth_brush_solve_collision(data->ob, cloth_sim, i);
diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.c b/source/blender/editors/sculpt_paint/sculpt_transform.c
index d3ea6617f43..c6b4a05305a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_transform.c
+++ b/source/blender/editors/sculpt_paint/sculpt_transform.c
@@ -62,6 +62,8 @@
#include <math.h>
#include <stdlib.h>
+#define CLOTH_DEFORM_TARGET true
+
void ED_sculpt_init_transform(struct bContext *C)
{
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
@@ -78,15 +80,25 @@ void ED_sculpt_init_transform(struct bContext *C)
copy_v3_v3(ss->prev_pivot_scale, ss->pivot_scale);
SCULPT_undo_push_begin(ob, "Transform");
- BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false, false);
+ BKE_sculpt_update_object_for_edit(depsgraph, ob, CLOTH_DEFORM_TARGET, CLOTH_DEFORM_TARGET, false);
ss->pivot_rot[3] = 1.0f;
+
SCULPT_vertex_random_access_ensure(ss);
SCULPT_filter_cache_init(C, ob, sd, SCULPT_UNDO_COORDS);
+
+ if (CLOTH_DEFORM_TARGET) {
+ ss->filter_cache->cloth_sim = SCULPT_cloth_brush_simulation_create(
+ ss, 1.0f, 0.0f, 0.0f, true, false);
+ SCULPT_cloth_brush_simulation_init(ss, ss->filter_cache->cloth_sim);
+ SCULPT_cloth_brush_store_simulation_state(ss, ss->filter_cache->cloth_sim);
+ SCULPT_cloth_brush_ensure_nodes_constraints(
+ sd, ob, ss->filter_cache->nodes, ss->filter_cache->totnode, ss->filter_cache->cloth_sim, ss->pivot_pos, FLT_MAX);
+ }
}
-void sculpt_transform_matrices_init(SculptSession *ss,
+static void sculpt_transform_matrices_init(SculptSession *ss,
const char symm,
float r_transform_mats[8][4][4])
{
@@ -160,7 +172,12 @@ static void sculpt_transform_task_cb(void *__restrict userdata,
mul_m4_v3(data->transform_mats[(int)symm_area], transformed_co);
sub_v3_v3v3(disp, transformed_co, vd.co);
mul_v3_fl(disp, 1.0f - fade);
- add_v3_v3v3(vd.co, vd.co, disp);
+ if (ss->filter_cache->cloth_sim) {
+ add_v3_v3(ss->filter_cache->cloth_sim->pos[vd.index], disp);
+ }
+ else {
+ add_v3_v3v3(vd.co, vd.co, disp);
+ }
if (vd.mvert) {
vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
@@ -298,6 +315,11 @@ void ED_sculpt_update_modal_transform(struct bContext *C)
copy_v4_v4(ss->prev_pivot_rot, ss->pivot_rot);
copy_v3_v3(ss->prev_pivot_scale, ss->pivot_scale);
+ if (CLOTH_DEFORM_TARGET) {
+ SCULPT_cloth_sim_activate_nodes(ss->filter_cache->cloth_sim, ss->filter_cache->nodes, ss->filter_cache->totnode);
+ SCULPT_cloth_brush_do_simulation_step(sd, ob, ss->filter_cache->cloth_sim, ss->filter_cache->nodes, ss->filter_cache->totnode);
+ }
+
if (ss->deform_modifiers_active || ss->shapekey_active) {
SCULPT_flush_stroke_deform(sd, ob, true);
}