Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions | Variables
sculpt_cloth.c File Reference
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_dial_2d.h"
#include "BLI_edgehash.h"
#include "BLI_gsqueue.h"
#include "BLI_hash.h"
#include "BLI_math.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "DNA_brush_types.h"
#include "DNA_customdata_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BKE_brush.h"
#include "BKE_bvhutils.h"
#include "BKE_ccg.h"
#include "BKE_collision.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_image.h"
#include "BKE_kelvinlet.h"
#include "BKE_key.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_mesh_mirror.h"
#include "BKE_modifier.h"
#include "BKE_multires.h"
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_paint.h"
#include "BKE_particle.h"
#include "BKE_pbvh.h"
#include "BKE_pointcache.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_subdiv_ccg.h"
#include "BKE_subsurf.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "WM_api.h"
#include "WM_message.h"
#include "WM_toolsystem.h"
#include "WM_types.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_sculpt.h"
#include "ED_view3d.h"
#include "paint_intern.h"
#include "sculpt_intern.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_matrix.h"
#include "GPU_state.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "bmesh.h"
#include "bmesh_tools.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  ClothBrushCollision
 

Macros

#define CLOTH_LENGTH_CONSTRAINTS_BLOCK   100000
 
#define CLOTH_SIMULATION_ITERATIONS   5
 
#define CLOTH_SOLVER_DISPLACEMENT_FACTOR   0.6f
 
#define CLOTH_MAX_CONSTRAINTS_PER_VERTEX   1024
 
#define CLOTH_SIMULATION_TIME_STEP   0.01f
 
#define CLOTH_DEFORMATION_SNAKEHOOK_STRENGTH   0.35f
 
#define CLOTH_DEFORMATION_TARGET_STRENGTH   0.01f
 
#define CLOTH_DEFORMATION_GRAB_STRENGTH   0.1f
 

Typedefs

typedef struct ClothBrushCollision ClothBrushCollision
 
typedef enum eSculpClothFilterType eSculptClothFilterType
 
typedef enum eClothFilterForceAxis eClothFilterForceAxis
 

Enumerations

enum  eSculpClothFilterType {
  CLOTH_FILTER_GRAVITY , CLOTH_FILTER_INFLATE , CLOTH_FILTER_EXPAND , CLOTH_FILTER_PINCH ,
  CLOTH_FILTER_SCALE
}
 
enum  eClothFilterForceAxis { CLOTH_FILTER_FORCE_X = 1 << 0 , CLOTH_FILTER_FORCE_Y = 1 << 1 , CLOTH_FILTER_FORCE_Z = 1 << 2 }
 

Functions

static void cloth_brush_simulation_location_get (SculptSession *ss, const Brush *brush, float r_location[3])
 
PBVHNode ** SCULPT_cloth_brush_affected_nodes_gather (SculptSession *ss, Brush *brush, int *r_totnode)
 
static float cloth_brush_simulation_falloff_get (const Brush *brush, const float radius, const float location[3], const float co[3])
 
static bool cloth_brush_sim_has_length_constraint (SculptClothSimulation *cloth_sim, const int v1, const int v2)
 
static void cloth_brush_reallocate_constraints (SculptClothSimulation *cloth_sim)
 
static void cloth_brush_add_length_constraint (SculptSession *ss, SculptClothSimulation *cloth_sim, const int node_index, const int v1, const int v2, const bool use_persistent)
 
static void cloth_brush_add_softbody_constraint (SculptClothSimulation *cloth_sim, const int node_index, const int v, const float strength)
 
static void cloth_brush_add_pin_constraint (SculptClothSimulation *cloth_sim, const int node_index, const int v, const float strength)
 
static void cloth_brush_add_deformation_constraint (SculptClothSimulation *cloth_sim, const int node_index, const int v, const float strength)
 
