Home / Xpresso / Xpresso Anonymous / Softbody


Thinking Particles Softbodies

First of all lets make clear that this has nothing to do with the way Dynamics does softbodies. In Dynamics there are springs defined inbetween points that cause the mesh to behave like cloth while in TP there is no connection between the points, only between the points of one mesh, only between the points of the deformed and the default mesh.
We are working with a default geometry and a geometry that is deformed by particle actions. The soft effect is generated by applying a force to the particles that tries to move them to the default position defined by the default geometry. You can think of this as a ball at the bottom of a mould. If you kick the ball it will move but it will always return to the lowest part of the mould. A punching ball is working in much the same way.

We will start with a simple scene that contains two identical planes named Default and Softbody. Default is made invisible since we want to see the deformed mesh in the end.
Now we have to create one particle for each vertex (Info) of the Softbody.
To make controlling our Softbody easier we will create the Xpresso tag on it and make all the needed parameters available as properties of it (Info) available.

Before starting to create the setup you should think about what you want to achieve and what you want to control.

In our case we want the following controls (datatype in brackets):
  • Enable/Disable switch (Bool)
  • Particle group (Link)
  • Default Geometry (Link)
  • Time of particle creation (Time)
  • Lifetime of the particles (Time)
  • Flexibility of the Softbody (Float)

  • Remember to switch Port Names on (Info)
    Our setup will consist of three main parts
  • The emittion of the particles and initialisation of the needed information
  • Fixing the particles elasticaly to their default position
  • Connecting the Softbody mesh to the particles

  • To emitt particles we have a number of generator nodes available. In our case we will need PBorn which allows for the most flexibility.
    First of all we need the number of particles. This is dependent on the number of vertices (Info) of the geometry. The Point node can give us this information. Just connect it's object input port to the Default Geometry port of the main XGroup and the Point Count output to the Shot input port of PBorn. Why Shot? We want all the particles created on one single frame not over a period of time. For this we have to set the PBorn node to Shot mode.
    Another part is the start and Lifetime control. Lifetime can simply be connected to PBorn but the start time needs some detection. With a Compare node we can determine if the current animation time equals the set start time and enable PBorn accordingly. Since we also have a general Enable port we have to do a boolean function (AND) to make sure that Enable as well as the Compare node give their ok to start emission. scene / documented scene
    A major part is still missing and thats the assignement of the particle position. For this we need a second Point node and a PSetData node. The second Point node is neccesary because you can't use on node for two different thing sin one setup. The first point node is used only one time when the PBorn node needs to know how many particles will be emitted, while the second node is used as often as there are particles and points. Basicaly PBorn is an iterator (Info) node.
    Set the Point node to evaluate deformation, in case we have an animated mesh here, also make sure that it is set to Global Coordinates (Info) since a particles position is always a global position.
    PSetData will need a connection to the Birth port of PBorn to know with which particle it has to work. The point index is controlled by Birth Num which gives you the index of the currently active particle. This resembles very much the counter variable in a For Next loop. scene documented scene
    As you can see our setup is getting bigger and it's about time we do something about it. Please select the nodes that determine the Start time and convert them to a single XGroup by selecting Convert to XGroup from the context menu. Switch the view mode for this group to Standard and enable the port names. Renaming the group to something meaningfull ensures that we will know later on what it does.
    Switch the view mode for this group to Standard and enable the port names. Renaming the group to something meaningfull ensures that we will know later on what it does. scene
    It's about time we see if it works. Check the enable box from the Xpresso tag parameters and make sure the default geometry object is referenced in the according link field. Particle lifetime should be set to the length of your document and starttime should be 1 (Second Frame).
    Press play
    Hopefully you have been rewarded by a small white cross for every vertex of the default plane.

    Now that we have the particles in place what do we need more?
    First of all we need them to stay in place and as usual there is more then one way to do this.
    The first option would be to store the current position and use it as a reference, another would be to always use the positions of the Default objects vetrtices. We are going for the second option, since it will allow us to fix the softbody to a moving/deforming mesh.
    Since this part is completely seperate from the first one it makes sense to clean up our workspace a bit more to make room for more nodes. Simply select all your nodes and create a Xgroup from them. Again switch the view mode to Standard. scene

    At this point i noticed i forgot two things in the first setup. What to do? Rewrite all the stuff and make new screenshots and scenes? No! Why? It will happen to you too and pretty often that is, so this is a good way to have a look how to change things that are already finished.
    What is missing? It might not look very important but later on it would render our setup more or less useless. It's the particle group that does not get assigned. Particle groups are needed to be able to seperate particles from one another. Without them it would be very hard if not impossible to differentiate what particle should be used in which way.

    The second thing missing is a way to store the connection between particles and vertices, right now we have a simple bunch of particles but no way to tell where they belong.
    First of all draw a wire from the link port of the outer XGroup to the top left blue square of our newly created Xgroup and create a link port with it. Now switch the view mode of this Xgroup to Fullscreen. The new PGroup node gets connected to PBorn->Birth and the link port from the outside we just created.
    The second part is a bit more complex. We will need the Thinking Particles settings manager (available either in the Plugins menu or in the custom menu of the Xpresso editor). In the manager switch to the Channels (Info) tab and create an integer channel with the name Number.
    To set this number simply drag an additional wire from the Birth Num port of the PBorn node and drop it on the top left blue rectangle of the PSetData node. Our newly created channel is available as a port.
    After the correction is made switch the view back to Standard and we are set. scene
    Now for the elasticity of our Softbody. We will need the particles to follow the Default mesh in a flexible way. Our prime candidate for doing this is the PPositionFollow node. It will move a particle to a certain position, not in one step but slowly. It can be set to Constant Speed or Spring. We are using Spring since Constant Speed wouldn't look good in this case. The option Spring Speed sets the force with which the particle is pulled to the position. 100% means it will be there immediately giving us no elasticity at all.
    To adjust our Elasticity value to this range we are using a simple math node to substract the the Flexibility value from 1 thereby inverting the range.
    To get access to the particles we will need a PPass node. The Particle Group we need is determined by connecting the Particle Group link port of the outer Xpresso group to the matching input port of the PGroup node.
    We will need the Number of the particle which can be achieved with PGetData. This Number feeds in a point node to select the correct vertex of the default object (Make sure to connect the Point node to the Defaul link port and switch the node to use deformed meshes).
    The position we get from the point node for each particle is used to set the Follow Position.
    This way we ensure that every particle will follow the vertex it was assigned to in the first place.
    With the Math node set to Substract and a value of one in the first field we can adjust the flexibility range.
    Now a Flexibility value of 0 will result in a completely stiff Softbody while values between 0 and 1 make it flexible. scene
    If you move the Default Object while the animation is playing you can see how the particles follow it.

    Now for the last part, the assignement of the Softbody mesh to our particles
    This setup is similar to the last one in that we need a PPass node and PGetData. From PGetData we need the particle position as well as the Number. Theses parameters are then fed in a point node. The point nodes Object input port gets connected to a new Object node that we create by dragging the Softbody object in the Xpresso editor. Switching the reference of the object node to Start Position ensures that the setup will work even if we move the tag to a different object that we want to use as a softbody. scene

    Now this is cool, we have a real working Softbody, only one thing is still missing Action
    Whats left to do is to influence our Softbody in some way so we can realy see what it can do.
    One way to do this is by shooting at it with other particles. We will need an emitter and a way to make the particles collide.
    I think we had enough of setting up complex Xpressions and thats why we will use some of the presets that come with Tinking Particles to have some fun.
    In the Objects->Object Library menu you will find TP Basic Emitter and TP Particle Collision. Move the emitter to -300 on the z axis. We will need to use Particle Groups to seperate the Softbody Particles from the ones we are shooting at them. In the Thinking Particles Settings create two groups below the All group and rename them according to their function.
    Assign the groups to the presets. The projectile group is for the emitter and the collisson preset, while the Softbody group is for the Softbody setup and also for the collsion preset.scene
    You can spice the scene up by adding a wind preset with high strength and turbulence settings.
    In the last scene i made some adjustments to the emitter speed as well as the particle size. movie


    Back to Xpresso Anonymous