Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_cloth.c
| Show First 20 Lines • Show All 610 Lines • ▼ Show 20 Lines | if (hit.index != -1) { | ||||
| copy_v3_v3(cloth_sim->pos[i], hit.co); | copy_v3_v3(cloth_sim->pos[i], hit.co); | ||||
| add_v3_v3(cloth_sim->pos[i], movement_disp); | add_v3_v3(cloth_sim->pos[i], movement_disp); | ||||
| add_v3_v3(cloth_sim->pos[i], collision_disp); | add_v3_v3(cloth_sim->pos[i], collision_disp); | ||||
| mul_v3_m4v3(cloth_sim->pos[i], obmat_inv, cloth_sim->pos[i]); | mul_v3_m4v3(cloth_sim->pos[i], obmat_inv, cloth_sim->pos[i]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void cloth_simulation_noise_get(float *r_noise, | |||||
| SculptSession *ss, | |||||
| const int index, | |||||
| const float strength) | |||||
| { | |||||
| const uint *hash_co = (const uint *)SCULPT_vertex_co_get(ss, index); | |||||
| for (int i = 0; i < 3; i++) { | |||||
| const uint hash = BLI_hash_int_2d(hash_co[0], hash_co[1]) ^ BLI_hash_int_2d(hash_co[2], i); | |||||
| r_noise[i] = (hash * (1.0f / 0xFFFFFFFF) - 0.5f) * strength; | |||||
| } | |||||
| }; | |||||
| static void do_cloth_brush_solve_simulation_task_cb_ex( | static void do_cloth_brush_solve_simulation_task_cb_ex( | ||||
| void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) | void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptClothSimulation *cloth_sim = data->cloth_sim; | SculptClothSimulation *cloth_sim = data->cloth_sim; | ||||
| Show All 18 Lines | if (sim_factor > 0.0f) { | ||||
| mul_v3_fl(pos_diff, (1.0f - cloth_sim->damping)); | mul_v3_fl(pos_diff, (1.0f - cloth_sim->damping)); | ||||
| const float mask_v = (1.0f - (vd.mask ? *vd.mask : 0.0f)) * | const float mask_v = (1.0f - (vd.mask ? *vd.mask : 0.0f)) * | ||||
| SCULPT_automasking_factor_get(ss, vd.index); | SCULPT_automasking_factor_get(ss, vd.index); | ||||
| madd_v3_v3fl(cloth_sim->pos[i], pos_diff, mask_v); | madd_v3_v3fl(cloth_sim->pos[i], pos_diff, mask_v); | ||||
| madd_v3_v3fl(cloth_sim->pos[i], cloth_sim->acceleration[i], mask_v); | madd_v3_v3fl(cloth_sim->pos[i], cloth_sim->acceleration[i], mask_v); | ||||
| /* Prevents the vertices from sliding without creating folds when all vertices and forces are | |||||
| * in the same plane. */ | |||||
| float noise[3]; | |||||
| cloth_simulation_noise_get(noise, ss, vd.index, 0.00001f); | |||||
| add_v3_v3(cloth_sim->pos[i], noise); | |||||
| if (cloth_sim->collider_list != NULL) { | if (cloth_sim->collider_list != NULL) { | ||||
| cloth_brush_solve_collision(data->ob, cloth_sim, i); | cloth_brush_solve_collision(data->ob, cloth_sim, i); | ||||
| } | } | ||||
| copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]); | copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]); | ||||
| copy_v3_v3(cloth_sim->prev_pos[i], temp); | copy_v3_v3(cloth_sim->prev_pos[i], temp); | ||||
| copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]); | copy_v3_v3(cloth_sim->last_iteration_pos[i], cloth_sim->pos[i]); | ||||
| ▲ Show 20 Lines • Show All 668 Lines • Show Last 20 Lines | |||||