Compare commits
154 Commits
temp-inter
...
soc-2019-a
Author | SHA1 | Date | |
---|---|---|---|
3c6a26d35b | |||
a78d0f7ac2 | |||
6022ea47aa | |||
64bdb89aba | |||
b000354226 | |||
4844469ebc | |||
25fa832d01 | |||
0bf78faa1d | |||
09565017ae | |||
e3ddf0f8bc | |||
197bb8b69b | |||
5f6fad8f75 | |||
5268cbdb84 | |||
c3553c719b | |||
6bb7f27f32 | |||
2aa0cbfd8d | |||
4edf29ba38 | |||
dffa1972af | |||
725b088979 | |||
a6284e4774 | |||
11195356ba | |||
4b3539ec60 | |||
0adfa2d970 | |||
aad285e6d6 | |||
07e365dbaa | |||
80cf4f4496 | |||
84421b3973 | |||
54cd8de4da | |||
7e26b28e2b | |||
51c57993d9 | |||
0916ed8dbe | |||
58a80eb44e | |||
15ba172e16 | |||
c6f4dd4b0a | |||
1d4a3ecfb2 | |||
fd08bbb95d | |||
5c9c25a99f | |||
4866294a43 | |||
316e77be93 | |||
e24fca7f1d | |||
5035e4cb34 | |||
b32f857715 | |||
46aeecb51d | |||
380382a7c7 | |||
f34e958553 | |||
28e19184f9 | |||
e23ce1f407 | |||
ea499dbba2 | |||
85c125b470 | |||
c6e48575d6 | |||
dc45061510 | |||
849ec1350e | |||
e7a6a80552 | |||
77d3d8b778 | |||
2d9989e18b | |||
8def5a98db | |||
7527a0b434 | |||
97ef5d6389 | |||
cd173b442b | |||
814861cec1 | |||
4ddf80cf04 | |||
0210741877 | |||
199bc50925 | |||
65b8e525d8 | |||
7797336f25 | |||
23cbf600b2 | |||
412bce877e | |||
832201400f | |||
b6911a66c6 | |||
c4990aa993 | |||
4a4214e4a1 | |||
5be534cd40 | |||
0232ee6bc6 | |||
0b546f15d6 | |||
82ef6423eb | |||
76a122f496 | |||
f5e098dd11 | |||
f38f73d997 | |||
57df2985e3 | |||
224821f4bd | |||
b39b5d4e37 | |||
997182c5f7 | |||
0231bacb31 | |||
f2bebfc27d | |||
15f2aab82a | |||
a31eb9d550 | |||
69969bf170 | |||
3a5c9a0e6c | |||
c43df425ba | |||
9069233250 | |||
c80184bdea | |||
6084d2e1b8 | |||
50f1f85272 | |||
65b4c99e7d | |||
1543aed088 | |||
7103009a45 | |||
acd989adb7 | |||
fa801b2f0c | |||
7806b1ed81 | |||
ca6e4b6be8 | |||
320013cf29 | |||
b94c7562cd | |||
5192228e71 | |||
a5243b6e67 | |||
01012fd2f0 | |||
328988960a | |||
37f1a6f398 | |||
cafb5b81ee | |||
5689627957 | |||
7dd1ad6790 | |||
c3560029a3 | |||
7730efedbc | |||
d5c41954a4 | |||
8b0ef43de9 | |||
d7c7e62636 | |||
3fd16180d7 | |||
a657c33770 | |||
f112ca46a9 | |||
79f714db6e | |||
c8d8f1b793 | |||
428ff2217a | |||
f74cc4040b | |||
2befa73279 | |||
436bbb05ce | |||
a8e5ed2331 | |||
5b5a870685 | |||
d5e0229416 | |||
2468f54190 | |||
34454a0aab | |||
1435385d25 | |||
23f0f6fdf5 | |||
3487d13a7e | |||
ad1af6e243 | |||
90a52c22a2 | |||
0cb99641e1 | |||
3f1ee807b6 | |||
d882e3abd9 | |||
5eeb22cb40 | |||
f7d2e5c0ca | |||
a5e9b66be2 | |||
18e0d06cfa | |||
e2cd13e8a7 | |||
d40a988078 | |||
55c0521210 | |||
88a57a6ac5 | |||
c032a9face | |||
7c854763fe | |||
adccee62d3 | |||
93c0c0c4e0 | |||
207c740a85 | |||
7204fb3af9 | |||
a321cd7226 | |||
af9eedc626 | |||
b2b6d2c764 |
@@ -24,13 +24,12 @@ from bpy.types import (
|
||||
from bl_ui.utils import PresetPanel
|
||||
|
||||
from bl_ui.properties_physics_common import (
|
||||
point_cache_ui,
|
||||
#point_cache_ui,
|
||||
effector_weights_ui,
|
||||
)
|
||||
|
||||
|
||||
def cloth_panel_enabled(md):
|
||||
return md.point_cache.is_baked is False
|
||||
#def cloth_panel_enabled(md):
|
||||
#return md.point_cache.is_baked is False
|
||||
|
||||
|
||||
class CLOTH_PT_presets(PresetPanel, Panel):
|
||||
@@ -65,7 +64,7 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel):
|
||||
md = context.cloth
|
||||
cloth = md.settings
|
||||
|
||||
layout.active = cloth_panel_enabled(md)
|
||||
#layout.active = cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -87,7 +86,7 @@ class PHYSICS_PT_cloth_physical_properties(PhysicButtonsPanel, Panel):
|
||||
md = context.cloth
|
||||
cloth = md.settings
|
||||
|
||||
layout.active = cloth_panel_enabled(md)
|
||||
#layout.active = cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -111,7 +110,7 @@ class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel, Panel):
|
||||
md = context.cloth
|
||||
cloth = md.settings
|
||||
|
||||
layout.active = cloth_panel_enabled(md)
|
||||
#layout.active = cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -142,7 +141,7 @@ class PHYSICS_PT_cloth_damping(PhysicButtonsPanel, Panel):
|
||||
md = context.cloth
|
||||
cloth = md.settings
|
||||
|
||||
layout.active = cloth_panel_enabled(md)
|
||||
#layout.active = cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -160,16 +159,15 @@ class PHYSICS_PT_cloth_damping(PhysicButtonsPanel, Panel):
|
||||
col = flow.column()
|
||||
col.prop(cloth, "bending_damping", text="Bending")
|
||||
|
||||
#class PHYSICS_PT_cloth_cache(PhysicButtonsPanel, Panel):
|
||||
#bl_label = "Cache"
|
||||
#bl_parent_id = 'PHYSICS_PT_cloth'
|
||||
#bl_options = {'DEFAULT_CLOSED' }
|
||||
#COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH' }
|
||||
|
||||
class PHYSICS_PT_cloth_cache(PhysicButtonsPanel, Panel):
|
||||
bl_label = "Cache"
|
||||
bl_parent_id = 'PHYSICS_PT_cloth'
|
||||
bl_options = {'DEFAULT_CLOSED'}
|
||||
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
|
||||
|
||||
def draw(self, context):
|
||||
md = context.cloth
|
||||
point_cache_ui(self, md.point_cache, cloth_panel_enabled(md), 'CLOTH')
|
||||
#def draw(self, context):
|
||||
#md = context.cloth
|
||||
#point_cache_ui(self, md.point_cache, cloth_panel_enabled(md), 'CLOTH')
|
||||
|
||||
|
||||
class PHYSICS_PT_cloth_shape(PhysicButtonsPanel, Panel):
|
||||
@@ -186,7 +184,7 @@ class PHYSICS_PT_cloth_shape(PhysicButtonsPanel, Panel):
|
||||
ob = context.object
|
||||
cloth = md.settings
|
||||
|
||||
layout.active = cloth_panel_enabled(md)
|
||||
#layout.active = cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -235,7 +233,7 @@ class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
|
||||
cloth = context.cloth.collision_settings
|
||||
md = context.cloth
|
||||
|
||||
layout.active = (cloth.use_collision or cloth.use_self_collision) and cloth_panel_enabled(md)
|
||||
layout.active = (cloth.use_collision or cloth.use_self_collision)# and cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -251,7 +249,7 @@ class PHYSICS_PT_cloth_object_collision(PhysicButtonsPanel, Panel):
|
||||
def draw_header(self, context):
|
||||
cloth = context.cloth.collision_settings
|
||||
|
||||
self.layout.active = cloth_panel_enabled(context.cloth)
|
||||
#self.layout.active = cloth_panel_enabled(context.cloth)
|
||||
self.layout.prop(cloth, "use_collision", text="")
|
||||
|
||||
def draw(self, context):
|
||||
@@ -261,7 +259,7 @@ class PHYSICS_PT_cloth_object_collision(PhysicButtonsPanel, Panel):
|
||||
cloth = context.cloth.collision_settings
|
||||
md = context.cloth
|
||||
|
||||
layout.active = cloth.use_collision and cloth_panel_enabled(md)
|
||||
layout.active = cloth.use_collision# and cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -283,7 +281,7 @@ class PHYSICS_PT_cloth_self_collision(PhysicButtonsPanel, Panel):
|
||||
def draw_header(self, context):
|
||||
cloth = context.cloth.collision_settings
|
||||
|
||||
self.layout.active = cloth_panel_enabled(context.cloth)
|
||||
#self.layout.active = cloth_panel_enabled(context.cloth)
|
||||
self.layout.prop(cloth, "use_self_collision", text="")
|
||||
|
||||
def draw(self, context):
|
||||
@@ -294,7 +292,7 @@ class PHYSICS_PT_cloth_self_collision(PhysicButtonsPanel, Panel):
|
||||
md = context.cloth
|
||||
ob = context.object
|
||||
|
||||
layout.active = cloth.use_self_collision and cloth_panel_enabled(md)
|
||||
layout.active = cloth.use_self_collision# and cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -311,6 +309,49 @@ class PHYSICS_PT_cloth_self_collision(PhysicButtonsPanel, Panel):
|
||||
col.prop_search(cloth, "vertex_group_self_collisions", ob, "vertex_groups", text="Vertex Group")
|
||||
|
||||
|
||||
class PHYSICS_PT_cloth_remeshing(PhysicButtonsPanel, Panel):
|
||||
bl_label = "Remeshing"
|
||||
bl_parent_id = 'PHYSICS_PT_cloth'
|
||||
bl_options = {'DEFAULT_CLOSED'}
|
||||
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
|
||||
|
||||
def draw_header(self, context):
|
||||
md = context.cloth
|
||||
cloth = md.settings
|
||||
|
||||
#self.layout.active = cloth_panel_enabled(context.cloth)
|
||||
self.layout.prop(cloth, "use_adaptive_remeshing", text="")
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
|
||||
md = context.cloth
|
||||
cloth = md.settings
|
||||
|
||||
layout.active = cloth.use_adaptive_remeshing# and cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
col = flow.column()
|
||||
col.prop(cloth, "remeshing_model")
|
||||
col = flow.column()
|
||||
col.prop(cloth, "aspect_min", text="Aspect Minimum")
|
||||
col = flow.column()
|
||||
col.prop(cloth, "size_min", text="Size Minimum")
|
||||
if cloth.remeshing_model == 'REMESHING_DYNAMIC':
|
||||
col = flow.column()
|
||||
col.prop(cloth, "size_max", text="Size Maximum")
|
||||
col = flow.column()
|
||||
col.prop(cloth, "refine_angle", text="Refine Angle")
|
||||
col = flow.column()
|
||||
col.prop(cloth, "refine_compression", text="Refine Compression")
|
||||
col = flow.column()
|
||||
col.prop(cloth, "refine_velocity", text="Refine Velocity")
|
||||
col = flow.column()
|
||||
col.prop(cloth, "refine_obstacle", text="Refine Obstacle")
|
||||
|
||||
|
||||
class PHYSICS_PT_cloth_property_weights(PhysicButtonsPanel, Panel):
|
||||
bl_label = "Property Weights"
|
||||
bl_parent_id = 'PHYSICS_PT_cloth'
|
||||
@@ -325,7 +366,7 @@ class PHYSICS_PT_cloth_property_weights(PhysicButtonsPanel, Panel):
|
||||
ob = context.object
|
||||
cloth = context.cloth.settings
|
||||
|
||||
layout.active = cloth_panel_enabled(md)
|
||||
#layout.active = cloth_panel_enabled(md)
|
||||
|
||||
flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
|
||||
|
||||
@@ -382,11 +423,12 @@ classes = (
|
||||
PHYSICS_PT_cloth_physical_properties,
|
||||
PHYSICS_PT_cloth_stiffness,
|
||||
PHYSICS_PT_cloth_damping,
|
||||
PHYSICS_PT_cloth_cache,
|
||||
#PHYSICS_PT_cloth_cache,
|
||||
PHYSICS_PT_cloth_shape,
|
||||
PHYSICS_PT_cloth_collision,
|
||||
PHYSICS_PT_cloth_object_collision,
|
||||
PHYSICS_PT_cloth_self_collision,
|
||||
PHYSICS_PT_cloth_remeshing,
|
||||
PHYSICS_PT_cloth_property_weights,
|
||||
PHYSICS_PT_cloth_field_weights,
|
||||
)
|
||||
|
@@ -33,6 +33,8 @@ struct MFace;
|
||||
struct Mesh;
|
||||
struct Object;
|
||||
struct Scene;
|
||||
struct BVHTree;
|
||||
struct ClothSizing;
|
||||
|
||||
#define DO_INLINE MALWAYS_INLINE
|
||||
|
||||
@@ -43,10 +45,14 @@ struct Scene;
|
||||
* represented by a float, given its precision. */
|
||||
#define ALMOST_ZERO FLT_EPSILON
|
||||
|
||||
/* Toggle Cloth Cache */
|
||||
#define USE_CLOTH_CACHE 0
|
||||
|
||||
/* Bits to or into the ClothVertex.flags. */
|
||||
typedef enum eClothVertexFlag {
|
||||
CLOTH_VERT_FLAG_PINNED = 1,
|
||||
CLOTH_VERT_FLAG_NOSELFCOLL = 2, /* vertex NOT used for self collisions */
|
||||
CLOTH_VERT_FLAG_PRESERVE = 4, /* vertex to preserve during remeshing */
|
||||
} eClothVertexFlag;
|
||||
|
||||
typedef struct ClothHairData {
|
||||
@@ -79,8 +85,11 @@ typedef struct 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 mvert_num_prev;
|
||||
unsigned int tri_num;
|
||||
unsigned char old_solver_type; /* unused, only 1 solver here */
|
||||
struct BMesh *bm; /* Used for remeshing step, initialized and deleted then and there */
|
||||
struct BMesh *bm_prev; /* Used for remeshing step, initialized and deleted then and there */
|
||||
unsigned char pad2;
|
||||
short pad3;
|
||||
struct BVHTree *bvhtree; /* collision tree for this cloth object */
|
||||
@@ -88,7 +97,7 @@ typedef struct Cloth {
|
||||
struct MVertTri *tri;
|
||||
struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */
|
||||
struct EdgeSet *edgeset; /* used for selfcollisions */
|
||||
int last_frame, pad4;
|
||||
int last_frame;
|
||||
} Cloth;
|
||||
|
||||
/**
|
||||
@@ -113,8 +122,9 @@ typedef struct ClothVertex {
|
||||
float struct_stiff;
|
||||
float bend_stiff;
|
||||
float shear_stiff;
|
||||
int spring_count; /* how many springs attached? */
|
||||
float shrink_factor; /* how much to shrink this cloth */
|
||||
int spring_count; /* how many springs attached? */
|
||||
float shrink_factor; /* how much to shrink this cloth */
|
||||
struct ClothSizing *sizing; /* Sizing during adaptive remeshing */
|
||||
} ClothVertex;
|
||||
|
||||
/**
|
||||
@@ -203,6 +213,8 @@ typedef enum {
|
||||
CLOTH_SIMSETTINGS_FLAG_SEW = (1 << 14),
|
||||
/** Make simulation respect deformations in the base object. */
|
||||
CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH = (1 << 15),
|
||||
/** if true, use adaptive remeshing */
|
||||
CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_REMESHING = (1 << 16),
|
||||
} CLOTH_SIMSETTINGS_FLAGS;
|
||||
|
||||
/* ClothSimSettings.bending_model. */
|
||||
@@ -211,6 +223,12 @@ typedef enum {
|
||||
CLOTH_BENDING_ANGULAR = 1,
|
||||
} CLOTH_BENDING_MODEL;
|
||||
|
||||
/* ClothSimSettings.remeshing_model. */
|
||||
typedef enum {
|
||||
CLOTH_REMESHING_STATIC = 0,
|
||||
CLOTH_REMESHING_DYNAMIC = 1,
|
||||
} CLOTH_REMESHING_MODEL;
|
||||
|
||||
/* COLLISION FLAGS */
|
||||
typedef enum {
|
||||
CLOTH_COLLSETTINGS_FLAG_ENABLED = (1 << 1), /* enables cloth - object collisions */
|
||||
@@ -273,20 +291,21 @@ void cloth_free_contacts(ColliderContacts *collider_contacts, int totcolliders);
|
||||
void cloth_free_modifier_extern(struct ClothModifierData *clmd);
|
||||
void cloth_free_modifier(struct ClothModifierData *clmd);
|
||||
void cloth_init(struct ClothModifierData *clmd);
|
||||
void clothModifier_do(struct ClothModifierData *clmd,
|
||||
struct Depsgraph *depsgraph,
|
||||
struct Scene *scene,
|
||||
struct Object *ob,
|
||||
struct Mesh *me,
|
||||
float (*vertexCos)[3]);
|
||||
struct Mesh *clothModifier_do(struct ClothModifierData *clmd,
|
||||
struct Depsgraph *depsgraph,
|
||||
struct Scene *scene,
|
||||
struct Object *ob,
|
||||
struct Mesh *mesh);
|
||||
|
||||
int cloth_uses_vgroup(struct ClothModifierData *clmd);
|
||||
|
||||
// needed for collision.c
|
||||
void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving, bool self);
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
// needed for button_object.c
|
||||
void cloth_clear_cache(struct Object *ob, struct ClothModifierData *clmd, float framenr);
|
||||
#endif
|
||||
|
||||
void cloth_parallel_transport_hair_frame(float mat[3][3],
|
||||
const float dir_old[3],
|
||||
@@ -294,4 +313,10 @@ void cloth_parallel_transport_hair_frame(float mat[3][3],
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/* for cloth_remeshing.cpp */
|
||||
void cloth_to_mesh(struct Object *ob, struct ClothModifierData *clmd, struct Mesh *r_mesh);
|
||||
int cloth_build_springs(struct ClothModifierData *clmd, struct Mesh *mesh);
|
||||
struct BVHTree *bvhtree_build_from_cloth(struct ClothModifierData *clmd, float epsilon);
|
||||
void cloth_apply_vgroup(struct ClothModifierData *clmd, struct Mesh *mesh);
|
||||
|
||||
#endif
|
||||
|
71
source/blender/blenkernel/BKE_cloth_remeshing.h
Normal file
71
source/blender/blenkernel/BKE_cloth_remeshing.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __BKE_CLOTH_REMESHING_H__
|
||||
#define __BKE_CLOTH_REMESHING_H__
|
||||
|
||||
/** \file
|
||||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include "BLI_math_inline.h"
|
||||
|
||||
#define DO_INLINE MALWAYS_INLINE
|
||||
|
||||
struct ClothModifierData;
|
||||
struct Mesh;
|
||||
struct Object;
|
||||
struct ClothSizing;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Mesh *cloth_remeshing_step(struct Depsgraph *depsgraph,
|
||||
struct Object *ob,
|
||||
struct ClothModifierData *clmd,
|
||||
struct Mesh *mesh);
|
||||
CustomData_MeshMasks cloth_remeshing_get_cd_mesh_masks(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
/**
|
||||
*The definition of sizing used for remeshing
|
||||
*/
|
||||
|
||||
/* TODO(Ish): figure out how to write a wrapper that can be used in c when ClothSizing is converted
|
||||
* to a class */
|
||||
typedef struct ClothSizing {
|
||||
float m[2][2];
|
||||
ClothSizing()
|
||||
{
|
||||
zero_m2(m);
|
||||
}
|
||||
ClothSizing(float a[2][2])
|
||||
{
|
||||
copy_m2_m2(m, a);
|
||||
}
|
||||
ClothSizing &operator+=(const ClothSizing &size);
|
||||
ClothSizing &operator/=(float value);
|
||||
ClothSizing operator*(float value);
|
||||
} ClothSizing;
|
||||
|
||||
#endif
|
||||
#endif
|
@@ -86,6 +86,8 @@ struct Scene;
|
||||
struct SmokeModifierData;
|
||||
struct SoftBody;
|
||||
struct ViewLayer;
|
||||
struct Mesh;
|
||||
struct Depsgraph;
|
||||
|
||||
struct OpenVDBReader;
|
||||
struct OpenVDBWriter;
|
||||
|
@@ -50,6 +50,7 @@ set(INC
|
||||
../../../intern/opensubdiv
|
||||
../../../extern/curve_fit_nd
|
||||
../../../intern/smoke/extern
|
||||
../editors/include
|
||||
)
|
||||
|
||||
set(INC_SYS
|
||||
@@ -85,6 +86,7 @@ set(SRC
|
||||
intern/camera.c
|
||||
intern/cdderivedmesh.c
|
||||
intern/cloth.c
|
||||
intern/cloth_remeshing.cpp
|
||||
intern/collection.c
|
||||
intern/collision.c
|
||||
intern/colorband.c
|
||||
@@ -245,6 +247,7 @@ set(SRC
|
||||
BKE_ccg.h
|
||||
BKE_cdderivedmesh.h
|
||||
BKE_cloth.h
|
||||
BKE_cloth_remeshing.h
|
||||
BKE_collection.h
|
||||
BKE_collision.h
|
||||
BKE_colorband.h
|
||||
|
@@ -28,22 +28,33 @@
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_customdata_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_edgehash.h"
|
||||
#include "BLI_linklist.h"
|
||||
#include "BLI_array.h"
|
||||
|
||||
#include "DEG_depsgraph.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "BKE_bvhutils.h"
|
||||
#include "BKE_cloth.h"
|
||||
#include "BKE_cloth_remeshing.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_pointcache.h"
|
||||
#include "BKE_library.h"
|
||||
#if USE_CLOTH_CACHE
|
||||
# include "BKE_pointcache.h"
|
||||
#endif
|
||||
|
||||
#include "bmesh.h"
|
||||
#include "bmesh_tools.h"
|
||||
|
||||
#include "BPH_mass_spring.h"
|
||||
|
||||
@@ -59,8 +70,6 @@ static int cloth_from_object(
|
||||
static void cloth_update_springs(ClothModifierData *clmd);
|
||||
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);
|
||||
|
||||
typedef struct BendSpringRef {
|
||||
int index;
|
||||
@@ -101,6 +110,7 @@ void cloth_init(ClothModifierData *clmd)
|
||||
clmd->sim_parms->mass = 0.3f;
|
||||
clmd->sim_parms->stepsPerFrame = 5;
|
||||
clmd->sim_parms->flags = 0;
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_REMESHING;
|
||||
clmd->sim_parms->solver_type = 0;
|
||||
clmd->sim_parms->maxspringlen = 10;
|
||||
clmd->sim_parms->vgroup_mass = 0;
|
||||
@@ -113,7 +123,8 @@ void cloth_init(ClothModifierData *clmd)
|
||||
clmd->sim_parms->presets = 2; /* cotton as start setting */
|
||||
clmd->sim_parms->timescale = 1.0f; /* speed factor, describes how fast cloth moves */
|
||||
clmd->sim_parms->time_scale = 1.0f; /* multiplies cloth speed */
|
||||
clmd->sim_parms->reset = 0;
|
||||
clmd->sim_parms->reset = 1;
|
||||
clmd->sim_parms->remeshing_reset = 1;
|
||||
|
||||
clmd->coll_parms->self_friction = 5.0;
|
||||
clmd->coll_parms->friction = 5.0;
|
||||
@@ -142,16 +153,30 @@ void cloth_init(ClothModifierData *clmd)
|
||||
|
||||
clmd->sim_parms->bending_model = CLOTH_BENDING_ANGULAR;
|
||||
|
||||
/**
|
||||
*remeshing parameters
|
||||
*/
|
||||
clmd->sim_parms->remeshing_model = CLOTH_REMESHING_DYNAMIC;
|
||||
clmd->sim_parms->refine_angle = 0.3f;
|
||||
clmd->sim_parms->refine_compression = 0.005f;
|
||||
clmd->sim_parms->refine_velocity = 0.5f;
|
||||
clmd->sim_parms->refine_obstacle = 1.0f;
|
||||
clmd->sim_parms->size_min = 50e-3f;
|
||||
clmd->sim_parms->size_max = 200e-3f;
|
||||
clmd->sim_parms->aspect_min = 0.5f;
|
||||
|
||||
if (!clmd->sim_parms->effector_weights) {
|
||||
clmd->sim_parms->effector_weights = BKE_effector_add_weights(NULL);
|
||||
}
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
if (clmd->point_cache) {
|
||||
clmd->point_cache->step = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon)
|
||||
BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon)
|
||||
{
|
||||
unsigned int i;
|
||||
BVHTree *bvhtree;
|
||||
@@ -255,6 +280,7 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self)
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
{
|
||||
PTCacheID pid;
|
||||
@@ -268,23 +294,30 @@ void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
|
||||
BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_AFTER, framenr);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
|
||||
{
|
||||
#if USE_CLOTH_CACHE
|
||||
PointCache *cache;
|
||||
|
||||
cache = clmd->point_cache;
|
||||
#endif
|
||||
|
||||
/* initialize simulation data if it didn't exist already */
|
||||
if (clmd->clothObject == NULL) {
|
||||
if (!cloth_from_object(ob, clmd, result, framenr, 1)) {
|
||||
#if USE_CLOTH_CACHE
|
||||
BKE_ptcache_invalidate(cache);
|
||||
#endif
|
||||
modifier_setError(&(clmd->modifier), "Can't initialize cloth");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (clmd->clothObject == NULL) {
|
||||
#if USE_CLOTH_CACHE
|
||||
BKE_ptcache_invalidate(cache);
|
||||
#endif
|
||||
modifier_setError(&(clmd->modifier), "Null cloth object");
|
||||
return 0;
|
||||
}
|
||||
@@ -298,7 +331,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int do_step_cloth(
|
||||
static Mesh *do_step_cloth(
|
||||
Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
|
||||
{
|
||||
ClothVertex *verts = NULL;
|
||||
@@ -331,7 +364,17 @@ static int do_step_cloth(
|
||||
}
|
||||
|
||||
/* Support for dynamic vertex groups, changing from frame to frame */
|
||||
|
||||
#if 1
|
||||
if (clmd->mesh) {
|
||||
cloth_apply_vgroup(clmd, clmd->mesh);
|
||||
}
|
||||
else {
|
||||
cloth_apply_vgroup(clmd, result);
|
||||
}
|
||||
#else
|
||||
cloth_apply_vgroup(clmd, result);
|
||||
#endif
|
||||
|
||||
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH) ||
|
||||
(clmd->sim_parms->vgroup_shrink > 0) || (clmd->sim_parms->shrink_min > 0.0f)) {
|
||||
@@ -351,19 +394,35 @@ static int do_step_cloth(
|
||||
|
||||
// printf ( "%f\n", ( float ) tval() );
|
||||
|
||||
return ret;
|
||||
Mesh *mesh_result = NULL;
|
||||
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_REMESHING) {
|
||||
mesh_result = cloth_remeshing_step(depsgraph, ob, clmd, result);
|
||||
}
|
||||
|
||||
#if 1
|
||||
if (clmd->mesh) {
|
||||
BKE_id_free(NULL, (ID *)clmd->mesh);
|
||||
}
|
||||
BKE_id_copy_ex(NULL, (ID *)mesh_result, (ID **)&clmd->mesh, LIB_ID_COPY_LOCALIZE);
|
||||
#endif
|
||||
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
return mesh_result;
|
||||
}
|
||||
|
||||
/************************************************
|
||||
* clothModifier_do - main simulation function
|
||||
************************************************/
|
||||
void clothModifier_do(ClothModifierData *clmd,
|
||||
Depsgraph *depsgraph,
|
||||
Scene *scene,
|
||||
Object *ob,
|
||||
Mesh *mesh,
|
||||
float (*vertexCos)[3])
|
||||
Mesh *clothModifier_do(
|
||||
ClothModifierData *clmd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh)
|
||||
{
|
||||
clmd->depsgraph = depsgraph;
|
||||
clmd->ob = ob;
|
||||
Mesh *mesh_result = NULL;
|
||||
BKE_id_copy_ex(NULL, (ID *)mesh, (ID **)&mesh_result, LIB_ID_COPY_LOCALIZE);
|
||||
#if USE_CLOTH_CACHE
|
||||
PointCache *cache;
|
||||
PTCacheID pid;
|
||||
float timescale;
|
||||
@@ -376,50 +435,102 @@ void clothModifier_do(ClothModifierData *clmd,
|
||||
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;
|
||||
#else
|
||||
int framenr = DEG_get_ctime(depsgraph);
|
||||
int startframe = scene->r.sfra;
|
||||
int endframe = scene->r.efra;
|
||||
clmd->sim_parms->timescale = 1.0f;
|
||||
#endif
|
||||
|
||||
if (!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_REMESHING)) {
|
||||
printf("Currently no remeshing\n");
|
||||
}
|
||||
else {
|
||||
printf("Currently remeshing\n");
|
||||
}
|
||||
|
||||
if (clmd->sim_parms->reset ||
|
||||
(clmd->clothObject && mesh->totvert != clmd->clothObject->mvert_num)) {
|
||||
(clmd->clothObject && mesh_result->totvert != clmd->clothObject->mvert_num &&
|
||||
!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_REMESHING))) {
|
||||
printf("this is called\n");
|
||||
clmd->sim_parms->reset = 0;
|
||||
clmd->sim_parms->remeshing_reset = 1;
|
||||
#if USE_CLOTH_CACHE
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
clmd->sim_parms->remeshing_reset = 0;
|
||||
}
|
||||
|
||||
/* simulation is only active during a specific period */
|
||||
if (framenr < startframe) {
|
||||
#if USE_CLOTH_CACHE
|
||||
BKE_ptcache_invalidate(cache);
|
||||
return;
|
||||
#endif
|
||||
return mesh_result;
|
||||
}
|
||||
else if (framenr > endframe) {
|
||||
framenr = endframe;
|
||||
}
|
||||
|
||||
/* initialize simulation data if it didn't exist already */
|
||||
if (!do_init_cloth(ob, clmd, mesh, framenr)) {
|
||||
return;
|
||||
if (!do_init_cloth(ob, clmd, mesh_result, framenr)) {
|
||||
return mesh_result;
|
||||
}
|
||||
|
||||
if (framenr == startframe) {
|
||||
#if USE_CLOTH_CACHE
|
||||
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
|
||||
do_init_cloth(ob, clmd, mesh, framenr);
|
||||
#endif
|
||||
do_init_cloth(ob, clmd, mesh_result, framenr);
|
||||
#if USE_CLOTH_CACHE
|
||||
BKE_ptcache_validate(cache, framenr);
|
||||
cache->flag &= ~PTCACHE_REDO_NEEDED;
|
||||
clmd->clothObject->last_frame = framenr;
|
||||
return;
|
||||
return mesh_result;
|
||||
}
|
||||
|
||||
/* try to read from cache */
|
||||
bool can_simulate = (framenr == clmd->clothObject->last_frame + 1) &&
|
||||
!(cache->flag & PTCACHE_BAKED);
|
||||
|
||||
/* TODO(Ish): clmd->mesh = mesh_result should be done only on the first frame of reading the
|
||||
* cache */
|
||||
if (clmd->mesh) {
|
||||
printf("\nclmd->mesh in %s before has totvert: %d totedge: %d totface: %d\n",
|
||||
__func__,
|
||||
clmd->mesh->totvert,
|
||||
clmd->mesh->totedge,
|
||||
clmd->mesh->totpoly);
|
||||
}
|
||||
else {
|
||||
printf("\n");
|
||||
}
|
||||
if (clmd->flags & MOD_CLOTH_FLAG_PREV_FRAME_READ_CACHE) {
|
||||
printf("Previous read from cache\n");
|
||||
}
|
||||
else {
|
||||
printf("Previous frame was simulated\n");
|
||||
clmd->mesh = mesh_result;
|
||||
}
|
||||
cache_result = BKE_ptcache_read(&pid, (float)framenr + scene->r.subframe, can_simulate);
|
||||
|
||||
if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED ||
|
||||
(!can_simulate && cache_result == PTCACHE_READ_OLD)) {
|
||||
/* TODO(Ish): Need to update mesh_result to be the new mesh that was generated while reading
|
||||
* the cache */
|
||||
printf("cache_result: %d\n", cache_result);
|
||||
mesh_result = clmd->mesh;
|
||||
BKE_id_copy_ex(NULL, (ID *)clmd->mesh, (ID **)&mesh_result, LIB_ID_COPY_LOCALIZE);
|
||||
BKE_cloth_solver_set_positions(clmd);
|
||||
cloth_to_object(ob, clmd, vertexCos);
|
||||
cloth_to_mesh(ob, clmd, mesh_result);
|
||||
|
||||
clmd->flags |= MOD_CLOTH_FLAG_PREV_FRAME_READ_CACHE;
|
||||
|
||||
BKE_ptcache_validate(cache, framenr);
|
||||
|
||||
@@ -427,9 +538,17 @@ void clothModifier_do(ClothModifierData *clmd,
|
||||
BKE_ptcache_write(&pid, framenr);
|
||||
}
|
||||
|
||||
#endif
|
||||
clmd->clothObject->last_frame = framenr;
|
||||
|
||||
return;
|
||||
if (clmd->mesh) {
|
||||
printf("clmd->mesh in %s after has totvert: %d totedge: %d totface: %d\n",
|
||||
__func__,
|
||||
clmd->mesh->totvert,
|
||||
clmd->mesh->totedge,
|
||||
clmd->mesh->totpoly);
|
||||
}
|
||||
#if USE_CLOTH_CACHE
|
||||
return mesh_result;
|
||||
}
|
||||
else if (cache_result == PTCACHE_READ_OLD) {
|
||||
BKE_cloth_solver_set_positions(clmd);
|
||||
@@ -439,9 +558,13 @@ void clothModifier_do(ClothModifierData *clmd,
|
||||
/*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) {
|
||||
/* if baked and nothing in cache, do nothing */
|
||||
BKE_ptcache_invalidate(cache);
|
||||
return;
|
||||
#endif
|
||||
return mesh_result;
|
||||
}
|
||||
|
||||
clmd->flags &= ~MOD_CLOTH_FLAG_PREV_FRAME_READ_CACHE;
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
/* if on second frame, write cache for first frame */
|
||||
if (cache->simframe == startframe &&
|
||||
(cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
|
||||
@@ -449,19 +572,42 @@ void clothModifier_do(ClothModifierData *clmd,
|
||||
}
|
||||
|
||||
clmd->sim_parms->timescale *= framenr - cache->simframe;
|
||||
#endif
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
#else
|
||||
if (framenr != clmd->clothObject->last_frame + 1) {
|
||||
return mesh_result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* do simulation */
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
BKE_ptcache_validate(cache, framenr);
|
||||
|
||||
if (!do_step_cloth(depsgraph, ob, clmd, mesh, framenr)) {
|
||||
Mesh *mesh_next = do_step_cloth(depsgraph, ob, clmd, mesh_result, framenr);
|
||||
|
||||
if (!mesh_next) {
|
||||
BKE_ptcache_invalidate(cache);
|
||||
}
|
||||
else {
|
||||
BKE_id_free(NULL, (ID *)mesh_result);
|
||||
mesh_result = mesh_next;
|
||||
BKE_ptcache_write(&pid, framenr);
|
||||
}
|
||||
#else
|
||||
Mesh *mesh_next = do_step_cloth(depsgraph, ob, clmd, mesh_result, framenr);
|
||||
|
||||
cloth_to_object(ob, clmd, vertexCos);
|
||||
if (mesh_next) {
|
||||
BKE_id_free(NULL, (ID *)mesh_result);
|
||||
mesh_result = mesh_next;
|
||||
}
|
||||
#endif
|
||||
cloth_to_mesh(ob, clmd, mesh_result);
|
||||
clmd->clothObject->last_frame = framenr;
|
||||
|
||||
return mesh_result;
|
||||
}
|
||||
|
||||
/* frees all */
|
||||
@@ -472,14 +618,32 @@ void cloth_free_modifier(ClothModifierData *clmd)
|
||||
if (!clmd) {
|
||||
return;
|
||||
}
|
||||
/* clmd->depsgraph = NULL; */
|
||||
/* clmd->ob = NULL; */
|
||||
/* clmd->mesh = NULL; */
|
||||
|
||||
cloth = clmd->clothObject;
|
||||
|
||||
if (cloth) {
|
||||
BPH_cloth_solver_free(clmd);
|
||||
|
||||
if (cloth->bm) {
|
||||
BM_mesh_free(cloth->bm);
|
||||
cloth->bm = NULL;
|
||||
}
|
||||
if (cloth->bm_prev) {
|
||||
BM_mesh_free(cloth->bm_prev);
|
||||
cloth->bm_prev = NULL;
|
||||
}
|
||||
|
||||
// Free the verts.
|
||||
if (cloth->verts != NULL) {
|
||||
for (int i = 0; i < cloth->mvert_num; i++) {
|
||||
if (cloth->verts[i].sizing != NULL) {
|
||||
MEM_freeN(cloth->verts[i].sizing);
|
||||
cloth->verts[i].sizing = NULL;
|
||||
}
|
||||
}
|
||||
MEM_freeN(cloth->verts);
|
||||
}
|
||||
|
||||
@@ -546,6 +710,10 @@ void cloth_free_modifier_extern(ClothModifierData *clmd)
|
||||
return;
|
||||
}
|
||||
|
||||
/* clmd->depsgraph = NULL; */
|
||||
/* clmd->ob = NULL; */
|
||||
/* clmd->mesh = NULL; */
|
||||
|
||||
cloth = clmd->clothObject;
|
||||
|
||||
if (cloth) {
|
||||
@@ -553,10 +721,25 @@ void cloth_free_modifier_extern(ClothModifierData *clmd)
|
||||
printf("cloth_free_modifier_extern in\n");
|
||||
}
|
||||
|
||||
if (cloth->bm) {
|
||||
BM_mesh_free(cloth->bm);
|
||||
cloth->bm = NULL;
|
||||
}
|
||||
if (cloth->bm_prev) {
|
||||
BM_mesh_free(cloth->bm_prev);
|
||||
cloth->bm_prev = NULL;
|
||||
}
|
||||
|
||||
BPH_cloth_solver_free(clmd);
|
||||
|
||||
// Free the verts.
|
||||
if (cloth->verts != NULL) {
|
||||
for (int i = 0; i < cloth->mvert_num; i++) {
|
||||
if (cloth->verts[i].sizing != NULL) {
|
||||
MEM_freeN(cloth->verts[i].sizing);
|
||||
cloth->verts[i].sizing = NULL;
|
||||
}
|
||||
}
|
||||
MEM_freeN(cloth->verts);
|
||||
}
|
||||
|
||||
@@ -636,6 +819,25 @@ static void cloth_to_object(Object *ob, ClothModifierData *clmd, float (*vertexC
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies deformed vertices to already existing Mesh
|
||||
*/
|
||||
|
||||
void cloth_to_mesh(Object *ob, ClothModifierData *clmd, Mesh *r_mesh)
|
||||
{
|
||||
int numVerts;
|
||||
float(*vertexCos)[3] = BKE_mesh_vertexCos_get(r_mesh, &numVerts);
|
||||
|
||||
cloth_to_object(ob, clmd, vertexCos);
|
||||
|
||||
BKE_mesh_apply_vert_coords(r_mesh, vertexCos);
|
||||
|
||||
if (vertexCos) {
|
||||
MEM_freeN(vertexCos);
|
||||
vertexCos = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int cloth_uses_vgroup(ClothModifierData *clmd)
|
||||
{
|
||||
return (((clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF) &&
|
||||
@@ -647,8 +849,32 @@ int cloth_uses_vgroup(ClothModifierData *clmd)
|
||||
/**
|
||||
* Applies a vertex group as specified by type.
|
||||
*/
|
||||
static void cloth_apply_vgroup(ClothModifierData *clmd, Mesh *mesh)
|
||||
void cloth_apply_vgroup(ClothModifierData *clmd, Mesh *mesh)
|
||||
{
|
||||
#if 0
|
||||
{
|
||||
printf("mesh in %s totvert: %d\n", __func__, mesh->totvert);
|
||||
MDeformVert *dvert = NULL;
|
||||
for (int i = 0; i < mesh->totvert; i++) {
|
||||
dvert = (MDeformVert *)CustomData_get(&mesh->vdata, i, CD_MDEFORMVERT);
|
||||
if (dvert) {
|
||||
printf("v: %f %f %f weights: ",
|
||||
mesh->mvert[i].co[0],
|
||||
mesh->mvert[i].co[1],
|
||||
mesh->mvert[i].co[2]);
|
||||
for (int j = 0; j < dvert->totweight; j++) {
|
||||
if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass - 1)) {
|
||||
printf("%f ", pow4f(dvert->dw[j].weight));
|
||||
if (dvert->dw[j].weight < 0.9999f) {
|
||||
dvert->totweight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Can be optimized to do all groups in one loop. */
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
@@ -771,6 +997,8 @@ static int cloth_from_object(
|
||||
if (clmd->clothObject) {
|
||||
clmd->clothObject->old_solver_type = 255;
|
||||
clmd->clothObject->edgeset = NULL;
|
||||
clmd->clothObject->bm = NULL;
|
||||
clmd->clothObject->bm_prev = NULL;
|
||||
}
|
||||
else if (!clmd->clothObject) {
|
||||
modifier_setError(&(clmd->modifier), "Out of memory on allocating clmd->clothObject");
|
||||
@@ -835,6 +1063,7 @@ static int cloth_from_object(
|
||||
|
||||
verts->impulse_count = 0;
|
||||
copy_v3_v3(verts->impulse, tnull);
|
||||
verts->sizing = NULL;
|
||||
}
|
||||
|
||||
// apply / set vertex groups
|
||||
@@ -1381,7 +1610,7 @@ BLI_INLINE bool cloth_bend_set_poly_vert_array(int **poly, int len, const MLoop
|
||||
return true;
|
||||
}
|
||||
|
||||
static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
|
||||
int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
|
||||
{
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
ClothSpring *spring = NULL, *tspring = NULL, *tspring2 = NULL;
|
||||
|
3018
source/blender/blenkernel/intern/cloth_remeshing.cpp
Normal file
3018
source/blender/blenkernel/intern/cloth_remeshing.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3491,9 +3491,11 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
|
||||
|
||||
BKE_id_copy_ex(NULL, &psys->hair_in_mesh->id, (ID **)&psys->hair_out_mesh, LIB_ID_COPY_LOCALIZE);
|
||||
deformedVerts = BKE_mesh_vertexCos_get(psys->hair_out_mesh, NULL);
|
||||
clothModifier_do(
|
||||
psys->clmd, sim->depsgraph, sim->scene, sim->ob, psys->hair_in_mesh, deformedVerts);
|
||||
BKE_mesh_apply_vert_coords(psys->hair_out_mesh, deformedVerts);
|
||||
/* TODO(Ish): Due to change in the cloth simulation code, clothModifier_do now is returning a
|
||||
* mesh, this change needs to be reflected in the hair simulation code */
|
||||
/* clothModifier_do( */
|
||||
/* psys->clmd, sim->depsgraph, sim->scene, sim->ob, psys->hair_in_mesh, deformedVerts); */
|
||||
/* BKE_mesh_apply_vert_coords(psys->hair_out_mesh, deformedVerts); */
|
||||
|
||||
MEM_freeN(deformedVerts);
|
||||
|
||||
|
@@ -41,6 +41,8 @@
|
||||
#include "DNA_rigidbody_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_smoke_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_cloth_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_math.h"
|
||||
@@ -49,11 +51,14 @@
|
||||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
#include "DEG_depsgraph.h"
|
||||
|
||||
#include "PIL_time.h"
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
#include "BKE_anim.h"
|
||||
#include "BKE_cloth.h"
|
||||
#include "BKE_cloth_remeshing.h"
|
||||
#include "BKE_collection.h"
|
||||
#include "BKE_dynamicpaint.h"
|
||||
#include "BKE_global.h"
|
||||
@@ -66,6 +71,7 @@
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_smoke.h"
|
||||
#include "BKE_softbody.h"
|
||||
#include "BKE_mesh.h"
|
||||
|
||||
#include "BIK_api.h"
|
||||
|
||||
@@ -505,6 +511,7 @@ static void ptcache_particle_extra_read(void *psys_v, PTCacheMem *pm, float UNUS
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
/* Cloth functions */
|
||||
static int ptcache_cloth_write(int index, void *cloth_v, void **data, int UNUSED(cfra))
|
||||
{
|
||||
@@ -535,6 +542,18 @@ static void ptcache_cloth_read(
|
||||
PTCACHE_DATA_TO(data, BPHYS_DATA_VELOCITY, 0, vert->v);
|
||||
PTCACHE_DATA_TO(data, BPHYS_DATA_XCONST, 0, vert->xconst);
|
||||
}
|
||||
/* TODO(Ish): add the remeshing step here, so that the mesh has been updated with the correct
|
||||
* number of vertices for the next frame */
|
||||
/* Object *ob = clmd->ob; */
|
||||
/* Depsgraph *depsgraph = clmd->depsgraph; */
|
||||
/* Mesh *mesh = clmd->mesh; */
|
||||
/* printf("mesh in %s has totvert: %d totedge: %d totface %d\n", */
|
||||
/* __func__, */
|
||||
/* mesh->totvert, */
|
||||
/* mesh->totedge, */
|
||||
/* mesh->totpoly); */
|
||||
/* clmd->sim_parms->remeshing_reset = 1; */
|
||||
/* cloth_remeshing_step(depsgraph, ob, clmd, mesh); */
|
||||
}
|
||||
static void ptcache_cloth_interpolate(
|
||||
int index, void *cloth_v, void **data, float cfra, float cfra1, float cfra2, float *old_data)
|
||||
@@ -586,6 +605,7 @@ static void ptcache_cloth_error(void *cloth_v, const char *message)
|
||||
ClothModifierData *clmd = cloth_v;
|
||||
modifier_setError(&clmd->modifier, "%s", message);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SMOKE
|
||||
/* Smoke functions */
|
||||
@@ -1659,6 +1679,7 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p
|
||||
pid->max_step = 20;
|
||||
pid->file_type = PTCACHE_FILE_PTCACHE;
|
||||
}
|
||||
#if USE_CLOTH_CACHE
|
||||
void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *clmd)
|
||||
{
|
||||
memset(pid, 0, sizeof(PTCacheID));
|
||||
@@ -1698,6 +1719,7 @@ void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *cl
|
||||
pid->max_step = 1;
|
||||
pid->file_type = PTCACHE_FILE_PTCACHE;
|
||||
}
|
||||
#endif
|
||||
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd)
|
||||
{
|
||||
SmokeDomainSettings *sds = smd->domain;
|
||||
@@ -1898,6 +1920,7 @@ static bool foreach_object_modifier_ptcache(Object *object,
|
||||
{
|
||||
PTCacheID pid;
|
||||
for (ModifierData *md = object->modifiers.first; md != NULL; md = md->next) {
|
||||
#if USE_CLOTH_CACHE
|
||||
if (md->type == eModifierType_Cloth) {
|
||||
BKE_ptcache_id_from_cloth(&pid, object, (ClothModifierData *)md);
|
||||
if (!callback(&pid, callback_user_data)) {
|
||||
@@ -1913,6 +1936,17 @@ static bool foreach_object_modifier_ptcache(Object *object,
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (md->type == eModifierType_Smoke) {
|
||||
SmokeModifierData *smd = (SmokeModifierData *)md;
|
||||
if (smd->type & MOD_SMOKE_TYPE_DOMAIN) {
|
||||
BKE_ptcache_id_from_smoke(&pid, object, (SmokeModifierData *)md);
|
||||
if (!callback(&pid, callback_user_data)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (md->type == eModifierType_DynamicPaint) {
|
||||
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
|
||||
if (pmd->canvas) {
|
||||
@@ -2561,9 +2595,11 @@ static int ptcache_old_elemsize(PTCacheID *pid)
|
||||
else if (pid->type == PTCACHE_TYPE_PARTICLES) {
|
||||
return sizeof(ParticleKey);
|
||||
}
|
||||
#if USE_CLOTH_CACHE
|
||||
else if (pid->type == PTCACHE_TYPE_CLOTH) {
|
||||
return 9 * sizeof(float);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2913,10 +2949,48 @@ static int ptcache_read(PTCacheID *pid, int cfra)
|
||||
int totpoint = pm->totpoint;
|
||||
|
||||
if ((pid->data_types & (1 << BPHYS_DATA_INDEX)) == 0) {
|
||||
if (pid->type == PTCACHE_TYPE_CLOTH) {
|
||||
ClothModifierData *clmd = pid->calldata;
|
||||
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_REMESHING) {
|
||||
Object *ob = clmd->ob;
|
||||
Depsgraph *depsgraph = clmd->depsgraph;
|
||||
Mesh *mesh = clmd->mesh;
|
||||
printf("mesh in %s before remeshing has totvert: %d totedge: %d totface %d\n",
|
||||
__func__,
|
||||
mesh->totvert,
|
||||
mesh->totedge,
|
||||
mesh->totpoly);
|
||||
#if 1
|
||||
if (clmd->flags & MOD_CLOTH_FLAG_PREV_FRAME_READ_CACHE) {
|
||||
}
|
||||
else {
|
||||
clmd->sim_parms->remeshing_reset = 1;
|
||||
}
|
||||
#else
|
||||
printf("reset: %d\n", clmd->sim_parms->reset);
|
||||
printf("remeshing_reset: %d\n", clmd->sim_parms->remeshing_reset);
|
||||
clmd->sim_parms->remeshing_reset = 1;
|
||||
#endif
|
||||
Mesh *mesh_result = cloth_remeshing_step(depsgraph, ob, clmd, mesh);
|
||||
if (clmd->mesh && mesh_result) {
|
||||
/* BKE_mesh_free(clmd->mesh); */
|
||||
BKE_id_copy_ex(NULL, (ID *)mesh_result, (ID **)&clmd->mesh, LIB_ID_COPY_LOCALIZE);
|
||||
printf("mesh in %s after remeshing has totvert: %d totedge: %d totface %d\n",
|
||||
__func__,
|
||||
clmd->mesh->totvert,
|
||||
clmd->mesh->totedge,
|
||||
clmd->mesh->totpoly);
|
||||
}
|
||||
}
|
||||
}
|
||||
int pid_totpoint = pid->totpoint(pid->calldata, cfra);
|
||||
|
||||
if (totpoint != pid_totpoint) {
|
||||
#if 1
|
||||
printf("memory_cache_totpoint: %d pid_totpoint: %d\n", totpoint, pid_totpoint);
|
||||
pid->error(pid->calldata, "Number of points in cache does not match mesh");
|
||||
#else
|
||||
pid->error(pid->calldata, "Number of points in cache does not match mesh");
|
||||
#endif
|
||||
totpoint = MIN2(totpoint, pid_totpoint);
|
||||
}
|
||||
}
|
||||
@@ -3672,12 +3746,18 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
|
||||
BKE_ptcache_invalidate(cache);
|
||||
cache->flag &= ~PTCACHE_REDO_NEEDED;
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
if (pid->type == PTCACHE_TYPE_CLOTH) {
|
||||
cloth_free_modifier(pid->calldata);
|
||||
}
|
||||
else if (pid->type == PTCACHE_TYPE_SOFTBODY) {
|
||||
sbFreeSimulation(pid->calldata);
|
||||
}
|
||||
#else
|
||||
if (pid->type == PTCACHE_TYPE_SOFTBODY) {
|
||||
sbFreeSimulation(pid->calldata);
|
||||
}
|
||||
#endif
|
||||
else if (pid->type == PTCACHE_TYPE_PARTICLES) {
|
||||
psys_reset(pid->calldata, PSYS_RESET_DEPSGRAPH);
|
||||
}
|
||||
@@ -3716,6 +3796,7 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
|
||||
/* Baked cloth hair has to be checked too, because we don't want to reset */
|
||||
/* particles or cloth in that case -jahka */
|
||||
}
|
||||
#if USE_CLOTH_CACHE
|
||||
else if (psys->clmd) {
|
||||
BKE_ptcache_id_from_cloth(&pid, ob, psys->clmd);
|
||||
if (mode == PSYS_RESET_ALL ||
|
||||
@@ -3726,6 +3807,7 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
|
||||
skip = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (skip == 0 && psys->part) {
|
||||
BKE_ptcache_id_from_particles(&pid, ob, psys);
|
||||
@@ -3734,10 +3816,12 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
|
||||
}
|
||||
|
||||
for (md = ob->modifiers.first; md; md = md->next) {
|
||||
#if USE_CLOTH_CACHE
|
||||
if (md->type == eModifierType_Cloth) {
|
||||
BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData *)md);
|
||||
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
|
||||
}
|
||||
#endif
|
||||
if (md->type == eModifierType_Smoke) {
|
||||
SmokeModifierData *smd = (SmokeModifierData *)md;
|
||||
if (smd->type & MOD_SMOKE_TYPE_DOMAIN) {
|
||||
|
@@ -56,12 +56,14 @@ void swap_m4m4(float A[4][4], float B[4][4]);
|
||||
|
||||
/******************************** Arithmetic *********************************/
|
||||
|
||||
void add_m2_m2m2(float m1[2][2], const float m2[2][2], const float m3[2][2]);
|
||||
void add_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3]);
|
||||
void add_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4]);
|
||||
|
||||
void madd_m3_m3m3fl(float R[3][3], const float A[3][3], const float B[3][3], const float f);
|
||||
void madd_m4_m4m4fl(float R[4][4], const float A[4][4], const float B[4][4], const float f);
|
||||
|
||||
void sub_m2_m2m2(float m1[2][2], const float m2[2][2], const float m3[2][2]);
|
||||
void sub_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3]);
|
||||
void sub_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4]);
|
||||
|
||||
@@ -194,6 +196,7 @@ void mul_transposed_m3_v3(const float M[3][3], float r[3]);
|
||||
void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3]);
|
||||
void mul_m3_v3_double(const float M[3][3], double r[3]);
|
||||
|
||||
void mul_m2_fl(float R[2][2], float f);
|
||||
void mul_m3_fl(float R[3][3], float f);
|
||||
void mul_m4_fl(float R[4][4], float f);
|
||||
void mul_mat3_m4_fl(float R[4][4], float f);
|
||||
@@ -205,6 +208,7 @@ void negate_m4(float R[4][4]);
|
||||
bool invert_m3_ex(float m[3][3], const float epsilon);
|
||||
bool invert_m3_m3_ex(float m1[3][3], const float m2[3][3], const float epsilon);
|
||||
|
||||
bool invert_m2_m2(float r[2][2], float m[2][2], float epsilon);
|
||||
bool invert_m3(float R[3][3]);
|
||||
bool invert_m3_m3(float R[3][3], const float A[3][3]);
|
||||
bool invert_m4(float R[4][4]);
|
||||
@@ -221,6 +225,7 @@ void mul_m3_v3_db(const double M[3][3], double r[3]);
|
||||
|
||||
/****************************** Linear Algebra *******************************/
|
||||
|
||||
void transpose_m2(float mat[2][2]);
|
||||
void transpose_m3(float R[3][3]);
|
||||
void transpose_m3_m3(float R[3][3], const float A[3][3]);
|
||||
void transpose_m3_m4(float R[3][3], const float A[4][4]);
|
||||
|
@@ -782,6 +782,17 @@ void mul_transposed_mat3_m4_v3(const float mat[4][4], float vec[3])
|
||||
vec[2] = x * mat[2][0] + y * mat[2][1] + mat[2][2] * vec[2];
|
||||
}
|
||||
|
||||
void mul_m2_fl(float m[2][2], float f)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
m[i][j] *= f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mul_m3_fl(float m[3][3], float f)
|
||||
{
|
||||
int i, j;
|
||||
@@ -858,6 +869,17 @@ void mul_m3_v3_double(const float mat[3][3], double vec[3])
|
||||
vec[2] = x * (double)mat[0][2] + y * (double)mat[1][2] + (double)mat[2][2] * vec[2];
|
||||
}
|
||||
|
||||
void add_m2_m2m2(float m1[2][2], const float m2[2][2], const float m3[2][2])
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
m1[i][j] = m2[i][j] + m3[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void add_m3_m3m3(float m1[3][3], const float m2[3][3], const float m3[3][3])
|
||||
{
|
||||
int i, j;
|
||||
@@ -902,6 +924,17 @@ void madd_m4_m4m4fl(float m1[4][4], const float m2[4][4], const float m3[4][4],
|
||||
}
|
||||
}
|
||||
|
||||
void sub_m2_m2m2(float m1[2][2], const float m2[2][2], const float m3[2][2])
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
m1[i][j] = m2[i][j] - m3[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sub_m3_m3m3(float m1[3][3], const float m2[3][3], const float m3[3][3])
|
||||
{
|
||||
int i, j;
|
||||
@@ -938,6 +971,21 @@ float determinant_m4_mat3_array(const float m[4][4])
|
||||
m[2][0] * (m[0][1] * m[1][2] - m[0][2] * m[1][1]));
|
||||
}
|
||||
|
||||
bool invert_m2_m2(float r[2][2], float m[2][2], float epsilon)
|
||||
{
|
||||
float det = determinant_m2(m[0][0], m[0][1], m[1][0], m[1][1]);
|
||||
if (fabsf(det) < epsilon) {
|
||||
return false;
|
||||
}
|
||||
r[0][0] = m[1][1];
|
||||
r[0][1] = -m[0][1];
|
||||
|
||||
r[1][0] = -m[1][0];
|
||||
r[1][1] = m[0][0];
|
||||
mul_m2_fl(r, 1.0f / det);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool invert_m3_ex(float m[3][3], const float epsilon)
|
||||
{
|
||||
float tmp[3][3];
|
||||
@@ -1107,6 +1155,15 @@ bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
|
||||
|
||||
/****************************** Linear Algebra *******************************/
|
||||
|
||||
void transpose_m2(float mat[2][2])
|
||||
{
|
||||
float t;
|
||||
|
||||
t = mat[0][1];
|
||||
mat[0][1] = mat[1][0];
|
||||
mat[1][0] = t;
|
||||
}
|
||||
|
||||
void transpose_m3(float mat[3][3])
|
||||
{
|
||||
float t;
|
||||
|
@@ -130,8 +130,9 @@ typedef struct ClothSimSettings {
|
||||
/** Used for presets on GUI. */
|
||||
short presets;
|
||||
short reset;
|
||||
short remeshing_reset;
|
||||
|
||||
char _pad0[4];
|
||||
char _pad0[2];
|
||||
struct EffectorWeights *effector_weights;
|
||||
|
||||
short bending_model;
|
||||
@@ -147,6 +148,17 @@ typedef struct ClothSimSettings {
|
||||
float compression_damp;
|
||||
/** Mechanical damping of shear springs. */
|
||||
float shear_damp;
|
||||
|
||||
/** Remeshing parameters **/
|
||||
short remeshing_model;
|
||||
char _pad1[2];
|
||||
float refine_angle;
|
||||
float refine_compression;
|
||||
float refine_velocity;
|
||||
float refine_obstacle;
|
||||
float size_min;
|
||||
float size_max;
|
||||
float aspect_min;
|
||||
} ClothSimSettings;
|
||||
|
||||
typedef struct ClothCollSettings {
|
||||
|
@@ -728,6 +728,12 @@ typedef struct ClothModifierData {
|
||||
/** Definition is in DNA_object_force_types.h. */
|
||||
struct PointCache *point_cache;
|
||||
struct ListBase ptcaches;
|
||||
struct Depsgraph *depsgraph;
|
||||
struct Object *ob;
|
||||
struct Mesh *mesh;
|
||||
|
||||
int flags;
|
||||
char _pad[4];
|
||||
|
||||
/* XXX nasty hack, remove once hair can be separated from cloth modifier data */
|
||||
struct ClothHairData *hairdata;
|
||||
@@ -740,6 +746,11 @@ typedef struct ClothModifierData {
|
||||
struct ClothSolverResult *solver_result;
|
||||
} ClothModifierData;
|
||||
|
||||
enum {
|
||||
/* Flag to check if previous frame was read from cache */
|
||||
MOD_CLOTH_FLAG_PREV_FRAME_READ_CACHE = (1 << 0),
|
||||
};
|
||||
|
||||
typedef struct CollisionModifierData {
|
||||
ModifierData modifier;
|
||||
|
||||
|
@@ -461,6 +461,19 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
|
||||
"Cloth model with linear bending springs (legacy)"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
static const EnumPropertyItem prop_remeshing_model_items[] = {
|
||||
{CLOTH_REMESHING_STATIC,
|
||||
"REMESHING_STATIC",
|
||||
0,
|
||||
"Static",
|
||||
"Cloth remeshing model with statically determined vertices"},
|
||||
{CLOTH_REMESHING_DYNAMIC,
|
||||
"REMESHING_DYNAMIC",
|
||||
0,
|
||||
"Dynamic",
|
||||
"Cloth remeshing model with dynamically changing vertices"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
srna = RNA_def_struct(brna, "ClothSettings", NULL);
|
||||
RNA_def_struct_ui_text(srna, "Cloth Settings", "Cloth simulation settings for an object");
|
||||
@@ -774,6 +787,64 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
|
||||
/* remeshing */
|
||||
prop = RNA_def_property(srna, "use_adaptive_remeshing", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_REMESHING);
|
||||
RNA_def_property_ui_text(prop, "Adaptive Remeshing", "Enables adaptive remeshing");
|
||||
RNA_def_property_clear_flag(prop, PROP_NONE);
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
|
||||
prop = RNA_def_property(srna, "remeshing_model", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "remeshing_model");
|
||||
RNA_def_property_enum_items(prop, prop_remeshing_model_items);
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Remeshing Model", "Remeshing model for determining how vertices are created/removed");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
|
||||
prop = RNA_def_property(srna, "refine_angle", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "refine_angle");
|
||||
RNA_def_property_range(prop, 0.0f, 10.0f);
|
||||
RNA_def_property_ui_text(prop, "Remeshing Refine Angle", "Remeshing refine angle");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
|
||||
prop = RNA_def_property(srna, "refine_compression", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "refine_compression");
|
||||
RNA_def_property_range(prop, 0.0f, 10.0f);
|
||||
RNA_def_property_ui_text(prop, "Remeshing Refine Compression", "Remeshing refine compression");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
|
||||
prop = RNA_def_property(srna, "refine_velocity", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "refine_velocity");
|
||||
RNA_def_property_range(prop, 0.0f, 10.0f);
|
||||
RNA_def_property_ui_text(prop, "Remeshing Refine Velocity", "Remeshing refine velocity");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
|
||||
prop = RNA_def_property(srna, "refine_obstacle", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "refine_obstacle");
|
||||
RNA_def_property_range(prop, 0.0f, 10.0f);
|
||||
RNA_def_property_ui_text(prop, "Remeshing Refine Obstacle", "Remeshing refine obstacle");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
|
||||
prop = RNA_def_property(srna, "size_min", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "size_min");
|
||||
RNA_def_property_range(prop, 0.0f, 10.0f);
|
||||
RNA_def_property_ui_text(prop, "Remeshing Size Min", "Remeshing size minimum");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
|
||||
prop = RNA_def_property(srna, "size_max", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "size_max");
|
||||
RNA_def_property_range(prop, 0.0f, 10.0f);
|
||||
RNA_def_property_ui_text(prop, "Remeshing Size Max", "Remeshing size maximum");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
|
||||
prop = RNA_def_property(srna, "aspect_min", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "aspect_min");
|
||||
RNA_def_property_range(prop, 0.0f, 10.0f);
|
||||
RNA_def_property_ui_text(prop, "Remeshing Aspect Min", "Remeshing aspect minimum");
|
||||
RNA_def_property_update(prop, 0, "rna_cloth_update");
|
||||
|
||||
/* unused */
|
||||
|
||||
/* unused still */
|
||||
|
@@ -31,6 +31,13 @@
|
||||
#include "DNA_key_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#define USE_CLOTH_CACHE 0
|
||||
#if USE_CLOTH_CACHE
|
||||
#else
|
||||
# include "DNA_object_force_types.h"
|
||||
# include "DNA_collection_types.h"
|
||||
#endif
|
||||
#undef USE_CLOTH_CACHE
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
@@ -43,7 +50,9 @@
|
||||
#include "BKE_library_query.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_pointcache.h"
|
||||
#if USE_CLOTH_CACHE
|
||||
# include "BKE_pointcache.h"
|
||||
#endif
|
||||
|
||||
#include "DEG_depsgraph_physics.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
@@ -56,23 +65,29 @@ static void initData(ModifierData *md)
|
||||
|
||||
clmd->sim_parms = MEM_callocN(sizeof(ClothSimSettings), "cloth sim parms");
|
||||
clmd->coll_parms = MEM_callocN(sizeof(ClothCollSettings), "cloth coll parms");
|
||||
#if USE_CLOTH_CACHE
|
||||
clmd->point_cache = BKE_ptcache_add(&clmd->ptcaches);
|
||||
clmd->flags = 0;
|
||||
#endif
|
||||
|
||||
/* check for alloc failing */
|
||||
/* check for alloc failing */
|
||||
#if USE_CLOTH_CACHE
|
||||
if (!clmd->sim_parms || !clmd->coll_parms || !clmd->point_cache) {
|
||||
#else
|
||||
if (!clmd->sim_parms || !clmd->coll_parms) {
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
cloth_init(clmd);
|
||||
}
|
||||
|
||||
static void deformVerts(ModifierData *md,
|
||||
const ModifierEvalContext *ctx,
|
||||
Mesh *mesh,
|
||||
float (*vertexCos)[3],
|
||||
int numVerts)
|
||||
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
||||
{
|
||||
Mesh *mesh_result;
|
||||
|
||||
Mesh *mesh_src;
|
||||
int numVerts = mesh->totvert;
|
||||
ClothModifierData *clmd = (ClothModifierData *)md;
|
||||
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
||||
|
||||
@@ -81,7 +96,7 @@ static void deformVerts(ModifierData *md,
|
||||
initData(md);
|
||||
|
||||
if (!clmd->sim_parms || !clmd->coll_parms) {
|
||||
return;
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,11 +129,15 @@ static void deformVerts(ModifierData *md,
|
||||
}
|
||||
}
|
||||
|
||||
float(*vertexCos)[3] = BKE_mesh_vertexCos_get(mesh_src, &numVerts);
|
||||
BKE_mesh_apply_vert_coords(mesh_src, vertexCos);
|
||||
|
||||
clothModifier_do(clmd, ctx->depsgraph, scene, ctx->object, mesh_src, vertexCos);
|
||||
mesh_result = clothModifier_do(clmd, ctx->depsgraph, scene, ctx->object, mesh_src);
|
||||
|
||||
BKE_id_free(NULL, mesh_src);
|
||||
MEM_freeN(vertexCos);
|
||||
|
||||
return mesh_result;
|
||||
}
|
||||
|
||||
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
||||
@@ -170,6 +189,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
|
||||
MEM_freeN(tclmd->coll_parms);
|
||||
}
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
BKE_ptcache_free_list(&tclmd->ptcaches);
|
||||
if (flag & LIB_ID_CREATE_NO_MAIN) {
|
||||
/* Share the cache with the original object's modifier. */
|
||||
@@ -181,6 +201,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
|
||||
tclmd->point_cache = BKE_ptcache_add(&tclmd->ptcaches);
|
||||
tclmd->point_cache->step = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
tclmd->sim_parms = MEM_dupallocN(clmd->sim_parms);
|
||||
if (clmd->sim_parms->effector_weights) {
|
||||
@@ -218,6 +239,7 @@ static void freeData(ModifierData *md)
|
||||
MEM_freeN(clmd->coll_parms);
|
||||
}
|
||||
|
||||
#if USE_CLOTH_CACHE
|
||||
if (md->flag & eModifierFlag_SharedCaches) {
|
||||
BLI_listbase_clear(&clmd->ptcaches);
|
||||
}
|
||||
@@ -225,6 +247,7 @@ static void freeData(ModifierData *md)
|
||||
BKE_ptcache_free_list(&clmd->ptcaches);
|
||||
}
|
||||
clmd->point_cache = NULL;
|
||||
#endif
|
||||
|
||||
if (clmd->hairdata) {
|
||||
MEM_freeN(clmd->hairdata);
|
||||
@@ -253,17 +276,17 @@ ModifierTypeInfo modifierType_Cloth = {
|
||||
/* name */ "Cloth",
|
||||
/* structName */ "ClothModifierData",
|
||||
/* structSize */ sizeof(ClothModifierData),
|
||||
/* type */ eModifierTypeType_OnlyDeform,
|
||||
/* type */ eModifierTypeType_Nonconstructive,
|
||||
/* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_UsesPointCache |
|
||||
eModifierTypeFlag_Single,
|
||||
|
||||
/* copyData */ copyData,
|
||||
|
||||
/* deformVerts */ deformVerts,
|
||||
/* deformVerts */ NULL,
|
||||
/* deformMatrices */ NULL,
|
||||
/* deformVertsEM */ NULL,
|
||||
/* deformMatricesEM */ NULL,
|
||||
/* applyModifier */ NULL,
|
||||
/* applyModifier */ applyModifier,
|
||||
|
||||
/* initData */ initData,
|
||||
/* requiredDataMask */ requiredDataMask,
|
||||
|
Reference in New Issue
Block a user