2011-02-18 14:05:18 +01:00
|
|
|
/*
|
2008-01-29 22:01:12 +01: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
|
2008-04-17 00:40:48 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-01-29 22:01:12 +01:00
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 14:34:04 +01:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-01-29 22:01:12 +01:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2012-02-17 19:59:41 +01:00
|
|
|
#pragma once
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-18 14:05:18 +01:00
|
|
|
*/
|
|
|
|
|
2011-05-01 23:39:13 +02:00
|
|
|
#include "BLI_math_inline.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <float.h>
|
2008-02-05 15:11:48 +01:00
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-01-29 22:01:12 +01:00
|
|
|
struct ClothModifierData;
|
2014-09-03 15:44:03 +02:00
|
|
|
struct CollisionModifierData;
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph;
|
2020-03-14 05:22:04 +01:00
|
|
|
struct GHash;
|
2019-01-28 11:08:24 +01:00
|
|
|
struct Mesh;
|
|
|
|
struct Object;
|
|
|
|
struct Scene;
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2011-05-01 23:39:13 +02:00
|
|
|
#define DO_INLINE MALWAYS_INLINE
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* Goal defines. */
|
2008-02-08 01:55:48 +01:00
|
|
|
#define SOFTGOALSNAP 0.999f
|
|
|
|
|
|
|
|
/* This is approximately the smallest number that can be
|
2012-03-03 21:19:11 +01:00
|
|
|
* represented by a float, given its precision. */
|
2008-02-08 01:55:48 +01:00
|
|
|
#define ALMOST_ZERO FLT_EPSILON
|
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* Bits to or into the #ClothVertex.flags. */
|
2014-10-07 10:12:42 +02:00
|
|
|
typedef enum eClothVertexFlag {
|
2020-03-02 14:52:58 +01:00
|
|
|
CLOTH_VERT_FLAG_PINNED = (1 << 0),
|
|
|
|
CLOTH_VERT_FLAG_NOSELFCOLL = (1 << 1), /* vertex NOT used for self collisions */
|
2021-01-08 11:02:40 +01:00
|
|
|
CLOTH_VERT_FLAG_NOOBJCOLL = (1 << 2), /* vertex NOT used for object collisions */
|
2014-10-07 10:12:42 +02:00
|
|
|
} eClothVertexFlag;
|
2008-02-08 01:55:48 +01:00
|
|
|
|
2014-11-17 19:44:42 +01:00
|
|
|
typedef struct ClothHairData {
|
2014-09-11 14:19:52 +02:00
|
|
|
float loc[3];
|
|
|
|
float rot[3][3];
|
2014-09-25 15:42:08 +02:00
|
|
|
float rest_target[3]; /* rest target direction for each segment */
|
2014-12-16 19:40:29 +01:00
|
|
|
float radius;
|
2014-11-17 19:44:42 +01:00
|
|
|
float bending_stiffness;
|
|
|
|
} ClothHairData;
|
2014-09-11 14:19:52 +02:00
|
|
|
|
2014-09-20 21:05:46 +02:00
|
|
|
typedef struct ClothSolverResult {
|
|
|
|
int status;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-20 21:05:46 +02:00
|
|
|
int max_iterations, min_iterations;
|
|
|
|
float avg_iterations;
|
|
|
|
float max_error, min_error, avg_error;
|
|
|
|
} ClothSolverResult;
|
|
|
|
|
2008-04-28 00:04:47 +02:00
|
|
|
/**
|
2012-03-03 21:19:11 +01:00
|
|
|
* This structure describes a cloth object against which the
|
|
|
|
* simulation can run.
|
|
|
|
*
|
|
|
|
* The m and n members of this structure represent the assumed
|
|
|
|
* rectangular ordered grid for which the original paper is written.
|
|
|
|
* At some point they need to disappear and we need to determine out
|
|
|
|
* own connectivity of the mesh based on the actual edges in the mesh.
|
|
|
|
*/
|
2012-06-07 00:38:39 +02:00
|
|
|
typedef struct Cloth {
|
2020-01-16 18:45:23 +01:00
|
|
|
struct ClothVertex *verts; /* The vertices that represent this cloth. */
|
|
|
|
struct LinkNode *springs; /* The springs connecting the mesh. */
|
|
|
|
unsigned int numsprings; /* The count of springs. */
|
|
|
|
unsigned int mvert_num; /* The number of verts == m * n. */
|
|
|
|
unsigned int primitive_num; /* Number of triangles for cloth and edges for hair. */
|
2008-04-28 00:04:47 +02:00
|
|
|
unsigned char old_solver_type; /* unused, only 1 solver here */
|
|
|
|
unsigned char pad2;
|
|
|
|
short pad3;
|
2008-05-07 22:42:16 +02:00
|
|
|
struct BVHTree *bvhtree; /* collision tree for this cloth object */
|
2008-05-23 22:20:14 +02:00
|
|
|
struct BVHTree *bvhselftree; /* collision tree for this cloth object */
|
2015-07-31 06:00:07 +02:00
|
|
|
struct MVertTri *tri;
|
2008-04-28 00:04:47 +02:00
|
|
|
struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */
|
2014-04-04 05:15:57 +02:00
|
|
|
struct EdgeSet *edgeset; /* used for selfcollisions */
|
2019-11-27 14:56:16 +01:00
|
|
|
int last_frame;
|
2020-07-06 19:44:30 +02:00
|
|
|
float initial_mesh_volume; /* Initial volume of the mesh. Used for pressure */
|
|
|
|
float average_acceleration[3]; /* Moving average of overall acceleration. */
|
|
|
|
struct MEdge *edges; /* Used for hair collisions. */
|
|
|
|
struct EdgeSet *sew_edge_graph; /* Sewing edges represented using a GHash */
|
2008-04-28 00:04:47 +02:00
|
|
|
} Cloth;
|
|
|
|
|
2008-01-29 22:01:12 +01:00
|
|
|
/**
|
|
|
|
* The definition of a cloth vertex.
|
|
|
|
*/
|
2012-06-07 00:38:39 +02:00
|
|
|
typedef struct ClothVertex {
|
2021-06-24 07:56:58 +02:00
|
|
|
int flags; /* General flags per vertex. */
|
|
|
|
float v[3]; /* The velocity of the point. */
|
2012-04-12 02:15:02 +02:00
|
|
|
float xconst[3]; /* constrained position */
|
|
|
|
float x[3]; /* The current position of this vertex. */
|
2021-06-26 13:35:18 +02:00
|
|
|
float xold[3]; /* The previous position of this vertex. */
|
2012-04-12 02:15:02 +02:00
|
|
|
float tx[3]; /* temporary position */
|
|
|
|
float txold[3]; /* temporary old position */
|
2008-01-29 22:01:12 +01:00
|
|
|
float tv[3]; /* temporary "velocity", mostly used as tv = tx-txold */
|
|
|
|
float mass; /* mass / weight of the vertex */
|
|
|
|
float goal; /* goal, from SB */
|
|
|
|
float impulse[3]; /* used in collision.c */
|
2016-04-18 17:48:22 +02:00
|
|
|
float xrest[3]; /* rest position of the vertex */
|
2018-09-26 17:18:16 +02:00
|
|
|
float dcvel[3]; /* delta velocities to be applied by collision response */
|
2008-01-29 22:01:12 +01:00
|
|
|
unsigned int impulse_count; /* same as above */
|
2008-02-12 12:04:58 +01:00
|
|
|
float avg_spring_len; /* average length of connected springs */
|
2008-01-29 22:01:12 +01:00
|
|
|
float struct_stiff;
|
|
|
|
float bend_stiff;
|
|
|
|
float shear_stiff;
|
2019-12-04 11:24:46 +01:00
|
|
|
int spring_count; /* how many springs attached? */
|
|
|
|
float shrink_factor; /* how much to shrink this cloth */
|
2019-12-09 19:10:55 +01:00
|
|
|
float internal_stiff; /* internal spring stiffness scaling */
|
2019-12-04 11:24:46 +01:00
|
|
|
float pressure_factor; /* how much pressure should affect this vertex */
|
2008-01-29 22:01:12 +01:00
|
|
|
} ClothVertex;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The definition of a spring.
|
|
|
|
*/
|
2012-06-07 00:38:39 +02:00
|
|
|
typedef struct ClothSpring {
|
2021-02-13 07:44:51 +01:00
|
|
|
int ij; /* `Pij` from the paper, one end of the spring. */
|
|
|
|
int kl; /* `Pkl` from the paper, one end of the 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-06 00:39:29 +01:00
|
|
|
int mn; /* For hair springs: third vertex index; For bending springs: edge index; */
|
|
|
|
int *pa; /* Array of vert indices for poly a (for bending springs). */
|
|
|
|
int *pb; /* Array of vert indices for poly b (for bending springs). */
|
2021-02-13 07:44:51 +01:00
|
|
|
int la; /* Length of `*pa`. */
|
|
|
|
int lb; /* Length of `*pb`. */
|
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-06 00:39:29 +01:00
|
|
|
float restlen; /* The original length of the spring. */
|
|
|
|
float restang; /* The original angle of the bending springs. */
|
|
|
|
int type; /* Types defined in BKE_cloth.h ("springType"). */
|
|
|
|
int flags; /* Defined in BKE_cloth.h, e.g. deactivated due to tearing. */
|
|
|
|
float lin_stiffness; /* Linear stiffness factor from the vertex groups. */
|
|
|
|
float ang_stiffness; /* Angular stiffness factor from the vertex groups. */
|
2008-02-05 15:11:48 +01:00
|
|
|
float editrestlen;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-25 15:42:08 +02:00
|
|
|
/* angular bending spring target and derivatives */
|
|
|
|
float target[3];
|
2008-01-29 22:01:12 +01:00
|
|
|
} ClothSpring;
|
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* Some macro enhancements for vector treatment. */
|
2019-04-02 08:54:04 +02:00
|
|
|
#define VECSUBADDSS(v1, v2, aS, v3, bS) \
|
|
|
|
{ \
|
|
|
|
*(v1) -= *(v2)*aS + *(v3)*bS; \
|
|
|
|
*(v1 + 1) -= *(v2 + 1) * aS + *(v3 + 1) * bS; \
|
|
|
|
*(v1 + 2) -= *(v2 + 2) * aS + *(v3 + 2) * bS; \
|
|
|
|
} \
|
|
|
|
((void)0)
|
|
|
|
#define VECADDSS(v1, v2, aS, v3, bS) \
|
|
|
|
{ \
|
|
|
|
*(v1) = *(v2)*aS + *(v3)*bS; \
|
|
|
|
*(v1 + 1) = *(v2 + 1) * aS + *(v3 + 1) * bS; \
|
|
|
|
*(v1 + 2) = *(v2 + 2) * aS + *(v3 + 2) * bS; \
|
|
|
|
} \
|
|
|
|
((void)0)
|
|
|
|
#define VECADDS(v1, v2, v3, bS) \
|
|
|
|
{ \
|
|
|
|
*(v1) = *(v2) + *(v3)*bS; \
|
|
|
|
*(v1 + 1) = *(v2 + 1) + *(v3 + 1) * bS; \
|
|
|
|
*(v1 + 2) = *(v2 + 2) + *(v3 + 2) * bS; \
|
|
|
|
} \
|
|
|
|
((void)0)
|
|
|
|
#define VECSUBMUL(v1, v2, aS) \
|
|
|
|
{ \
|
|
|
|
*(v1) -= *(v2)*aS; \
|
|
|
|
*(v1 + 1) -= *(v2 + 1) * aS; \
|
|
|
|
*(v1 + 2) -= *(v2 + 2) * aS; \
|
|
|
|
} \
|
|
|
|
((void)0)
|
|
|
|
#define VECSUBS(v1, v2, v3, bS) \
|
|
|
|
{ \
|
|
|
|
*(v1) = *(v2) - *(v3)*bS; \
|
|
|
|
*(v1 + 1) = *(v2 + 1) - *(v3 + 1) * bS; \
|
|
|
|
*(v1 + 2) = *(v2 + 2) - *(v3 + 2) * bS; \
|
|
|
|
} \
|
|
|
|
((void)0)
|
|
|
|
#define VECADDMUL(v1, v2, aS) \
|
|
|
|
{ \
|
|
|
|
*(v1) += *(v2)*aS; \
|
|
|
|
*(v1 + 1) += *(v2 + 1) * aS; \
|
|
|
|
*(v1 + 2) += *(v2 + 2) * aS; \
|
2019-04-17 06:17:24 +02:00
|
|
|
} \
|
|
|
|
((void)0)
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2021-06-26 13:35:18 +02:00
|
|
|
/* Spring types as defined in the paper. */
|
2012-06-07 00:38:39 +02:00
|
|
|
typedef enum {
|
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-06 00:39:29 +01:00
|
|
|
CLOTH_SPRING_TYPE_STRUCTURAL = (1 << 1),
|
|
|
|
CLOTH_SPRING_TYPE_SHEAR = (1 << 2),
|
|
|
|
CLOTH_SPRING_TYPE_BENDING = (1 << 3),
|
|
|
|
CLOTH_SPRING_TYPE_GOAL = (1 << 4),
|
|
|
|
CLOTH_SPRING_TYPE_SEWING = (1 << 5),
|
|
|
|
CLOTH_SPRING_TYPE_BENDING_HAIR = (1 << 6),
|
2019-12-09 19:10:55 +01:00
|
|
|
CLOTH_SPRING_TYPE_INTERNAL = (1 << 7),
|
2008-01-29 22:01:12 +01:00
|
|
|
} CLOTH_SPRING_TYPES;
|
|
|
|
|
|
|
|
/* SPRING FLAGS */
|
2012-06-07 00:38:39 +02:00
|
|
|
typedef enum {
|
2008-01-29 22:01:12 +01:00
|
|
|
CLOTH_SPRING_FLAG_DEACTIVATE = (1 << 1),
|
2021-02-13 07:44:51 +01:00
|
|
|
CLOTH_SPRING_FLAG_NEEDED = (1 << 2), /* Springs has values to be applied. */
|
2008-01-29 22:01:12 +01:00
|
|
|
} CLOTH_SPRINGS_FLAGS;
|
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* collision.c */
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2014-09-03 15:44:03 +02:00
|
|
|
struct CollPair;
|
|
|
|
|
|
|
|
typedef struct ColliderContacts {
|
|
|
|
struct Object *ob;
|
|
|
|
struct CollisionModifierData *collmd;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-09-03 15:44:03 +02:00
|
|
|
struct CollPair *collisions;
|
|
|
|
int totcollisions;
|
|
|
|
} ColliderContacts;
|
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* needed for implicit.c */
|
2018-09-26 17:18:16 +02:00
|
|
|
int cloth_bvh_collision(struct Depsgraph *depsgraph,
|
|
|
|
struct Object *ob,
|
|
|
|
struct ClothModifierData *clmd,
|
|
|
|
float step,
|
|
|
|
float dt);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* cloth.c */
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* Needed for modifier.c */
|
2021-12-07 07:19:15 +01:00
|
|
|
/** Frees all. */
|
2012-03-11 20:09:01 +01:00
|
|
|
void cloth_free_modifier_extern(struct ClothModifierData *clmd);
|
2021-12-07 07:19:15 +01:00
|
|
|
/** Frees all. */
|
2012-03-11 20:09:01 +01:00
|
|
|
void cloth_free_modifier(struct ClothModifierData *clmd);
|
2018-10-23 06:00:40 +02:00
|
|
|
void clothModifier_do(struct ClothModifierData *clmd,
|
|
|
|
struct Depsgraph *depsgraph,
|
|
|
|
struct Scene *scene,
|
|
|
|
struct Object *ob,
|
|
|
|
struct Mesh *me,
|
|
|
|
float (*vertexCos)[3]);
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2010-08-10 07:41:51 +02:00
|
|
|
int cloth_uses_vgroup(struct ClothModifierData *clmd);
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* Needed for collision.c */
|
2018-09-26 17:18:16 +02:00
|
|
|
void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving, bool self);
|
2008-01-29 22:01:12 +01:00
|
|
|
|
2021-07-20 07:01:05 +02:00
|
|
|
/* Needed for button_object.c */
|
2018-02-06 09:34:36 +01:00
|
|
|
void cloth_clear_cache(struct Object *ob, struct ClothModifierData *clmd, float framenr);
|
2008-02-08 01:55:48 +01: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
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|