How to create collisions in a MASH network with nCloth instances?

How to create collisions in a MASH network with nCloth instances?

maja.divjakW2VMQ
Advocate Advocate
8,783 Views
37 Replies
Message 1 of 38

How to create collisions in a MASH network with nCloth instances?

maja.divjakW2VMQ
Advocate
Advocate

I’ve been trying to learn MASH and use it to create a lipid bilayer, which is the fatty layer surrounding all animal cells, to keep the cell contents in and all foreign bodies out. I’ve created three nCloth animated lipids, created a MASH network and then assigned them using the ID node. I then used replicator nodes to repeat the lipids numerous times and then another to create the inside layer, by rotating in Z 180 and offsetting the position in X and Y. This works really well and plays back really quickly, compared with my previous approaches. The problem I’m having is with collisions. I will need to be able to collide molecules with the inner layer of lipids and also have the lipids collide with molecules that actually reside within the membranes. I've attached a couple of images of the lipid bilayer, with animated nCloth lipid instances. You can see a lot of repetition and intersection because I only used three instances in this rough test.

 

What I’d like to do is have the lipids close to the grey cylinder (a receptor standin) collide with it and I’ve been tearing my hair out as to how to do this. I’ve tried adding a MASH dynamics node and then a spring constraint within that, but the dynamics node slows the system to virtually zero. I’ve tried to find a way of limiting the dynamics effect to a small area around the cylinder, but couldn’t work this out. I’m sure there is a really simple way to achieve this, but my inexperience is hindering me. If you could please advise how to limit where the dynamics node is felt or a way of achieving collisions without the dynamics node, that would be absolutely fantastic.

0 Likes
8,784 Views
37 Replies
Replies (37)
Message 2 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hello there,

Is this really not possible? I would be very surprised...Waiting with bated breath.

Thank you!

0 Likes
Message 3 of 38

t_chanma
Autodesk
Autodesk

Hey there,

 

So this is certainly possible, though my approach would be a little different from yours.  Just to preface though: simulation is slow and complex by its very nature, so don't expect to run a scene like this interactively at full speed.  What you're likely going to have to do is test it with fewer / lower detailed lipids until you have a sim that's working roughly the way you like.  Then you can increase the number and quality of them, cache the simulation, then either playblast or render the result into a movie file (which can then play back at full speed).  

 

It sounds like you've got the right idea, but the implementation is a little off.  Here's a couple of suggestions for how I'd do this:

 

  1. Cache your 3 animated lipids (I recommend using an Alembic Cache), then make the MASH network out of those animated caches.  This will strip out the nCloth calculations from them.  Yes, this will remove their ability to collide with each other, but as you discovered MASH doesn't support nCloth collisions this way anyway (we'll fix it using another method).
  2. Use MASH however you like to generate the instances / animate the movement of the lipids.  It sounds like you already got this part down pat.  🙂
  3. Cache the Repro Mesh (again, I recommend Alembic).  This will strip out all the MASH calculations and just leave you with an animated mesh representing ALL your lipids at once.
  4. Apply nCloth to that cache.  This way, you're dealing with a single nCloth simulation - not with a complex system of MASH on top of multiple nCloth simulations.
  5. Now for the tricky part.  Applying nCloth to the MASH cache will block your lipids from animating, because they're now being driven by the nucleus solver.  To get them moving again, we need to constrain them in order to "influence" them in the directions they were originally going.  To do that, import the MASH cache a second time, then select both versions of it and use nConstraint > Attract to matching mesh to constrain the nCloth lipids to the animated lipids.  You can then hide the animated MASH cache.
  6. Introduce any passive colliders (like your cylinder) and assign them as such.  If you play the scene now, the lipids should fold around any colliders as well as each other.  You can then adjust the cloth properties to control things like rigidity.

This method will be significantly lighter on your system, which should allow it to run much more smoothly.  Of course, individual performance will very based on your system specs and the number of lipids you decide to simulate.  Just remember, if you want to change either the individual lipid appearance or MASH distribution/animation, you'll need to re-cache the appropriate files.

 

I've attached a little example file I made (although I just used spheres for the lipids, but you get the idea).  Also note this isn't the only way to do this - it's likely possible (and probably even more efficient) to do it in Bifrost.  However, I figured this was an easier solution since you're already 70% of the way there.

 

 



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes
Message 4 of 38

maja.divjakW2VMQ
Advocate
Advocate

Wow, this looks amazing! I'll have a closer look at it and let you know how I go. Thanks so much for such a comprehensive, detailed reply, I really appreciate it. Will get back to you.

Thanks so much and best wishes,

Maja

0 Likes
Message 5 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hi Matt,

I've downloaded your files and imported the alembic cache. The spheres kind of collide with the cylinder, but some sort of pass through it. I'm working with Maya 2018. 

I've started following your instructions though, so I'll let you know how I go. So far, so good.

 

Thanks so much,

 

Maja

0 Likes
Message 6 of 38

t_chanma
Autodesk
Autodesk

