diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2019-11-27 16:56:16 +0300 |
---|---|---|
committer | Sebastian Parborg <darkdefende@gmail.com> | 2019-11-27 17:01:15 +0300 |
commit | f6cefbef22c8c6583b4927c179dabac3eb57aa22 (patch) | |
tree | 96785e2ee93f34bb14975a53bc2a4e003ee3fb59 /source/blender/blenkernel | |
parent | eb798de101ac7946e2d719e763ad1f0fd3e26acd (diff) |
Fix T30941: Add cloth air pressure simulation
This adds some basic simulation of internal air pressure inside of
closed cloth mesh objects.
Reviewed By: Jacques Lucke
Differential Revision: http://developer.blender.org/D5473
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_cloth.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cloth.c | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_evaluate.c | 4 |
3 files changed, 21 insertions, 7 deletions
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index 01f94c39215..0543021afef 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -87,7 +87,8 @@ typedef struct Cloth { struct MVertTri *tri; struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */ struct EdgeSet *edgeset; /* used for selfcollisions */ - int last_frame, pad4; + int last_frame; + float initial_mesh_volume; /* Initial volume of the mesh. Used for pressure */ } Cloth; /** @@ -192,6 +193,10 @@ typedef enum { CLOTH_SIMSETTINGS_FLAG_GOAL = (1 << 3), /** True if tearing is enabled. */ CLOTH_SIMSETTINGS_FLAG_TEARING = (1 << 4), + /** True if pressure sim is enabled. */ + CLOTH_SIMSETTINGS_FLAG_PRESSURE = (1 << 5), + /** Use the user defined target volume. */ + CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL = (1 << 6), /** DEPRECATED, for versioning only. */ CLOTH_SIMSETTINGS_FLAG_SCALING = (1 << 8), /** Edit cache in edit-mode. */ diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 463cbd4f378..2be312bc4d9 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -130,6 +130,11 @@ void cloth_init(ClothModifierData *clmd) clmd->sim_parms->eff_force_scale = 1000.0; clmd->sim_parms->eff_wind_scale = 250.0; + /* Pressure settings */ + clmd->sim_parms->uniform_pressure_force = 0.0f; + clmd->sim_parms->target_volume = 0.0f; + clmd->sim_parms->pressure_factor = 1.0f; + // also from softbodies clmd->sim_parms->maxgoal = 1.0f; clmd->sim_parms->mingoal = 0.0f; @@ -291,6 +296,12 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int BKE_cloth_solver_set_positions(clmd); + ClothSimSettings *parms = clmd->sim_parms; + if (parms->flags & CLOTH_SIMSETTINGS_FLAG_PRESSURE && + !(parms->flags & CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL)) { + BKE_cloth_solver_set_volume(clmd); + } + clmd->clothObject->last_frame = MINFRAME - 1; clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame; } @@ -1742,6 +1753,6 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) return 1; } /* cloth_build_springs */ -/*************************************************************************************** - * SPRING NETWORK GPU_BATCH_BUILDING IMPLEMENTATION END - ***************************************************************************************/ + /*************************************************************************************** + * SPRING NETWORK GPU_BATCH_BUILDING IMPLEMENTATION END + ***************************************************************************************/ diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 2b3051b766a..7b655b2d8fc 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -2392,9 +2392,7 @@ static float mesh_calc_poly_volume_centroid(const MPoly *mpoly, /* Calculate the 6x volume of the tetrahedron formed by the 3 vertices * of the triangle and the origin as the fourth vertex */ - float v_cross[3]; - cross_v3_v3v3(v_cross, v_pivot, v_step1); - const float tetra_volume = dot_v3v3(v_cross, v_step2); + const float tetra_volume = volume_tri_tetrahedron_signed_v3_6x(v_pivot, v_step1, v_step2); total_volume += tetra_volume; /* Calculate the centroid of the tetrahedron formed by the 3 vertices |