Renamed functions to make them explicitly refer to cloth, and split the
create/free functions for solver data off from the cloth solver.
This commit is contained in:
parent
5322def57c
commit
0d60337a83
|
@ -246,9 +246,9 @@ typedef enum {
|
|||
typedef struct {
|
||||
const char *name;
|
||||
CM_SOLVER_ID id;
|
||||
int ( *init ) (struct Object *ob, struct ClothModifierData *clmd );
|
||||
int ( *solver ) (struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors );
|
||||
int ( *free ) (struct ClothModifierData *clmd );
|
||||
int ( *init ) (struct Object *ob, struct ClothModifierData *clmd );
|
||||
int ( *solver ) (struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors );
|
||||
void ( *free ) (struct ClothModifierData *clmd );
|
||||
}
|
||||
CM_SOLVER_DEF;
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@
|
|||
// 254 = MAX!
|
||||
static CM_SOLVER_DEF solvers [] =
|
||||
{
|
||||
{ "Implicit", CM_IMPLICIT, implicit_init, implicit_solver, implicit_free },
|
||||
// { "Implicit C++", CM_IMPLICITCPP, implicitcpp_init, implicitcpp_solver, implicitcpp_free },
|
||||
{ "Implicit", CM_IMPLICIT, BPH_cloth_solver_init, BPH_cloth_solve, BPH_cloth_solver_free },
|
||||
// { "Implicit C++", CM_IMPLICITCPP, implicitcpp_init, implicitcpp_solver, implicitcpp_free },
|
||||
};
|
||||
|
||||
/* ********** cloth engine ******* */
|
||||
|
@ -345,7 +345,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
|
|||
return 0;
|
||||
}
|
||||
|
||||
implicit_set_positions(clmd);
|
||||
BKE_cloth_solver_set_positions(clmd);
|
||||
|
||||
clmd->clothObject->last_frame= MINFRAME-1;
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
|
|||
cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe);
|
||||
|
||||
if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
|
||||
implicit_set_positions(clmd);
|
||||
BKE_cloth_solver_set_positions(clmd);
|
||||
cloth_to_object (ob, clmd, vertexCos);
|
||||
|
||||
BKE_ptcache_validate(cache, framenr);
|
||||
|
@ -541,7 +541,7 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
|
|||
return;
|
||||
}
|
||||
else if (cache_result==PTCACHE_READ_OLD) {
|
||||
implicit_set_positions(clmd);
|
||||
BKE_cloth_solver_set_positions(clmd);
|
||||
}
|
||||
else if ( /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */
|
||||
/* if baked and nothing in cache, do nothing */
|
||||
|
@ -938,7 +938,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
|
|||
}
|
||||
|
||||
if (!first)
|
||||
implicit_set_positions(clmd);
|
||||
BKE_cloth_solver_set_positions(clmd);
|
||||
|
||||
clmd->clothObject->bvhtree = bvhtree_build_from_cloth ( clmd, MAX2(clmd->coll_parms->epsilon, clmd->coll_parms->distance_repel) );
|
||||
|
||||
|
|
|
@ -28,10 +28,15 @@
|
|||
#ifndef __BPH_MASS_SPRING_H__
|
||||
#define __BPH_MASS_SPRING_H__
|
||||
|
||||
int implicit_init (struct Object *ob, struct ClothModifierData *clmd );
|
||||
int implicit_free (struct ClothModifierData *clmd );
|
||||
int implicit_solver (struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors );
|
||||
void implicit_set_positions (struct ClothModifierData *clmd );
|
||||
struct Implicit_Data;
|
||||
|
||||
struct Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings);
|
||||
void BPH_mass_spring_solver_free(struct Implicit_Data *id);
|
||||
|
||||
int BPH_cloth_solver_init(struct Object *ob, struct ClothModifierData *clmd);
|
||||
void BPH_cloth_solver_free(struct ClothModifierData *clmd);
|
||||
int BPH_cloth_solve(struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors);
|
||||
void BKE_cloth_solver_set_positions (struct ClothModifierData *clmd );
|
||||
|
||||
bool implicit_hair_volume_get_texture_data(struct Object *UNUSED(ob), struct ClothModifierData *clmd, struct ListBase *UNUSED(effectors), struct VoxelData *vd);
|
||||
|
||||
|
|
|
@ -681,58 +681,81 @@ typedef struct Implicit_Data {
|
|||
fmatrix3x3 *P, *Pinv; /* pre-conditioning matrix */
|
||||
} Implicit_Data;
|
||||
|
||||
int implicit_init(Object *UNUSED(ob), ClothModifierData *clmd)
|
||||
Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
Cloth *cloth = NULL;
|
||||
ClothVertex *verts = NULL;
|
||||
ClothSpring *spring = NULL;
|
||||
Implicit_Data *id = NULL;
|
||||
LinkNode *search = NULL;
|
||||
Implicit_Data *id = (Implicit_Data *)MEM_callocN(sizeof(Implicit_Data), "implicit vecmat");
|
||||
|
||||
/* process diagonal elements */
|
||||
id->A = create_bfmatrix(numverts, numsprings);
|
||||
id->dFdV = create_bfmatrix(numverts, numsprings);
|
||||
id->dFdX = create_bfmatrix(numverts, numsprings);
|
||||
id->S = create_bfmatrix(numverts, 0);
|
||||
id->Pinv = create_bfmatrix(numverts, numsprings);
|
||||
id->P = create_bfmatrix(numverts, numsprings);
|
||||
id->bigI = create_bfmatrix(numverts, numsprings); // TODO 0 springs
|
||||
id->M = create_bfmatrix(numverts, numsprings);
|
||||
id->X = create_lfvector(numverts);
|
||||
id->Xnew = create_lfvector(numverts);
|
||||
id->V = create_lfvector(numverts);
|
||||
id->Vnew = create_lfvector(numverts);
|
||||
id->F = create_lfvector(numverts);
|
||||
id->B = create_lfvector(numverts);
|
||||
id->dV = create_lfvector(numverts);
|
||||
id->z = create_lfvector(numverts);
|
||||
|
||||
id->root = MEM_callocN(sizeof(RootTransform) * numverts, "root transforms");
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void BPH_mass_spring_solver_free(Implicit_Data *id)
|
||||
{
|
||||
del_bfmatrix(id->A);
|
||||
del_bfmatrix(id->dFdV);
|
||||
del_bfmatrix(id->dFdX);
|
||||
del_bfmatrix(id->S);
|
||||
del_bfmatrix(id->P);
|
||||
del_bfmatrix(id->Pinv);
|
||||
del_bfmatrix(id->bigI);
|
||||
del_bfmatrix(id->M);
|
||||
|
||||
del_lfvector(id->X);
|
||||
del_lfvector(id->Xnew);
|
||||
del_lfvector(id->V);
|
||||
del_lfvector(id->Vnew);
|
||||
del_lfvector(id->F);
|
||||
del_lfvector(id->B);
|
||||
del_lfvector(id->dV);
|
||||
del_lfvector(id->z);
|
||||
|
||||
MEM_freeN(id->root);
|
||||
|
||||
MEM_freeN(id);
|
||||
}
|
||||
|
||||
int BPH_cloth_solver_init(Object *UNUSED(ob), ClothModifierData *clmd)
|
||||
{
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
ClothVertex *verts = cloth->verts;
|
||||
Implicit_Data *id;
|
||||
unsigned int i;
|
||||
LinkNode *search;
|
||||
|
||||
if (G.debug_value > 0)
|
||||
printf("implicit_init\n");
|
||||
|
||||
// init memory guard
|
||||
// BLI_listbase_clear(&MEMORY_BASE);
|
||||
|
||||
cloth = (Cloth *)clmd->clothObject;
|
||||
verts = cloth->verts;
|
||||
|
||||
// create implicit base
|
||||
id = (Implicit_Data *)MEM_callocN(sizeof(Implicit_Data), "implicit vecmat");
|
||||
cloth->implicit = id;
|
||||
|
||||
/* process diagonal elements */
|
||||
id->A = create_bfmatrix(cloth->numverts, cloth->numsprings);
|
||||
id->dFdV = create_bfmatrix(cloth->numverts, cloth->numsprings);
|
||||
id->dFdX = create_bfmatrix(cloth->numverts, cloth->numsprings);
|
||||
id->S = create_bfmatrix(cloth->numverts, 0);
|
||||
id->Pinv = create_bfmatrix(cloth->numverts, cloth->numsprings);
|
||||
id->P = create_bfmatrix(cloth->numverts, cloth->numsprings);
|
||||
id->bigI = create_bfmatrix(cloth->numverts, cloth->numsprings); // TODO 0 springs
|
||||
id->M = create_bfmatrix(cloth->numverts, cloth->numsprings);
|
||||
id->X = create_lfvector(cloth->numverts);
|
||||
id->Xnew = create_lfvector(cloth->numverts);
|
||||
id->V = create_lfvector(cloth->numverts);
|
||||
id->Vnew = create_lfvector(cloth->numverts);
|
||||
id->F = create_lfvector(cloth->numverts);
|
||||
id->B = create_lfvector(cloth->numverts);
|
||||
id->dV = create_lfvector(cloth->numverts);
|
||||
id->z = create_lfvector(cloth->numverts);
|
||||
|
||||
id->root = MEM_callocN(sizeof(RootTransform) * cloth->numverts, "root transforms");
|
||||
|
||||
|
||||
cloth->implicit = id = BPH_mass_spring_solver_create(cloth->numverts, cloth->numsprings);
|
||||
|
||||
for (i = 0; i < cloth->numverts; i++) {
|
||||
id->A[i].r = id->A[i].c = id->dFdV[i].r = id->dFdV[i].c = id->dFdX[i].r = id->dFdX[i].c = id->P[i].c = id->P[i].r = id->Pinv[i].c = id->Pinv[i].r = id->bigI[i].c = id->bigI[i].r = id->M[i].r = id->M[i].c = i;
|
||||
|
||||
initdiag_fmatrixS(id->M[i].m, verts[i].mass);
|
||||
}
|
||||
|
||||
|
||||
// init springs
|
||||
search = cloth->springs;
|
||||
for (i = 0; i < cloth->numsprings; i++) {
|
||||
spring = search->link;
|
||||
ClothSpring *spring = search->link;
|
||||
|
||||
// dFdV_start[i].r = big_I[i].r = big_zero[i].r =
|
||||
id->A[i+cloth->numverts].r = id->dFdV[i+cloth->numverts].r = id->dFdX[i+cloth->numverts].r =
|
||||
|
@ -752,45 +775,18 @@ int implicit_init(Object *UNUSED(ob), ClothModifierData *clmd)
|
|||
for (i = 0; i < cloth->numverts; i++) {
|
||||
copy_v3_v3(id->X[i], verts[i].x);
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int implicit_free(ClothModifierData *clmd)
|
||||
void BPH_cloth_solver_free(ClothModifierData *clmd)
|
||||
{
|
||||
Implicit_Data *id;
|
||||
Cloth *cloth;
|
||||
cloth = (Cloth *)clmd->clothObject;
|
||||
|
||||
if (cloth) {
|
||||
id = cloth->implicit;
|
||||
|
||||
if (id) {
|
||||
del_bfmatrix(id->A);
|
||||
del_bfmatrix(id->dFdV);
|
||||
del_bfmatrix(id->dFdX);
|
||||
del_bfmatrix(id->S);
|
||||
del_bfmatrix(id->P);
|
||||
del_bfmatrix(id->Pinv);
|
||||
del_bfmatrix(id->bigI);
|
||||
del_bfmatrix(id->M);
|
||||
|
||||
del_lfvector(id->X);
|
||||
del_lfvector(id->Xnew);
|
||||
del_lfvector(id->V);
|
||||
del_lfvector(id->Vnew);
|
||||
del_lfvector(id->F);
|
||||
del_lfvector(id->B);
|
||||
del_lfvector(id->dV);
|
||||
del_lfvector(id->z);
|
||||
|
||||
MEM_freeN(id->root);
|
||||
|
||||
MEM_freeN(id);
|
||||
}
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
|
||||
if (cloth->implicit) {
|
||||
BPH_mass_spring_solver_free(cloth->implicit);
|
||||
cloth->implicit = NULL;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ==== Transformation of Moving Reference Frame ====
|
||||
|
@ -2526,7 +2522,7 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo
|
|||
return 1;
|
||||
}
|
||||
|
||||
int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors)
|
||||
int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors)
|
||||
{
|
||||
unsigned int i=0;
|
||||
float step=0.0f, tf=clmd->sim_parms->timescale;
|
||||
|
@ -2718,7 +2714,7 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase *
|
|||
return 1;
|
||||
}
|
||||
|
||||
void implicit_set_positions(ClothModifierData *clmd)
|
||||
void BKE_cloth_solver_set_positions(ClothModifierData *clmd)
|
||||
{
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
ClothVertex *verts = cloth->verts;
|
||||
|
|
Loading…
Reference in New Issue