static void do_cloth_brush_build_constraints_task_cb_ex (void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
 
static void cloth_brush_apply_force_to_vertex (SculptSession *UNUSED(ss), SculptClothSimulation *cloth_sim, const float force[3], const int vertex_index)
 
static void do_cloth_brush_apply_forces_task_cb_ex (void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
 
static ListBasecloth_brush_collider_cache_create (Object *object, Depsgraph *depsgraph)
 
static void cloth_brush_collision_cb (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 
static void cloth_brush_solve_collision (Object *object, SculptClothSimulation *cloth_sim, const int i)
 
static void do_cloth_brush_solve_simulation_task_cb_ex (void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
 
static void cloth_brush_satisfy_constraints (SculptSession *ss, Brush *brush, SculptClothSimulation *cloth_sim)
 
void SCULPT_cloth_brush_do_simulation_step (Sculpt *sd, Object *ob, SculptClothSimulation *cloth_sim, PBVHNode **nodes, int totnode)
 
static void cloth_brush_apply_brush_foces (Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
 
static void cloth_sim_initialize_default_node_state (SculptSession *ss, SculptClothSimulation *cloth_sim)
 
SculptClothSimulationSCULPT_cloth_brush_simulation_create (Object *ob, const float cloth_mass, const float cloth_damping, const float cloth_softbody_strength, const bool use_collisions, const bool needs_deform_coords)
 
void SCULPT_cloth_brush_ensure_nodes_constraints (Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, SculptClothSimulation *cloth_sim, float initial_location[3], const float radius)
 
void SCULPT_cloth_brush_simulation_init (SculptSession *ss, SculptClothSimulation *cloth_sim)
 
void SCULPT_cloth_brush_store_simulation_state (SculptSession *ss, SculptClothSimulation *cloth_sim)
 
void SCULPT_cloth_sim_activate_nodes (SculptClothSimulation *cloth_sim, PBVHNode **nodes, int totnode)
 
static void sculpt_cloth_ensure_constraints_in_simulation_area (Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
 
void SCULPT_do_cloth_brush (Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
 
void SCULPT_cloth_simulation_free (struct SculptClothSimulation *cloth_sim)
 
void SCULPT_cloth_simulation_limits_draw (const uint gpuattr, const Brush *brush, const float location[3], const float normal[3], const float rds, const float line_width, const float outline_col[3], const float alpha)
 
void SCULPT_cloth_plane_falloff_preview_draw (const uint gpuattr, SculptSession *ss, const float outline_col[3], float outline_alpha)
 
static bool cloth_filter_is_deformation_filter (eSculptClothFilterType filter_type)
 
static void cloth_filter_apply_displacement_to_deform_co (const int v_index, const float disp[3], FilterCache *filter_cache)
 
static void cloth_filter_apply_forces_to_vertices (const int v_index, const float force[3], const float gravity[3], FilterCache *filter_cache)
 
static void cloth_filter_apply_forces_task_cb (void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls))
 
static int sculpt_cloth_filter_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static int sculpt_cloth_filter_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
void SCULPT_OT_cloth_filter (struct wmOperatorType *ot)
 

Variables

static EnumPropertyItem prop_cloth_filter_type []
 
static EnumPropertyItem prop_cloth_filter_orientation_items []
 
static EnumPropertyItem prop_cloth_filter_force_axis_items []
 

Macro Definition Documentation

◆ CLOTH_DEFORMATION_GRAB_STRENGTH

#define CLOTH_DEFORMATION_GRAB_STRENGTH   0.1f

Definition at line 183 of file sculpt_cloth.c.

◆ CLOTH_DEFORMATION_SNAKEHOOK_STRENGTH

#define CLOTH_DEFORMATION_SNAKEHOOK_STRENGTH   0.35f

Definition at line 181 of file sculpt_cloth.c.

◆ CLOTH_DEFORMATION_TARGET_STRENGTH

#define CLOTH_DEFORMATION_TARGET_STRENGTH   0.01f

Definition at line 182 of file sculpt_cloth.c.

◆ CLOTH_LENGTH_CONSTRAINTS_BLOCK

#define CLOTH_LENGTH_CONSTRAINTS_BLOCK   100000

Definition at line 175 of file sculpt_cloth.c.

◆ CLOTH_MAX_CONSTRAINTS_PER_VERTEX

#define CLOTH_MAX_CONSTRAINTS_PER_VERTEX   1024

Definition at line 179 of file sculpt_cloth.c.

◆ CLOTH_SIMULATION_ITERATIONS

#define CLOTH_SIMULATION_ITERATIONS   5

Definition at line 176 of file sculpt_cloth.c.

◆ CLOTH_SIMULATION_TIME_STEP

#define CLOTH_SIMULATION_TIME_STEP   0.01f

Definition at line 180 of file sculpt_cloth.c.

◆ CLOTH_SOLVER_DISPLACEMENT_FACTOR

#define CLOTH_SOLVER_DISPLACEMENT_FACTOR   0.6f

Definition at line 178 of file sculpt_cloth.c.

Typedef Documentation

◆ ClothBrushCollision

◆ eClothFilterForceAxis

◆ eSculptClothFilterType

Enumeration Type Documentation

◆ eClothFilterForceAxis

Enumerator
CLOTH_FILTER_FORCE_X 
CLOTH_FILTER_FORCE_Y 
CLOTH_FILTER_FORCE_Z 

Definition at line 1362 of file sculpt_cloth.c.

◆ eSculpClothFilterType

Enumerator
CLOTH_FILTER_GRAVITY 
CLOTH_FILTER_INFLATE 
CLOTH_FILTER_EXPAND 
CLOTH_FILTER_PINCH 
CLOTH_FILTER_SCALE 

Definition at line 1322 of file sculpt_cloth.c.

Function Documentation

◆ cloth_brush_add_deformation_constraint()

static void cloth_brush_add_deformation_constraint ( SculptClothSimulation cloth_sim,
const int  node_index,
const int  v,
const float  strength 
)
static

◆ cloth_brush_add_length_constraint()

static void cloth_brush_add_length_constraint ( SculptSession ss,
SculptClothSimulation cloth_sim,
const int  node_index,
const int  v1,
const int  v2,
const bool  use_persistent 
)
static

◆ cloth_brush_add_pin_constraint()

static void cloth_brush_add_pin_constraint ( SculptClothSimulation cloth_sim,
const int  node_index,
const int  v,
const float  strength 
)
static

◆ cloth_brush_add_softbody_constraint()

static void cloth_brush_add_softbody_constraint ( SculptClothSimulation cloth_sim,
const int  node_index,
const int  v,
const float  strength 
)
static

◆ cloth_brush_apply_brush_foces()

static void cloth_brush_apply_brush_foces ( Sculpt sd,
Object ob,
PBVHNode **  nodes,
int  totnode 
)
static

◆ cloth_brush_apply_force_to_vertex()

static void cloth_brush_apply_force_to_vertex ( SculptSession UNUSEDss,
SculptClothSimulation cloth_sim,
const float  force[3],
const int  vertex_index 
)
static

◆ cloth_brush_collider_cache_create()

static ListBase* cloth_brush_collider_cache_create ( Object object,
Depsgraph depsgraph 
)
static

◆ cloth_brush_collision_cb()

static void cloth_brush_collision_cb ( void userdata,
int  index,
const BVHTreeRay ray,
BVHTreeRayHit hit 
)
static

◆ cloth_brush_reallocate_constraints()

static void cloth_brush_reallocate_constraints ( SculptClothSimulation cloth_sim)
static

◆ cloth_brush_satisfy_constraints()

static void cloth_brush_satisfy_constraints ( SculptSession ss,
Brush brush,
SculptClothSimulation cloth_sim 
)
static

◆ cloth_brush_sim_has_length_constraint()

static bool cloth_brush_sim_has_length_constraint ( SculptClothSimulation cloth_sim,
const int  v1,
const int  v2 
)
static

◆ cloth_brush_simulation_falloff_get()

static float cloth_brush_simulation_falloff_get ( const Brush brush,
const float  radius,
const float  location[3],
const float  co[3] 
)
static

◆ cloth_brush_simulation_location_get()

static void cloth_brush_simulation_location_get ( SculptSession ss,
const Brush brush,
float  r_location[3] 
)
static

◆ cloth_brush_solve_collision()

static void cloth_brush_solve_collision ( Object object,
SculptClothSimulation cloth_sim,
const int  i 
)
static

◆ cloth_filter_apply_displacement_to_deform_co()

static void cloth_filter_apply_displacement_to_deform_co ( const int  v_index,
const float  disp[3],
FilterCache filter_cache 
)
static

◆ cloth_filter_apply_forces_task_cb()

static void cloth_filter_apply_forces_task_cb ( void *__restrict  userdata,
const int  i,
const TaskParallelTLS *__restrict   UNUSEDtls 
)
static

◆ cloth_filter_apply_forces_to_vertices()

static void cloth_filter_apply_forces_to_vertices ( const int  v_index,
const float  force[3],
const float  gravity[3],
FilterCache filter_cache 
)
static

◆ cloth_filter_is_deformation_filter()

static bool cloth_filter_is_deformation_filter ( eSculptClothFilterType  filter_type)
static

Definition at line 1375 of file sculpt_cloth.c.

References CLOTH_FILTER_SCALE, and ELEM.

Referenced by cloth_filter_apply_forces_task_cb(), and sculpt_cloth_filter_invoke().

◆ cloth_sim_initialize_default_node_state()

static void cloth_sim_initialize_default_node_state ( SculptSession ss,
SculptClothSimulation cloth_sim 
)
static

◆ do_cloth_brush_apply_forces_task_cb_ex()

static void do_cloth_brush_apply_forces_task_cb_ex ( void *__restrict  userdata,
const int  n,
const TaskParallelTLS *__restrict  tls 
)
static

Definition at line 459 of file sculpt_cloth.c.

References add_v3_v3v3(), BKE_pbvh_vertex_iter_begin, BKE_pbvh_vertex_iter_end, BLI_task_parallel_thread_id(), BRUSH_CLOTH_DEFORM_DRAG, BRUSH_CLOTH_DEFORM_EXPAND, BRUSH_CLOTH_DEFORM_GRAB, BRUSH_CLOTH_DEFORM_INFLATE, BRUSH_CLOTH_DEFORM_PINCH_PERPENDICULAR, BRUSH_CLOTH_DEFORM_PINCH_POINT, BRUSH_CLOTH_DEFORM_PUSH, BRUSH_CLOTH_DEFORM_SNAKE_HOOK, BRUSH_CLOTH_FORCE_FALLOFF_PLANE, StrokeCache::bstrength, SculptSession::cache, clamp_f(), cloth_brush_apply_force_to_vertex(), cloth_brush_simulation_falloff_get(), cloth_brush_simulation_location_get(), Brush::cloth_deform_type, Brush::cloth_force_falloff_type, StrokeCache::cloth_sim, PBVHVertexIter::co, copy_v3_v3(), data, SculptClothSimulation::deformation_pos, SculptClothSimulation::deformation_strength, SculptBrushTest::dist, dist_signed_to_plane_v3(), dist_to_plane_v3(), blender::math::distance(), dot_v3v3(), fade(), float(), PBVHVertexIter::fno, StrokeCache::grab_delta_symmetry, StrokeCache::gravity_direction, PBVHVertexIter::index, SculptClothSimulation::init_pos, StrokeCache::last_location, SculptClothSimulation::length_constraint_tweak, StrokeCache::location, madd_v3_v3fl(), madd_v3_v3v3fl(), PBVHVertexIter::mask, mul_v3_fl(), mul_v3_v3fl(), PBVHVertexIter::no, normalize_v3(), normalize_v3_v3(), offset, SculptSession::pbvh, PBVH_ITER_UNIQUE, plane_from_point_normal_v3(), SculptClothSimulation::pos, StrokeCache::radius, SCULPT_brush_strength_factor(), SCULPT_brush_test_init_with_falloff_shape(), sqrtf, sub_v3_v3v3(), StrokeCache::supports_gravity, blender::threading::enumerable_thread_specific_utils::thread_id, and zero_v3().

Referenced by cloth_brush_apply_brush_foces().

◆ do_cloth_brush_build_constraints_task_cb_ex()

static void do_cloth_brush_build_constraints_task_cb_ex ( void *__restrict  userdata,
const int  n,
const TaskParallelTLS *__restrict   UNUSEDtls 
)
static

◆ 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   UNUSEDtls 
)
static

◆ SCULPT_cloth_brush_affected_nodes_gather()

PBVHNode** SCULPT_cloth_brush_affected_nodes_gather ( SculptSession ss,
Brush brush,
int *  r_totnode 
)

◆ SCULPT_cloth_brush_do_simulation_step()

void SCULPT_cloth_brush_do_simulation_step ( Sculpt sd,
Object ob,
SculptClothSimulation cloth_sim,
PBVHNode **  nodes,
int  totnode 
)

◆ SCULPT_cloth_brush_ensure_nodes_constraints()

void SCULPT_cloth_brush_ensure_nodes_constraints ( Sculpt sd,
Object ob,
PBVHNode **  nodes,
int  totnode,
SculptClothSimulation cloth_sim,
float  initial_location[3],
const float  radius 
)

◆ SCULPT_cloth_brush_simulation_create()

SculptClothSimulation* SCULPT_cloth_brush_simulation_create ( Object ob,
const float  cloth_mass,
const float  cloth_damping,
const float  cloth_softbody_strength,
const bool  use_collisions,
const bool  needs_deform_coords 
)

◆ SCULPT_cloth_brush_simulation_init()

void SCULPT_cloth_brush_simulation_init ( SculptSession ss,
SculptClothSimulation cloth_sim 
)

◆ SCULPT_cloth_brush_store_simulation_state()

void SCULPT_cloth_brush_store_simulation_state ( SculptSession ss,
SculptClothSimulation cloth_sim 
)

◆ sculpt_cloth_ensure_constraints_in_simulation_area()

static void sculpt_cloth_ensure_constraints_in_simulation_area ( Sculpt sd,
Object ob,
PBVHNode **  nodes,
int  totnode 
)
static

◆ sculpt_cloth_filter_invoke()

static int sculpt_cloth_filter_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ sculpt_cloth_filter_modal()

static int sculpt_cloth_filter_modal ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ SCULPT_cloth_plane_falloff_preview_draw()

void SCULPT_cloth_plane_falloff_preview_draw ( const uint  gpuattr,
SculptSession ss,
const float  outline_col[3],
float  outline_alpha 
)

◆ SCULPT_cloth_sim_activate_nodes()

void SCULPT_cloth_sim_activate_nodes ( SculptClothSimulation cloth_sim,
PBVHNode **  nodes,
int  totnode 
)

◆ SCULPT_cloth_simulation_free()

void SCULPT_cloth_simulation_free ( struct SculptClothSimulation cloth_sim)

◆ SCULPT_cloth_simulation_limits_draw()

void SCULPT_cloth_simulation_limits_draw ( const uint  gpuattr,
const Brush brush,
const float  location[3],
const float  normal[3],
const float  rds,
const float  line_width,
const float  outline_col[3],
const float  alpha 
)

◆ SCULPT_do_cloth_brush()

void SCULPT_do_cloth_brush ( Sculpt sd,
Object ob,
PBVHNode **  nodes,
int  totnode 
)

◆ SCULPT_OT_cloth_filter()

void SCULPT_OT_cloth_filter ( struct wmOperatorType ot)

Variable Documentation

◆ prop_cloth_filter_force_axis_items

EnumPropertyItem prop_cloth_filter_force_axis_items[]
static
Initial value:
= {
{CLOTH_FILTER_FORCE_X, "X", 0, "X", "Apply force in the X axis"},
{CLOTH_FILTER_FORCE_Y, "Y", 0, "Y", "Apply force in the Y axis"},
{CLOTH_FILTER_FORCE_Z, "Z", 0, "Z", "Apply force in the Z axis"},
{0, NULL, 0, NULL, NULL},
}
@ CLOTH_FILTER_FORCE_Z
@ CLOTH_FILTER_FORCE_X
@ CLOTH_FILTER_FORCE_Y

Definition at line 1368 of file sculpt_cloth.c.

Referenced by SCULPT_OT_cloth_filter().

◆ prop_cloth_filter_orientation_items

EnumPropertyItem prop_cloth_filter_orientation_items[]
static
Initial value:
= {
"LOCAL",
0,
"Local",
"Use the local axis to limit the force and set the gravity direction"},
"WORLD",
0,
"World",
"Use the global axis to limit the force and set the gravity direction"},
"VIEW",
0,
"View",
"Use the view axis to limit the force and set the gravity direction"},
{0, NULL, 0, NULL, NULL},
}
@ SCULPT_FILTER_ORIENTATION_WORLD
@ SCULPT_FILTER_ORIENTATION_VIEW
@ SCULPT_FILTER_ORIENTATION_LOCAL

Definition at line 1343 of file sculpt_cloth.c.

Referenced by SCULPT_OT_cloth_filter().

◆ prop_cloth_filter_type

EnumPropertyItem prop_cloth_filter_type[]
static
Initial value:
= {
{CLOTH_FILTER_GRAVITY, "GRAVITY", 0, "Gravity", "Applies gravity to the simulation"},
{CLOTH_FILTER_INFLATE, "INFLATE", 0, "Inflate", "Inflates the cloth"},
{CLOTH_FILTER_EXPAND, "EXPAND", 0, "Expand", "Expands the cloth's dimensions"},
{CLOTH_FILTER_PINCH, "PINCH", 0, "Pinch", "Pulls the cloth to the cursor's start position"},
"SCALE",
0,
"Scale",
"Scales the mesh as a soft body using the origin of the object as scale"},
{0, NULL, 0, NULL, NULL},
}
@ CLOTH_FILTER_SCALE
@ CLOTH_FILTER_GRAVITY
@ CLOTH_FILTER_INFLATE
@ CLOTH_FILTER_EXPAND
@ CLOTH_FILTER_PINCH

Definition at line 1330 of file sculpt_cloth.c.

Referenced by SCULPT_OT_cloth_filter().