1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2006 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  */
23 
24 #pragma once
25 
26 #include "DNA_defs.h"
27 
28 /**
29  * This struct contains all the global data required to run a simulation.
30  * At the time of this writing, this structure contains data appropriate
31  * to run a simulation as described in Deformation Constraints in a
32  * Mass-Spring Model to Describe Rigid Cloth Behavior by Xavier Provot.
33  *
34  * I've tried to keep similar, if not exact names for the variables as
35  * are presented in the paper.  Where I've changed the concept slightly,
36  * as in stepsPerFrame compared to the time step in the paper, I've used
37  * variables with different names to minimize confusion.
38  */
39 
40 typedef struct ClothSimSettings {
41   /** UNUSED atm. */
42   struct LinkNode *cache;
43   /** See SB. */
44   float mingoal;
45   /** Mechanical damping of springs. */
46   float Cdis DNA_DEPRECATED;
47   /** Viscous/fluid damping. */
48   float Cvi;
49   /** Gravity/external force vector. */
50   float gravity[3];
51   /** This is the duration of our time step, computed..   */
52   float dt;
53   /** The mass of the entire cloth. */
54   float mass;
55   /** Structural spring stiffness. */
56   float structural DNA_DEPRECATED;
57   /** Shear spring stiffness. */
58   float shear;
59   /** Flexion spring stiffness. */
60   float bending;
61   /** Max bending scaling value, min is "bending". */
62   float max_bend;
63   /** Max structural scaling value, min is "structural". */
64   float max_struct DNA_DEPRECATED;
65   /** Max shear scaling value. */
66   float max_shear;
67   /** Max sewing force. */
68   float max_sewing;
69   /** Used for normalized springs. */
70   float avg_spring_len;
71   /** Parameter how fast cloth runs. */
72   float timescale;
73   /** Multiplies cloth speed. */
74   float time_scale;
75   /** See SB. */
76   float maxgoal;
77   /** Scaling of effector forces (see softbody_calc_forces)..*/
78   float eff_force_scale;
79   /** Scaling of effector wind (see softbody_calc_forces)..   */
80   float eff_wind_scale;
81   float sim_time_old;
82   float defgoal;
83   float goalspring;
84   float goalfrict;
85   /** Smoothing of velocities for hair. */
86   float velocity_smooth;
87   /** Minimum density for hair. */
88   float density_target;
89   /** Influence of hair density. */
90   float density_strength;
91   /** Friction with colliders. */
92   float collider_friction;
93   /** Damp the velocity to speed up getting to the resting position. */
94   float vel_damping DNA_DEPRECATED;
95   /** Min amount to shrink cloth by 0.0f (no shrink), 1.0f (shrink to nothing), -1.0f (double the
96    * edge length). */
97   float shrink_min;
98   /** Max amount to shrink cloth by 0.0f (no shrink), 1.0f (shrink to nothing), -1.0f (double the
99    * edge length). */
100   float shrink_max;
101 
102   /* Air pressure */
103   /* The uniform pressure that is constanty applied to the mesh. Can be negative */
104   float uniform_pressure_force;
105   /* User set volume. This is the volume the mesh wants to expand to (the equilibrium volume). */
106   float target_volume;
107   /* The scaling factor to apply to the actual pressure.
108    * pressure=( (current_volume/target_volume) - 1 + uniform_pressure_force) *
109    * pressure_factor */
110   float pressure_factor;
111   /* Density of the fluid inside or outside the object for use in the hydrostatic pressure
112    * gradient. */
113   float fluid_density;
114   short vgroup_pressure;
115   char _pad7[6];
116 
117   /* XXX various hair stuff
118    * should really be separate, this struct is a horrible mess already
119    */
120   /** Damping of bending springs. */
121   float bending_damping;
122   /** Size of voxel grid cells for continuum dynamics. */
123   float voxel_cell_size;
124 
125   /** Number of time steps per frame. */
126   int stepsPerFrame;
127   /** Flags, see CSIMSETT_FLAGS enum above. */
128   int flags;
129   /** How many frames of simulation to do before we start. */
130   int preroll DNA_DEPRECATED;
131   /** In percent!; if tearing enabled, a spring will get cut. */
132   int maxspringlen;
133   /** Which solver should be used? txold. */
134   short solver_type;
135   /** Vertex group for scaling bending stiffness. */
136   short vgroup_bend;
137   /** Optional vertexgroup name for assigning weight..*/
138   short vgroup_mass;
139   /** Vertex group for scaling structural stiffness. */
140   short vgroup_struct;
141   /** Vertex group for shrinking cloth. */
142   short vgroup_shrink;
143   /** Vertex group for scaling structural stiffness. */
144   short shapekey_rest;
145   /** Used for presets on GUI. */
146   short presets;
147   short reset;
148 
149   struct EffectorWeights *effector_weights;
150 
151   short bending_model;
152   /** Vertex group for scaling structural stiffness. */
153   short vgroup_shear;
154   float tension;
155   float compression;
156   float max_tension;
157   float max_compression;
158   /** Mechanical damping of tension springs. */
159   float tension_damp;
160   /** Mechanical damping of compression springs. */
161   float compression_damp;
162   /** Mechanical damping of shear springs. */
163   float shear_damp;
164 
165   /** The maximum lenght an internal spring can have during creation. */
166   float internal_spring_max_length;
167   /** How much the interal spring can diverge from the vertex normal during creation. */
168   float internal_spring_max_diversion;
169   /** Vertex group for scaling structural stiffness. */
170   short vgroup_intern;
171   char _pad1[2];
172   float internal_tension;
173   float internal_compression;
174   float max_internal_tension;
175   float max_internal_compression;
176   char _pad0[4];
177 
178 } ClothSimSettings;
179 
180 /* SIMULATION FLAGS: goal flags,.. */
181 /* These are the bits used in SimSettings.flags. */
182 typedef enum {
183   /** Object is only collision object, no cloth simulation is done. */
184   CLOTH_SIMSETTINGS_FLAG_COLLOBJ = (1 << 2),
185   /** DEPRECATED, for versioning only. */
186   CLOTH_SIMSETTINGS_FLAG_GOAL = (1 << 3),
187   /** True if tearing is enabled. */
188   CLOTH_SIMSETTINGS_FLAG_TEARING = (1 << 4),
189   /** True if pressure sim is enabled. */
190   CLOTH_SIMSETTINGS_FLAG_PRESSURE = (1 << 5),
191   /** Use the user defined target volume. */
192   CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL = (1 << 6),
193   /** True if internal spring generation is enabled. */
194   CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS = (1 << 7),
195   /** DEPRECATED, for versioning only. */
196   CLOTH_SIMSETTINGS_FLAG_SCALING = (1 << 8),
197   /** Require internal springs to be created between points with opposite normals. */
198   CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL = (1 << 9),
199   /** Edit cache in edit-mode. */
200   /* CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12), */ /* UNUSED */
201   /** Don't allow spring compression. */
202   CLOTH_SIMSETTINGS_FLAG_RESIST_SPRING_COMPRESS = (1 << 13),
203   /** Pull ends of loose edges together. */
204   CLOTH_SIMSETTINGS_FLAG_SEW = (1 << 14),
205   /** Make simulation respect deformations in the base object. */
206   CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH = (1 << 15),
207 } CLOTH_SIMSETTINGS_FLAGS;
208 
209 /* ClothSimSettings.bending_model. */
210 typedef enum {
211   CLOTH_BENDING_LINEAR = 0,
212   CLOTH_BENDING_ANGULAR = 1,
213 } CLOTH_BENDING_MODEL;
214 
215 typedef struct ClothCollSettings {
216   /** E.g. pointer to temp memory for collisions. */
217   struct LinkNode *collision_list;
218   /** Min distance for collisions. */
219   float epsilon;
220   /** Fiction/damping with self contact. */
221   float self_friction;
222   /** Friction/damping applied on contact with other object. */
223   float friction;
224   /** Collision restitution on contact with other object. */
225   float damping;
226   /** For selfcollision. */
227   float selfepsilon;
228   float repel_force DNA_DEPRECATED;
229   float distance_repel DNA_DEPRECATED;
230   /** Collision flags defined in BKE_cloth.h. */
231   int flags;
232   /** How many iterations for the selfcollision loop. */
233   short self_loop_count DNA_DEPRECATED;
234   /** How many iterations for the collision loop. */
235   short loop_count;
236   char _pad[4];
237   /** Only use colliders from this group of objects. */
238   struct Collection *group;
239   /** Vgroup to paint which vertices are used for self collisions. */
240   short vgroup_selfcol;
241   char _pad2[6];
242   /** Impulse clamp for object collisions. */
243   float clamp;
244   /** Impulse clamp for self collisions. */
245   float self_clamp;
246 } ClothCollSettings;
247 
248 /* COLLISION FLAGS */
249 typedef enum {
250   CLOTH_COLLSETTINGS_FLAG_ENABLED = (1 << 1), /* enables cloth - object collisions */
251   CLOTH_COLLSETTINGS_FLAG_SELF = (1 << 2),    /* enables selfcollisions */
252 } CLOTH_COLLISIONSETTINGS_FLAGS;
253