Bugfix: scaling/rotation/translation works again

This commit is contained in:
Daniel Genrich 2007-11-19 23:45:26 +00:00
parent b2705bbe5c
commit f28ab5de21
2 changed files with 18 additions and 18 deletions

@ -862,13 +862,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
/* create springs */
clmd->clothObject->springs = NULL;
clmd->clothObject->numsprings = -1;
if (!cloth_build_springs (clmd->clothObject, dm) )
{
modifier_setError (&(clmd->modifier), "Can't build springs.");
return 0;
}
/* set initial values */
for (i = 0; i < numverts; ++i)
{
@ -889,6 +883,12 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
clmd->clothObject->verts [i].impulse_count = 0;
VECCOPY ( clmd->clothObject->verts [i].impulse, tnull );
}
if (!cloth_build_springs (clmd->clothObject, dm) )
{
modifier_setError (&(clmd->modifier), "Can't build springs.");
return 0;
}
/* apply / set vertex groups */
if (clmd->sim_parms->vgroup_mass > 0)
@ -1044,7 +1044,6 @@ int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
unsigned int numverts = dm->getNumVerts ( dm );
unsigned int numedges = dm->getNumEdges ( dm );
unsigned int numfaces = dm->getNumFaces ( dm );
MVert *mvert = CDDM_get_verts ( dm );
MEdge *medge = CDDM_get_edges ( dm );
MFace *mface = CDDM_get_faces ( dm );
unsigned int index2 = 0; // our second vertex index
@ -1081,7 +1080,7 @@ int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
{
spring->ij = medge[i].v1;
spring->kl = medge[i].v2;
VECSUB ( temp, mvert[spring->kl].co, mvert[spring->ij].co );
VECSUB ( temp, cloth->x[spring->kl], cloth->x[spring->ij] );
spring->restlen = sqrt ( INPR ( temp, temp ) );
spring->type = CLOTH_SPRING_TYPE_STRUCTURAL;
spring->flags = 0;
@ -1102,7 +1101,7 @@ int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
spring->ij = mface[i].v1;
spring->kl = mface[i].v3;
VECSUB ( temp, mvert[spring->kl].co, mvert[spring->ij].co );
VECSUB ( temp, cloth->x[spring->kl], cloth->x[spring->ij] );
spring->restlen = sqrt ( INPR ( temp, temp ) );
spring->type = CLOTH_SPRING_TYPE_SHEAR;
@ -1119,7 +1118,7 @@ int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
spring->ij = mface[i].v2;
spring->kl = mface[i].v4;
VECSUB ( temp, mvert[spring->kl].co, mvert[spring->ij].co );
VECSUB ( temp, cloth->x[spring->kl], cloth->x[spring->ij] );
spring->restlen = sqrt ( INPR ( temp, temp ) );
spring->type = CLOTH_SPRING_TYPE_SHEAR;
@ -1156,7 +1155,7 @@ int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
spring->ij = tspring2->ij;
spring->kl = index2;
VECSUB ( temp, mvert[index2].co, mvert[tspring2->ij].co );
VECSUB ( temp, cloth->x[index2], cloth->x[tspring2->ij] );
spring->restlen = sqrt ( INPR ( temp, temp ) );
spring->type = CLOTH_SPRING_TYPE_BENDING;
BLI_edgehash_insert ( edgehash, spring->ij, index2, NULL );

@ -1233,6 +1233,7 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
VECADD(s->f, s->f, damping_force);
// Formula from Ascher / Boxman, Speeding up cloth simulation
// couldn't see any speedup
// if((dt * (k*dt + 2 * clmd->sim_parms->Cdis * 0.01)) > 0.01 )
{
dfdx_spring_type1(s->dfdx, dir,length,L,clmd->sim_parms->structural);
@ -1256,12 +1257,12 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
// DG: My formula to handle bending for the AIMEX scheme
// multiply with 1000 because of numerical problems
// if( ((k*1000)*dt*dt) < -0.18 )
if( ((k*1000.0)*dt*dt) < -0.18 )
{
dfdx_spring_type2(s->dfdx, dir,length,L,clmd->sim_parms->bending, cb);
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_BIG_FORCE;
}
// printf("(dt*k*dt) ): %f, k: %f\n", (dt*dt*k*-1.0), k);
// printf("(dt*k*dt) ): %f, k: %f\n", (dt*dt*(1000.0*k)), k);
}
}
}
@ -1279,8 +1280,8 @@ DO_INLINE int cloth_apply_spring_force(ClothModifierData *clmd, ClothSpring *s,
sub_fmatrix_fmatrix(dFdV[s->kl].m, dFdV[s->kl].m, s->dfdv);
add_fmatrix_fmatrix(dFdV[s->matrix_index].m, dFdV[s->matrix_index].m, s->dfdv);
}
else if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_BIG_FORCE))
return 0;
// else if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_BIG_FORCE))
// return 0;
sub_fmatrix_fmatrix(dFdX[s->ij].m, dFdX[s->ij].m, s->dfdx);
sub_fmatrix_fmatrix(dFdX[s->kl].m, dFdX[s->kl].m, s->dfdx);
@ -1466,8 +1467,8 @@ void simulate_implicit_euler(lfVector *Vnew, lfVector *lX, lfVector *lV, lfVecto
add_lfvectorS_lfvectorS(B, lF, dt, dFdXmV, (dt*dt), numverts);
// cg_filtered(dV, A, B, z, S); // conjugate gradient algorithm to solve Ax=b
cg_filtered_pre(dV, A, B, z, S, P, Pinv);
cg_filtered(dV, A, B, z, S); // conjugate gradient algorithm to solve Ax=b
// cg_filtered_pre(dV, A, B, z, S, P, Pinv);
// advance velocities
add_lfvector_lfvector(Vnew, lV, dV, numverts);