1
1

Compare commits

...

154 Commits

Author SHA1 Message Date
3c6a26d35b Cloth: fix memory leaks from recent change 2019-08-26 09:20:17 +05:30
a78d0f7ac2 Cloth: pinned vertices now works with adaptive remeshing
The customdata for newly created vertices is now modified to remove any weight for that vertex. Also the correct mesh is being passed to cloth_apply_vgroup().
2019-08-23 19:39:35 +05:30
6022ea47aa Cloth: some code to better understand problems with pinning 2019-08-19 21:11:59 +05:30
64bdb89aba Cloth: cache read check for adaptive cloth 2019-08-17 15:16:32 +05:30
b000354226 Cloth: silence some print statements 2019-08-15 18:47:25 +05:30
4844469ebc Cloth: new method for collapsing an edge 2019-08-15 17:57:41 +05:30
25fa832d01 Cloth: attempt at fixing extra face after collapsing edge 2019-08-15 12:16:39 +05:30
0bf78faa1d Cloth: debugging statements for finding bug in collapse edges
There is a bug in collapse edges which leaves 3 triangles for an edge in a special case. This might be an issue with the bmesh api. Now that the problem has been isolated, it can now be worked on.
2019-08-13 19:46:17 +05:30
09565017ae Cloth: revert back to using previous splitting method
The problem arises when a particular edge has more than 2 faces. This shouldn't ever happen. There must be problem with collapse edges or flip edges that introduces these extra number of faces for the edge.
2019-08-12 14:51:53 +05:30
e3ddf0f8bc Cloth: attempt fix for rare error when not all faces remain as triangles
After spliting an edge, there are some instances when faces around the new_vert are not triangles. This attempts to fix this.
2019-08-10 18:06:23 +05:30
197bb8b69b Cloth: change intial values of the remeshing parameters 2019-08-09 19:02:31 +05:30
5f6fad8f75 Cloth: UI to choose static or dynamic remeshing 2019-08-09 15:14:39 +05:30
5268cbdb84 Cloth: add support for turning adaptive remeshing on or off 2019-08-09 13:02:29 +05:30
c3553c719b Cloth: new attempt at sewing
Now it works for the most part but the mesh that is generated has some problems with the rendering. Need to look into this.
The cloth doesn't seem to get the updated vertices.
2019-08-08 00:37:23 +05:30
6bb7f27f32 Cloth: attempt at fixing caching
clmd->mesh was being changed when it was returned as mesh_result, so now we are creating a local copy of the same.
This is introduced another problem of the mesh not being correct when the playback is stopped. Need to look into this.
2019-08-07 18:22:39 +05:30
2aa0cbfd8d Cloth: fix memory leak while removing vertex
ClothSizing was not being freed when the vertex was removed, now it is.
2019-08-06 18:19:57 +05:30
4edf29ba38 Cloth: fix bug while removing vertex from cvm 2019-08-06 17:48:31 +05:30
dffa1972af Cloth: try storing localized mesh 2019-08-06 17:00:16 +05:30
725b088979 Cloth: switch cloth flag to be part of clmd directly
This is important so that the flag is not reset every frame rather the information is actually stored.
2019-08-05 23:51:08 +05:30
a6284e4774 Cloth: Added flagging if previous frame was read from cache
It might be necessary to move this part to clmd itself instead of the clothObject.
2019-08-05 15:43:29 +05:30
11195356ba Cloth: Added comments for what needs to be added for the caching 2019-08-04 17:01:49 +05:30
4b3539ec60 Cloth: initial steps towards dynamic caching 2019-08-02 18:31:52 +05:30
0adfa2d970 Cloth: fix aspect ratio calculation
This does bring out the bugs in collapse edges, need to figure out where and how to fix them.
2019-08-01 23:42:45 +05:30
aad285e6d6 Cloth: add back support for preserve verts and label edges
This is required for keeping the structure of the original mesh.
2019-08-01 20:57:14 +05:30
07e365dbaa Cloth: optimization: uv offset calculated only every frame 2019-08-01 19:47:46 +05:30
80cf4f4496 Cloth: better preverse vertex labeling and optimization: new way to update active faces
Massive speed up, because it no longer goes through the entire mesh every single time flip edges is called while updating the faces. Same optimization can be applied to updating active faces in collapse edges.
2019-08-01 18:47:38 +05:30
84421b3973 Cloth: changes in matrices
Some matrices were transposed than what they should be leading to logical errors. There still might be more, but a lot of it has been fixed.
2019-08-01 15:42:37 +05:30
54cd8de4da Cloth: fix in eigen decomposition, b now refers to correct element of mat 2019-08-01 14:01:40 +05:30
7e26b28e2b Cloth: added refine obstacle metric parameter 2019-08-01 13:06:08 +05:30
51c57993d9 Cloth: more debugging statements for face sizing 2019-08-01 02:19:44 +05:30
0916ed8dbe Cloth: fixed eigen decomposition floating point errors
This should generally work but needs further testing. Currently, the plan to check for floating point errors in compression metric.
2019-08-01 00:11:11 +05:30
58a80eb44e Cloth: multiply object matrix with bmesh vertices 2019-07-31 21:28:09 +05:30
15ba172e16 Cloth: preserve count, labeled edges and improved debug statements 2019-07-31 20:13:55 +05:30
c6f4dd4b0a Cloth: find nearest planes only every frame for much faster excecution 2019-07-31 13:55:48 +05:30
1d4a3ecfb2 Cloth: fix bug in eigen decomposition 2019-07-31 13:10:29 +05:30
fd08bbb95d Cloth: fix bug in invert_m2_m2() 2019-07-31 01:18:31 +05:30
5c9c25a99f Cloth: more face sizing debugging statements 2019-07-30 23:59:10 +05:30
4866294a43 Cloth: optimize obstacle metric by returning if planes is empty 2019-07-30 17:36:56 +05:30
316e77be93 Cloth: fix issue in compute_face_sizing, epsilon for invert_m2, face_sizing debug statements
Problem was that the det(facedm) was 0.0f or at least close to 0.0f which means inverse would lead to division by 0.0f error which resulted in -nan.
2019-07-30 16:44:43 +05:30
e24fca7f1d Cloth: initial steps towards edge label support 2019-07-30 01:02:14 +05:30
5035e4cb34 Cloth: revert back to using bm_prev
This is important to ensure correct collisions and other stuff, maybe there is a more effictient way without bm_prev, need to check later.
2019-07-30 00:33:51 +05:30
b32f857715 Cloth: prevent unnecessary copy of vertices 2019-07-29 20:36:46 +05:30
46aeecb51d Cloth: intial steps towards preserving original mesh data 2019-07-26 23:46:21 +05:30
380382a7c7 Cloth: different seam or boundary detection 2019-07-26 13:16:48 +05:30
f34e958553 Cloth: fix some bugs in a hacky way, must see again later 2019-07-26 12:34:52 +05:30
28e19184f9 Cloth: switch to cpp style while finding bad_edges 2019-07-26 12:26:37 +05:30
e23ce1f407 Cloth: remove unnecessary code 2019-07-26 10:48:00 +05:30
ea499dbba2 Cloth: fix bug while reindexing vertices
Ensure it uses the ClothVertMap size while allocating memory for cloth->verts.
2019-07-26 10:32:08 +05:30
85c125b470 Cloth: stop using bm_prev 2019-07-26 02:29:24 +05:30
c6e48575d6 Cloth: nearly completed transition to using ClothVertMap 2019-07-26 02:07:04 +05:30
dc45061510 Cloth: initial steps towards creating a mapping between BMVert* and ClothVertex for improving efficiency 2019-07-26 00:33:49 +05:30
849ec1350e Cloth: better handling of sizing 2019-07-25 19:06:55 +05:30
e7a6a80552 Cloth: better flip edges implementation 2019-07-25 17:16:59 +05:30
77d3d8b778 Cloth: fix updating active faces after fixing mesh in collapse edges 2019-07-25 14:03:43 +05:30
2d9989e18b Cloth: better handling of split_edges() 2019-07-25 13:48:15 +05:30
8def5a98db Cloth: better edge_size() when edge is given 2019-07-25 13:25:20 +05:30
7527a0b434 Cloth: fixed bug in cloth_remeshing_edge_face_pair() 2019-07-25 12:52:47 +05:30
97ef5d6389 Cloth: stop using uv_of_vert() to increase uv finding accuracy 2019-07-25 12:14:57 +05:30
cd173b442b Cloth: edge_opposite_vert() now returns the vertex uv if needed 2019-07-25 10:58:08 +05:30
814861cec1 Cloth: edge_vert() now returns the vertex uv if needed 2019-07-25 10:44:08 +05:30
4ddf80cf04 Cloth: switch from BM_edge_face_pair() to cloth_remeshing_edge_face_pair() 2019-07-24 13:21:26 +05:30
0210741877 Cloth: better seam or boundary test 2019-07-24 13:16:10 +05:30
199bc50925 Cloth: collapse correct vertex 2019-07-24 00:08:16 +05:30
65b8e525d8 Cloth: improved flip checking
No longer relies on edge_size_with_vert() which means no longer need to figure out why it returns 100.0f.
2019-07-23 18:56:39 +05:30
7797336f25 Cloth: switch to different method for collapse edges
This method is significantly different and does not depend on edge_size_with_vert() which means that there is no error with that size becoming 100.0f.
Now need to change flip edges to use the new edge metric method.
2019-07-23 17:51:35 +05:30
23cbf600b2 Cloth: better edge_size calculation 2019-07-23 12:38:24 +05:30
412bce877e Cloth: collapse edges debugging statements 2019-07-23 11:46:10 +05:30
832201400f Cloth: fix bug in collapse edges
When the face is not collapsed, it needs to be removed from the active faces. To prevent a crash, doing a double i-- helps it only get faces which are within the size() and not capacity().
2019-07-22 23:53:27 +05:30
b6911a66c6 Cloth: improved updating active faces 2019-07-22 19:52:52 +05:30
c4990aa993 Cloth: fix memory leak while finding nearest plane 2019-07-21 16:03:56 +05:30
4a4214e4a1 Cloth: split edges now flips edges for newly created faces 2019-07-21 15:54:21 +05:30
5be534cd40 Cloth: obstacle metric implemented 2019-07-21 15:04:00 +05:30
0232ee6bc6 Cloth: added derivative for single value
Important for obstacle metric calculation.
2019-07-19 21:18:06 +05:30
0b546f15d6 Cloth: fix derivative function
The matrix was being transposed instead of inversing.
2019-07-19 20:40:07 +05:30
82ef6423eb Cloth: initial steps for obstacle metric planes calculation 2019-07-19 20:16:53 +05:30
76a122f496 Cloth: initial steps for obstacle metric 2019-07-19 14:45:50 +05:30
f5e098dd11 Cloth: added derivative and compression metric support 2019-07-18 19:43:54 +05:30
f38f73d997 Cloth: added curvature metric support 2019-07-18 17:41:58 +05:30
57df2985e3 Cloth: added eigen decomposition support for 2x2 matrix 2019-07-18 16:33:02 +05:30
224821f4bd Cloth: initial steps towards computing face sizing 2019-07-18 14:49:04 +05:30
b39b5d4e37 Cloth: initial steps towards dynamic remeshing 2019-07-18 12:42:21 +05:30
997182c5f7 Cloth: support individual vertex sizing
This is important to proceed forward with dynamic remeshing.
2019-07-17 22:14:44 +05:30
0231bacb31 Cloth: change sizing to be a mapping between BMVert and ClothSizing
This is done to allow dynamic remeshing to work properly. It needs individual vertex sizing.
2019-07-17 21:35:04 +05:30
f2bebfc27d Cloth: fix bug in sewing
v5v1 may not always exist (eg. cube with loose edges when triangulated can have different triangulation, may not be perfectly mirrored). This is now taken into account.
2019-07-17 15:52:33 +05:30
15f2aab82a Cloth: fix compilation error
"count" was a global variable which caused an error while compiling on Windows with Ninja, switched to using local variable.
2019-07-17 00:48:25 +05:30
a31eb9d550 Cloth: close to finishing implementation for sewing 2019-07-17 00:25:16 +05:30
69969bf170 Cloth: initial steps for adaptive sewing 2019-07-16 00:13:40 +05:30
3a5c9a0e6c Cloth: flags support for new vertices 2019-07-14 22:59:40 +05:30
c43df425ba Cloth: boundary test for collapse edges 2019-07-14 22:56:20 +05:30
9069233250 Cloth: fix rare bug by updating normals before triangulation
This was a rare bug when face normals doesn't match the calculated face normal of the BMesh triangulate function. Simple fix by updating the normals before the triangulation.
2019-07-12 12:33:09 +05:30
c80184bdea Cloth: update_active_faces ensures no duplication of faces 2019-07-12 12:24:54 +05:30
6084d2e1b8 Cloth: convert bad_edges in split edges to vector<> 2019-07-12 12:02:00 +05:30
50f1f85272 Cloth: better implementation for updating active_faces 2019-07-12 11:05:32 +05:30
65b4c99e7d Cloth: initial implementation of flip edges 2019-07-10 19:02:53 +05:30
1543aed088 Cloth: fix rare infinite loop in split edges and some other issues 2019-07-10 16:44:23 +05:30
7103009a45 Cloth: implemented independent edges 2019-07-10 16:33:36 +05:30
acd989adb7 Cloth: improve edge flip condition 2019-07-10 16:26:43 +05:30
fa801b2f0c Cloth: find edges to flip is implemented 2019-07-10 16:05:33 +05:30
7806b1ed81 Cloth: remove uv islands from bmesh 2019-07-10 12:27:13 +05:30
ca6e4b6be8 Cloth: update default aspect ratio for better topology 2019-07-09 20:53:48 +05:30
320013cf29 Cloth: fix collapse edge, seam issue
The edges on the seam should also be allowed to collapse.
2019-07-09 20:50:50 +05:30
b94c7562cd Merge branch 'master' into soc-2019-adaptive-cloth 2019-07-09 19:50:27 +05:30
5192228e71 Cloth: aspect ratio parameter implemented
Now, while collapsing an edge, the aspect ratio is determined by the user, this ensures better quality of the triangles.
2019-07-09 16:32:41 +05:30
a5243b6e67 Cloth: remove uv_from_face 2019-07-09 12:07:25 +05:30
01012fd2f0 Cloth: fix try_edge_collapse issue 2019-07-09 11:25:12 +05:30
328988960a Cloth: silence print statements 2019-07-09 00:47:17 +05:30
37f1a6f398 Cloth: fix seam detection which solved collapse edges bugs to large extent
This commit ensures collapse edges works mostly correct. Now to move on to solving issues related to boundary detection, and then flip edges.
2019-07-09 00:35:58 +05:30
cafb5b81ee Cloth: vertex on seam test during collapse edges
Now it ensures that vertices that are on the seam are not killed while collapse the edge.
Leads to new problem, possibly related to reindex vertices.
2019-07-08 20:04:34 +05:30
5689627957 Cloth: updating active_faces and fixed bug for collapse edges
Now collapse edges works but incorrectly most of the time.
2019-07-07 22:38:41 +05:30
7dd1ad6790 Cloth: set bmesh vert->co to cloth verts[i].x
This is possible to do now since the cloth is reindexed, important when the length of the edges changes after the initial position of the cloth
2019-07-04 19:05:25 +05:30
c3560029a3 Cloth: now reindexing the clothObject->verts to match bmesh 2019-07-03 15:23:03 +05:30
7730efedbc Cloth: collapse edges now deletes vertices from clothObject
This is crucial step, now need to reindex the vertices to properly match the bmesh verts
2019-07-03 14:50:49 +05:30
d5c41954a4 Cloth: fix collapse edges working on vertex with upto 2 edges 2019-07-02 18:07:35 +05:30
8b0ef43de9 Cloth: collapse edges is now sort of working
Need to find a way to collapse a vertex with more than 2 edges connected to it.
Also need to remove the vertex from the ClothObject that was removed from BMesh
2019-07-02 17:23:05 +05:30
d7c7e62636 Cloth: added support for edge size with vert
Important for collapse edges, it determines the edge size when the edge is collapsed (does not actually collapse edge)
2019-07-01 18:35:48 +05:30
3fd16180d7 Cloth: switch active_faces from LinkNodePair to vector<> 2019-06-28 18:25:20 +05:30
a657c33770 Cloth: convert ClothSizing from LinkNodePair to vector<> 2019-06-28 17:40:33 +05:30
f112ca46a9 Cloth: ported remeshing code to cpp
This has been done to simplify the code (especially with the use of vector<> over BLI_array and BLI_linklist). This will allow for faster iteration of the code as well.
2019-06-27 16:43:58 +05:30
79f714db6e Cloth: Initial steps for flip edges
Basic foundation for the general flow of the flip edges has been set. This is extremely important for both split edges and collapse edges.
2019-06-27 13:23:22 +05:30
c8d8f1b793 Cloth: remove redundant code 2019-06-27 12:50:16 +05:30
428ff2217a Cloth: further additions to collapse edges 2019-06-27 12:47:29 +05:30
f74cc4040b Cloth: initial steps towards collapse edges 2019-06-25 17:56:56 +05:30
2befa73279 Cloth: fix object transformations not used during remeshing
Needed to make sure each of the vertices is multiplied by the object matrix so that vertices can be found properly.
2019-06-24 19:48:10 +05:30
436bbb05ce Cloth: use better system for checking equality
Due to floating point precision errors, equality of floats are not always precise, this means we need to use some epsilon value which acts as the range for the allowable errors.
2019-06-21 17:59:25 +05:30
a8e5ed2331 Cloth: fix memory leak
Memory leak was caused due to improper freeing of cloth parameters that need to be reset when the number of vertices in the cloth change
2019-06-20 12:49:40 +05:30
5b5a870685 Cloth: fix cloth constantly being reset
Did this by adding a flag to enable or disable adaptive cloth simualtion. Need to add this to the UI at some point.
2019-06-20 12:48:03 +05:30
d5e0229416 Cloth: adding vertices into Cloth is faster now
Instead of increasing the size of cloth->verts by one each time, it is much faster and better to do so before itself, number of vertices that will be added is already known.
2019-06-20 11:36:44 +05:30
2468f54190 Cloth: fix some errors 2019-06-20 11:22:44 +05:30
34454a0aab Cloth: fix cloth vertices not found
Made the mistake of not using copies of the ClothVertex(s) while finding the mean, even the old vertex values were changed, this is now fixed.
2019-06-19 11:36:40 +05:30
1435385d25 Cloth: hacky way of adding newly created vertices
This has been done just for testing purposes, to see if new vertices can be added one by one. It works, now to resolve all the crashes.
Newly added vertices seem to remove the old vertices, so next splitting of edges leads to crash.
Newly added vert and corresponding edges, seem to have rest lengths of 0 leading to the entire cloth collapsing.
2019-06-19 11:15:53 +05:30
23f0f6fdf5 Cloth: don't use current method of adding verts
The current method will not work after collapse edges is implemented, it might cause lose of information thus simulation would not be accurate.
Need to convert ClothVertex to be an array instead, and work from there.
2019-06-17 17:01:20 +05:30
3487d13a7e Cloth: fix edge size error
If there are sewing edges (loose edges), those edges would not have loops, finding the UVs was dependent on the loops, now there is check to see if there is a loop.
TODO: when splitting edges that are connected to sewing edges, need to find a way to add a new sewing edge
2019-06-15 01:33:03 +05:30
ad1af6e243 Cloth: fix compile errors from recent commits 2019-06-15 01:32:03 +05:30
90a52c22a2 Cloth: more work done to update cloth after remesh
Getting closer and closer to updating the cloth mesh
Better method to get values of the new ClothVertex
Freeing previous cloth and assigning the clothObject to the new cloth
Some obstacles to tackle include: finding ClothVertex from MVert in an efficient manner; recreating many parts of the Cloth (bvhtree, tri, springs, etc)
2019-06-14 23:56:38 +05:30
0cb99641e1 Cloth: start implementation of updating cloth with new vertices
Idea is to flag all the newly created vertices. After all of the remeshing, create a new Cloth and add all the flagged vertices as well, switch out old Cloth for new Cloth. This is done because it seems harder to update the Cloth every time a new vertex is formed, would be easier to flag those vertices in BMesh and update the Cloth after the fact.
Currently added support to find the new ClothVertex's values.
Some design via comments added.
2019-06-14 20:53:15 +05:30
3f1ee807b6 Cloth: accurately find UVs for the edges
Earlier, the mesh would keep splitting at the seams of the UV islands because the distance would be so large. This is now fixed, it correctly finds the UVs of the corresponding edge that match the world space positions as well.
2019-06-14 00:08:14 +05:30
d882e3abd9 Cloth: Improved split edges significantly
Now it sorts the bad edges based on the size and then splits the edges. This ensures proper size and aspect ratio of the triangles.
2019-06-13 13:14:09 +05:30
5eeb22cb40 Cloth: support for UVs during obj export 2019-06-13 01:50:08 +05:30
f7d2e5c0ca Cloth: obj export support
Done for testing purposes, export out the meshes as obj and render the obj sequence separately
Current limitation: only upto 6 verts per face supported, easy to add more but mesh should stay triangulated for the most part
2019-06-12 22:48:19 +05:30
a5e9b66be2 Cloth: split face to triangles test
It works for meshes that have convex uv layouts, otherwise goes into an infinite loop
2019-06-12 16:43:25 +05:30
18e0d06cfa Cloth: Basic UI Implemented
This is not the final UI, only a rough UI for current usage, need to add option for whether or not remeshing should be enabled.
2019-06-11 16:32:30 +05:30
e2cd13e8a7 Cloth: custom split edges function
Now no need to call triangulate function after splitting edges, custom split edges function triangulates the face(s) that contain the edges that has been split
2019-06-11 15:08:24 +05:30
d40a988078 Cloth: split edges implemented partially
Currently splitting is done by BM_edge_split() but this is not ideal because we are working with triangulated meshes, so we would prefer the split edge function to split and triangulate that nearby area rather than the current approach of splitting first and then triangulating whole mesh after all the BM_edge_split() have been called.
TODO: need to figure out why split edges doesn't work for meshes with UVs that have angles other than 90 degrees.
2019-06-07 22:36:59 +05:30
55c0521210 Cloth: edge size and find bad edges implemented 2019-06-06 14:41:03 +05:30
88a57a6ac5 Cloth: remeshing parameters added 2019-06-06 12:48:33 +05:30
c032a9face Merge branch 'master' into soc-2019-adaptive-cloth 2019-06-05 15:32:42 +05:30
7c854763fe Cloth: fix memory leak 2019-06-05 15:30:08 +05:30
adccee62d3 Cloth: Store previous mesh for remeshing step
Final puzzle to connect the remeshing step with the modifier
Currently a hack, but seems like the best possible method for now, will need to interfere with code that calls the modifier stack otherwise. This method uses more memory.
Now can finally proceed with the actual implementation of the paper
2019-06-04 16:07:41 +05:30
93c0c0c4e0 Cloth: Initial step towards remeshing
Currently, the mesh is triangulated. This is a necessary step in the remeshing pipeline and it also serves as a means of testing the functionality of the recent change wherein the cloth modifier has been changed to an applyModifier() based modifier.

