Blender  V3.3
Classes | Typedefs | Functions
cloth.c File Reference
#include "MEM_guardedalloc.h"
#include "DNA_cloth_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_edgehash.h"
#include "BLI_linklist.h"
#include "BLI_math.h"
#include "BLI_rand.h"
#include "BLI_utildefines.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "BKE_bvhutils.h"
#include "BKE_cloth.h"
#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_modifier.h"
#include "BKE_pointcache.h"
#include "SIM_mass_spring.h"

Go to the source code of this file.

Classes

struct  BendSpringRef
 

Typedefs

typedef struct BendSpringRef BendSpringRef
 

Functions

static void cloth_to_object (Object *ob, ClothModifierData *clmd, float(*vertexCos)[3])
 
static void cloth_from_mesh (ClothModifierData *clmd, const Object *ob, Mesh *mesh)
 
static bool cloth_from_object (Object *ob, ClothModifierData *clmd, Mesh *mesh, float framenr, int first)
 
static void cloth_apply_vgroup (ClothModifierData *clmd, Mesh *mesh)
 
static BVHTreebvhtree_build_from_cloth (ClothModifierData *clmd, float epsilon)
 
void bvhtree_update_from_cloth (ClothModifierData *clmd, bool moving, bool self)
 
void cloth_clear_cache (Object *ob, ClothModifierData *clmd, float framenr)
 
