Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorover0219 <over0219@umn.edu>2020-06-10 23:03:20 +0300
committerover0219 <over0219@umn.edu>2020-06-10 23:03:20 +0300
commita6c7484d1b898e5535e4a4a8a852420498b2f74d (patch)
tree753ccbfb6f7bee97e8404818261bea5ff1311411
parent2ace45220db036c448c223286926e1526165fc5d (diff)
update api a bit
-rw-r--r--intern/softbody/admmpd_api.cpp45
-rw-r--r--intern/softbody/admmpd_api.h18
-rw-r--r--source/blender/blenkernel/intern/softbody.c16
3 files changed, 54 insertions, 25 deletions
diff --git a/intern/softbody/admmpd_api.cpp b/intern/softbody/admmpd_api.cpp
index 915b20b299a..62dc1e7bba5 100644
--- a/intern/softbody/admmpd_api.cpp
+++ b/intern/softbody/admmpd_api.cpp
@@ -41,17 +41,30 @@ struct ADMMPDInternalData {
};
-void admmpd_alloc(ADMMPDInterfaceData *iface, int in_verts, int in_faces)
+void admmpd_alloc(ADMMPDInterfaceData *iface)
{
if (iface==NULL)
return;
- iface->in_totverts = in_verts;
- iface->in_verts = (float *)MEM_mallocN(in_verts*3*sizeof(float), "admmpd_verts");
- iface->in_vel = (float *)MEM_mallocN(in_verts*3*sizeof(float), "admmpd_vel");
+ if (iface->in_verts != NULL)
+ {
+ MEM_freeN(iface->in_verts);
+ iface->in_verts = NULL;
+ }
+ if (iface->in_vel != NULL)
+ {
+ MEM_freeN(iface->in_vel);
+ iface->in_vel = NULL;
+ }
+ if (iface->in_faces != NULL)
+ {
+ MEM_freeN(iface->in_faces);
+ iface->in_faces = NULL;
+ }
- iface->in_totfaces = in_faces;
- iface->in_faces = (unsigned int *)MEM_mallocN(in_faces*3*sizeof(unsigned int), "admmpd_faces");
+ iface->in_verts = (float *)MEM_mallocN(iface->in_totverts*3*sizeof(float), "admmpd_verts");
+ iface->in_vel = (float *)MEM_mallocN(iface->in_totverts*3*sizeof(float), "admmpd_vel");
+ iface->in_faces = (unsigned int *)MEM_mallocN(iface->in_totfaces*3*sizeof(unsigned int), "admmpd_faces");
}
void admmpd_dealloc(ADMMPDInterfaceData *iface)
@@ -114,10 +127,20 @@ int admmpd_init(ADMMPDInterfaceData *iface)
// Resize data
iface->out_totverts = tg.out_totverts;
+ if (iface->out_verts != NULL)
+ {
+ MEM_freeN(iface->out_verts);
+ iface->out_verts = NULL;
+ }
+ if (iface->out_vel != NULL)
+ {
+ MEM_freeN(iface->out_vel);
+ iface->out_vel = NULL;
+ }
iface->out_verts = (float *)MEM_callocN(
iface->out_totverts*3*sizeof(float), "ADMMPD_out_verts");
iface->out_vel = (float *)MEM_callocN(
- iface->out_totverts*3*sizeof(float), "ADMMPD_out_verts");
+ iface->out_totverts*3*sizeof(float), "ADMMPD_out_vel");
// Create initializer for ADMMPD
int nv = tg.out_totverts;
@@ -168,14 +191,6 @@ int admmpd_init(ADMMPDInterfaceData *iface)
return int(init_success);
}
-int admmpd_cache_valid(ADMMPDInterfaceData *iface, int numVerts)
-{
- if (iface == NULL) // we haven't initialized yet
- return true;
-
- return iface->in_totverts == numVerts;
-}
-
void admmpd_solve(ADMMPDInterfaceData *iface)
{
if (iface == NULL)
diff --git a/intern/softbody/admmpd_api.h b/intern/softbody/admmpd_api.h
index 3ee43cd5948..f90f75a0405 100644
--- a/intern/softbody/admmpd_api.h
+++ b/intern/softbody/admmpd_api.h
@@ -36,7 +36,8 @@ typedef struct ADMMPDInterfaceData {
int in_totverts;
// Num output verts might be different than num input verts.
// This is due to the lattice/tetmesh that is generated
- // in init. They need to be cached by the system
+ // in init. You can use them as input if reading from cache,
+ // as they will be copied to internal solver data before admmpd_solve.
float *out_verts;
float *out_vel;
int out_totverts;
@@ -44,11 +45,22 @@ typedef struct ADMMPDInterfaceData {
struct ADMMPDInternalData *data;
} ADMMPDInterfaceData;
-void admmpd_alloc(ADMMPDInterfaceData*, int in_verts, int in_faces);
+// Allocates ADMMPDInterfaceData, using in_totfaces and in_totverts.
+// Does not allocate solver data, which is created on admmpd_init
+void admmpd_alloc(ADMMPDInterfaceData*);
+
+// Clears all solver data and ADMMPDInterfaceData
void admmpd_dealloc(ADMMPDInterfaceData*);
+
+// Initializes solver and allocates internal data
int admmpd_init(ADMMPDInterfaceData*);
-int admmpd_cache_valid(ADMMPDInterfaceData*, int numVerts);
+
+// Copies out_verts and out_verts to internal data
+// Performs solve over the time step
+// Copies internal data to out_verts and out_vel
void admmpd_solve(ADMMPDInterfaceData*);
+
+// Copies ADMMPDInterfaceData::out_ to vertexCos
void admmpd_get_vertices(ADMMPDInterfaceData*, float (*vertexCos)[3], int numVerts);
#ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 03df1878b00..026acd06b04 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -859,8 +859,9 @@ static void renew_softbody(Scene *scene, Object *ob, int totpoint, int totspring
if (ob->type == OB_MESH)
{
const Mesh *me = ob->data;
- int totfaces = poly_to_tri_count(me->totpoly, me->totloop);
- admmpd_alloc(sb->admmpd, totpoint, totfaces);
+ sb->admmpd->in_totfaces = poly_to_tri_count(me->totpoly, me->totloop);
+ sb->admmpd->in_totverts = me->totvert;
+ admmpd_alloc(sb->admmpd);
}
/* initialize BodyPoint array */
@@ -3571,7 +3572,7 @@ static void admmpd_copy_to_softbody(Object *ob)
if (sb->totpoint != admmpd->out_totverts)
{
- printf("**admmpd_copy_to_softbody error: DOF missmatch");
+ printf("**admm_copy_to_softbody error: DOF missmatch");
return;
}
@@ -3598,8 +3599,9 @@ static void init_admmpd_interface(Object *ob, float (*vertexCos)[3])
// Resize data
admmpd_dealloc(sb->admmpd);
- int totfaces = poly_to_tri_count(me->totpoly, me->totloop);
- admmpd_alloc(sb->admmpd, me->totvert, totfaces);
+ sb->admmpd->in_totfaces = poly_to_tri_count(me->totpoly, me->totloop);
+ sb->admmpd->in_totverts = me->totvert;
+ admmpd_alloc(sb->admmpd);
// Initialize input data
for (int i=0; i<me->totvert; ++i)
@@ -3617,9 +3619,9 @@ static void init_admmpd_interface(Object *ob, float (*vertexCos)[3])
}
}
MLoopTri *looptri, *lt;
- looptri = lt = MEM_mallocN(sizeof(*looptri)*totfaces, __func__);
+ looptri = lt = MEM_mallocN(sizeof(*looptri)*sb->admmpd->in_totfaces, __func__);
BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri);
- for (int i=0; i<totfaces; ++i, ++lt)
+ for (int i=0; i<sb->admmpd->in_totfaces; ++i, ++lt)
{
sb->admmpd->in_faces[i*3+0] = me->mloop[lt->tri[0]].v;
sb->admmpd->in_faces[i*3+1] = me->mloop[lt->tri[1]].v;