Mesh generated by cloth_remeshing_step() needs to be sent to clothModifier_do for the changes to reflect in the viewport.
2019-06-03 23:50:19 +05:30
207c740a85 Converted clothModifier_do() to return Mesh
This has been done for the simulator to work with changing vertex count.
TODO: particle_system.c has hair simulation which uses clothModifier_do, need to convert the hair sim to work with new clothModifier_do()
2019-06-02 12:53:24 +05:30
7204fb3af9 Merge branch 'master' into soc-2019-adaptive-cloth 2019-05-31 14:44:11 +05:30
a321cd7226 Merge branch 'master' into soc-2019-adaptive-cloth 2019-05-31 14:28:15 +05:30
af9eedc626 Initial steps to let modifier have changing vertices 2019-05-31 14:06:13 +05:30
b2b6d2c764 Removed Cloth Cache System
This has been done to minimize the possible areas of bugs when adding the remeshing steps, current point cache system may not be compatible.

Python file for the UI has cache related lines commented.
C files has a macro in BKE_cloth.h which can be set to 1 to enable caching again.
2019-05-28 00:06:07 +05:30
15 changed files with 3733 additions and 78 deletions

View File

@@ -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,
)

View File

@@ -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

View 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

View File

@@ -86,6 +86,8 @@ struct Scene;
struct SmokeModifierData;
struct SoftBody;
struct ViewLayer;
struct Mesh;
struct Depsgraph;
struct OpenVDBReader;
struct OpenVDBWriter;

View File

@@ -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

View File

@@ -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, &timescale);
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;

File diff suppressed because it is too large Load Diff

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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]);

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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,