146 if (
verts && vert_tris) {
148 float co[3][3], co_moving[3][3];
261 bool vert_mass_changed =
false;
278 if (vert_mass_changed) {
325 float (*vertexCos)[3])
330 int framenr, startframe, endframe;
352 if (framenr < startframe) {
356 framenr = std::min(framenr, endframe);
363 if (framenr == startframe) {
434 Cloth *cloth =
nullptr;
450 if (cloth->
springs !=
nullptr) {
459 search = search->
next;
495 Cloth *cloth =
nullptr;
497 printf(
"cloth_free_modifier_extern\n");
508 printf(
"cloth_free_modifier_extern in\n");
518 if (cloth->
springs !=
nullptr) {
527 search = search->
next;
581 mul_m4_v3(ob->world_to_object().ptr(), vertexCos[
i]);
603 if (!clmd || !mesh) {
614 for (
int i = 0;
i < mvert_num;
i++,
verts++) {
625 verts->shrink_factor = 0.0f;
633 for (
int j = 0; j < dvert->
totweight; j++) {
700 float k1 = base + shrink_factor_delta *
verts[i1].shrink_factor;
701 float k2 = base + shrink_factor_delta *
verts[i2].shrink_factor;
705 return sqrtf(k1 * k2);
714 const float (*shapekey_rest)[3] =
nullptr;
715 const float tnull[3] = {0, 0, 0};
721 printf(
"cloth_free_modifier cloth_from_object\n");
749 shapekey_rest =
static_cast<const float (*)[3]
>(
775 verts->impulse_count = 0;
784 verts->shrink_factor = 0.0f;
793 verts->impulse_count = 0;
890 for (
uint i = 0;
i < mvert_num;
i++) {
902 if (cloth->
springs !=
nullptr) {
911 search = search->
next;
929 float fact = 1.0f /
len;
931 for (
int x = 0;
x <
len;
x++) {
941 float dir_a[3], dir_b[3];
942 float tmp[3], vec_e[3];
966 float hair_frame[3][3], dir_old[3], dir_new[3];
982 for (search = cloth->
springs; search; search = search->
next) {
985 bool is_root = spring->
kl != prev_mn;
1016 prev_mn = spring->
mn;
1024 float hair_frame[3][3], dir_old[3], dir_new[3];
1040 for (search = cloth->
springs; search; search = search->
next) {
1043 bool is_root = spring->
kl != prev_mn;
1071 prev_mn = spring->
mn;
1140 search = search->
next;
1171 positions[
i] =
verts[
i].xrest;
1173 new_mesh->tag_positions_changed();
1183 uint struct_springs = 0;
1186 float shrink_factor;
1190 for (
i = 0;
i < mvert_num;
i++) {
1204 shrink_factor = 1.0f;
1212 cloth->
verts, spring->
ij, spring->
kl, spring->
pa, spring->
pb, spring->
la, spring->
lb);
1223 search = search->
next;
1226 if (struct_springs > 0) {
1230 for (
i = 0;
i < mvert_num;
i++) {
1251 r[0][0] += m[0][0] * f;
1252 r[0][1] += m[0][1] * f;
1253 r[0][2] += m[0][2] * f;
1254 r[1][0] += m[1][0] * f;
1255 r[1][1] += m[1][1] * f;
1256 r[1][2] += m[1][2] * f;
1257 r[2][0] += m[2][0] * f;
1258 r[2][1] += m[2][1] * f;
1259 r[2][2] += m[2][2] * f;
1263 const float dir_old[3],
1264 const float dir_new[3])
1286 const int *tmp_corner;
1287 float shrink_factor;
1316 spring->
la = k - j + 1;
1317 spring->
lb =
faces[
i].size() - k + j + 1;
1329 tmp_corner = &corner_verts[
faces[
i].start()];
1331 for (
x = 0;
x < spring->
la;
x++) {
1332 spring->
pa[
x] = tmp_corner[j +
x];
1335 for (
x = 0;
x <= j;
x++) {
1336 spring->
pb[
x] = tmp_corner[
x];
1340 spring->
pb[
x] = tmp_corner[
y];
1346 cloth->
verts, spring->
ij, spring->
kl, spring->
pa, spring->
pb, spring->
la, spring->
lb);
1366 for (
int i = 0;
i <
len;
i++) {
1367 p[
i] = corner_verts[
i];
1380 float max_diversion,
1384 float co[3], no[3], new_co[3];
1390 float vec_len =
sin(max_diversion);
1408 if (max_length == 0.0f) {
1414 rayhit.
dist = max_length;
1422 if (rayhit.
index != -1 && rayhit.
dist <= max_length) {
1423 if (check_normal &&
dot_v3v3(rayhit.
no, no) < 0.0f) {
1431 for (
int i = 0;
i < 3;
i++) {
1432 int tmp_vert_idx = corner_verts[tri[
i]];
1433 if (tmp_vert_idx == v_idx) {
1439 if (
len < min_len) {
1441 vert_idx = tmp_vert_idx;
1445 *r_tar_v_idx = vert_idx;
1457 ClothSpring *spring =
nullptr, *tspring =
nullptr, *tspring2 =
nullptr;
1458 uint struct_springs = 0, shear_springs = 0, bend_springs = 0, struct_springs_real = 0;
1462 float shrink_factor;
1469 LinkNode *search =
nullptr, *search2 =
nullptr;
1473 if (numedges == 0) {
1501 if (use_internal_springs && numface > 0) {
1503 Mesh *tmp_mesh =
nullptr;
1515 mesh->bvh_corner_tris();
1519 mesh->vert_normals();
1521 for (
int i = 0;
i < mvert_num;
i++) {
1532 if (existing_vert_pairs.
contains({i, tar_v_idx})) {
1537 existing_vert_pairs.
add({
i, tar_v_idx});
1558 spring_ref[
i].
spring = spring;
1571 existing_vert_pairs.
clear();
1579 for (
int i = 0;
i < mvert_num;
i++) {
1590 for (
int i = 0;
i < numedges;
i++) {
1620 struct_springs_real++;
1629 spring_ref[
i].
spring = spring;
1638 if (struct_springs_real > 0) {
1642 for (
int i = 0;
i < mvert_num;
i++) {
1652 for (
int i = 0;
i < numface;
i++) {
1656 for (
int j = 1; j <
faces[
i].size() - 1; j++) {
1671 for (
int k = j + 2; k <
faces[
i].size(); k++) {
1689 for (
int j = 0; j <
faces[
i].size(); j++) {
1690 const int edge_i = corner_edges[
faces[
i][j]];
1695 if (curr_ref->
face == 1) {
1699 else if (curr_ref->
face == 2) {
1700 spring = curr_ref->
spring;
1708 &spring->
pa, spring->
la, &corner_verts[
faces[curr_ref->
index].start()]) ||
1710 &spring->
pb, spring->
lb, &corner_verts[
faces[
i].start()]))
1716 spring->
mn = edge_i;
1733 else if (curr_ref->
face == 3) {
1734 spring = curr_ref->
spring;
1739 spring->
pa =
nullptr;
1740 spring->
pb =
nullptr;
1752 for (
int i = struct_springs;
i < struct_springs + shear_springs;
i++) {
1757 tspring2 =
static_cast<ClothSpring *
>(search2->link);
1758 search = edgelist[tspring2->kl].
list;
1762 index2 = ((tspring->ij == tspring2->kl) ? (tspring->kl) : (tspring->ij));
1766 if ((index2 != tspring2->ij) && !cloth->
edgeset.
contains({tspring2->ij, index2})) {
1789 search = search->
next;
1792 search2 = search2->
next;
1796 else if (struct_springs > 2) {
1797 if (
G.debug_value != 1112) {
1799 search2 = search->
next;
1800 while (search && search2) {
1802 tspring2 =
static_cast<ClothSpring *
>(search2->link);
1804 if (tspring->ij == tspring2->kl) {
1812 spring->
ij = tspring2->ij;
1813 spring->
kl = tspring->ij;
1814 spring->
mn = tspring->kl;
1826 search = search->
next;
1827 search2 = search2->
next;
1839 search2 = search->
next;
1840 while (search && search2) {
1842 tspring2 =
static_cast<ClothSpring *
>(search2->link);
1844 if (tspring->ij == tspring2->kl) {
1852 spring->
ij = tspring2->ij;
1853 spring->
kl = tspring->kl;
1865 search = search->
next;
1866 search2 = search2->
next;
1877 for (
int i = 0;
i < numedges;
i++) {
1881 for (
int i = 0;
i < numface;
i++) {
1890 cloth->
numsprings = struct_springs + shear_springs + bend_springs;
1895 if (
G.debug_value > 0) {
@ CLOTH_SPRING_TYPE_SEWING
@ CLOTH_SPRING_TYPE_SHEAR
@ CLOTH_SPRING_TYPE_BENDING_HAIR
@ CLOTH_SPRING_TYPE_STRUCTURAL
@ CLOTH_SPRING_TYPE_BENDING
@ CLOTH_SPRING_TYPE_INTERNAL
@ CLOTH_VERT_FLAG_NOSELFCOLL
@ CLOTH_VERT_FLAG_NOOBJCOLL
@ CLOTH_SPRING_FLAG_DEACTIVATE
CustomData interface, see also DNA_customdata_types.h.
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void BKE_effectors_free(struct ListBase *lb)
struct ListBase * BKE_effectors_create(struct Depsgraph *depsgraph, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool use_rotation)
void BKE_id_free(Main *bmain, void *idv)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
void BKE_modifier_set_error(const Object *ob, ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
#define PTCACHE_CLEAR_AFTER
void BKE_ptcache_validate(struct PointCache *cache, int framenr)
#define PTCACHE_READ_INTERPOLATED
int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd)
int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
#define PTCACHE_RESET_OUTDATED
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode)
void BKE_ptcache_invalidate(struct PointCache *cache)
#define PTCACHE_READ_EXACT
BVHTree * BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
void BLI_bvhtree_balance(BVHTree *tree)
void BLI_bvhtree_update_tree(BVHTree *tree)
void BLI_bvhtree_free(BVHTree *tree)
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints)
bool BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints)
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc)
void void void void BLI_linklist_append(LinkNodePair *list_pair, void *ptr) ATTR_NONNULL(1)
void void BLI_linklist_prepend(LinkNode **listp, void *ptr) ATTR_NONNULL(1)
MINLINE int compare_ff(float a, float b, float max_diff)
MINLINE float pow4f(float x)
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void zero_m3(float m[3][3])
void mul_m4_v3(const float M[4][4], float r[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void mul_transposed_m3_v3(const float M[3][3], float r[3])
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void rotation_between_vecs_to_mat3(float m[3][3], const float v1[3], const float v2[3])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
struct RNG * BLI_rng_new_srandom(unsigned int seed)
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
float DEG_get_ctime(const Depsgraph *graph)
@ CLOTH_COLLSETTINGS_FLAG_ENABLED
@ CLOTH_COLLSETTINGS_FLAG_SELF
@ CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH
@ CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL
@ CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL
@ CLOTH_SIMSETTINGS_FLAG_SEW
@ CLOTH_SIMSETTINGS_FLAG_PRESSURE
@ CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
void SIM_cloth_solver_free(ClothModifierData *clmd)
int SIM_cloth_solver_init(Object *, ClothModifierData *clmd)
void SIM_cloth_solver_set_volume(ClothModifierData *clmd)
void SIM_mass_spring_set_implicit_vertex_mass(Implicit_Data *data, int index, float mass)
void SIM_cloth_solver_set_positions(ClothModifierData *clmd)
int SIM_cloth_solve(Depsgraph *depsgraph, Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
BPy_StructRNA * depsgraph
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr IndexRange index_range() const
void reserve(const int64_t n)
bool contains(const Key &key) const
constexpr const T * data() const
constexpr int64_t size() const
constexpr bool is_empty() const
static int do_step_cloth(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, const Mesh *result, int framenr)
static bool cloth_build_springs(ClothModifierData *clmd, const Mesh *mesh)
static float cloth_spring_angle(ClothVertex *verts, int i, int j, int *i_a, int *i_b, int len_a, int len_b)
BLI_INLINE void cross_identity_v3(float r[3][3], const float v[3])
static void cloth_from_mesh(ClothModifierData *clmd, const Object *ob, const Mesh *mesh)
void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
BLI_INLINE void cloth_bend_poly_dir(ClothVertex *verts, int i, int j, const int *inds, int len, float r_dir[3])
static void cloth_to_object(Object *ob, ClothModifierData *clmd, float(*vertexCos)[3])
static void cloth_free_edgelist(LinkNodePair *edgelist, uint mvert_num)
static bool cloth_add_shear_bend_spring(ClothModifierData *clmd, LinkNodePair *edgelist, const blender::Span< int > corner_verts, const blender::OffsetIndices< int > faces, int i, int j, int k)
static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, int i1, int i2)
BLI_INLINE void madd_m3_m3fl(float r[3][3], const float m[3][3], float f)
static void cloth_update_spring_lengths(ClothModifierData *clmd, const Mesh *mesh)
static void cloth_hair_update_bending_rest_targets(ClothModifierData *clmd)
static void cloth_hair_update_bending_targets(ClothModifierData *clmd)
void cloth_free_modifier_extern(ClothModifierData *clmd)
void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self)
void clothModifier_do(ClothModifierData *clmd, Depsgraph *depsgraph, Scene *scene, Object *ob, const Mesh *mesh, float(*vertexCos)[3])
static void cloth_update_verts(Object *ob, ClothModifierData *clmd, const Mesh *mesh)
int cloth_uses_vgroup(ClothModifierData *clmd)
static void cloth_update_springs(ClothModifierData *clmd)
void cloth_parallel_transport_hair_frame(float mat[3][3], const float dir_old[3], const float dir_new[3])
BLI_INLINE bool cloth_bend_set_poly_vert_array(int **poly, int len, const int *corner_verts)
static Mesh * cloth_make_rest_mesh(ClothModifierData *clmd, const Mesh *mesh)
BLI_INLINE void spring_verts_ordered_set(ClothSpring *spring, int v0, int v1)
static void cloth_apply_vgroup(ClothModifierData *clmd, const Mesh *mesh)
static bool find_internal_spring_target_vertex(blender::bke::BVHTreeFromMesh *treedata, const blender::Span< blender::float3 > vert_normals, uint v_idx, RNG *rng, float max_length, float max_diversion, bool check_normal, int *r_tar_v_idx)
static bool cloth_from_object(Object *ob, ClothModifierData *clmd, const Mesh *mesh, float framenr, int first)
static void cloth_free_errorsprings(Cloth *cloth, LinkNodePair *edgelist, BendSpringRef *spring_ref)
void cloth_free_modifier(ClothModifierData *clmd)
static BVHTree * bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon)
static bool do_init_cloth(Object *ob, ClothModifierData *clmd, const Mesh *result, int framenr)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
void vert_tris_from_corner_tris(Span< int > corner_verts, Span< int3 > corner_tris, MutableSpan< int3 > vert_tris)
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
struct ClothHairData * hairdata
struct Cloth * clothObject
struct PointCache * point_cache
struct ClothSimSettings * sim_parms
struct ClothCollSettings * coll_parms
struct EffectorWeights * effector_weights
float internal_spring_max_length
float internal_spring_max_diversion
blender::Set< blender::OrderedEdge > edgeset
unsigned char old_solver_type
const blender::int2 * edges
blender::int3 * vert_tris
blender::Set< blender::OrderedEdge > sew_edge_graph
unsigned int primitive_num
ObjectRuntimeHandle * runtime
struct PointCache * cache
struct PTCacheEdit * edit
BVHTree_RayCastCallback raycast_callback
Span< float3 > vert_positions
blender::BitVector is_loose_bits