Yeah, you may want to avoid having two objects directly collide into each other at their centers, because that'll make it difficult for them to deform around each other.  What you see in the example file is the constraint influence basically "brute forcing" the cloth through the collider.



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes
Message 7 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hi Matt,

I've followed your instructions, but found if I create a MASH node with mesh type, then try to build the membrane composed of many lipids (as I originally did with instancing) it gets really heavy and barely plays. Caching it as alembic is also incredibly slow. So I tried building the membrane again with an instancer network, which runs so much faster, BUT unfortunately can't be exported as alembic. I tried exporting as FBX, as suggested on the Autodesk site, but the original nCloth animation on the lipids is not preserved and you get a whole list of instancer objects, instead of a single mesh, which again can't be converted to nCloth without completely locking up the system. So, I tried building the membrane with an instancer network until I was happy, then converted it to a mesh network, the system again became pretty slow, cached as alembic, again really slow and then reimported the cache to a new scene, still running really slowly. Adding nCloth on top of this locks up everything. It seems like I'm caught between a rock and a hard place- the mesh geometry type is just way too slow and heavy and the instancing type can't be converted to alembic to give a single mesh. Just wondering if you have any suggestions please?

Thanks so much for all your wonderful help thus far,

Maja

0 Likes
Message 8 of 38

t_chanma
Autodesk
Autodesk

Judging by the sheer number of lipids you want to build, you might be better off animating a small subset of lipids, then instancing that small subset many times over.  To generate a system this big, you will need to cheat - you can't just do it "for real" and expect fast performance (this is true of even the biggest film productions).

 

After talking to a colleague about this internally though, we're also looking into a solution to this using Bifrost, which is significantly more efficient than combining nCloth and MASH.  The general premise is this:

  • Generate particles representing one lipid each and animate those particles (much like you were doing in MASH), then cache that out.
  • Generate a second set of particles representing the internal portion of a lipid.
  • Surround this second set of particles with an MPM cloth sphere representing the outer part of the lipid.
  • Instance one of these combined lipids at each of the first set of particles.
  • Use the motion of each particle to drive the internal part of each lipid, which will in turn drive the outer membrane as well once they collide.  

No guarantees this will work, but we're going to give it a shot (feel free to try it for yourself too).



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes
Message 9 of 38

t_chanma
Autodesk
Autodesk
Accepted solution

Setting aside Bifrost for a moment, here's an alternative nCloth/MASH solution I came up with today, which builds on this tutorial: https://www.youtube.com/watch?v=sluBJ8xA4wM&feature=youtu.be

 

The basic breakdown is as follows:

  1. Use MASH to generate internal lipid movement.
  2. Create an nCloth membrane for the reproMesh, then export the result as an Alembic Cache.  Repeat to create as many different kinds of membranes as you want (to break up monotony).
  3. Create a second MASH network using the animated alembic cache membrane as the input object.
  4. Enable MASH dynamics, and crank up Position Strength.

Of course, this is still a bit of a cheat - the membranes will collide with each other / external objects as hard bodies rather than soft bodies.  However, the performance is excellent (certainly better than trying to do the entire thing as nCloth), which will let you iterate the look very quickly and organically.  And for a visual demonstration it still looks fairly convincing.  With just the right settings most viewers probably won't even notice the hard body collisions.  



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes
Message 10 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hi Matt,

Apologies for the late reply. It's been a long weekend here and I've been working on other stuff. I'll try working with small numbers of instances and then work my way up from there. 

Thanks so much,

Maja

0 Likes
Message 11 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hi Matt,

I've tried your first method again and it definitely works with a much smaller membrane construction in MASH. I also tested it with a colliding sphere and a cylinder embedded in the membrane and the lipids do respond and collide, which is great. I couldn't attach playblasts to demonstrate as they wouldn't zip small enough. The only issues, as you say are then being able to instance this small patch multiple times and have the edges interact and the issue of repetition. I think you could get round the latter by using a lot more nCloth animated lipids to begin with. But as a proof of concept, it works!

0 Likes
Message 12 of 38

maja.divjakW2VMQ
Advocate
Advocate

Thank you Matt, I'll have to take a closer look at this alternate method after the weekend. I have attached a screen shot of your file. I'm not sure this is what I should be seeing?

 

Thanks so much,

 

Maja

0 Likes
Message 13 of 38

t_chanma
Autodesk
Autodesk

