Commit: dc45061510e29e44d889eb3dd20fe8357b3b36cb Author: ishbosamiya Date: Fri Jul 26 00:33:49 2019 +0530 Branches: soc-2019-adaptive-cloth https://developer.blender.org/rBdc45061510e29e44d889eb3dd20fe8357b3b36cb
Cloth: initial steps towards creating a mapping between BMVert* and ClothVertex for improving efficiency =================================================================== M source/blender/blenkernel/BKE_cloth.h M source/blender/blenkernel/BKE_cloth_remeshing.h M source/blender/blenkernel/intern/cloth.c M source/blender/blenkernel/intern/cloth_remeshing.cpp =================================================================== diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index 8b344414e5c..968e69ffa70 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -34,6 +34,7 @@ struct Mesh; struct Object; struct Scene; struct BVHTree; +struct ClothSizing; #define DO_INLINE MALWAYS_INLINE @@ -125,8 +126,9 @@ typedef struct ClothVertex { float struct_stiff; float bend_stiff; float shear_stiff; - int spring_count; /* how many springs attached? */ - float shrink_factor; /* how much to shrink this cloth */ + int spring_count; /* how many springs attached? */ + float shrink_factor; /* how much to shrink this cloth */ + struct ClothSizing *sizing; /* Sizing during adaptive remeshing */ } ClothVertex; /** diff --git a/source/blender/blenkernel/BKE_cloth_remeshing.h b/source/blender/blenkernel/BKE_cloth_remeshing.h index de65a177973..c3b1c5506bb 100644 --- a/source/blender/blenkernel/BKE_cloth_remeshing.h +++ b/source/blender/blenkernel/BKE_cloth_remeshing.h @@ -31,6 +31,7 @@ struct ClothModifierData; struct Mesh; struct Object; +struct ClothSizing; #ifdef __cplusplus extern "C" { @@ -40,6 +41,27 @@ Mesh *cloth_remeshing_step(Depsgraph *depsgraph, Object *ob, ClothModifierData * #ifdef __cplusplus } -#endif +/** + *The definition of sizing used for remeshing + */ + +/* TODO(Ish): figure out how to write a wrapper that can be used in c when ClothSizing is converted + * to a class */ +typedef struct ClothSizing { + float m[2][2]; + ClothSizing() + { + zero_m2(m); + } + ClothSizing(float a[2][2]) + { + copy_m2_m2(m, a); + } + ClothSizing &operator+=(const ClothSizing &size); + ClothSizing &operator/=(float value); + ClothSizing operator*(float value); +} ClothSizing; + +#endif #endif diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 320857984f3..430887e1c0e 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -570,6 +570,12 @@ void cloth_free_modifier(ClothModifierData *clmd) // Free the verts. if (cloth->verts != NULL) { + for (int i = 0; i < cloth->mvert_num; i++) { + if (cloth->verts[i].sizing != NULL) { + MEM_freeN(cloth->verts[i].sizing); + cloth->verts[i].sizing = NULL; + } + } MEM_freeN(cloth->verts); } @@ -656,6 +662,12 @@ void cloth_free_modifier_extern(ClothModifierData *clmd) // Free the verts. if (cloth->verts != NULL) { + for (int i = 0; i < cloth->mvert_num; i++) { + if (cloth->verts[i].sizing != NULL) { + MEM_freeN(cloth->verts[i].sizing); + cloth->verts[i].sizing = NULL; + } + } MEM_freeN(cloth->verts); } @@ -955,6 +967,7 @@ static int cloth_from_object( verts->impulse_count = 0; copy_v3_v3(verts->impulse, tnull); + verts->sizing = NULL; } // apply / set vertex groups diff --git a/source/blender/blenkernel/intern/cloth_remeshing.cpp b/source/blender/blenkernel/intern/cloth_remeshing.cpp index 4526693a49c..d641fcbeb67 100644 --- a/source/blender/blenkernel/intern/cloth_remeshing.cpp +++ b/source/blender/blenkernel/intern/cloth_remeshing.cpp @@ -78,30 +78,12 @@ using namespace std; * reference http://graphics.berkeley.edu/papers/Narain-AAR-2012-11/index.html ******************************************************************************/ +typedef map<BMVert *, ClothVertex> VertMap; + #define COLLAPSE_EDGES_DEBUG 1 #define NEXT(x) ((x) < 2 ? (x) + 1 : (x)-2) #define PREV(x) ((x) > 0 ? (x)-1 : (x) + 2) -/** - *The definition of sizing used for remeshing - */ -class ClothSizing { - public: - /* TODO(Ish): Make "m" private */ - float m[2][2]; - ClothSizing() - { - zero_m2(m); - } - ClothSizing(float a[2][2]) - { - copy_m2_m2(m, a); - } - ClothSizing &operator+=(const ClothSizing &size); - ClothSizing &operator/=(float value); - ClothSizing operator*(float value); -}; - ClothSizing &ClothSizing::operator+=(const ClothSizing &size) { add_m2_m2m2(m, m, size.m); @@ -716,6 +698,7 @@ static float cloth_remeshing_edge_size(BMesh *bm, float uv12[2]; sub_v2_v2v2(uv12, uv1, uv2); + return sqrtf( (cloth_remeshing_norm2(uv12, sizing[v1]) + cloth_remeshing_norm2(uv12, sizing[v2])) * 0.5f); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs