[Bf-blender-cvs] [207c740a857] soc-2019-adaptive-cloth: Converted clothModifier_do() to return Mesh
ishbosamiya
noreply at git.blender.org
Mon Jun 3 09:38:26 CEST 2019
Commit: 207c740a857e8cbbbe405e9f44e6e164326b06ba
Author: ishbosamiya
Date: Sun Jun 2 12:53:24 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rB207c740a857e8cbbbe405e9f44e6e164326b06ba
Converted clothModifier_do() to return Mesh
This has been done for the simulator to work with changing vertex count.
TODO: particle_system.c has hair simulation which uses clothModifier_do, need to convert the hair sim to work with new clothModifier_do()
===================================================================
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/particle_system.c
M source/blender/modifiers/intern/MOD_cloth.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 0a371549aef..c5bfd08ce59 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -270,12 +270,11 @@ void cloth_free_contacts(ColliderContacts *collider_contacts, int totcolliders);
void cloth_free_modifier_extern(struct ClothModifierData *clmd);
void cloth_free_modifier(struct ClothModifierData *clmd);
void cloth_init(struct ClothModifierData *clmd);
-void clothModifier_do(struct ClothModifierData *clmd,
- struct Depsgraph *depsgraph,
- struct Scene *scene,
- struct Object *ob,
- struct Mesh *me,
- float (*vertexCos)[3]);
+struct Mesh *clothModifier_do(struct ClothModifierData *clmd,
+ struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob,
+ struct Mesh *mesh);
int cloth_uses_vgroup(struct ClothModifierData *clmd);
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 4ad94a0da31..251df663c52 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -41,8 +41,10 @@
#include "BKE_cloth.h"
#include "BKE_effect.h"
#include "BKE_global.h"
+#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_modifier.h"
+#include "BKE_library.h"
#if USE_CLOTH_CACHE
# include "BKE_pointcache.h"
#endif
@@ -55,6 +57,7 @@
/* Prototypes for internal functions.
*/
static void cloth_to_object(Object *ob, ClothModifierData *clmd, float (*vertexCos)[3]);
+static void cloth_to_mesh(Object *ob, ClothModifierData *clmd, Mesh *r_mesh);
static void cloth_from_mesh(ClothModifierData *clmd, Mesh *mesh);
static int cloth_from_object(
Object *ob, ClothModifierData *clmd, Mesh *mesh, float framenr, int first);
@@ -367,13 +370,11 @@ static int do_step_cloth(
/************************************************
* clothModifier_do - main simulation function
************************************************/
-void clothModifier_do(ClothModifierData *clmd,
- Depsgraph *depsgraph,
- Scene *scene,
- Object *ob,
- Mesh *mesh,
- float (*vertexCos)[3])
+Mesh *clothModifier_do(
+ ClothModifierData *clmd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh)
{
+ Mesh *mesh_result = mesh;
+ BKE_id_copy_ex(NULL, (ID *)mesh, (ID **)&mesh_result, LIB_ID_COPY_LOCALIZE);
#if USE_CLOTH_CACHE
PointCache *cache;
PTCacheID pid;
@@ -411,7 +412,7 @@ void clothModifier_do(ClothModifierData *clmd,
#if USE_CLOTH_CACHE
BKE_ptcache_invalidate(cache);
#endif
- return;
+ return mesh_result;
}
else if (framenr > endframe) {
framenr = endframe;
@@ -419,7 +420,7 @@ void clothModifier_do(ClothModifierData *clmd,
/* initialize simulation data if it didn't exist already */
if (!do_init_cloth(ob, clmd, mesh, framenr)) {
- return;
+ return mesh_result;
}
if (framenr == startframe) {
@@ -431,7 +432,7 @@ void clothModifier_do(ClothModifierData *clmd,
BKE_ptcache_validate(cache, framenr);
cache->flag &= ~PTCACHE_REDO_NEEDED;
clmd->clothObject->last_frame = framenr;
- return;
+ return mesh_result;
}
/* try to read from cache */
@@ -443,7 +444,7 @@ void clothModifier_do(ClothModifierData *clmd,
if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED ||
(!can_simulate && cache_result == PTCACHE_READ_OLD)) {
BKE_cloth_solver_set_positions(clmd);
- cloth_to_object(ob, clmd, vertexCos);
+ cloth_to_mesh(ob, clmd, mesh_result);
BKE_ptcache_validate(cache, framenr);
@@ -455,7 +456,7 @@ void clothModifier_do(ClothModifierData *clmd,
clmd->clothObject->last_frame = framenr;
#if USE_CLOTH_CACHE
- return;
+ return mesh_result;
}
else if (cache_result == PTCACHE_READ_OLD) {
BKE_cloth_solver_set_positions(clmd);
@@ -466,7 +467,7 @@ void clothModifier_do(ClothModifierData *clmd,
/* if baked and nothing in cache, do nothing */
BKE_ptcache_invalidate(cache);
#endif
- return;
+ return mesh_result;
}
#if USE_CLOTH_CACHE
@@ -482,7 +483,7 @@ void clothModifier_do(ClothModifierData *clmd,
#if USE_CLOTH_CACHE
#else
if (framenr != clmd->clothObject->last_frame + 1) {
- return;
+ return mesh_result;
}
#endif
@@ -500,9 +501,10 @@ void clothModifier_do(ClothModifierData *clmd,
#else
do_step_cloth(depsgraph, ob, clmd, mesh, framenr);
#endif
-
- cloth_to_object(ob, clmd, vertexCos);
+ cloth_to_mesh(ob, clmd, mesh_result);
clmd->clothObject->last_frame = framenr;
+
+ return mesh_result;
}
/* frees all */
@@ -677,6 +679,25 @@ static void cloth_to_object(Object *ob, ClothModifierData *clmd, float (*vertexC
}
}
+/**
+ * Copies deformed vertices to Mesh
+ */
+
+static void cloth_to_mesh(Object *ob, ClothModifierData *clmd, Mesh *r_mesh)
+{
+ int numVerts;
+ float(*vertexCos)[3] = BKE_mesh_vertexCos_get(r_mesh, &numVerts);
+
+ cloth_to_object(ob, clmd, vertexCos);
+
+ BKE_mesh_apply_vert_coords(r_mesh, vertexCos);
+
+ if (vertexCos) {
+ MEM_freeN(vertexCos);
+ vertexCos = NULL;
+ }
+}
+
int cloth_uses_vgroup(ClothModifierData *clmd)
{
return (((clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF) &&
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 27722aab2d9..08f902f1dbd 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -3491,9 +3491,11 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
BKE_id_copy_ex(NULL, &psys->hair_in_mesh->id, (ID **)&psys->hair_out_mesh, LIB_ID_COPY_LOCALIZE);
deformedVerts = BKE_mesh_vertexCos_get(psys->hair_out_mesh, NULL);
- clothModifier_do(
- psys->clmd, sim->depsgraph, sim->scene, sim->ob, psys->hair_in_mesh, deformedVerts);
- BKE_mesh_apply_vert_coords(psys->hair_out_mesh, deformedVerts);
+ /* TODO(Ish): Due to change in the cloth simulation code, clothModifier_do now is returning a
+ * mesh, this change needs to be reflected in the hair simulation code */
+ /* clothModifier_do( */
+ /* psys->clmd, sim->depsgraph, sim->scene, sim->ob, psys->hair_in_mesh, deformedVerts); */
+ /* BKE_mesh_apply_vert_coords(psys->hair_out_mesh, deformedVerts); */
MEM_freeN(deformedVerts);
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c
index 679fa84df2d..8fa8f82bbc5 100644
--- a/source/blender/modifiers/intern/MOD_cloth.c
+++ b/source/blender/modifiers/intern/MOD_cloth.c
@@ -31,11 +31,13 @@
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
+#define USE_CLOTH_CACHE 0
#if USE_CLOTH_CACHE
#else
# include "DNA_object_force_types.h"
# include "DNA_collection_types.h"
#endif
+#undef USE_CLOTH_CACHE
#include "DNA_object_types.h"
#include "MEM_guardedalloc.h"
@@ -79,13 +81,12 @@ static void initData(ModifierData *md)
cloth_init(clmd);
}
-static void deformVerts(ModifierData *md,
- const ModifierEvalContext *ctx,
- Mesh *mesh,
- float (*vertexCos)[3],
- int numVerts)
+static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
+ Mesh *mesh_result;
+
Mesh *mesh_src;
+ int numVerts = mesh->totvert;
ClothModifierData *clmd = (ClothModifierData *)md;
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
@@ -94,7 +95,7 @@ static void deformVerts(ModifierData *md,
initData(md);
if (!clmd->sim_parms || !clmd->coll_parms) {
- return;
+ return mesh;
}
}
@@ -127,26 +128,15 @@ static void deformVerts(ModifierData *md,
}
}
+ float(*vertexCos)[3] = BKE_mesh_vertexCos_get(mesh_src, &numVerts);
BKE_mesh_apply_vert_coords(mesh_src, vertexCos);
- clothModifier_do(clmd, ctx->depsgraph, scene, ctx->object, mesh_src, vertexCos);
+ mesh_result = clothModifier_do(clmd, ctx->depsgraph, scene, ctx->object, mesh_src);
BKE_id_free(NULL, mesh_src);
-}
-
-static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
-{
- Mesh *result;
- int numVerts;
- float(*deformedVerts)[3] = BKE_mesh_vertexCos_get(mesh, &numVerts);
-
- BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
- deformVerts(md, ctx, result, deformedVerts, numVerts);
- BKE_mesh_apply_vert_coords(result, deformedVerts);
-
- MEM_freeN(deformedVerts);
+ MEM_freeN(vertexCos);
- return result;
+ return mesh_result;
}
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
More information about the Bf-blender-cvs
mailing list