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 matrix_index; /* needed for implicit solver (fast lookup) */
|
||||||
int type; /* types defined in BKE_cloth.h ("springType") */
|
int type; /* types defined in BKE_cloth.h ("springType") */
|
||||||
int flags; /* defined in BKE_cloth.h, e.g. deactivated due to tearing */
|
int flags; /* defined in BKE_cloth.h, e.g. deactivated due to tearing */
|
||||||
float dfdx[3][4];
|
float dfdx[3][3];
|
||||||
float dfdv[3][4];
|
float dfdv[3][3];
|
||||||
float f[3];
|
float f[3];
|
||||||
} ClothSpring;
|
} ClothSpring;
|
||||||
|
|
||||||
@ -91,13 +91,13 @@ typedef struct Cloth {
|
|||||||
unsigned int numothersprings;
|
unsigned int numothersprings;
|
||||||
unsigned int numspringssave;
|
unsigned int numspringssave;
|
||||||
unsigned int old_solver_type;
|
unsigned int old_solver_type;
|
||||||
float (*x)[4]; /* The current position of all vertices.*/
|
float (*x)[3]; /* The current position of all vertices.*/
|
||||||
float (*xold)[4]; /* The previous position of all vertices.*/
|
float (*xold)[3]; /* The previous position of all vertices.*/
|
||||||
float (*current_x)[4]; /* The TEMPORARY current position of all vertices.*/
|
float (*current_x)[3]; /* The TEMPORARY current position of all vertices.*/
|
||||||
float (*current_xold)[4]; /* The TEMPORARY previous 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 (*v)[4]; /* the current velocity of all vertices */
|
||||||
float (*current_v)[4];
|
float (*current_v)[3];
|
||||||
float (*xconst)[4];
|
float (*xconst)[3];
|
||||||
} Cloth;
|
} Cloth;
|
||||||
|
|
||||||
/* goal defines */
|
/* goal defines */
|
||||||
|
@ -90,9 +90,9 @@ double tval()
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
static struct timeval _tstart, _tend;
|
static struct timeval _tstart, _tend;
|
||||||
static struct timezone tz;
|
static struct timezone tz;
|
||||||
void tstart ( void )
|
void tstart ( void )
|
||||||
{
|
{
|
||||||
gettimeofday ( &_tstart, &tz );
|
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.
|
* cloth_init - creates a new cloth simulation.
|
||||||
*
|
*
|
||||||
* 1. create object
|
* 1. create object
|
||||||
* 2. fill object with standard values or with the GUI settings if given
|
* 2. fill object with standard values or with the GUI settings if given
|
||||||
*/
|
*/
|
||||||
void cloth_init (ClothModifierData *clmd)
|
void cloth_init (ClothModifierData *clmd)
|
||||||
{
|
{
|
||||||
/* Initialize our new data structure to reasonable values. */
|
/* Initialize our new data structure to reasonable values. */
|
||||||
@ -206,7 +206,7 @@ DerivedMesh *CDDM_convert_to_triangle(DerivedMesh *dm)
|
|||||||
numquads++;
|
numquads++;
|
||||||
else
|
else
|
||||||
numtris++;
|
numtris++;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = CDDM_from_template(dm, numverts, 0, numtris + 2*numquads);
|
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);
|
DM_copy_vert_data(dm, result, a, a, 1);
|
||||||
*mv = *inMV;
|
*mv = *inMV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// do faces
|
// do faces
|
||||||
@ -246,13 +246,13 @@ DerivedMesh *CDDM_convert_to_triangle(DerivedMesh *dm)
|
|||||||
mf->v1 = mface[a].v2;
|
mf->v1 = mface[a].v2;
|
||||||
mf->v2 = mface[a].v3;
|
mf->v2 = mface[a].v3;
|
||||||
mf->v3 = mface[a].v4;
|
mf->v3 = mface[a].v4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mf->v1 = mface[a].v1;
|
mf->v1 = mface[a].v1;
|
||||||
mf->v2 = mface[a].v2;
|
mf->v2 = mface[a].v2;
|
||||||
mf->v3 = mface[a].v3;
|
mf->v3 = mface[a].v3;
|
||||||
}
|
}
|
||||||
|
|
||||||
mf->v4 = 0;
|
mf->v4 = 0;
|
||||||
mf->flag |= ME_SMOOTH;
|
mf->flag |= ME_SMOOTH;
|
||||||
@ -277,21 +277,21 @@ DerivedMesh *CDDM_convert_to_triangle(DerivedMesh *dm)
|
|||||||
mf2->v1 = mface[a].v1;
|
mf2->v1 = mface[a].v1;
|
||||||
mf2->v2 = mface[a].v2;
|
mf2->v2 = mface[a].v2;
|
||||||
mf2->v3 = mface[a].v4;
|
mf2->v3 = mface[a].v4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mf2->v1 = mface[a].v4;
|
mf2->v1 = mface[a].v4;
|
||||||
mf2->v2 = mface[a].v1;
|
mf2->v2 = mface[a].v1;
|
||||||
mf2->v3 = mface[a].v3;
|
mf2->v3 = mface[a].v3;
|
||||||
}
|
}
|
||||||
mf2->v4 = 0;
|
mf2->v4 = 0;
|
||||||
mf2->flag |= ME_SMOOTH;
|
mf2->flag |= ME_SMOOTH;
|
||||||
|
|
||||||
test_index_face(mf2, NULL, 0, 3);
|
test_index_face(mf2, NULL, 0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDDM_calc_edges(result);
|
CDDM_calc_edges(result);
|
||||||
CDDM_calc_normals(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].ij, springs[i].kl, NULL);
|
||||||
BLI_edgehash_insert(edgehash, springs[i].kl, springs[i].ij, NULL);
|
BLI_edgehash_insert(edgehash, springs[i].kl, springs[i].ij, NULL);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("found %d tears\n", 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);
|
DM_copy_vert_data(dm, result, a, a, 1);
|
||||||
*mv = *inMV;
|
*mv = *inMV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// do faces
|
// do faces
|
||||||
@ -387,8 +387,8 @@ DerivedMesh *CDDM_create_tearing(ClothModifierData *clmd, DerivedMesh *dm)
|
|||||||
test_index_face(mf, NULL, 0, 4);
|
test_index_face(mf, NULL, 0, 4);
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CDDM_lower_num_faces(result, i);
|
CDDM_lower_num_faces(result, i);
|
||||||
CDDM_calc_edges(result);
|
CDDM_calc_edges(result);
|
||||||
@ -536,9 +536,9 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
|
|||||||
{
|
{
|
||||||
cloth_cache_get_frame ( clmd, frametime );
|
cloth_cache_get_frame ( clmd, frametime );
|
||||||
cloth_to_object ( ob, result, clmd );
|
cloth_to_object ( ob, result, clmd );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if ( current_time > clmd->sim_parms->lastframe )
|
else if ( current_time > clmd->sim_parms->lastframe )
|
||||||
{
|
{
|
||||||
int frametime = cloth_cache_last_frame ( clmd );
|
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_cache_get_frame ( clmd, frametime );
|
||||||
cloth_to_object ( ob, result, clmd );
|
cloth_to_object ( ob, result, clmd );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if ( ABS ( deltaTime ) >= 2.0f ) // no timewarps allowed
|
else if ( ABS ( deltaTime ) >= 2.0f ) // no timewarps allowed
|
||||||
{
|
{
|
||||||
if ( cloth_cache_search_frame ( clmd, framenr ) )
|
if ( cloth_cache_search_frame ( clmd, framenr ) )
|
||||||
{
|
{
|
||||||
cloth_cache_get_frame ( clmd, framenr );
|
cloth_cache_get_frame ( clmd, framenr );
|
||||||
cloth_to_object ( ob, result, clmd );
|
cloth_to_object ( ob, result, clmd );
|
||||||
}
|
}
|
||||||
clmd->sim_parms->sim_time = current_time;
|
clmd->sim_parms->sim_time = current_time;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(deltaTime == 1.0f)
|
if(deltaTime == 1.0f)
|
||||||
@ -737,10 +737,10 @@ void cloth_free_modifier (ClothModifierData *clmd)
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cloth_to_object - copies the deformed vertices to the object.
|
* cloth_to_object - copies the deformed vertices to the object.
|
||||||
*
|
*
|
||||||
* This function is a modified version of the softbody.c:softbody_to_object() function.
|
* 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)
|
static void cloth_to_object (Object *ob, DerivedMesh *dm, ClothModifierData *clmd)
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
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)
|
static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, short vgroup)
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
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)
|
if (solvers [clmd->sim_parms->solver_type].init)
|
||||||
solvers [clmd->sim_parms->solver_type].init (ob, clmd);
|
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
|
// save initial state
|
||||||
cloth_write_cache(ob, clmd, framenr-1);
|
cloth_write_cache(ob, clmd, framenr-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
default: return 0; // TODO - we do not support changing meshes
|
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