Hmm, no that's not right.  It looks like the MASH repromesh is missing for some reason.  Looking in the Outliner, it looks like there's double the number of alembic caches for some reason (the file should only have lipid1-3, not sure where 4, 5, and 6 came from.

 

I'd reload the file or double-check the MASH network.  See the attached for how it should look.



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes
Message 14 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hi Matt,

No, that's definitely not what I'm seeing. I'm using Maya 2018 and I've placed your scene file in the scene folder and the alembic files in the alembic cache folder and then I'm simply opening the file. As I'm not at all experienced with MASH, not sure what I'm doing wrong.

Thanks so much,

Maja

0 Likes
Message 15 of 38

t_chanma
Autodesk
Autodesk

In the Outliner on the left side, can you select each of the lipid(1-3) objects, then in the Attribute Editor on the right side click on the "lipid_membrane_V2__AlembicNode".  Check to make sure the Abc File is pointed to the right spot (it's possible the path is still pointing to somewhere on my machine, rather than yours).



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes
Message 16 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hi Matt,

I was able to map the lipids to the correct caches, but still no joy, in fact I'm getting an error message, which I've attached, which I think is the source of the problem. I've tried resetting Maya preferences, but this doesn't resolve the problem. It appears to be specific to your file, as other opening files doesn't give this message and the same error message appears when I open your file on another computer. Nor sure what the problem might be...

 

Thanks so much,

Maja

0 Likes
Message 17 of 38

t_chanma
Autodesk
Autodesk

Don't worry about that error message.  It comes from a plugin that won't have any effect on the scene (you can actually fix it using this https://forums.autodesk.com/t5/maya-animation-and-rigging/onmodelchange3dc-error/m-p/8410192/highlig..., but even if you leave it alone it's benign enough).

 

So I did just try importing the file I sent into an empty scene and ran into the exact same issue as you did (one of the MASH networks was missing).  However, if I open that same file, then it works.  Maybe try that?  If that doesn't work, you may need to recreate the MASH network by doing the following:

 

  1. Select lipids 1-3 and create a new MASH network.  Set Distribution to Grid and lay out roughly 100 lipids so that they aren't touching to start.
  2. Add a Signal node to generate some noise.  At frame 0, keyframe their positions at 0,0,0.  Then later (say, frame 120), keyframe the positions at higher values so that the lipids gradually move more noisily.
  3. Next, add a Curve node and drag in the NURBS curve to give the lipids a general direction of movement.  You don't want them to move too fast, so you can adjust the Animation Speed and Step accordingly.
  4. Finally, add a Dynamics node to allow them to collide.  Turn up the Position Strength (80+) so that the lipids follow the curve and don't just fall down.

Hopefully, that works for you.  Just note that my original lipid caches are only 400 frames long.  To do a longer animation, you'll need to use the "single_lipid" MASH network + nCloth (turn the solver back on) to simulate a longer animated lipid (preferably, multiple times at different settings to get different' looking lipids). 



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes
Message 18 of 38

maja.divjakW2VMQ
Advocate
Advocate

Hi Matt,

Unfortunately the file won't open correctly either by importing or directly opening it. Both MASH networks appear to be there, but the single lipid one has diagonal lines through it, suggesting as you say, that its no longer functioning (see attached image). I don't understand your instructions for recreating it as I'm not quite sure what this method is trying to achieve just yet. I think I need to go back to your original instructions and watch the Splanchnic tute to see what you've tried to do and try to recreate it from scratch. Hopefully then I'll understand what's going on! 

Thanks so much for your help, as always,

Maja

0 Likes
Message 19 of 38

maja.divjakW2VMQ
Advocate
Advocate
Accepted solution

Hi Matt,

Finally had a good amount of time to devote to this. I tried to follow your method as outlined, but made a few changes and I'm not really sure I've come up with what you had in mind. I didn't include the curve because I don't want my lipids flying around in a loop. So, this is what I did:

1. Using a set of 5 upper lipids and 5 lower lipids to make a bilayer, I used these 10 to make a linear MASH network, added an ID node and then a signal node to create movement on each lipid as a whole unit

2. I then created nCloth from the repromesh and switched off wind and gravity on the cloth, which then became completely static. So, I added a turbulence field to give soft, wavy deforming movement to each lipid

3. I then exported the repromesh as an alembic cache, which worked quite quickly, unlike before. If I tried to continue from there, unfortunately the file crashed and wouldn't reopen, so from then on I had to work with a new scene and importing the alembic caches

4. I repeated this process twice more, so that I had three alembic caches to work with 

5. I imported the three caches to a new scene, selected them and made a linear MASH network and added an ID node

6. I then added a dynamics node, turned off gravity on the bullet solver and set positional and rotational strength to 5.

With 30 quite complex lipid structures, this plays at about 6fps and has lovely colliding movement along with the nCloth. Unfortunately I would need a lot more than 30 lipids to make this viable, so I'm not sure what I've done is the right approach?

 

Thanks so much and best wishes,

 

Maja

0 Likes
Message 20 of 38

t_chanma
Autodesk
Autodesk
Accepted solution

That's more or less what I was suggesting (your alterations wouldn't affect performance too much).  One thing to consider is that you can now alembic cache your 30 lipid simulation, then do the whole thing again (MASH network that simulation, distribute it another 30 times, apply Dynamics, etc).

 

In general, you're trying to simulate a LOT of collisions - this is going to be computationally expensive, especially if you try to do it "for real".  It's usually better to cheat by recording smaller systems, then simulating those recordings to take some of the load off.  It also helps to have a lot of RAM and CPU available.  



Matt C

Senior Content Experience Designer

Maya Documentation | Maya Learning Channel |
0 Likes