[Bf-blender-cvs] [c8d8f1b793f] soc-2019-adaptive-cloth: Cloth: remove redundant code
ishbosamiya
noreply at git.blender.org
Fri Jun 28 19:52:36 CEST 2019
Commit: c8d8f1b793fc9fa124961e04160aac4cfe66f5cf
Author: ishbosamiya
Date: Thu Jun 27 12:50:16 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rBc8d8f1b793fc9fa124961e04160aac4cfe66f5cf
Cloth: remove redundant code
===================================================================
M source/blender/blenkernel/intern/cloth.c
===================================================================
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 4571fe832b2..fef64c41231 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -439,84 +439,6 @@ static void cloth_remeshing_init_bmesh(Object *ob, ClothModifierData *clmd, Mesh
clmd->clothObject->bm = clmd->clothObject->bm_prev;
}
-/* similar to cloth_free_modifier() but does not free everything, used when the number of verts
- * change */
-static void cloth_remeshing_cloth_object_free(Cloth *cloth)
-{
- if (cloth->implicit) {
- BPH_mass_spring_solver_free(cloth->implicit);
- cloth->implicit = NULL;
- }
-
- // Free the verts.
- if (cloth->verts != NULL) {
- MEM_freeN(cloth->verts);
- }
-
- cloth->verts = NULL;
- cloth->mvert_num = 0;
-
- // Free the springs.
- if (cloth->springs != NULL) {
- LinkNode *search = cloth->springs;
- while (search) {
- ClothSpring *spring = search->link;
-
- MEM_SAFE_FREE(spring->pa);
- MEM_SAFE_FREE(spring->pb);
-
- MEM_freeN(spring);
- search = search->next;
- }
- BLI_linklist_free(cloth->springs, NULL);
-
- cloth->springs = NULL;
- }
-
- cloth->springs = NULL;
- cloth->numsprings = 0;
-
- // we save our faces for collision objects
- if (cloth->tri) {
- MEM_freeN(cloth->tri);
- }
-
- if (cloth->edgeset) {
- BLI_edgeset_free(cloth->edgeset);
- }
-
-#if 0
- if (clmd->clothObject->facemarks) {
- MEM_freeN(clmd->clothObject->facemarks);
- }
-#endif
- MEM_freeN(cloth);
-}
-
-static void cloth_copy_cloth_vertex(ClothVertex *r, ClothVertex *src)
-{
- r->flags = src->flags;
- copy_v3_v3(r->v, src->v);
- copy_v3_v3(r->xconst, src->xconst);
- copy_v3_v3(r->x, src->x);
- copy_v3_v3(r->xold, src->xold);
- copy_v3_v3(r->tx, src->tx);
- copy_v3_v3(r->txold, src->txold);
- copy_v3_v3(r->tv, src->tv);
- copy_v3_v3(r->impulse, src->impulse);
- copy_v3_v3(r->xrest, src->xrest);
- copy_v3_v3(r->dcvel, src->dcvel);
- r->mass = src->mass;
- r->goal = src->goal;
- r->impulse_count = src->impulse_count;
- r->avg_spring_len = src->avg_spring_len;
- r->struct_stiff = src->struct_stiff;
- r->bend_stiff = src->bend_stiff;
- r->shear_stiff = src->shear_stiff;
- r->spring_count = src->spring_count;
- r->shrink_factor = src->shrink_factor;
-}
-
static ClothVertex cloth_remeshing_mean_cloth_vert(ClothVertex *v1, ClothVertex *v2)
{
ClothVertex new_vert;
@@ -564,109 +486,6 @@ static ClothVertex cloth_remeshing_mean_cloth_vert(ClothVertex *v1, ClothVertex
return new_vert;
}
-static void cloth_remeshing_update_cloth_object_mesh(ClothModifierData *clmd, Mesh *mesh)
-{
- Cloth *cloth = clmd->clothObject;
-
- /* We need to update Cloth only if number of verts change */
- if (mesh->totvert == cloth->mvert_num) {
- return;
- }
-
- Cloth *new_cloth = MEM_callocN(sizeof(Cloth), "New Cloth Object");
-
- /* copy most attributes from previous cloth data except:
- * verts, springs, tri, implicit, and
- * edgeset */
- new_cloth->old_solver_type = cloth->old_solver_type;
- new_cloth->bm = cloth->bm;
- new_cloth->bm_prev = cloth->bm_prev;
- new_cloth->bvhtree = cloth->bvhtree;
- new_cloth->bvhselftree = cloth->bvhselftree;
- new_cloth->last_frame = cloth->last_frame;
-
- /* start to either copy the verts */
- new_cloth->mvert_num = mesh->totvert;
- new_cloth->verts = MEM_callocN(sizeof(ClothVertex) * new_cloth->mvert_num,
- "New Cloth Object Verts");
-
- int new_vert_count = 0;
- for (int i = 0; i < mesh->totvert; i++) {
- MVert *mvert = &mesh->mvert[i];
- /* if new vert */
- if (mvert->flag & SELECT) {
- new_vert_count++;
-
- /* We search the previous and next vertices until
- * we find a vert that has not been selected
- * and count how many selected verts between these 2
- * This can give us a factor that we use while
- * finding the values for that vertex. */
- int prev_count = 0, next_count = 0;
- MVert *prev_mvert, *next_mvert;
- for (int j = mesh->totvert - 1; j >= 0; j--) {
- prev_count++;
- if (!(mesh->mvert[(i + j) % mesh->totvert].flag & SELECT)) {
- prev_mvert = &mesh->mvert[(i + j) % mesh->totvert];
- break;
- }
- }
- for (int j = 0; j < mesh->totvert; j++) {
- next_count++;
- if (!(mesh->mvert[(i + j) % mesh->totvert].flag & SELECT)) {
- next_mvert = &mesh->mvert[(i + j) % mesh->totvert];
- break;
- }
- }
- int tot_count = prev_count + next_count;
- float factor = (float)prev_count / (float)tot_count;
- /* need to find prev_mvert and next_mvert's corresponding ClothVertex */
- ClothVertex prev_vert;
- ClothVertex next_vert;
- for (int j = i - 1; j >= 0; j--) {
- /* CHECKHERE(Ish) */
- if (equals_v3v3(prev_mvert->co, cloth->verts[j].xold)) {
- /* cloth_copy_cloth_vertex(&prev_vert, &cloth->verts[j]); */
- prev_vert = cloth->verts[j];
- break;
- }
- }
- for (int j = i; j < cloth->mvert_num; j++) {
- /* CHECKHERE(Ish) */
- if (equals_v3v3(next_mvert->co, cloth->verts[j].xold)) {
- /* cloth_copy_cloth_vertex(&next_vert, &cloth->verts[j]); */
- next_vert = cloth->verts[j];
- break;
- }
- }
- new_cloth->verts[i] = cloth_remeshing_mean_cloth_vert(&prev_vert, &next_vert);
- }
- /* if old vert */
- else {
- for (int j = 0; j < cloth->mvert_num; j++) {
- /* CHECKHERE(Ish) */
- if (equals_v3v3(mvert->co, cloth->verts[j].xold)) {
- /* cloth_copy_cloth_vertex(&new_cloth->verts[i], &cloth->verts[j]); */
- new_cloth->verts[i] = cloth->verts[j];
- break;
- }
- }
- }
- }
-
- /* set clothObject to new_cloth and free cloth */
- clmd->clothObject = new_cloth;
- cloth_remeshing_cloth_object_free(cloth);
- cloth = NULL;
-
- /* Tag all verts as old */
- BMVert *v;
- BMIter iter;
- BM_ITER_MESH (v, &iter, clmd->clothObject->bm, BM_VERTS_OF_MESH) {
- BM_elem_flag_disable(v, BM_ELEM_SELECT);
- }
-}
-
static Mesh *cloth_remeshing_update_cloth_object_bmesh(Object *ob, ClothModifierData *clmd)
{
Mesh *mesh_result = NULL;
More information about the Bf-blender-cvs
mailing list