Page MenuHome

Sculpt: Cloth Brush/Filter Collisions
ClosedPublic

Authored by Pablo Dobarro (pablodp606) on Jun 13 2020, 6:46 PM.
Tags
None
Tokens
"Like" token, awarded by IPv6."100" token, awarded by rlsl0422."Love" token, awarded by lopoIsaac."Mountain of Wealth" token, awarded by Brandon777."Love" token, awarded by kenziemac130."Burninate" token, awarded by reanimate."Like" token, awarded by Quargzon."Dat Boi" token, awarded by shader."Burninate" token, awarded by ruthwikrao."Love" token, awarded by andruxa696."Love" token, awarded by Alrob."Love" token, awarded by RodDavis."Burninate" token, awarded by DiogoX2."Love" token, awarded by Dardranight."100" token, awarded by Frozen_Death_Knight."Love" token, awarded by kouza."Burninate" token, awarded by brilliant_ape."Burninate" token, awarded by ZohaibAli."Burninate" token, awarded by ostapblender.

Details

Summary

This implements collisions in the solver of the cloth brush/filter. It
uses the scene colliders as a regular physics simulation.

There are still some parameters (friction, distance to the surface...)
that can be exposed as properties in later patches.

To make it work it needs an object with a collider and a softbody
enabled. The softbody is needed because otherwise collisions relations
are not created and the solver can't get the colliders. I'm not sure if
there is currently a way to request the collisions relations from a
brush/tool.

Thanks to @Sebastian Parborg (zeddb) for helping me with the implementation.

Diff Detail

Repository
rB Blender

Event Timeline

Pablo Dobarro (pablodp606) requested review of this revision.Jun 13 2020, 6:46 PM
Pablo Dobarro (pablodp606) created this revision.

From reading the code seems ok. But maybe @Sebastian Parborg (zeddb) wants to give a pass a swell.

This revision is now accepted and ready to land.Jun 15 2020, 9:23 AM

@Sergey Sharybin (sergey) The thing that is missing here is that we have to tag the depsgraph someway that the cloth brush is going to use collisions.

When using modifiers, we can use DEG_add_collision_relations. But neither Pablo or I am sure how we should add this relation when using a tool/brush.

Now we hack around this by adding an other modifier to the mesh that adds this relation (so that the collision data is available). But this is not a good solution.
So we are wondering if you know any good way to do this.

Well, ok. Couple of things here:

  • There is no such thing as dependency to/from a brush, as the brush is not covered by the dependency graph (while it is internally an ID, it is considered a tool/interface).
  • You wouldn't want to add/remove relations on stroke begin/end, as rebuilding relations is not entirely cheap and you don't want any lag.

Easiest is probably to consider that brush is handled from an evaluated dependency graph state, which would mean that all colliders are at their final evaluated state. And then for the brush/sculpted object you "by-pass" dependency graph by providing explicit list of colliders (ideally ,without using temporary modifications to the object).

  • Use custom function to build the collider cache

As it is now, it works, but ss->bmain is not updated before each operation, so it crashes quite often. Is there a way to iterate over all objects without using bmain? Otherwise I'll need to include a big refactor in a lot of files to pass bmain to BKE_sculpt_update_object_for_edit

  • Update bmain initialization in the SculptSession

@Sergey Sharybin (sergey) If the way of initializing the colliders using bmain is ok, then I think this should be ready for 2.91

If the way of initializing the colliders using bmain is ok

Not in this way, no. bmain is a pointer to the main database the depsgrah has been created from. In general case, depsgraph will be created for a subset of them. This means that ierating the bmain and requesting evaluated IDs for objects from the bmain is wrong, as there might not be such an object.

You can iterate over objects from the depsgraph using the DEG_depsgraph_query.h.

Sergey Sharybin (sergey) requested changes to this revision.Jul 28 2020, 10:04 AM

Wasn't expecting to have the patch accepted. Using ht query API should be more correct.

This revision now requires changes to proceed.Jul 28 2020, 10:04 AM
  • Review Update: Use depsgraph to get the collider list
source/blender/editors/sculpt_paint/sculpt_cloth.c
481

Why do you have this? The iterator is supposed to give evaluated objects?

Pablo Dobarro (pablodp606) marked an inline comment as done.
  • Review Update: remove object_eval

Seems from from my side.
Maybe @Sebastian Parborg (zeddb) want to have a second pass?

This revision is now accepted and ready to land.Jul 30 2020, 2:30 PM

LGTM as well!

I'm guessing the TODO about the brush thing I just a reminder that it could be exposed in the future?

This revision was automatically updated to reflect the committed changes.