forked from bartvdbraak/blender
Fixed numerical issues, hardened it again.
This commit is contained in:
parent
4cb5470f82
commit
83c1dd78a6
@ -72,8 +72,8 @@ typedef struct ClothSpring {
|
||||
int matrix_index; /* needed for implicit solver (fast lookup) */
|
||||
int type; /* types defined in BKE_cloth.h ("springType") */
|
||||
int flags; /* defined in BKE_cloth.h, e.g. deactivated due to tearing */
|
||||
float dfdx[3][4];
|
||||
float dfdv[3][4];
|
||||
float dfdx[3][3];
|
||||
float dfdv[3][3];
|
||||
float f[3];
|
||||
} ClothSpring;
|
||||
|
||||
@ -91,13 +91,13 @@ typedef struct Cloth {
|
||||
unsigned int numothersprings;
|
||||
unsigned int numspringssave;
|
||||
unsigned int old_solver_type;
|
||||
float (*x)[4]; /* The current position of all vertices.*/
|
||||
float (*xold)[4]; /* The previous position of all vertices.*/
|
||||
float (*current_x)[4]; /* The TEMPORARY current position of all vertices.*/
|
||||
float (*current_xold)[4]; /* The TEMPORARY previous position of all vertices.*/
|
||||
float (*x)[3]; /* The current position of all vertices.*/
|
||||
float (*xold)[3]; /* The previous position of all vertices.*/
|
||||
float (*current_x)[3]; /* The TEMPORARY current position of all vertices.*/
|
||||
float (*current_xold)[3]; /* The TEMPORARY previous position of all vertices.*/
|
||||
float (*v)[4]; /* the current velocity of all vertices */
|
||||
float (*current_v)[4];
|
||||
float (*xconst)[4];
|
||||
float (*current_v)[3];
|
||||
float (*xconst)[3];
|
||||
} Cloth;
|
||||
|
||||
/* goal defines */
|
||||
|
@ -90,9 +90,9 @@ double tval()
|
||||
}
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
static struct timeval _tstart, _tend;
|
||||
static struct timezone tz;
|
||||
void tstart ( void )
|
||||
static struct timeval _tstart, _tend;
|
||||
static struct timezone tz;
|
||||
void tstart ( void )
|
||||
{
|
||||
gettimeofday ( &_tstart, &tz );
|
||||
}
|
||||
@ -133,11 +133,11 @@ static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, short v
|
||||
*
|
||||
******************************************************************************/
|
||||
/**
|
||||
* cloth_init - creates a new cloth simulation.
|
||||
*
|
||||
* 1. create object
|
||||
* 2. fill object with standard values or with the GUI settings if given
|
||||
*/
|
||||
* cloth_init - creates a new cloth simulation.
|
||||
*
|
||||
* 1. create object
|
||||
* 2. fill object with standard values or with the GUI settings if given
|
||||
*/
|
||||
void cloth_init (ClothModifierData *clmd)
|
||||
{
|
||||
/* Initialize our new data structure to reasonable values. */
|
||||
@ -206,7 +206,7 @@ DerivedMesh *CDDM_convert_to_triangle(DerivedMesh *dm)
|
||||
numquads++;
|
||||
else
|
||||
numtris++;
|
||||
}
|
||||
}
|
||||
|
||||
result = CDDM_from_template(dm, numverts, 0, numtris + 2*numquads);
|
||||
|
||||
@ -224,7 +224,7 @@ DerivedMesh *CDDM_convert_to_triangle(DerivedMesh *dm)
|
||||
|
||||
DM_copy_vert_data(dm, result, a, a, 1);
|
||||
*mv = *inMV;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// do faces
|
||||
@ -246,13 +246,13 @@ DerivedMesh *CDDM_convert_to_triangle(DerivedMesh *dm)
|
||||
mf->v1 = mface[a].v2;
|
||||
mf->v2 = mface[a].v3;
|
||||
mf->v3 = mface[a].v4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mf->v1 = mface[a].v1;
|
||||
mf->v2 = mface[a].v2;
|
||||
mf->v3 = mface[a].v3;
|
||||
}
|
||||
}
|
||||
|
||||
mf->v4 = 0;
|
||||
mf->flag |= ME_SMOOTH;
|
||||
@ -277,21 +277,21 @@ DerivedMesh *CDDM_convert_to_triangle(DerivedMesh *dm)
|
||||
mf2->v1 = mface[a].v1;
|
||||
mf2->v2 = mface[a].v2;
|
||||
mf2->v3 = mface[a].v4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mf2->v1 = mface[a].v4;
|
||||
mf2->v2 = mface[a].v1;
|
||||
mf2->v3 = mface[a].v3;
|
||||
}
|
||||
}
|
||||
mf2->v4 = 0;
|
||||
mf2->flag |= ME_SMOOTH;
|
||||
|
||||
test_index_face(mf2, NULL, 0, 3);
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
CDDM_calc_edges(result);
|
||||
CDDM_calc_normals(result);
|
||||
@ -336,8 +336,8 @@ DerivedMesh *CDDM_create_tearing(ClothModifierData *clmd, DerivedMesh *dm)
|
||||
BLI_edgehash_insert(edgehash, springs[i].ij, springs[i].kl, NULL);
|
||||
BLI_edgehash_insert(edgehash, springs[i].kl, springs[i].ij, NULL);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// printf("found %d tears\n", j);
|
||||
|
||||
@ -357,7 +357,7 @@ DerivedMesh *CDDM_create_tearing(ClothModifierData *clmd, DerivedMesh *dm)
|
||||
|
||||
DM_copy_vert_data(dm, result, a, a, 1);
|
||||
*mv = *inMV;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// do faces
|
||||
@ -387,8 +387,8 @@ DerivedMesh *CDDM_create_tearing(ClothModifierData *clmd, DerivedMesh *dm)
|
||||
test_index_face(mf, NULL, 0, 4);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CDDM_lower_num_faces(result, i);
|
||||
CDDM_calc_edges(result);
|
||||
@ -536,9 +536,9 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
|
||||
{
|
||||
cloth_cache_get_frame ( clmd, frametime );
|
||||
cloth_to_object ( ob, result, clmd );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if ( current_time > clmd->sim_parms->lastframe )
|
||||
{
|
||||
int frametime = cloth_cache_last_frame ( clmd );
|
||||
@ -546,21 +546,21 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
|
||||
{
|
||||
cloth_cache_get_frame ( clmd, frametime );
|
||||
cloth_to_object ( ob, result, clmd );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if ( ABS ( deltaTime ) >= 2.0f ) // no timewarps allowed
|
||||
{
|
||||
if ( cloth_cache_search_frame ( clmd, framenr ) )
|
||||
{
|
||||
cloth_cache_get_frame ( clmd, framenr );
|
||||
cloth_to_object ( ob, result, clmd );
|
||||
}
|
||||
}
|
||||
clmd->sim_parms->sim_time = current_time;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if(deltaTime == 1.0f)
|
||||
@ -737,10 +737,10 @@ void cloth_free_modifier (ClothModifierData *clmd)
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* cloth_to_object - copies the deformed vertices to the object.
|
||||
*
|
||||
* This function is a modified version of the softbody.c:softbody_to_object() function.
|
||||
**/
|
||||
* cloth_to_object - copies the deformed vertices to the object.
|
||||
*
|
||||
* This function is a modified version of the softbody.c:softbody_to_object() function.
|
||||
**/
|
||||
static void cloth_to_object (Object *ob, DerivedMesh *dm, ClothModifierData *clmd)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
@ -765,9 +765,9 @@ static void cloth_to_object (Object *ob, DerivedMesh *dm, ClothModifierData *cl
|
||||
|
||||
|
||||
/**
|
||||
* cloth_apply_vgroup - applies a vertex group as specified by type
|
||||
*
|
||||
**/
|
||||
* cloth_apply_vgroup - applies a vertex group as specified by type
|
||||
*
|
||||
**/
|
||||
static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, short vgroup)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
@ -898,14 +898,13 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
|
||||
if (solvers [clmd->sim_parms->solver_type].init)
|
||||
solvers [clmd->sim_parms->solver_type].init (ob, clmd);
|
||||
|
||||
clmd->clothObject->tree = bvh_build_from_float4(CDDM_get_faces(dm), dm->getNumFaces(dm), clmd->clothObject->x, numverts, clmd->coll_parms->epsilon);
|
||||
clmd->clothObject->tree = bvh_build_from_float3(CDDM_get_faces(dm), dm->getNumFaces(dm), clmd->clothObject->x, numverts, clmd->coll_parms->epsilon);
|
||||
|
||||
clmd->clothObject->selftree = bvh_build_from_float4(NULL, 0, clmd->clothObject->x, numverts, clmd->coll_parms->selfepsilon);
|
||||
clmd->clothObject->selftree = bvh_build_from_float3(NULL, 0, clmd->clothObject->x, numverts, clmd->coll_parms->selfepsilon);
|
||||
|
||||
// save initial state
|
||||
cloth_write_cache(ob, clmd, framenr-1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
default: return 0; // TODO - we do not support changing meshes
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user