Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_cloth.c
| Show First 20 Lines • Show All 1,121 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* Activate the nodes inside the simulation area. */ | /* Activate the nodes inside the simulation area. */ | ||||
| for (int n = 0; n < totnode; n++) { | for (int n = 0; n < totnode; n++) { | ||||
| const int node_index = POINTER_AS_INT(BLI_ghash_lookup(cloth_sim->node_state_index, nodes[n])); | const int node_index = POINTER_AS_INT(BLI_ghash_lookup(cloth_sim->node_state_index, nodes[n])); | ||||
| cloth_sim->node_state[node_index] = SCULPT_CLOTH_NODE_ACTIVE; | cloth_sim->node_state[node_index] = SCULPT_CLOTH_NODE_ACTIVE; | ||||
| } | } | ||||
| } | } | ||||
| static void sculpt_cloth_ensure_constraints_in_simulation_area(Sculpt *sd, | |||||
| Object *ob, | |||||
| PBVHNode **nodes, | |||||
| int totnode) | |||||
| { | |||||
| SculptSession *ss = ob->sculpt; | |||||
| Brush *brush = BKE_paint_brush(&sd->paint); | |||||
| const float radius = ss->cache->initial_radius; | |||||
| const float limit = radius + (radius * brush->cloth_sim_limit); | |||||
| float sim_location[3]; | |||||
| cloth_brush_simulation_location_get(ss, brush, sim_location); | |||||
| SCULPT_cloth_brush_ensure_nodes_constraints( | |||||
| sd, ob, nodes, totnode, ss->cache->cloth_sim, sim_location, limit); | |||||
| } | |||||
| /* Main Brush Function. */ | /* Main Brush Function. */ | ||||
| void SCULPT_do_cloth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | void SCULPT_do_cloth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| { | { | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| Brush *brush = BKE_paint_brush(&sd->paint); | Brush *brush = BKE_paint_brush(&sd->paint); | ||||
| /* In the first brush step of each symmetry pass, build the constraints for the vertices in all | |||||
| * nodes inside the simulation's limits. */ | |||||
| /* Brushes that use anchored strokes and restore the mesh can't rely on symmetry passes and steps | /* Brushes that use anchored strokes and restore the mesh can't rely on symmetry passes and steps | ||||
| * count as it is always the first step, so the simulation needs to be created when it does not | * count as it is always the first step, so the simulation needs to be created when it does not | ||||
| * exist for this stroke. */ | * exist for this stroke. */ | ||||
| if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache) || !ss->cache->cloth_sim) { | if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache) || !ss->cache->cloth_sim) { | ||||
| /* The simulation structure only needs to be created on the first symmetry pass. */ | /* The simulation structure only needs to be created on the first symmetry pass. */ | ||||
| if (SCULPT_stroke_is_first_brush_step(ss->cache) || !ss->cache->cloth_sim) { | if (SCULPT_stroke_is_first_brush_step(ss->cache) || !ss->cache->cloth_sim) { | ||||
| ss->cache->cloth_sim = SCULPT_cloth_brush_simulation_create( | ss->cache->cloth_sim = SCULPT_cloth_brush_simulation_create( | ||||
| ss, | ss, | ||||
| brush->cloth_mass, | brush->cloth_mass, | ||||
| brush->cloth_damping, | brush->cloth_damping, | ||||
| brush->cloth_constraint_softbody_strength, | brush->cloth_constraint_softbody_strength, | ||||
| (brush->flag2 & BRUSH_CLOTH_USE_COLLISION), | (brush->flag2 & BRUSH_CLOTH_USE_COLLISION), | ||||
| SCULPT_is_cloth_deform_brush(brush)); | SCULPT_is_cloth_deform_brush(brush)); | ||||
| SCULPT_cloth_brush_simulation_init(ss, ss->cache->cloth_sim); | SCULPT_cloth_brush_simulation_init(ss, ss->cache->cloth_sim); | ||||
| } | } | ||||
| if (brush->cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_LOCAL) { | |||||
| /* When using simulation a fixed local simulation area, constraints are created only using | |||||
| * the initial stroke position and initial radius (per symmetry pass) instead of per node. | |||||
| * This allows skipping unnecesary constraints that won't never be simulated, making the | |||||
sergey: Double negation. Suggestion:
This allows to skip unnecessary constraints that will never be… | |||||
| * solver faster. When the simulation starts for a node, the node gets activated and all its | |||||
| * constraints are considered final. As the same node can be included inside the brush radius | |||||
| * from multiple symmetry passes, the cloth brush can't activate the node for simulation yet. | |||||
sergeyUnsubmitted Done Inline ActionsCan you explain why is it so? sergey: Can you explain why is it so? | |||||
| * It needs to build the constraints here and skip simulating the first step, so all passes | |||||
| * can add their constraints to all affected nodes. */ | |||||
| sculpt_cloth_ensure_constraints_in_simulation_area(sd, ob, nodes, totnode); | |||||
| } | |||||
| /* The first step of a symmetry pass is never simulated as deformation modes need valid delta | |||||
| * for brush tip alignement. */ | |||||
| return; | return; | ||||
| } | } | ||||
| /* Ensure the constraints for the nodes. */ | /* Ensure the constraints for the nodes. */ | ||||
| const float radius = ss->cache->initial_radius; | sculpt_cloth_ensure_constraints_in_simulation_area(sd, ob, nodes, totnode); | ||||
| const float limit = radius + (radius * brush->cloth_sim_limit); | |||||
| SCULPT_cloth_brush_ensure_nodes_constraints( | |||||
| sd, ob, nodes, totnode, ss->cache->cloth_sim, ss->cache->location, limit); | |||||
| /* Store the initial state in the simulation. */ | /* Store the initial state in the simulation. */ | ||||
| SCULPT_cloth_brush_store_simulation_state(ss, ss->cache->cloth_sim); | SCULPT_cloth_brush_store_simulation_state(ss, ss->cache->cloth_sim); | ||||
| /* Enable the nodes that should be simulated. */ | /* Enable the nodes that should be simulated. */ | ||||
| SCULPT_cloth_sim_activate_nodes(ss->cache->cloth_sim, nodes, totnode); | SCULPT_cloth_sim_activate_nodes(ss->cache->cloth_sim, nodes, totnode); | ||||
| /* Apply forces to the vertices. */ | /* Apply forces to the vertices. */ | ||||
| ▲ Show 20 Lines • Show All 454 Lines • Show Last 20 Lines | |||||
Double negation. Suggestion: