2011-02-23 18:03:40 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) Blender Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "DNA_cloth_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2018-05-18 17:32:22 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
2011-05-09 04:06:48 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_edgehash.h"
|
2011-10-22 01:53:35 +00:00
|
|
|
#include "BLI_linklist.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
|
2018-02-06 19:34:36 +11:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-05-18 17:31:59 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2018-02-06 19:34:36 +11:00
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
#include "BKE_bvhutils.h"
|
2010-05-25 13:33:59 +00:00
|
|
|
#include "BKE_cloth.h"
|
2008-01-29 21:01:12 +00:00
|
|
|
#include "BKE_effect.h"
|
|
|
|
#include "BKE_global.h"
|
2018-06-05 15:59:53 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2008-01-29 21:01:12 +00:00
|
|
|
#include "BKE_modifier.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_pointcache.h"
|
2008-05-07 20:42:16 +00:00
|
|
|
|
2014-09-13 14:36:46 +02:00
|
|
|
#include "BPH_mass_spring.h"
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
// #include "PIL_time.h" /* timing for debug prints */
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
/* ********** cloth engine ******* */
|
|
|
|
/* Prototypes for internal functions.
|
2012-05-16 23:37:23 +00:00
|
|
|
*/
|
2012-05-15 12:26:29 +00:00
|
|
|
static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3]);
|
2018-05-18 17:32:22 +02:00
|
|
|
static void cloth_from_mesh ( ClothModifierData *clmd, Mesh *mesh );
|
|
|
|
static int cloth_from_object(Object *ob, ClothModifierData *clmd, Mesh *mesh, float framenr, int first);
|
2012-08-09 13:33:27 +00:00
|
|
|
static void cloth_update_springs( ClothModifierData *clmd );
|
2018-05-18 17:32:22 +02:00
|
|
|
static void cloth_update_verts( Object *ob, ClothModifierData *clmd, Mesh *mesh );
|
|
|
|
static void cloth_update_spring_lengths( ClothModifierData *clmd, Mesh *mesh );
|
|
|
|
static int cloth_build_springs ( ClothModifierData *clmd, Mesh *mesh );
|
|
|
|
static void cloth_apply_vgroup ( ClothModifierData *clmd, Mesh *mesh );
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
typedef struct BendSpringRef {
|
|
|
|
int index;
|
|
|
|
int polys;
|
|
|
|
ClothSpring *spring;
|
|
|
|
} BendSpringRef;
|
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
/******************************************************************************
|
2012-05-16 23:37:23 +00:00
|
|
|
*
|
|
|
|
* External interface called by modifier.c clothModifier functions.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2008-01-29 21:01:12 +00:00
|
|
|
/**
|
2012-06-23 23:22:19 +00:00
|
|
|
* cloth_init - creates a new cloth simulation.
|
2008-01-29 21:01:12 +00:00
|
|
|
*
|
|
|
|
* 1. create object
|
|
|
|
* 2. fill object with standard values or with the GUI settings if given
|
|
|
|
*/
|
2012-04-29 17:11:40 +00:00
|
|
|
void cloth_init(ClothModifierData *clmd )
|
2018-06-17 17:05:51 +02:00
|
|
|
{
|
2008-01-29 21:01:12 +00:00
|
|
|
/* Initialize our new data structure to reasonable values. */
|
2012-04-12 00:15:02 +00:00
|
|
|
clmd->sim_parms->gravity[0] = 0.0;
|
|
|
|
clmd->sim_parms->gravity[1] = 0.0;
|
|
|
|
clmd->sim_parms->gravity[2] = -9.81;
|
2018-08-29 00:29:37 +02:00
|
|
|
clmd->sim_parms->tension = 15.0;
|
|
|
|
clmd->sim_parms->max_tension = 15.0;
|
|
|
|
clmd->sim_parms->compression = 15.0;
|
|
|
|
clmd->sim_parms->max_compression = 15.0;
|
|
|
|
clmd->sim_parms->shear = 5.0;
|
|
|
|
clmd->sim_parms->max_shear = 5.0;
|
2008-03-12 10:41:47 +00:00
|
|
|
clmd->sim_parms->bending = 0.5;
|
2016-08-13 19:40:22 +03:00
|
|
|
clmd->sim_parms->max_bend = 0.5;
|
2018-08-29 00:29:37 +02:00
|
|
|
clmd->sim_parms->tension_damp = 5.0;
|
|
|
|
clmd->sim_parms->compression_damp = 5.0;
|
|
|
|
clmd->sim_parms->shear_damp = 5.0;
|
2014-09-26 17:25:21 +02:00
|
|
|
clmd->sim_parms->bending_damping = 0.5;
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->sim_parms->Cvi = 1.0;
|
2008-03-12 10:41:47 +00:00
|
|
|
clmd->sim_parms->mass = 0.3f;
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->sim_parms->stepsPerFrame = 5;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
clmd->sim_parms->flags = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->sim_parms->solver_type = 0;
|
|
|
|
clmd->sim_parms->maxspringlen = 10;
|
|
|
|
clmd->sim_parms->vgroup_mass = 0;
|
2014-02-06 18:44:05 +01:00
|
|
|
clmd->sim_parms->vgroup_shrink = 0;
|
|
|
|
clmd->sim_parms->shrink_min = 0.0f; /* min amount the fabric will shrink by 0.0 = no shrinking, 1.0 = shrink to nothing*/
|
2008-02-12 11:04:58 +00:00
|
|
|
clmd->sim_parms->avg_spring_len = 0.0;
|
2008-02-28 00:01:19 +00:00
|
|
|
clmd->sim_parms->presets = 2; /* cotton as start setting */
|
2008-04-09 16:38:26 +00:00
|
|
|
clmd->sim_parms->timescale = 1.0f; /* speed factor, describes how fast cloth moves */
|
2016-07-30 14:46:19 +10:00
|
|
|
clmd->sim_parms->time_scale = 1.0f; /* multiplies cloth speed */
|
2009-11-18 13:33:52 +00:00
|
|
|
clmd->sim_parms->reset = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->coll_parms->self_friction = 5.0;
|
2008-02-03 22:37:43 +00:00
|
|
|
clmd->coll_parms->friction = 5.0;
|
2008-07-02 20:28:49 +00:00
|
|
|
clmd->coll_parms->loop_count = 2;
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->coll_parms->epsilon = 0.015f;
|
|
|
|
clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
|
2008-02-11 13:30:52 +00:00
|
|
|
clmd->coll_parms->collision_list = NULL;
|
2018-09-26 17:18:16 +02:00
|
|
|
clmd->coll_parms->selfepsilon = 0.015;
|
2012-06-06 13:30:05 +00:00
|
|
|
clmd->coll_parms->vgroup_selfcol = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
/* These defaults are copied from softbody.c's
|
2012-05-16 23:37:23 +00:00
|
|
|
* softbody_calc_forces() function.
|
|
|
|
*/
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->sim_parms->eff_force_scale = 1000.0;
|
|
|
|
clmd->sim_parms->eff_wind_scale = 250.0;
|
|
|
|
|
|
|
|
// also from softbodies
|
|
|
|
clmd->sim_parms->maxgoal = 1.0f;
|
|
|
|
clmd->sim_parms->mingoal = 0.0f;
|
|
|
|
clmd->sim_parms->defgoal = 0.0f;
|
2008-02-27 03:23:17 +00:00
|
|
|
clmd->sim_parms->goalspring = 1.0f;
|
2008-02-28 23:12:50 +00:00
|
|
|
clmd->sim_parms->goalfrict = 0.0f;
|
2009-12-11 00:09:58 +00:00
|
|
|
clmd->sim_parms->velocity_smooth = 0.0f;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2014-11-06 14:05:32 +01:00
|
|
|
clmd->sim_parms->voxel_cell_size = 0.1f;
|
2014-09-17 14:21:06 +02:00
|
|
|
|
2018-08-29 00:29:37 +02:00
|
|
|
clmd->sim_parms->bending_model = CLOTH_BENDING_ANGULAR;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!clmd->sim_parms->effector_weights)
|
2018-12-02 14:14:51 +11:00
|
|
|
clmd->sim_parms->effector_weights = BKE_effector_add_weights(NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (clmd->point_cache)
|
|
|
|
clmd->point_cache->step = 1;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
static BVHTree *bvhtree_build_from_cloth (ClothModifierData *clmd, float epsilon)
|
2008-01-21 02:23:03 +00:00
|
|
|
{
|
2008-08-17 17:08:00 +00:00
|
|
|
unsigned int i;
|
2008-05-07 20:42:16 +00:00
|
|
|
BVHTree *bvhtree;
|
2009-06-08 20:08:19 +00:00
|
|
|
Cloth *cloth;
|
2008-05-07 20:42:16 +00:00
|
|
|
ClothVertex *verts;
|
2015-07-31 14:00:07 +10:00
|
|
|
const MVertTri *vt;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!clmd)
|
2008-01-21 02:23:03 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cloth = clmd->clothObject;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!cloth)
|
2008-01-21 02:23:03 +00:00
|
|
|
return NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-21 02:23:03 +00:00
|
|
|
verts = cloth->verts;
|
2015-07-31 14:00:07 +10:00
|
|
|
vt = cloth->tri;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* in the moment, return zero if no faces there */
|
2015-07-31 14:00:07 +10:00
|
|
|
if (!cloth->tri_num)
|
2008-02-26 14:25:29 +00:00
|
|
|
return NULL;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
|
|
|
/* create quadtree with k=26 */
|
2015-07-31 14:00:07 +10:00
|
|
|
bvhtree = BLI_bvhtree_new(cloth->tri_num, epsilon, 4, 26);
|
2012-07-06 23:56:59 +00:00
|
|
|
|
|
|
|
/* fill tree */
|
2015-07-31 14:00:07 +10:00
|
|
|
for (i = 0; i < cloth->tri_num; i++, vt++) {
|
|
|
|
float co[3][3];
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
copy_v3_v3(co[0], verts[vt->tri[0]].xold);
|
|
|
|
copy_v3_v3(co[1], verts[vt->tri[1]].xold);
|
|
|
|
copy_v3_v3(co[2], verts[vt->tri[2]].xold);
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
BLI_bvhtree_insert(bvhtree, i, co[0], 3);
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
|
|
|
/* balance tree */
|
2008-05-07 20:42:16 +00:00
|
|
|
BLI_bvhtree_balance(bvhtree);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-05-07 20:42:16 +00:00
|
|
|
return bvhtree;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 17:18:16 +02:00
|
|
|
void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self)
|
2018-06-17 17:05:51 +02:00
|
|
|
{
|
2008-01-29 21:01:12 +00:00
|
|
|
unsigned int i = 0;
|
|
|
|
Cloth *cloth = clmd->clothObject;
|
2018-09-26 17:18:16 +02:00
|
|
|
BVHTree *bvhtree;
|
2008-01-29 21:01:12 +00:00
|
|
|
ClothVertex *verts = cloth->verts;
|
2015-07-31 14:00:07 +10:00
|
|
|
const MVertTri *vt;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-09-26 17:18:16 +02:00
|
|
|
if (self) {
|
|
|
|
bvhtree = cloth->bvhselftree;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bvhtree = cloth->bvhtree;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!bvhtree)
|
2008-01-29 21:01:12 +00:00
|
|
|
return;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
vt = cloth->tri;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
/* update vertex position in bvh tree */
|
|
|
|
if (verts && vt) {
|
|
|
|
for (i = 0; i < cloth->tri_num; i++, vt++) {
|
|
|
|
float co[3][3], co_moving[3][3];
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
/* copy new locations into array */
|
2012-04-28 06:31:57 +00:00
|
|
|
if (moving) {
|
2018-09-26 17:18:16 +02:00
|
|
|
copy_v3_v3(co[0], verts[vt->tri[0]].txold);
|
|
|
|
copy_v3_v3(co[1], verts[vt->tri[1]].txold);
|
|
|
|
copy_v3_v3(co[2], verts[vt->tri[2]].txold);
|
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
/* update moving positions */
|
|
|
|
copy_v3_v3(co_moving[0], verts[vt->tri[0]].tx);
|
|
|
|
copy_v3_v3(co_moving[1], verts[vt->tri[1]].tx);
|
|
|
|
copy_v3_v3(co_moving[2], verts[vt->tri[2]].tx);
|
|
|
|
|
|
|
|
ret = BLI_bvhtree_update_node(bvhtree, i, co[0], co_moving[0], 3);
|
2008-05-07 20:42:16 +00:00
|
|
|
}
|
2012-03-06 18:40:15 +00:00
|
|
|
else {
|
2018-09-26 17:18:16 +02:00
|
|
|
copy_v3_v3(co[0], verts[vt->tri[0]].tx);
|
|
|
|
copy_v3_v3(co[1], verts[vt->tri[1]].tx);
|
|
|
|
copy_v3_v3(co[2], verts[vt->tri[2]].tx);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-09-26 17:18:16 +02:00
|
|
|
ret = BLI_bvhtree_update_node(bvhtree, i, co[0], NULL, 3);
|
2008-05-23 20:20:14 +00:00
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
/* check if tree is already full */
|
|
|
|
if (ret == false) {
|
2008-05-23 20:20:14 +00:00
|
|
|
break;
|
2015-07-31 14:00:07 +10:00
|
|
|
}
|
2008-05-23 20:20:14 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-05-23 20:20:14 +00:00
|
|
|
BLI_bvhtree_update_tree(bvhtree);
|
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PTCacheID pid;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_id_from_cloth(&pid, ob, clmd);
|
|
|
|
|
|
|
|
// don't do anything as long as we're in editmode!
|
2018-04-05 18:20:27 +02:00
|
|
|
if (pid.cache->edit && ob->mode & OB_MODE_PARTICLE_EDIT)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_AFTER, framenr);
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
static int do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
PointCache *cache;
|
|
|
|
|
|
|
|
cache= clmd->point_cache;
|
|
|
|
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
/* initialize simulation data if it didn't exist already */
|
2012-10-21 05:46:41 +00:00
|
|
|
if (clmd->clothObject == NULL) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!cloth_from_object(ob, clmd, result, framenr, 1)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_invalidate(cache);
|
2013-08-24 14:32:43 +00:00
|
|
|
modifier_setError(&(clmd->modifier), "Can't initialize cloth");
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clmd->clothObject == NULL) {
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_invalidate(cache);
|
2013-08-24 14:32:43 +00:00
|
|
|
modifier_setError(&(clmd->modifier), "Null cloth object");
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-13 18:45:58 +02:00
|
|
|
BKE_cloth_solver_set_positions(clmd);
|
2012-01-09 14:08:06 +00:00
|
|
|
|
|
|
|
clmd->clothObject->last_frame= MINFRAME-1;
|
2018-09-26 17:18:16 +02:00
|
|
|
clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
return 1;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 14:42:03 +02:00
|
|
|
static int do_step_cloth(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
|
|
|
ClothVertex *verts = NULL;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
Cloth *cloth;
|
|
|
|
ListBase *effectors = NULL;
|
|
|
|
MVert *mvert;
|
2010-10-21 08:32:53 +00:00
|
|
|
unsigned int i = 0;
|
|
|
|
int ret = 0;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
|
|
|
/* simulate 1 frame forward */
|
|
|
|
cloth = clmd->clothObject;
|
|
|
|
verts = cloth->verts;
|
2018-05-18 17:32:22 +02:00
|
|
|
mvert = result->mvert;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
|
|
|
/* force any pinned verts to their constrained location. */
|
2015-07-31 14:00:07 +10:00
|
|
|
for (i = 0; i < clmd->clothObject->mvert_num; i++, verts++) {
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
/* save the previous position. */
|
2011-11-06 16:38:21 +00:00
|
|
|
copy_v3_v3(verts->xold, verts->xconst);
|
|
|
|
copy_v3_v3(verts->txold, verts->x);
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
|
|
|
/* Get the current position. */
|
2012-08-12 22:54:35 +00:00
|
|
|
copy_v3_v3(verts->xconst, mvert[i].co);
|
|
|
|
mul_m4_v3(ob->obmat, verts->xconst);
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2018-06-22 14:42:03 +02:00
|
|
|
effectors = BKE_effectors_create(depsgraph, ob, NULL, clmd->sim_parms->effector_weights);
|
2012-08-09 13:33:27 +00:00
|
|
|
|
2016-07-30 14:47:31 +10:00
|
|
|
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH )
|
|
|
|
cloth_update_verts ( ob, clmd, result );
|
|
|
|
|
2012-08-09 13:33:27 +00:00
|
|
|
/* Support for dynamic vertex groups, changing from frame to frame */
|
|
|
|
cloth_apply_vgroup ( clmd, result );
|
2016-04-11 12:21:17 +03:00
|
|
|
|
2018-09-14 15:46:55 +02:00
|
|
|
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH) ||
|
|
|
|
(clmd->sim_parms->vgroup_shrink > 0) || (clmd->sim_parms->shrink_min > 0.0f))
|
|
|
|
{
|
2016-04-11 12:21:17 +03:00
|
|
|
cloth_update_spring_lengths ( clmd, result );
|
2018-09-14 15:46:55 +02:00
|
|
|
}
|
2016-04-11 12:21:17 +03:00
|
|
|
|
2012-08-09 13:33:27 +00:00
|
|
|
cloth_update_springs( clmd );
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
// TIMEIT_START(cloth_step)
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
|
|
|
/* call the solver. */
|
2018-06-22 14:42:03 +02:00
|
|
|
ret = BPH_cloth_solve(depsgraph, ob, framenr, clmd, effectors);
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
// TIMEIT_END(cloth_step)
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2018-06-21 19:45:39 +02:00
|
|
|
BKE_effectors_free(effectors);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2008-07-02 20:28:49 +00:00
|
|
|
// printf ( "%f\n", ( float ) tval() );
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
* clothModifier_do - main simulation function
|
2012-05-16 23:37:23 +00:00
|
|
|
************************************************/
|
2018-06-22 14:42:03 +02:00
|
|
|
void clothModifier_do(ClothModifierData *clmd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh, float (*vertexCos)[3])
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
PointCache *cache;
|
|
|
|
PTCacheID pid;
|
|
|
|
float timescale;
|
|
|
|
int framenr, startframe, endframe;
|
|
|
|
int cache_result;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2018-05-18 17:31:59 +02:00
|
|
|
framenr = DEG_get_ctime(depsgraph);
|
2016-12-28 17:30:58 +01:00
|
|
|
cache= clmd->point_cache;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_id_from_cloth(&pid, ob, clmd);
|
|
|
|
BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale);
|
|
|
|
clmd->sim_parms->timescale= timescale * clmd->sim_parms->time_scale;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
if (clmd->sim_parms->reset || (clmd->clothObject && mesh->totvert != clmd->clothObject->mvert_num)) {
|
2009-11-18 13:33:52 +00:00
|
|
|
clmd->sim_parms->reset = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
cache->flag |= PTCACHE_OUTDATED;
|
|
|
|
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
|
|
|
|
BKE_ptcache_validate(cache, 0);
|
|
|
|
cache->last_exact= 0;
|
|
|
|
cache->flag &= ~PTCACHE_REDO_NEEDED;
|
2009-11-18 13:33:52 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
/* simulation is only active during a specific period */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (framenr < startframe) {
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_invalidate(cache);
|
2012-05-15 12:26:29 +00:00
|
|
|
return;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (framenr > endframe) {
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
framenr= endframe;
|
2008-02-03 22:37:43 +00:00
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
/* initialize simulation data if it didn't exist already */
|
2018-05-18 17:32:22 +02:00
|
|
|
if (!do_init_cloth(ob, clmd, mesh, framenr))
|
2012-05-15 12:26:29 +00:00
|
|
|
return;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2015-02-12 16:28:15 +01:00
|
|
|
if (framenr == startframe) {
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
|
2018-05-18 17:32:22 +02:00
|
|
|
do_init_cloth(ob, clmd, mesh, framenr);
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_validate(cache, framenr);
|
|
|
|
cache->flag &= ~PTCACHE_REDO_NEEDED;
|
|
|
|
clmd->clothObject->last_frame= framenr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to read from cache */
|
|
|
|
bool can_simulate = (framenr == clmd->clothObject->last_frame+1) && !(cache->flag & PTCACHE_BAKED);
|
|
|
|
|
|
|
|
cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, can_simulate);
|
|
|
|
|
|
|
|
if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED ||
|
2018-04-16 18:13:48 +02:00
|
|
|
(!can_simulate && cache_result == PTCACHE_READ_OLD))
|
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_cloth_solver_set_positions(clmd);
|
|
|
|
cloth_to_object (ob, clmd, vertexCos);
|
|
|
|
|
|
|
|
BKE_ptcache_validate(cache, framenr);
|
|
|
|
|
|
|
|
if (cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
|
|
|
|
BKE_ptcache_write(&pid, framenr);
|
|
|
|
|
2012-01-09 14:08:06 +00:00
|
|
|
clmd->clothObject->last_frame= framenr;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (cache_result==PTCACHE_READ_OLD) {
|
|
|
|
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 */
|
|
|
|
BKE_ptcache_invalidate(cache);
|
2012-05-15 12:26:29 +00:00
|
|
|
return;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* if on second frame, write cache for first frame */
|
|
|
|
if (cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
|
|
|
|
BKE_ptcache_write(&pid, startframe);
|
|
|
|
|
|
|
|
clmd->sim_parms->timescale *= framenr - cache->simframe;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* do simulation */
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_validate(cache, framenr);
|
|
|
|
|
2018-06-22 14:42:03 +02:00
|
|
|
if (!do_step_cloth(depsgraph, ob, clmd, mesh, framenr)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_ptcache_invalidate(cache);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
BKE_ptcache_write(&pid, framenr);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-05-15 12:26:29 +00:00
|
|
|
cloth_to_object (ob, clmd, vertexCos);
|
2012-01-09 14:08:06 +00:00
|
|
|
clmd->clothObject->last_frame= framenr;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* frees all */
|
2010-10-16 14:32:17 +00:00
|
|
|
void cloth_free_modifier(ClothModifierData *clmd )
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
|
|
|
Cloth *cloth = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
if ( !clmd )
|
|
|
|
return;
|
|
|
|
|
|
|
|
cloth = clmd->clothObject;
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( cloth ) {
|
2015-01-19 18:39:41 +01:00
|
|
|
BPH_cloth_solver_free(clmd);
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
// Free the verts.
|
|
|
|
if ( cloth->verts != NULL )
|
|
|
|
MEM_freeN ( cloth->verts );
|
|
|
|
|
|
|
|
cloth->verts = NULL;
|
2015-07-31 14:00:07 +10:00
|
|
|
cloth->mvert_num = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
// Free the springs.
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( cloth->springs != NULL ) {
|
2008-01-29 21:01:12 +00:00
|
|
|
LinkNode *search = cloth->springs;
|
2012-04-28 06:31:57 +00:00
|
|
|
while (search) {
|
2008-01-29 21:01:12 +00:00
|
|
|
ClothSpring *spring = search->link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
MEM_SAFE_FREE(spring->pa);
|
|
|
|
MEM_SAFE_FREE(spring->pb);
|
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
MEM_freeN ( spring );
|
|
|
|
search = search->next;
|
|
|
|
}
|
|
|
|
BLI_linklist_free(cloth->springs, NULL);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
cloth->springs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cloth->springs = NULL;
|
|
|
|
cloth->numsprings = 0;
|
|
|
|
|
|
|
|
// free BVH collision tree
|
2008-05-07 20:42:16 +00:00
|
|
|
if ( cloth->bvhtree )
|
|
|
|
BLI_bvhtree_free ( cloth->bvhtree );
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-05-23 20:20:14 +00:00
|
|
|
if ( cloth->bvhselftree )
|
|
|
|
BLI_bvhtree_free ( cloth->bvhselftree );
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
// we save our faces for collision objects
|
2015-07-31 14:00:07 +10:00
|
|
|
if (cloth->tri)
|
|
|
|
MEM_freeN(cloth->tri);
|
|
|
|
|
2014-04-04 14:15:57 +11:00
|
|
|
if (cloth->edgeset)
|
|
|
|
BLI_edgeset_free(cloth->edgeset);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-09-02 18:28:27 +10:00
|
|
|
#if 0
|
|
|
|
if (clmd->clothObject->facemarks) {
|
|
|
|
MEM_freeN(clmd->clothObject->facemarks);
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-29 21:01:12 +00:00
|
|
|
MEM_freeN ( cloth );
|
|
|
|
clmd->clothObject = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* frees all */
|
2012-04-29 17:11:40 +00:00
|
|
|
void cloth_free_modifier_extern(ClothModifierData *clmd )
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
|
|
|
Cloth *cloth = NULL;
|
2019-01-16 19:41:29 +01:00
|
|
|
if (G.debug & G_DEBUG_SIMDATA) {
|
2008-01-29 21:01:12 +00:00
|
|
|
printf("cloth_free_modifier_extern\n");
|
2019-01-16 19:41:29 +01:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
if ( !clmd )
|
|
|
|
return;
|
|
|
|
|
|
|
|
cloth = clmd->clothObject;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( cloth ) {
|
2019-01-16 19:41:29 +01:00
|
|
|
if (G.debug & G_DEBUG_SIMDATA) {
|
2008-01-29 21:01:12 +00:00
|
|
|
printf("cloth_free_modifier_extern in\n");
|
2019-01-16 19:41:29 +01:00
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2015-01-19 18:39:41 +01:00
|
|
|
BPH_cloth_solver_free(clmd);
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
// Free the verts.
|
|
|
|
if ( cloth->verts != NULL )
|
|
|
|
MEM_freeN ( cloth->verts );
|
|
|
|
|
|
|
|
cloth->verts = NULL;
|
2015-07-31 14:00:07 +10:00
|
|
|
cloth->mvert_num = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
// Free the springs.
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( cloth->springs != NULL ) {
|
2008-01-29 21:01:12 +00:00
|
|
|
LinkNode *search = cloth->springs;
|
2012-04-28 06:31:57 +00:00
|
|
|
while (search) {
|
2008-01-29 21:01:12 +00:00
|
|
|
ClothSpring *spring = search->link;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
MEM_SAFE_FREE(spring->pa);
|
|
|
|
MEM_SAFE_FREE(spring->pb);
|
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
MEM_freeN ( spring );
|
|
|
|
search = search->next;
|
|
|
|
}
|
|
|
|
BLI_linklist_free(cloth->springs, NULL);
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
cloth->springs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cloth->springs = NULL;
|
|
|
|
cloth->numsprings = 0;
|
|
|
|
|
|
|
|
// free BVH collision tree
|
2008-05-07 20:42:16 +00:00
|
|
|
if ( cloth->bvhtree )
|
|
|
|
BLI_bvhtree_free ( cloth->bvhtree );
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-05-23 20:20:14 +00:00
|
|
|
if ( cloth->bvhselftree )
|
|
|
|
BLI_bvhtree_free ( cloth->bvhselftree );
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
// we save our faces for collision objects
|
2015-07-31 14:00:07 +10:00
|
|
|
if (cloth->tri)
|
|
|
|
MEM_freeN(cloth->tri);
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2014-04-04 14:15:57 +11:00
|
|
|
if (cloth->edgeset)
|
|
|
|
BLI_edgeset_free(cloth->edgeset);
|
2012-07-06 23:56:59 +00:00
|
|
|
|
|
|
|
|
2018-09-02 18:28:27 +10:00
|
|
|
#if 0
|
|
|
|
if (clmd->clothObject->facemarks) {
|
|
|
|
MEM_freeN(clmd->clothObject->facemarks);
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-29 21:01:12 +00:00
|
|
|
MEM_freeN ( cloth );
|
|
|
|
clmd->clothObject = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2012-05-16 23:37:23 +00:00
|
|
|
*
|
|
|
|
* Internal functions.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* cloth_to_object - copies the deformed vertices to the object.
|
|
|
|
*
|
|
|
|
**/
|
2012-05-15 12:26:29 +00:00
|
|
|
static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3])
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
2018-03-23 11:51:19 +01:00
|
|
|
unsigned int i = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
Cloth *cloth = clmd->clothObject;
|
|
|
|
|
|
|
|
if (clmd->clothObject) {
|
|
|
|
/* inverse matrix is not uptodate... */
|
2009-11-10 20:43:45 +00:00
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
for (i = 0; i < cloth->mvert_num; i++) {
|
2012-05-15 12:26:29 +00:00
|
|
|
copy_v3_v3 (vertexCos[i], cloth->verts[i].x);
|
|
|
|
mul_m4_v3(ob->imat, vertexCos[i]); /* cloth is in global coords */
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 11:49:07 +00:00
|
|
|
int cloth_uses_vgroup(ClothModifierData *clmd)
|
|
|
|
{
|
2018-09-14 15:46:55 +02:00
|
|
|
return (((clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF) && (clmd->coll_parms->vgroup_selfcol > 0)) ||
|
|
|
|
(clmd->sim_parms->vgroup_struct > 0) ||
|
|
|
|
(clmd->sim_parms->vgroup_bend > 0) ||
|
|
|
|
(clmd->sim_parms->vgroup_shrink > 0) ||
|
|
|
|
(clmd->sim_parms->vgroup_mass > 0));
|
2010-03-30 11:49:07 +00:00
|
|
|
}
|
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
/**
|
|
|
|
* cloth_apply_vgroup - applies a vertex group as specified by type
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
/* can be optimized to do all groups in one loop */
|
2018-05-18 17:32:22 +02:00
|
|
|
static void cloth_apply_vgroup ( ClothModifierData *clmd, Mesh *mesh )
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
2008-08-17 17:08:00 +00:00
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
MDeformVert *dvert = NULL;
|
|
|
|
Cloth *clothObj = NULL;
|
2015-07-31 14:00:07 +10:00
|
|
|
int mvert_num;
|
2011-09-28 15:22:13 +00:00
|
|
|
/* float goalfac = 0; */ /* UNUSED */
|
2008-01-29 21:01:12 +00:00
|
|
|
ClothVertex *verts = NULL;
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
if (!clmd || !mesh) return;
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
clothObj = clmd->clothObject;
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
mvert_num = mesh->totvert;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
verts = clothObj->verts;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (cloth_uses_vgroup(clmd)) {
|
2015-07-31 14:00:07 +10:00
|
|
|
for (i = 0; i < mvert_num; i++, verts++) {
|
2012-08-10 00:04:15 +00:00
|
|
|
|
|
|
|
/* Reset Goal values to standard */
|
2018-09-14 15:46:55 +02:00
|
|
|
if (clmd->sim_parms->vgroup_mass > 0)
|
2012-08-10 00:04:15 +00:00
|
|
|
verts->goal= clmd->sim_parms->defgoal;
|
|
|
|
else
|
|
|
|
verts->goal= 0.0f;
|
|
|
|
|
2016-04-28 17:53:34 +03:00
|
|
|
/* Compute base cloth shrink weight */
|
|
|
|
verts->shrink_factor = 0.0f;
|
|
|
|
|
2012-10-09 12:59:20 +00:00
|
|
|
/* Reset vertex flags */
|
|
|
|
verts->flags &= ~CLOTH_VERT_FLAG_PINNED;
|
|
|
|
verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL;
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
dvert = CustomData_get(&mesh->vdata, i, CD_MDEFORMVERT);
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( dvert ) {
|
2012-08-10 00:04:15 +00:00
|
|
|
for ( j = 0; j < dvert->totweight; j++ ) {
|
2018-09-14 15:46:55 +02:00
|
|
|
if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass - 1)) {
|
2008-01-29 21:01:12 +00:00
|
|
|
verts->goal = dvert->dw [j].weight;
|
2012-08-10 00:04:15 +00:00
|
|
|
|
2011-09-28 15:22:13 +00:00
|
|
|
/* goalfac= 1.0f; */ /* UNUSED */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
// Kicking goal factor to simplify things...who uses that anyway?
|
|
|
|
// ABS ( clmd->sim_parms->maxgoal - clmd->sim_parms->mingoal );
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-11-11 18:16:20 +01:00
|
|
|
verts->goal = pow4f(verts->goal);
|
2012-10-09 12:59:20 +00:00
|
|
|
if ( verts->goal >= SOFTGOALSNAP )
|
2013-03-15 10:48:48 +00:00
|
|
|
verts->flags |= CLOTH_VERT_FLAG_PINNED;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-09-14 15:46:55 +02:00
|
|
|
if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_struct - 1)) {
|
|
|
|
verts->struct_stiff = dvert->dw[j].weight;
|
|
|
|
}
|
2018-08-29 00:29:37 +02:00
|
|
|
|
2018-09-14 15:46:55 +02:00
|
|
|
if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_shear - 1)) {
|
|
|
|
verts->shear_stiff = dvert->dw[j].weight;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-09-14 15:46:55 +02:00
|
|
|
if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_bend - 1)) {
|
|
|
|
verts->bend_stiff = dvert->dw[j].weight;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2012-06-06 13:30:05 +00:00
|
|
|
|
|
|
|
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) {
|
|
|
|
if ( dvert->dw[j].def_nr == (clmd->coll_parms->vgroup_selfcol-1)) {
|
2012-06-23 23:22:19 +00:00
|
|
|
if (dvert->dw [j].weight > 0.0f) {
|
2012-06-06 13:30:05 +00:00
|
|
|
verts->flags |= CLOTH_VERT_FLAG_NOSELFCOLL;
|
2012-06-23 23:22:19 +00:00
|
|
|
}
|
2012-06-06 13:30:05 +00:00
|
|
|
}
|
2016-04-28 17:53:34 +03:00
|
|
|
}
|
2018-09-14 15:46:55 +02:00
|
|
|
if (clmd->sim_parms->vgroup_shrink > 0) {
|
|
|
|
if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_shrink - 1)) {
|
|
|
|
/* Used for linear interpolation between min and max shrink factor based on weight. */
|
|
|
|
verts->shrink_factor = dvert->dw[j].weight;
|
2015-03-11 13:14:24 +11:00
|
|
|
}
|
2012-06-06 13:30:05 +00:00
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 17:53:34 +03:00
|
|
|
static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, int i1, int i2)
|
|
|
|
{
|
2018-09-14 15:46:55 +02:00
|
|
|
/* Linear interpolation between min and max shrink factor based on weight. */
|
|
|
|
float base = 1.0f - clmd->sim_parms->shrink_min;
|
|
|
|
float delta = clmd->sim_parms->shrink_min - clmd->sim_parms->shrink_max;
|
2016-04-28 17:53:34 +03:00
|
|
|
|
2018-09-14 15:46:55 +02:00
|
|
|
float k1 = base + delta * verts[i1].shrink_factor;
|
|
|
|
float k2 = base + delta * verts[i2].shrink_factor;
|
2016-04-18 18:47:16 +03:00
|
|
|
|
2018-09-14 15:46:55 +02:00
|
|
|
/* Use geometrical mean to average two factors since it behaves better
|
|
|
|
for diagonals when a rectangle transforms into a trapezoid. */
|
|
|
|
return sqrtf(k1 * k2);
|
2016-04-28 17:53:34 +03:00
|
|
|
}
|
2014-02-06 18:44:05 +01:00
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
static int cloth_from_object(Object *ob, ClothModifierData *clmd, Mesh *mesh, float UNUSED(framenr), int first)
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
2008-08-17 17:08:00 +00:00
|
|
|
int i = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
MVert *mvert = NULL;
|
|
|
|
ClothVertex *verts = NULL;
|
2012-10-22 08:15:51 +00:00
|
|
|
float (*shapekey_rest)[3] = NULL;
|
2012-04-29 15:47:02 +00:00
|
|
|
float tnull[3] = {0, 0, 0};
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
// If we have a clothObject, free it.
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( clmd->clothObject != NULL ) {
|
2010-10-16 14:32:17 +00:00
|
|
|
cloth_free_modifier ( clmd );
|
2019-01-16 19:41:29 +01:00
|
|
|
if (G.debug & G_DEBUG_SIMDATA) {
|
2008-01-29 21:01:12 +00:00
|
|
|
printf("cloth_free_modifier cloth_from_object\n");
|
2019-01-16 19:41:29 +01:00
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a new cloth object.
|
|
|
|
clmd->clothObject = MEM_callocN ( sizeof ( Cloth ), "cloth" );
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( clmd->clothObject ) {
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->clothObject->old_solver_type = 255;
|
2014-04-04 14:15:57 +11:00
|
|
|
clmd->clothObject->edgeset = NULL;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2012-03-07 04:53:43 +00:00
|
|
|
else if (!clmd->clothObject) {
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(&(clmd->modifier), "Out of memory on allocating clmd->clothObject");
|
2008-01-29 21:01:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
// mesh input objects need Mesh
|
|
|
|
if ( !mesh )
|
2008-01-29 21:01:12 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
cloth_from_mesh ( clmd, mesh );
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
// create springs
|
2008-01-29 21:01:12 +00:00
|
|
|
clmd->clothObject->springs = NULL;
|
|
|
|
clmd->clothObject->numsprings = -1;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2016-07-30 14:47:31 +10:00
|
|
|
if ( clmd->sim_parms->shapekey_rest && !(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH ) )
|
2018-05-18 17:32:22 +02:00
|
|
|
shapekey_rest = CustomData_get_layer(&mesh->vdata, CD_CLOTH_ORCO);
|
2010-03-30 11:49:07 +00:00
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
mvert = mesh->mvert;
|
2010-03-30 11:49:07 +00:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
verts = clmd->clothObject->verts;
|
|
|
|
|
|
|
|
// set initial values
|
2018-05-18 17:32:22 +02:00
|
|
|
for ( i = 0; i < mesh->totvert; i++, verts++ ) {
|
2012-04-28 06:31:57 +00:00
|
|
|
if (first) {
|
2012-04-29 17:11:40 +00:00
|
|
|
copy_v3_v3(verts->x, mvert[i].co);
|
2010-03-30 11:49:07 +00:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
mul_m4_v3(ob->obmat, verts->x);
|
2010-03-30 11:49:07 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( shapekey_rest ) {
|
2016-04-18 18:48:22 +03:00
|
|
|
copy_v3_v3(verts->xrest, shapekey_rest[i]);
|
2012-04-29 17:11:40 +00:00
|
|
|
mul_m4_v3(ob->obmat, verts->xrest);
|
2010-03-30 11:49:07 +00:00
|
|
|
}
|
|
|
|
else
|
2016-04-18 18:48:22 +03:00
|
|
|
copy_v3_v3(verts->xrest, verts->x);
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-02-11 13:30:52 +00:00
|
|
|
/* no GUI interface yet */
|
2018-06-17 17:05:51 +02:00
|
|
|
verts->mass = clmd->sim_parms->mass;
|
2008-03-06 01:21:40 +00:00
|
|
|
verts->impulse_count = 0;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2018-09-14 15:46:55 +02:00
|
|
|
if (clmd->sim_parms->vgroup_mass > 0)
|
2008-01-29 21:01:12 +00:00
|
|
|
verts->goal= clmd->sim_parms->defgoal;
|
|
|
|
else
|
|
|
|
verts->goal= 0.0f;
|
|
|
|
|
2016-04-28 17:53:34 +03:00
|
|
|
verts->shrink_factor = 0.0f;
|
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
verts->flags = 0;
|
2011-11-06 16:38:21 +00:00
|
|
|
copy_v3_v3 ( verts->xold, verts->x );
|
|
|
|
copy_v3_v3 ( verts->xconst, verts->x );
|
|
|
|
copy_v3_v3 ( verts->txold, verts->x );
|
|
|
|
copy_v3_v3 ( verts->tx, verts->x );
|
2012-04-29 17:11:40 +00:00
|
|
|
mul_v3_fl(verts->v, 0.0f);
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
verts->impulse_count = 0;
|
2011-11-06 16:38:21 +00:00
|
|
|
copy_v3_v3 ( verts->impulse, tnull );
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
// apply / set vertex groups
|
|
|
|
// has to be happen before springs are build!
|
2018-05-18 17:32:22 +02:00
|
|
|
cloth_apply_vgroup (clmd, mesh);
|
2008-05-23 20:20:14 +00:00
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
if ( !cloth_build_springs ( clmd, mesh ) ) {
|
2010-10-16 14:32:17 +00:00
|
|
|
cloth_free_modifier ( clmd );
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(&(clmd->modifier), "Cannot build springs");
|
2008-01-29 21:01:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
// init our solver
|
2015-01-19 18:39:41 +01:00
|
|
|
BPH_cloth_solver_init(ob, clmd);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!first)
|
2014-09-13 18:45:58 +02:00
|
|
|
BKE_cloth_solver_set_positions(clmd);
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2018-09-26 17:18:16 +02:00
|
|
|
clmd->clothObject->bvhtree = bvhtree_build_from_cloth (clmd, clmd->coll_parms->epsilon);
|
|
|
|
clmd->clothObject->bvhselftree = bvhtree_build_from_cloth(clmd, clmd->coll_parms->selfepsilon);
|
2008-02-03 22:37:43 +00:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
static void cloth_from_mesh ( ClothModifierData *clmd, Mesh *mesh )
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
2018-05-18 17:32:22 +02:00
|
|
|
const MLoop *mloop = mesh->mloop;
|
|
|
|
const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
|
|
|
const unsigned int mvert_num = mesh->totvert;
|
|
|
|
const unsigned int looptri_num = mesh->runtime.looptris.len;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2008-02-12 11:04:58 +00:00
|
|
|
/* Allocate our vertices. */
|
2015-07-31 14:00:07 +10:00
|
|
|
clmd->clothObject->mvert_num = mvert_num;
|
|
|
|
clmd->clothObject->verts = MEM_callocN(sizeof(ClothVertex) * clmd->clothObject->mvert_num, "clothVertex");
|
|
|
|
if (clmd->clothObject->verts == NULL) {
|
|
|
|
cloth_free_modifier(clmd);
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(&(clmd->modifier), "Out of memory on allocating clmd->clothObject->verts");
|
2008-01-29 21:01:12 +00:00
|
|
|
printf("cloth_free_modifier clmd->clothObject->verts\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
/* save face information */
|
|
|
|
clmd->clothObject->tri_num = looptri_num;
|
|
|
|
clmd->clothObject->tri = MEM_mallocN(sizeof(MVertTri) * looptri_num, "clothLoopTris");
|
|
|
|
if (clmd->clothObject->tri == NULL) {
|
|
|
|
cloth_free_modifier(clmd);
|
|
|
|
modifier_setError(&(clmd->modifier), "Out of memory on allocating clmd->clothObject->looptri");
|
|
|
|
printf("cloth_free_modifier clmd->clothObject->looptri\n");
|
2008-01-29 21:01:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-18 17:32:22 +02:00
|
|
|
BKE_mesh_runtime_verttri_from_looptri(clmd->clothObject->tri, mloop, looptri, looptri_num);
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
/* Free the springs since they can't be correct if the vertices
|
2012-05-16 23:37:23 +00:00
|
|
|
* changed.
|
|
|
|
*/
|
2008-01-29 21:01:12 +00:00
|
|
|
if ( clmd->clothObject->springs != NULL )
|
|
|
|
MEM_freeN ( clmd->clothObject->springs );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************************
|
2018-07-18 00:12:21 +02:00
|
|
|
* SPRING NETWORK GPU_BATCH_BUILDING IMPLEMENTATION BEGIN
|
2012-05-16 23:37:23 +00:00
|
|
|
***************************************************************************************/
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2013-08-24 15:55:56 +00:00
|
|
|
BLI_INLINE void spring_verts_ordered_set(ClothSpring *spring, int v0, int v1)
|
|
|
|
{
|
|
|
|
if (v0 < v1) {
|
|
|
|
spring->ij = v0;
|
|
|
|
spring->kl = v1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
spring->ij = v1;
|
|
|
|
spring->kl = v0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
static void cloth_free_edgelist(LinkNodePair *edgelist, unsigned int mvert_num)
|
2013-08-24 14:32:43 +00:00
|
|
|
{
|
|
|
|
if (edgelist) {
|
|
|
|
unsigned int i;
|
2015-07-31 14:00:07 +10:00
|
|
|
for (i = 0; i < mvert_num; i++) {
|
2015-06-12 16:57:15 +10:00
|
|
|
BLI_linklist_free(edgelist[i].list, NULL);
|
2013-08-24 14:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(edgelist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
static void cloth_free_errorsprings(Cloth *cloth, LinkNodePair *edgelist, BendSpringRef *spring_ref)
|
2008-02-26 14:25:29 +00:00
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( cloth->springs != NULL ) {
|
2008-02-26 14:25:29 +00:00
|
|
|
LinkNode *search = cloth->springs;
|
2012-04-28 06:31:57 +00:00
|
|
|
while (search) {
|
2008-02-26 14:25:29 +00:00
|
|
|
ClothSpring *spring = search->link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
MEM_SAFE_FREE(spring->pa);
|
|
|
|
MEM_SAFE_FREE(spring->pb);
|
|
|
|
|
2008-02-26 14:25:29 +00:00
|
|
|
MEM_freeN ( spring );
|
|
|
|
search = search->next;
|
|
|
|
}
|
|
|
|
BLI_linklist_free(cloth->springs, NULL);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-02-26 14:25:29 +00:00
|
|
|
cloth->springs = NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
cloth_free_edgelist(edgelist, cloth->mvert_num);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
MEM_SAFE_FREE(spring_ref);
|
|
|
|
|
2014-04-04 14:15:57 +11:00
|
|
|
if (cloth->edgeset) {
|
|
|
|
BLI_edgeset_free(cloth->edgeset);
|
|
|
|
cloth->edgeset = NULL;
|
2013-08-24 14:32:43 +00:00
|
|
|
}
|
2008-02-26 14:25:29 +00:00
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
BLI_INLINE void cloth_bend_poly_dir(ClothVertex *verts, int i, int j, int *inds, int len, float r_dir[3])
|
|
|
|
{
|
|
|
|
float cent[3] = {0};
|
|
|
|
float fact = 1.0f / len;
|
|
|
|
|
|
|
|
for (int x = 0; x < len; x++) {
|
|
|
|
madd_v3_v3fl(cent, verts[inds[x]].xrest, fact);
|
|
|
|
}
|
|
|
|
|
|
|
|
normal_tri_v3(r_dir, verts[i].xrest, verts[j].xrest, cent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float cloth_spring_angle(ClothVertex *verts, int i, int j, int *i_a, int *i_b, int len_a, int len_b)
|
|
|
|
{
|
|
|
|
float dir_a[3], dir_b[3];
|
|
|
|
float tmp[3], vec_e[3];
|
|
|
|
float sin, cos;
|
|
|
|
|
|
|
|
/* Poly vectors. */
|
|
|
|
cloth_bend_poly_dir(verts, j, i, i_a, len_a, dir_a);
|
|
|
|
cloth_bend_poly_dir(verts, i, j, i_b, len_b, dir_b);
|
|
|
|
|
|
|
|
/* Edge vector. */
|
|
|
|
sub_v3_v3v3(vec_e, verts[i].xrest, verts[j].xrest);
|
|
|
|
normalize_v3(vec_e);
|
|
|
|
|
|
|
|
/* Compute angle. */
|
|
|
|
cos = dot_v3v3(dir_a, dir_b);
|
|
|
|
|
|
|
|
cross_v3_v3v3(tmp, dir_a, dir_b);
|
|
|
|
sin = dot_v3v3(tmp, vec_e);
|
|
|
|
|
|
|
|
return atan2f(sin, cos);
|
|
|
|
}
|
|
|
|
|
2014-12-22 11:54:24 +01:00
|
|
|
static void cloth_hair_update_bending_targets(ClothModifierData *clmd)
|
2014-09-25 15:42:08 +02:00
|
|
|
{
|
|
|
|
Cloth *cloth = clmd->clothObject;
|
|
|
|
LinkNode *search = NULL;
|
2014-09-25 23:19:20 +02:00
|
|
|
float hair_frame[3][3], dir_old[3], dir_new[3];
|
2014-09-26 09:26:08 +02:00
|
|
|
int prev_mn; /* to find hair chains */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-12-22 11:54:24 +01:00
|
|
|
if (!clmd->hairdata)
|
|
|
|
return;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 15:42:08 +02:00
|
|
|
/* XXX Note: we need to propagate frames from the root up,
|
|
|
|
* but structural hair springs are stored in reverse order.
|
|
|
|
* The bending springs however are then inserted in the same
|
|
|
|
* order as vertices again ...
|
|
|
|
* This messy situation can be resolved when solver data is
|
|
|
|
* generated directly from a dedicated hair system.
|
|
|
|
*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-26 09:26:08 +02:00
|
|
|
prev_mn = -1;
|
2014-09-25 15:42:08 +02:00
|
|
|
for (search = cloth->springs; search; search = search->next) {
|
2014-09-26 09:26:08 +02:00
|
|
|
ClothSpring *spring = search->link;
|
2014-11-17 19:44:42 +01:00
|
|
|
ClothHairData *hair_ij, *hair_kl;
|
2014-09-26 09:26:08 +02:00
|
|
|
bool is_root = spring->kl != prev_mn;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (spring->type != CLOTH_SPRING_TYPE_BENDING_HAIR) {
|
2014-09-25 15:42:08 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-11-17 19:44:42 +01:00
|
|
|
hair_ij = &clmd->hairdata[spring->ij];
|
|
|
|
hair_kl = &clmd->hairdata[spring->kl];
|
2014-09-25 15:42:08 +02:00
|
|
|
if (is_root) {
|
|
|
|
/* initial hair frame from root orientation */
|
2014-09-25 23:19:20 +02:00
|
|
|
copy_m3_m3(hair_frame, hair_ij->rot);
|
2014-09-25 15:42:08 +02:00
|
|
|
/* surface normal is the initial direction,
|
|
|
|
* parallel transport then keeps it aligned to the hair direction
|
|
|
|
*/
|
2014-09-25 23:19:20 +02:00
|
|
|
copy_v3_v3(dir_new, hair_frame[2]);
|
2014-09-25 15:42:08 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
copy_v3_v3(dir_old, dir_new);
|
|
|
|
sub_v3_v3v3(dir_new, cloth->verts[spring->mn].x, cloth->verts[spring->kl].x);
|
|
|
|
normalize_v3(dir_new);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
/* get local targets for kl/mn vertices by putting rest targets into the current frame,
|
|
|
|
* then multiply with the rest length to get the actual goals
|
|
|
|
*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
mul_v3_m3v3(spring->target, hair_frame, hair_kl->rest_target);
|
|
|
|
mul_v3_fl(spring->target, spring->restlen);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
/* move frame to next hair segment */
|
|
|
|
cloth_parallel_transport_hair_frame(hair_frame, dir_old, dir_new);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-26 09:26:08 +02:00
|
|
|
prev_mn = spring->mn;
|
2014-09-25 23:19:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 11:54:24 +01:00
|
|
|
static void cloth_hair_update_bending_rest_targets(ClothModifierData *clmd)
|
2014-09-25 23:19:20 +02:00
|
|
|
{
|
|
|
|
Cloth *cloth = clmd->clothObject;
|
|
|
|
LinkNode *search = NULL;
|
|
|
|
float hair_frame[3][3], dir_old[3], dir_new[3];
|
2014-09-26 09:26:08 +02:00
|
|
|
int prev_mn; /* to find hair roots */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-12-22 11:54:24 +01:00
|
|
|
if (!clmd->hairdata)
|
|
|
|
return;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
/* XXX Note: we need to propagate frames from the root up,
|
|
|
|
* but structural hair springs are stored in reverse order.
|
|
|
|
* The bending springs however are then inserted in the same
|
|
|
|
* order as vertices again ...
|
|
|
|
* This messy situation can be resolved when solver data is
|
|
|
|
* generated directly from a dedicated hair system.
|
|
|
|
*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-26 09:26:08 +02:00
|
|
|
prev_mn = -1;
|
2014-09-25 23:19:20 +02:00
|
|
|
for (search = cloth->springs; search; search = search->next) {
|
2014-09-26 09:26:08 +02:00
|
|
|
ClothSpring *spring = search->link;
|
2014-11-17 19:44:42 +01:00
|
|
|
ClothHairData *hair_ij, *hair_kl;
|
2014-09-26 09:26:08 +02:00
|
|
|
bool is_root = spring->kl != prev_mn;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (spring->type != CLOTH_SPRING_TYPE_BENDING_HAIR) {
|
2014-09-25 23:19:20 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-11-17 19:44:42 +01:00
|
|
|
hair_ij = &clmd->hairdata[spring->ij];
|
|
|
|
hair_kl = &clmd->hairdata[spring->kl];
|
2014-09-25 23:19:20 +02:00
|
|
|
if (is_root) {
|
|
|
|
/* initial hair frame from root orientation */
|
|
|
|
copy_m3_m3(hair_frame, hair_ij->rot);
|
|
|
|
/* surface normal is the initial direction,
|
|
|
|
* parallel transport then keeps it aligned to the hair direction
|
|
|
|
*/
|
|
|
|
copy_v3_v3(dir_new, hair_frame[2]);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
copy_v3_v3(dir_old, dir_new);
|
|
|
|
sub_v3_v3v3(dir_new, cloth->verts[spring->mn].xrest, cloth->verts[spring->kl].xrest);
|
|
|
|
normalize_v3(dir_new);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
/* dir expressed in the hair frame defines the rest target direction */
|
|
|
|
copy_v3_v3(hair_kl->rest_target, dir_new);
|
|
|
|
mul_transposed_m3_v3(hair_frame, hair_kl->rest_target);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
/* move frame to next hair segment */
|
|
|
|
cloth_parallel_transport_hair_frame(hair_frame, dir_old, dir_new);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-26 09:26:08 +02:00
|
|
|
prev_mn = spring->mn;
|
2014-09-25 15:42:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 13:33:27 +00:00
|
|
|
/* update stiffness if vertex group values are changing from frame to frame */
|
|
|
|
static void cloth_update_springs( ClothModifierData *clmd )
|
|
|
|
{
|
|
|
|
Cloth *cloth = clmd->clothObject;
|
|
|
|
LinkNode *search = NULL;
|
|
|
|
|
|
|
|
search = cloth->springs;
|
|
|
|
while (search) {
|
|
|
|
ClothSpring *spring = search->link;
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->lin_stiffness = 0.0f;
|
|
|
|
|
|
|
|
if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) {
|
|
|
|
if (spring->type & CLOTH_SPRING_TYPE_BENDING) {
|
|
|
|
spring->ang_stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f;
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 13:33:27 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (spring->type & CLOTH_SPRING_TYPE_STRUCTURAL) {
|
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].struct_stiff + cloth->verts[spring->ij].struct_stiff) / 2.0f;
|
2012-08-09 13:33:27 +00:00
|
|
|
}
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
else if (spring->type & CLOTH_SPRING_TYPE_SHEAR) {
|
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0f;
|
2012-08-09 13:33:27 +00:00
|
|
|
}
|
2012-10-21 07:58:38 +00:00
|
|
|
else if (spring->type == CLOTH_SPRING_TYPE_BENDING) {
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f;
|
2012-08-09 13:33:27 +00:00
|
|
|
}
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
else if (spring->type == CLOTH_SPRING_TYPE_BENDING_HAIR) {
|
2014-11-17 19:44:42 +01:00
|
|
|
ClothVertex *v1 = &cloth->verts[spring->ij];
|
|
|
|
ClothVertex *v2 = &cloth->verts[spring->kl];
|
|
|
|
if (clmd->hairdata) {
|
|
|
|
/* copy extra hair data to generic cloth vertices */
|
|
|
|
v1->bend_stiff = clmd->hairdata[spring->ij].bending_stiffness;
|
|
|
|
v2->bend_stiff = clmd->hairdata[spring->kl].bending_stiffness;
|
|
|
|
}
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->lin_stiffness = (v1->bend_stiff + v2->bend_stiff) / 2.0f;
|
2014-11-17 19:44:42 +01:00
|
|
|
}
|
2012-10-21 07:58:38 +00:00
|
|
|
else if (spring->type == CLOTH_SPRING_TYPE_GOAL) {
|
2012-08-10 00:04:15 +00:00
|
|
|
/* Warning: Appending NEW goal springs does not work because implicit solver would need reset! */
|
|
|
|
|
|
|
|
/* Activate / Deactivate existing springs */
|
2012-10-21 07:58:38 +00:00
|
|
|
if ((!(cloth->verts[spring->ij].flags & CLOTH_VERT_FLAG_PINNED)) &&
|
|
|
|
(cloth->verts[spring->ij].goal > ALMOST_ZERO))
|
2012-08-10 00:04:15 +00:00
|
|
|
{
|
|
|
|
spring->flags &= ~CLOTH_SPRING_FLAG_DEACTIVATE;
|
|
|
|
}
|
2012-10-21 07:58:38 +00:00
|
|
|
else {
|
2012-08-10 00:04:15 +00:00
|
|
|
spring->flags |= CLOTH_SPRING_FLAG_DEACTIVATE;
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-08-09 13:33:27 +00:00
|
|
|
search = search->next;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-12-22 11:54:24 +01:00
|
|
|
cloth_hair_update_bending_targets(clmd);
|
2014-09-25 15:42:08 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 14:47:31 +10:00
|
|
|
/* Update rest verts, for dynamically deformable cloth */
|
2018-05-18 17:32:22 +02:00
|
|
|
static void cloth_update_verts( Object *ob, ClothModifierData *clmd, Mesh *mesh )
|
2016-07-30 14:47:31 +10:00
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
2018-05-18 17:32:22 +02:00
|
|
|
MVert *mvert = mesh->mvert;
|
2016-07-30 14:47:31 +10:00
|
|
|
ClothVertex *verts = clmd->clothObject->verts;
|
|
|
|
|
|
|
|
/* vertex count is already ensured to match */
|
2018-05-18 17:32:22 +02:00
|
|
|
for ( i = 0; i < mesh->totvert; i++, verts++ ) {
|
2016-07-30 14:47:31 +10:00
|
|
|
copy_v3_v3(verts->xrest, mvert[i].co);
|
|
|
|
mul_m4_v3(ob->obmat, verts->xrest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 18:46:51 +02:00
|
|
|
/* Update spring rest length, for dynamically deformable cloth */
|
2018-05-18 17:32:22 +02:00
|
|
|
static void cloth_update_spring_lengths( ClothModifierData *clmd, Mesh *mesh )
|
2016-04-11 12:21:17 +03:00
|
|
|
{
|
|
|
|
Cloth *cloth = clmd->clothObject;
|
|
|
|
LinkNode *search = cloth->springs;
|
|
|
|
unsigned int struct_springs = 0;
|
|
|
|
unsigned int i = 0;
|
2018-05-18 17:32:22 +02:00
|
|
|
unsigned int mvert_num = (unsigned int)mesh->totvert;
|
2016-04-11 12:21:17 +03:00
|
|
|
float shrink_factor;
|
|
|
|
|
|
|
|
clmd->sim_parms->avg_spring_len = 0.0f;
|
|
|
|
|
|
|
|
for (i = 0; i < mvert_num; i++) {
|
|
|
|
cloth->verts[i].avg_spring_len = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (search) {
|
|
|
|
ClothSpring *spring = search->link;
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (spring->type != CLOTH_SPRING_TYPE_SEWING) {
|
|
|
|
if (spring->type & (CLOTH_SPRING_TYPE_STRUCTURAL | CLOTH_SPRING_TYPE_SHEAR | CLOTH_SPRING_TYPE_BENDING)) {
|
2016-04-18 18:49:03 +03:00
|
|
|
shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl);
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
}
|
|
|
|
else {
|
2016-04-18 18:49:03 +03:00
|
|
|
shrink_factor = 1.0f;
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
}
|
2016-04-18 18:49:03 +03:00
|
|
|
|
2016-04-11 12:21:17 +03:00
|
|
|
spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor;
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
|
|
|
|
if (spring->type & CLOTH_SPRING_TYPE_BENDING) {
|
|
|
|
spring->restang = cloth_spring_angle(cloth->verts, spring->ij, spring->kl,
|
|
|
|
spring->pa, spring->pb, spring->la, spring->lb);
|
|
|
|
}
|
2016-04-11 12:21:17 +03:00
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (spring->type & CLOTH_SPRING_TYPE_STRUCTURAL) {
|
2016-04-11 12:21:17 +03:00
|
|
|
clmd->sim_parms->avg_spring_len += spring->restlen;
|
|
|
|
cloth->verts[spring->ij].avg_spring_len += spring->restlen;
|
|
|
|
cloth->verts[spring->kl].avg_spring_len += spring->restlen;
|
|
|
|
struct_springs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
search = search->next;
|
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (struct_springs > 0) {
|
2016-04-11 12:21:17 +03:00
|
|
|
clmd->sim_parms->avg_spring_len /= struct_springs;
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
}
|
2016-04-11 12:21:17 +03:00
|
|
|
|
|
|
|
for (i = 0; i < mvert_num; i++) {
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (cloth->verts[i].spring_count > 0) {
|
2016-04-18 18:49:03 +03:00
|
|
|
cloth->verts[i].avg_spring_len = cloth->verts[i].avg_spring_len * 0.49f / ((float)cloth->verts[i].spring_count);
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
}
|
2016-04-11 12:21:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 15:42:08 +02:00
|
|
|
BLI_INLINE void cross_identity_v3(float r[3][3], const float v[3])
|
|
|
|
{
|
|
|
|
zero_m3(r);
|
|
|
|
r[0][1] = v[2];
|
|
|
|
r[0][2] = -v[1];
|
|
|
|
r[1][0] = -v[2];
|
|
|
|
r[1][2] = v[0];
|
|
|
|
r[2][0] = v[1];
|
|
|
|
r[2][1] = -v[0];
|
|
|
|
}
|
2012-08-09 13:33:27 +00:00
|
|
|
|
2014-09-25 15:42:08 +02:00
|
|
|
BLI_INLINE void madd_m3_m3fl(float r[3][3], float m[3][3], float f)
|
|
|
|
{
|
|
|
|
r[0][0] += m[0][0] * f;
|
|
|
|
r[0][1] += m[0][1] * f;
|
|
|
|
r[0][2] += m[0][2] * f;
|
|
|
|
r[1][0] += m[1][0] * f;
|
|
|
|
r[1][1] += m[1][1] * f;
|
|
|
|
r[1][2] += m[1][2] * f;
|
|
|
|
r[2][0] += m[2][0] * f;
|
|
|
|
r[2][1] += m[2][1] * f;
|
|
|
|
r[2][2] += m[2][2] * f;
|
|
|
|
}
|
2012-08-09 13:33:27 +00:00
|
|
|
|
2014-09-25 23:19:20 +02:00
|
|
|
void cloth_parallel_transport_hair_frame(float mat[3][3], const float dir_old[3], const float dir_new[3])
|
2014-09-25 15:42:08 +02:00
|
|
|
{
|
|
|
|
float rot[3][3];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 15:42:08 +02:00
|
|
|
/* rotation between segments */
|
|
|
|
rotation_between_vecs_to_mat3(rot, dir_old, dir_new);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-25 15:42:08 +02:00
|
|
|
/* rotate the frame */
|
|
|
|
mul_m3_m3m3(mat, rot, mat);
|
2012-08-09 13:33:27 +00:00
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
/* Add a shear and a bend spring between two verts within a poly. */
|
|
|
|
static bool cloth_add_shear_bend_spring(ClothModifierData *clmd, LinkNodePair *edgelist,
|
|
|
|
const MLoop *mloop, const MPoly *mpoly, int i, int j, int k)
|
|
|
|
{
|
|
|
|
Cloth *cloth = clmd->clothObject;
|
|
|
|
ClothSpring *spring;
|
|
|
|
const MLoop *tmp_loop;
|
|
|
|
float shrink_factor;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Combined shear/bend properties. */
|
|
|
|
spring = (ClothSpring *)MEM_callocN(sizeof(ClothSpring), "cloth spring");
|
|
|
|
|
|
|
|
if (!spring) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
spring_verts_ordered_set(spring,
|
|
|
|
mloop[mpoly[i].loopstart + j].v,
|
|
|
|
mloop[mpoly[i].loopstart + k].v);
|
|
|
|
|
|
|
|
shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl);
|
|
|
|
spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor;
|
|
|
|
spring->type |= CLOTH_SPRING_TYPE_SHEAR;
|
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0f;
|
|
|
|
|
|
|
|
if (edgelist) {
|
|
|
|
BLI_linklist_append(&edgelist[spring->ij], spring);
|
|
|
|
BLI_linklist_append(&edgelist[spring->kl], spring);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bending specific properties. */
|
|
|
|
if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) {
|
|
|
|
spring->type |= CLOTH_SPRING_TYPE_BENDING;
|
|
|
|
|
|
|
|
spring->la = k - j + 1;
|
|
|
|
spring->lb = mpoly[i].totloop - k + j + 1;
|
|
|
|
|
|
|
|
spring->pa = MEM_mallocN(sizeof(*spring->pa) * spring->la, "spring poly");
|
|
|
|
if (!spring->pa) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
spring->pb = MEM_mallocN(sizeof(*spring->pb) * spring->lb, "spring poly");
|
|
|
|
if (!spring->pb) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_loop = mloop + mpoly[i].loopstart;
|
|
|
|
|
|
|
|
for (x = 0; x < spring->la; x++) {
|
|
|
|
spring->pa[x] = tmp_loop[j + x].v;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; x <= j; x++) {
|
|
|
|
spring->pb[x] = tmp_loop[x].v;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (y = k; y < mpoly[i].totloop; x++, y++) {
|
|
|
|
spring->pb[x] = tmp_loop[y].v;
|
|
|
|
}
|
|
|
|
|
|
|
|
spring->mn = -1;
|
|
|
|
|
|
|
|
spring->restang = cloth_spring_angle(cloth->verts, spring->ij, spring->kl,
|
|
|
|
spring->pa, spring->pb, spring->la, spring->lb);
|
|
|
|
|
|
|
|
spring->ang_stiffness = (cloth->verts[spring->ij].bend_stiff + cloth->verts[spring->kl].bend_stiff) / 2.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_linklist_prepend(&cloth->springs, spring);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE bool cloth_bend_set_poly_vert_array(int **poly, int len, const MLoop *mloop)
|
|
|
|
{
|
|
|
|
int *p = MEM_mallocN(sizeof(int) * len, "spring poly");
|
|
|
|
|
|
|
|
if (!p) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < len; i++, mloop++) {
|
|
|
|
p[i] = mloop->v;
|
|
|
|
}
|
|
|
|
|
|
|
|
*poly = p;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:32:22 +02:00
|
|
|
static int cloth_build_springs ( ClothModifierData *clmd, Mesh *mesh )
|
2008-01-29 21:01:12 +00:00
|
|
|
{
|
|
|
|
Cloth *cloth = clmd->clothObject;
|
|
|
|
ClothSpring *spring = NULL, *tspring = NULL, *tspring2 = NULL;
|
2016-04-18 18:47:38 +03:00
|
|
|
unsigned int struct_springs = 0, shear_springs=0, bend_springs = 0, struct_springs_real = 0;
|
2018-05-18 17:32:22 +02:00
|
|
|
unsigned int mvert_num = (unsigned int)mesh->totvert;
|
|
|
|
unsigned int numedges = (unsigned int)mesh->totedge;
|
|
|
|
unsigned int numpolys = (unsigned int)mesh->totpoly;
|
2014-02-06 18:44:05 +01:00
|
|
|
float shrink_factor;
|
2018-05-18 17:32:22 +02:00
|
|
|
const MEdge *medge = mesh->medge;
|
|
|
|
const MPoly *mpoly = mesh->mpoly;
|
|
|
|
const MLoop *mloop = mesh->mloop;
|
2008-08-17 17:08:00 +00:00
|
|
|
int index2 = 0; // our second vertex index
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
LinkNodePair *edgelist = NULL;
|
2014-04-04 14:15:57 +11:00
|
|
|
EdgeSet *edgeset = NULL;
|
2008-01-29 21:01:12 +00:00
|
|
|
LinkNode *search = NULL, *search2 = NULL;
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
BendSpringRef *spring_ref = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
// error handling
|
|
|
|
if ( numedges==0 )
|
|
|
|
return 0;
|
|
|
|
|
2014-04-04 14:15:57 +11:00
|
|
|
/* NOTE: handling ownership of springs and edgeset is quite sloppy
|
2013-10-31 14:10:01 +00:00
|
|
|
* currently they are never initialized but assert just to be sure */
|
2013-08-24 14:32:43 +00:00
|
|
|
BLI_assert(cloth->springs == NULL);
|
2014-04-04 14:15:57 +11:00
|
|
|
BLI_assert(cloth->edgeset == NULL);
|
2013-08-24 14:32:43 +00:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
cloth->springs = NULL;
|
2014-04-04 14:15:57 +11:00
|
|
|
cloth->edgeset = NULL;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) {
|
|
|
|
spring_ref = MEM_callocN(sizeof(*spring_ref) * numedges, "temp bend spring reference");
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (!spring_ref) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
edgelist = MEM_callocN(sizeof(*edgelist) * mvert_num, "cloth_edgelist_alloc" );
|
|
|
|
|
|
|
|
if (!edgelist) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2018-12-27 11:35:31 +01:00
|
|
|
clmd->sim_parms->avg_spring_len = 0.0f;
|
2018-12-27 11:43:06 +01:00
|
|
|
for (int i = 0; i < mvert_num; i++) {
|
2018-12-27 11:35:31 +01:00
|
|
|
cloth->verts[i].avg_spring_len = 0.0f;
|
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
/* Structural springs. */
|
|
|
|
for (int i = 0; i < numedges; i++) {
|
2012-06-17 09:58:26 +00:00
|
|
|
spring = (ClothSpring *)MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" );
|
2008-01-29 21:01:12 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if ( spring ) {
|
2013-08-24 15:55:56 +00:00
|
|
|
spring_verts_ordered_set(spring, medge[i].v1, medge[i].v2);
|
2014-03-17 21:48:13 +11:00
|
|
|
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW && medge[i].flag & ME_LOOSEEDGE) {
|
2014-02-06 18:44:05 +01:00
|
|
|
// handle sewing (loose edges will be pulled together)
|
|
|
|
spring->restlen = 0.0f;
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->lin_stiffness = 1.0f;
|
2014-02-06 18:44:05 +01:00
|
|
|
spring->type = CLOTH_SPRING_TYPE_SEWING;
|
2014-03-17 21:48:13 +11:00
|
|
|
}
|
|
|
|
else {
|
2016-04-28 17:53:34 +03:00
|
|
|
shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl);
|
2014-02-06 18:44:05 +01:00
|
|
|
spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor;
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].struct_stiff + cloth->verts[spring->ij].struct_stiff) / 2.0f;
|
2014-02-06 18:44:05 +01:00
|
|
|
spring->type = CLOTH_SPRING_TYPE_STRUCTURAL;
|
2016-04-18 18:47:38 +03:00
|
|
|
|
|
|
|
clmd->sim_parms->avg_spring_len += spring->restlen;
|
|
|
|
cloth->verts[spring->ij].avg_spring_len += spring->restlen;
|
|
|
|
cloth->verts[spring->kl].avg_spring_len += spring->restlen;
|
|
|
|
cloth->verts[spring->ij].spring_count++;
|
|
|
|
cloth->verts[spring->kl].spring_count++;
|
|
|
|
struct_springs_real++;
|
2014-02-06 18:44:05 +01:00
|
|
|
}
|
2016-04-18 18:47:38 +03:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
spring->flags = 0;
|
|
|
|
struct_springs++;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-02-20 15:54:34 +00:00
|
|
|
BLI_linklist_prepend ( &cloth->springs, spring );
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
|
|
|
|
if (spring_ref) {
|
|
|
|
spring_ref[i].spring = spring;
|
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2012-03-06 18:40:15 +00:00
|
|
|
else {
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
cloth_free_errorsprings(cloth, edgelist, spring_ref);
|
2008-02-26 14:25:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2013-08-24 14:32:43 +00:00
|
|
|
|
2016-04-18 18:47:38 +03:00
|
|
|
if (struct_springs_real > 0)
|
|
|
|
clmd->sim_parms->avg_spring_len /= struct_springs_real;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
for (int i = 0; i < mvert_num; i++) {
|
2016-04-18 18:47:38 +03:00
|
|
|
if (cloth->verts[i].spring_count > 0)
|
|
|
|
cloth->verts[i].avg_spring_len = cloth->verts[i].avg_spring_len * 0.49f / ((float)cloth->verts[i].spring_count);
|
2008-02-12 11:04:58 +00:00
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
edgeset = BLI_edgeset_new_ex(__func__, numedges);
|
|
|
|
cloth->edgeset = edgeset;
|
|
|
|
|
|
|
|
if (numpolys) {
|
|
|
|
for (int i = 0; i < numpolys; i++) {
|
|
|
|
/* Shear springs. */
|
|
|
|
/* Triangle faces already have shear springs due to structural geometry. */
|
|
|
|
if (mpoly[i].totloop > 3) {
|
|
|
|
for (int j = 1; j < mpoly[i].totloop - 1; j++) {
|
|
|
|
if (j > 1) {
|
|
|
|
if (cloth_add_shear_bend_spring(clmd, edgelist, mloop, mpoly, i, 0, j)) {
|
|
|
|
shear_springs++;
|
|
|
|
|
|
|
|
if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) {
|
|
|
|
bend_springs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cloth_free_errorsprings(cloth, edgelist, spring_ref);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-06-12 16:57:15 +10:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
for (int k = j + 2; k < mpoly[i].totloop; k++) {
|
|
|
|
if (cloth_add_shear_bend_spring(clmd, edgelist, mloop, mpoly, i, j, k)) {
|
|
|
|
shear_springs++;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) {
|
|
|
|
bend_springs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cloth_free_errorsprings(cloth, edgelist, spring_ref);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-08-01 14:13:59 +10:00
|
|
|
}
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
/* Angular bending springs along struct springs. */
|
|
|
|
if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) {
|
|
|
|
const MLoop *ml = mloop + mpoly[i].loopstart;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
for (int j = 0; j < mpoly[i].totloop; j++, ml++) {
|
|
|
|
BendSpringRef *curr_ref = &spring_ref[ml->e];
|
|
|
|
curr_ref->polys++;
|
|
|
|
|
|
|
|
/* First poly found for this edge, store poly index. */
|
|
|
|
if (curr_ref->polys == 1) {
|
|
|
|
curr_ref->index = i;
|
|
|
|
}
|
2018-09-24 18:46:51 +02:00
|
|
|
/* Second poly found for this edge, add bending data. */
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
else if (curr_ref->polys == 2) {
|
|
|
|
spring = curr_ref->spring;
|
|
|
|
|
|
|
|
spring->type |= CLOTH_SPRING_TYPE_BENDING;
|
|
|
|
|
|
|
|
spring->la = mpoly[curr_ref->index].totloop;
|
|
|
|
spring->lb = mpoly[i].totloop;
|
|
|
|
|
|
|
|
if (!cloth_bend_set_poly_vert_array(&spring->pa, spring->la, &mloop[mpoly[curr_ref->index].loopstart]) ||
|
|
|
|
!cloth_bend_set_poly_vert_array(&spring->pb, spring->lb, &mloop[mpoly[i].loopstart]))
|
|
|
|
{
|
|
|
|
cloth_free_errorsprings(cloth, edgelist, spring_ref);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
spring->mn = ml->e;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->restang = cloth_spring_angle(cloth->verts, spring->ij, spring->kl,
|
|
|
|
spring->pa, spring->pb, spring->la, spring->lb);
|
2015-06-12 16:57:15 +10:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->ang_stiffness = (cloth->verts[spring->ij].bend_stiff + cloth->verts[spring->kl].bend_stiff) / 2.0f;
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
bend_springs++;
|
|
|
|
}
|
2018-09-24 18:46:51 +02:00
|
|
|
/* Third poly found for this edge, remove bending data. */
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
else if (curr_ref->polys == 3) {
|
|
|
|
spring = curr_ref->spring;
|
|
|
|
|
|
|
|
spring->type &= ~CLOTH_SPRING_TYPE_BENDING;
|
|
|
|
MEM_freeN(spring->pa);
|
|
|
|
MEM_freeN(spring->pb);
|
|
|
|
spring->pa = NULL;
|
|
|
|
spring->pb = NULL;
|
|
|
|
|
|
|
|
bend_springs--;
|
|
|
|
}
|
|
|
|
}
|
2015-08-01 14:13:59 +10:00
|
|
|
}
|
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
/* Linear bending springs. */
|
|
|
|
if (clmd->sim_parms->bending_model == CLOTH_BENDING_LINEAR) {
|
|
|
|
search2 = cloth->springs;
|
2013-08-24 14:32:43 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
for (int i = struct_springs; i < struct_springs+shear_springs; i++) {
|
|
|
|
if (!search2) {
|
|
|
|
break;
|
|
|
|
}
|
2008-01-29 21:01:12 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
tspring2 = search2->link;
|
|
|
|
search = edgelist[tspring2->kl].list;
|
|
|
|
|
|
|
|
while (search) {
|
|
|
|
tspring = search->link;
|
|
|
|
index2 = ((tspring->ij == tspring2->kl) ? (tspring->kl) : (tspring->ij));
|
|
|
|
|
|
|
|
/* Check for existing spring. */
|
|
|
|
/* Check also if startpoint is equal to endpoint. */
|
|
|
|
if ((index2 != tspring2->ij) &&
|
|
|
|
!BLI_edgeset_haskey(edgeset, tspring2->ij, index2))
|
|
|
|
{
|
|
|
|
spring = (ClothSpring *)MEM_callocN(sizeof(ClothSpring), "cloth spring");
|
|
|
|
|
|
|
|
if (!spring) {
|
|
|
|
cloth_free_errorsprings(cloth, edgelist, spring_ref);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring_verts_ordered_set(spring, tspring2->ij, index2);
|
|
|
|
shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl);
|
|
|
|
spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor;
|
|
|
|
spring->type = CLOTH_SPRING_TYPE_BENDING;
|
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f;
|
|
|
|
BLI_edgeset_insert(edgeset, spring->ij, spring->kl);
|
|
|
|
bend_springs++;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
BLI_linklist_prepend(&cloth->springs, spring);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
search = search->next;
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
|
|
|
|
search2 = search2->next;
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (struct_springs > 2) {
|
2014-09-19 11:15:16 +02:00
|
|
|
if (G.debug_value != 1112) {
|
|
|
|
search = cloth->springs;
|
|
|
|
search2 = search->next;
|
|
|
|
while (search && search2) {
|
|
|
|
tspring = search->link;
|
|
|
|
tspring2 = search2->link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
if (tspring->ij == tspring2->kl) {
|
|
|
|
spring = (ClothSpring *)MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" );
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
if (!spring) {
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
cloth_free_errorsprings(cloth, edgelist, spring_ref);
|
2014-09-19 11:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 16:53:35 +02:00
|
|
|
spring->ij = tspring2->ij;
|
2014-09-19 11:15:16 +02:00
|
|
|
spring->kl = tspring->ij;
|
2014-09-19 16:53:35 +02:00
|
|
|
spring->mn = tspring->kl;
|
2014-09-19 11:15:16 +02:00
|
|
|
spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest);
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->type = CLOTH_SPRING_TYPE_BENDING_HAIR;
|
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f;
|
2014-09-19 11:15:16 +02:00
|
|
|
bend_springs++;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
BLI_linklist_prepend ( &cloth->springs, spring );
|
2008-02-26 14:25:29 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
search = search->next;
|
|
|
|
search2 = search2->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* bending springs for hair strands
|
|
|
|
* The current algorithm only goes through the edges in order of the mesh edges list
|
|
|
|
* and makes springs between the outer vert of edges sharing a vertice. This works just
|
|
|
|
* fine for hair, but not for user generated string meshes. This could/should be later
|
|
|
|
* extended to work with non-ordered edges so that it can be used for general "rope
|
|
|
|
* dynamics" without the need for the vertices or edges to be ordered through the length
|
|
|
|
* of the strands. -jahka */
|
2014-09-19 11:15:16 +02:00
|
|
|
search = cloth->springs;
|
|
|
|
search2 = search->next;
|
|
|
|
while (search && search2) {
|
|
|
|
tspring = search->link;
|
|
|
|
tspring2 = search2->link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
if (tspring->ij == tspring2->kl) {
|
|
|
|
spring = (ClothSpring *)MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" );
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
if (!spring) {
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
cloth_free_errorsprings(cloth, edgelist, spring_ref);
|
2014-09-19 11:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
spring->ij = tspring2->ij;
|
|
|
|
spring->kl = tspring->kl;
|
|
|
|
spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest);
|
|
|
|
spring->type = CLOTH_SPRING_TYPE_BENDING;
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
spring->lin_stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f;
|
2014-09-19 11:15:16 +02:00
|
|
|
bend_springs++;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
BLI_linklist_prepend ( &cloth->springs, spring );
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-19 11:15:16 +02:00
|
|
|
search = search->next;
|
|
|
|
search2 = search2->next;
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-12-22 11:54:24 +01:00
|
|
|
cloth_hair_update_bending_rest_targets(clmd);
|
2008-01-29 21:01:12 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2013-08-24 16:06:18 +00:00
|
|
|
/* note: the edges may already exist so run reinsert */
|
|
|
|
|
2014-04-04 14:15:57 +11:00
|
|
|
/* insert other near springs in edgeset AFTER bending springs are calculated (for selfcolls) */
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
for (int i = 0; i < numedges; i++) { /* struct springs */
|
2014-05-29 14:00:11 +10:00
|
|
|
BLI_edgeset_add(edgeset, medge[i].v1, medge[i].v2);
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
for (int i = 0; i < numpolys; i++) { /* edge springs */
|
2015-08-01 14:13:59 +10:00
|
|
|
if (mpoly[i].totloop == 4) {
|
|
|
|
BLI_edgeset_add(edgeset, mloop[mpoly[i].loopstart + 0].v, mloop[mpoly[i].loopstart + 2].v);
|
|
|
|
BLI_edgeset_add(edgeset, mloop[mpoly[i].loopstart + 1].v, mloop[mpoly[i].loopstart + 3].v);
|
2008-02-28 23:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
2016-12-05 21:39:29 -02:00
|
|
|
MEM_SAFE_FREE(spring_ref);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-01-29 21:01:12 +00:00
|
|
|
cloth->numsprings = struct_springs + shear_springs + bend_springs;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2015-07-31 14:00:07 +10:00
|
|
|
cloth_free_edgelist(edgelist, mvert_num);
|
2013-08-24 14:32:43 +00:00
|
|
|
|
|
|
|
#if 0
|
2012-08-08 18:21:54 +00:00
|
|
|
if (G.debug_value > 0)
|
2012-04-29 15:47:02 +00:00
|
|
|
printf("avg_len: %f\n", clmd->sim_parms->avg_spring_len);
|
2013-08-24 14:32:43 +00:00
|
|
|
#endif
|
2008-01-29 21:01:12 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} /* cloth_build_springs */
|
|
|
|
/***************************************************************************************
|
2018-07-18 00:12:21 +02:00
|
|
|
* SPRING NETWORK GPU_BATCH_BUILDING IMPLEMENTATION END
|
2012-05-16 23:37:23 +00:00
|
|
|
***************************************************************************************/
|