static bool do_init_cloth (Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
 
static int do_step_cloth (Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
 
void clothModifier_do (ClothModifierData *clmd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh, float(*vertexCos)[3])
 
void cloth_free_modifier (ClothModifierData *clmd)
 
void cloth_free_modifier_extern (ClothModifierData *clmd)
 
int cloth_uses_vgroup (ClothModifierData *clmd)
 
static float cloth_shrink_factor (ClothModifierData *clmd, ClothVertex *verts, int i1, int i2)
 
static bool cloth_from_object (Object *ob, ClothModifierData *clmd, Mesh *mesh, float UNUSED(framenr), int first)
 
Spring Network Building Implementation
static void cloth_update_springs (ClothModifierData *clmd)
 
static void cloth_update_verts (Object *ob, ClothModifierData *clmd, Mesh *mesh)
 
static void cloth_update_spring_lengths (ClothModifierData *clmd, Mesh *mesh)
 
static bool cloth_build_springs (ClothModifierData *clmd, Mesh *mesh)
 
BLI_INLINE void spring_verts_ordered_set (ClothSpring *spring, int v0, int v1)
 
static void cloth_free_edgelist (LinkNodePair *edgelist, unsigned int mvert_num)
 
static void cloth_free_errorsprings (Cloth *cloth, LinkNodePair *edgelist, BendSpringRef *spring_ref)
 
BLI_INLINE void cloth_bend_poly_dir (ClothVertex *verts, int i, int j, const int *inds, int len, float r_dir[3])
 
static float cloth_spring_angle (ClothVertex *verts, int i, int j, int *i_a, int *i_b, int len_a, int len_b)
 
static void cloth_hair_update_bending_targets (ClothModifierData *clmd)
 
static void cloth_hair_update_bending_rest_targets (ClothModifierData *clmd)
 
static Meshcloth_make_rest_mesh (ClothModifierData *clmd, Mesh *mesh)
 
BLI_INLINE void cross_identity_v3 (float r[3][3], const float v[3])
 
BLI_INLINE void madd_m3_m3fl (float r[3][3], const float m[3][3], float f)
 
void cloth_parallel_transport_hair_frame (float mat[3][3], const float dir_old[3], const float dir_new[3])
 
static bool cloth_add_shear_bend_spring (ClothModifierData *clmd, LinkNodePair *edgelist, const MLoop *mloop, const MPoly *mpoly, int i, int j, int k)
 
BLI_INLINE bool cloth_bend_set_poly_vert_array (int **poly, int len, const MLoop *mloop)
 
static bool find_internal_spring_target_vertex (BVHTreeFromMesh *treedata, unsigned int v_idx, RNG *rng, float max_length, float max_diversion, bool check_normal, unsigned int *r_tar_v_idx)
 

Typedef Documentation

◆ BendSpringRef

typedef struct BendSpringRef BendSpringRef

Function Documentation

◆ bvhtree_build_from_cloth()

static BVHTree* bvhtree_build_from_cloth ( ClothModifierData clmd,
float  epsilon 
)
static

◆ bvhtree_update_from_cloth()

void bvhtree_update_from_cloth ( ClothModifierData clmd,
bool  moving,
bool  self 
)

◆ cloth_add_shear_bend_spring()

static bool cloth_add_shear_bend_spring ( ClothModifierData clmd,
LinkNodePair edgelist,
const MLoop mloop,
const MPoly mpoly,
int  i,
int  j,
int  k 
)
static

◆ cloth_apply_vgroup()

static void cloth_apply_vgroup ( ClothModifierData clmd,
Mesh mesh 
)
static

◆ cloth_bend_poly_dir()

BLI_INLINE void cloth_bend_poly_dir ( ClothVertex verts,
int  i,
int  j,
const int *  inds,
int  len,
float  r_dir[3] 
)

Definition at line 929 of file cloth.c.

References len, madd_v3_v3fl(), normal_tri_v3(), verts, and x.

Referenced by cloth_spring_angle().

◆ cloth_bend_set_poly_vert_array()

BLI_INLINE bool cloth_bend_set_poly_vert_array ( int **  poly,
int  len,
const MLoop mloop 
)

Definition at line 1359 of file cloth.c.

References len, MEM_mallocN, and MLoop::v.

Referenced by cloth_build_springs().

◆ cloth_build_springs()

static bool cloth_build_springs ( ClothModifierData clmd,
Mesh mesh 
)
static

Definition at line 1453 of file cloth.c.

References ClothSpring::ang_stiffness, ClothVertex::avg_spring_len, ClothSimSettings::avg_spring_len, ClothVertex::bend_stiff, ClothSimSettings::bending_model, BKE_bvhtree_from_mesh_get(), BKE_id_free(), BLI_assert, BLI_edgeset_add(), BLI_edgeset_free(), BLI_edgeset_haskey(), BLI_edgeset_insert(), BLI_edgeset_new(), BLI_edgeset_new_ex(), BLI_linklist_prepend(), BLI_rng_free(), BLI_rng_new_srandom(), BVHTREE_FROM_LOOPTRI, cloth_add_shear_bend_spring(), cloth_bend_set_poly_vert_array(), CLOTH_BENDING_ANGULAR, CLOTH_BENDING_LINEAR, cloth_free_edgelist(), cloth_free_errorsprings(), cloth_hair_update_bending_rest_targets(), cloth_make_rest_mesh(), cloth_shrink_factor(), CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH, CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS, CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL, CLOTH_SIMSETTINGS_FLAG_SEW, cloth_spring_angle(), CLOTH_SPRING_TYPE_BENDING, CLOTH_SPRING_TYPE_BENDING_HAIR, CLOTH_SPRING_TYPE_INTERNAL, CLOTH_SPRING_TYPE_SEWING, CLOTH_SPRING_TYPE_STRUCTURAL, ClothModifierData::clothObject, MLoop::e, Cloth::edgeset, find_internal_spring_target_vertex(), ClothSpring::flags, ClothSimSettings::flags, float(), free_bvhtree_from_mesh(), G, Mesh::id, if(), ClothSpring::ij, BendSpringRef::index, ClothSimSettings::internal_spring_max_diversion, ClothSimSettings::internal_spring_max_length, ClothVertex::internal_stiff, ClothSpring::kl, ClothSpring::la, ClothSpring::lb, len_v3v3(), ClothSpring::lin_stiffness, LinkNode::link, ME_LOOSEEDGE, Mesh::medge, MEM_callocN, MEM_freeN, MEM_SAFE_FREE, mesh, Mesh::mloop, ClothSpring::mn, Mesh::mpoly, LinkNode::next, NULL, Cloth::numsprings, ClothSpring::pa, ClothSpring::pb, BendSpringRef::polys, ClothSpring::restang, ClothSpring::restlen, Cloth::sew_edge_graph, ClothSimSettings::shapekey_rest, ClothModifierData::sim_parms, BendSpringRef::spring, ClothVertex::spring_count, spring_verts_ordered_set(), Cloth::springs, ClothVertex::struct_stiff, Mesh::totedge, Mesh::totpoly, Mesh::totvert, ClothSpring::type, v, v1, v2, Cloth::verts, and ClothVertex::xrest.

Referenced by cloth_from_object().

◆ cloth_clear_cache()

void cloth_clear_cache ( Object ob,
ClothModifierData clmd,
float  framenr 
)

◆ cloth_free_edgelist()

static void cloth_free_edgelist ( LinkNodePair edgelist,
unsigned int  mvert_num 
)
static

Definition at line 888 of file cloth.c.

References BLI_linklist_free(), MEM_freeN, and NULL.

Referenced by cloth_build_springs(), and cloth_free_errorsprings().

◆ cloth_free_errorsprings()

static void cloth_free_errorsprings ( Cloth cloth,
LinkNodePair edgelist,
BendSpringRef spring_ref 
)
static

◆ cloth_free_modifier()

void cloth_free_modifier ( struct ClothModifierData clmd)

◆ cloth_free_modifier_extern()

void cloth_free_modifier_extern ( struct ClothModifierData clmd)

◆ cloth_from_mesh()

static void cloth_from_mesh ( ClothModifierData clmd,
const Object ob,
Mesh mesh 
)
static

◆ cloth_from_object() [1/2]

static bool cloth_from_object ( Object ob,
ClothModifierData clmd,
Mesh mesh,
float  framenr,
int  first 
)
static

Referenced by do_init_cloth().

◆ cloth_from_object() [2/2]

static bool cloth_from_object ( Object ob,
ClothModifierData clmd,
Mesh mesh,
float   UNUSEDframenr,
int  first 
)
static

◆ cloth_hair_update_bending_rest_targets()

static void cloth_hair_update_bending_rest_targets ( ClothModifierData clmd)
static

◆ cloth_hair_update_bending_targets()

static void cloth_hair_update_bending_targets ( ClothModifierData clmd)
static

◆ cloth_make_rest_mesh()

static Mesh* cloth_make_rest_mesh ( ClothModifierData clmd,
Mesh mesh 
)
static

◆ cloth_parallel_transport_hair_frame()

void cloth_parallel_transport_hair_frame ( float  mat[3][3],
const float  dir_old[3],
const float  dir_new[3] 
)

◆ cloth_shrink_factor()

static float cloth_shrink_factor ( ClothModifierData clmd,
ClothVertex verts,
int  i1,
int  i2 
)
static

◆ cloth_spring_angle()

static float cloth_spring_angle ( ClothVertex verts,
int  i,
int  j,
int *  i_a,
int *  i_b,
int  len_a,
int  len_b 
)
static

◆ cloth_to_object()

static void cloth_to_object ( Object ob,
ClothModifierData clmd,
float(*)  vertexCos[3] 
)
static

Copies the deformed vertices to the object.

Definition at line 577 of file cloth.c.

References ClothModifierData::clothObject, copy_v3_v3(), Object::imat, invert_m4_m4(), mul_m4_v3(), Cloth::mvert_num, Object::obmat, Cloth::verts, and ClothVertex::x.

Referenced by clothModifier_do().

◆ cloth_update_spring_lengths()

static void cloth_update_spring_lengths ( ClothModifierData clmd,
Mesh mesh 
)
static

◆ cloth_update_springs()

static void cloth_update_springs ( ClothModifierData clmd)
static

◆ cloth_update_verts()

static void cloth_update_verts ( Object ob,
ClothModifierData clmd,
Mesh mesh 
)
static

◆ cloth_uses_vgroup()

int cloth_uses_vgroup ( ClothModifierData clmd)

◆ clothModifier_do()

void clothModifier_do ( ClothModifierData clmd,
Depsgraph depsgraph,
Scene scene,
Object ob,
Mesh mesh,
float(*)  vertexCos[3] 
)

◆ cross_identity_v3()

BLI_INLINE void cross_identity_v3 ( float  r[3][3],
const float  v[3] 
)

Definition at line 1238 of file cloth.c.

References r, v, and zero_m3().

◆ do_init_cloth()

static bool do_init_cloth ( Object ob,
ClothModifierData clmd,
Mesh result,
int  framenr 
)
static

◆ do_step_cloth()

static int do_step_cloth ( Depsgraph depsgraph,
Object ob,
ClothModifierData clmd,
Mesh result,
int  framenr 
)
static

◆ find_internal_spring_target_vertex()

static bool find_internal_spring_target_vertex ( BVHTreeFromMesh treedata,
unsigned int  v_idx,
RNG rng,
float  max_length,
float  max_diversion,
bool  check_normal,
unsigned int *  r_tar_v_idx 
)
static

◆ madd_m3_m3fl()

BLI_INLINE void madd_m3_m3fl ( float  r[3][3],
const float  m[3][3],
float  f 
)

Definition at line 1249 of file cloth.c.

References r.

◆ spring_verts_ordered_set()

BLI_INLINE void spring_verts_ordered_set ( ClothSpring spring,
int  v0,
int  v1 
)

Definition at line 876 of file cloth.c.

References ClothSpring::ij, ClothSpring::kl, and v1.

Referenced by cloth_add_shear_bend_spring(), and cloth_build_springs().