Monday, 18 May 2015

Blending nCloth caches using Blendshapes


With many thanks to David Knight, nCloth guru, I present his method for blending two nCloth caches on a per vertex basis. You can have one half of a nCloth following one cache and the other half following a different cache.



1. Create two simulations for your cloth sim. Use a copy of the mesh for each sim. If the meshes do not match exactly (same number of vertices) then this method of blending will not work.

In my example I have one wide simulation and one which is narrow.


2. Cache your simulations.

3. Make another copy of the mesh, label it 'blendMesh'

4. Select the two nCloth meshes and finally shift-select blendMesh. Create a Blend Shape deformer (Create Deformers > Blend Shape)

5. In the Blend Shape attributes, set the weights for each input to 1.0



6. Assign weights per vertex. To do this open the Paint Blend Weights Tool (in the Edit Deformers menu). Do not manually paint blend weights because the sum of blend weights on each vertex must be equal to 1.0. Painting will not allow fine control. You can edit blend weights per vertex  manually in the Component Editor, but it is also possible to use an image set weights.

7. I have created some ramps in photoshop and saved them as TIF files. First I created the blengMap_H ramp, then I inverted the image (ctrl-I) which will subtract the value of each pixel from 1.0. That inverted image becomes blendMap_H_inverted. This will ensure that when the two ramps are added together the result will equal 1.0



I followed the same procedure to create the vertical ramps. The version of the ramp you need to use will depend on the orientation of your simulations. It's useful to have any combination of ramps saved in a library.

8. Apply the blendMap ramp to the Blend Shape deformer. Choose one of the Targets on the Blend Shape node and then under the Attribute Maps section, press Import and browse to where the blendMap ramps are stored.



Once the blendMap is assigned to the first target, chose the second target and assign the inverted blendMap to it.

That's it. You should now have a mesh which one end follows one cache and the other end follows a different cache.




Thursday, 7 May 2015

nCloth Matching Mesh Constraint

If you want a high resolution nCloth, it can be very slow to simulate. One method is to generate a low resolution nCloth to produce the large scale movement that you require and then simulate a high resolution nCloth which follows the low resolution mesh on the large scale but will display small scale details of its own.

Here is one way to set up this systerm.

  1. Create a low resolution nCloth and simulate the large-scale motion. I will call that low resolution nCloth mesh "cloth_L0"
  2. Cache cloth_L0
  3. Smooth cloth_L0 using Mesh > Smooth. Be careful of having too many divisions as very high subdivision levels will cause significant slowing down of the simulation. I usually choose 1 to start with and then repeat the process if I need more detail.
  4. Export the smoothed cloth_L0 as Alembic using Pipeline Cache > Alembic Cache > Export Selected to Alembic. If you want to preserve UVs, remember to tick the check box in the options box.
  5. Import the Alembic file bac in to your scene. Rename that imported mesh as "Alembic_Import_L1"
  6. Duplicate Alembic_Import_L1. Rename the duplicate "cloth_L1"
  7. Create an nCloth from cloth_L1
  8. Select cloth_L1 and shift-select Alembic_Import_L1, then create an Attract to Matching Mesh constraint using nConstraint > Attract to Matching Mesh 
  9. In the constraint, choose a Dropoff Distance that makes sense in your scene. You want cloth_L1 to be able to deviate just enough from Alembic_Import_L1 to add some good detail, but not so much that it no longer the follows the large scale motion of the original simulation.
  10. In the Strength Dropoff ramp, create a profile that has a value of 0 in the left and 1 on the right. An exponential curve will work well.
  11. Tune the forces acting on cloth_L1 to give a variation over the movement of cloth_L0.
You should now have a high resolution nCloth which follows a low resolution cloth but has extra details. This process can be applied any number of times, depending on the power of your workstation.


In my example above I have chosen to use a division level of 2 because the original mesh was so low resolution I knew I would require quite a lot more resolution to get more detail.

Wednesday, 6 May 2015

Velocity Field from Moving Geometry

If you want to create a velocity field from a moving mesh, here is a way to do it:




1. With your geometry selected, emit nParticles.



2. For the emitter, set:
  • Emitter Type to 'surface'
  • Increase the rate to, say, 50000 (depending on the size of your mesh)
  • Key the emission rate so that emission stops after a couple of frames.
  • Emission Speed and Normal Speed to 0
  • check the 'Need Parent UV' option


  4 Add the following per-particles attributes:
  • parentU
  • parentV
  • goalU
  • goalV



Make a creation expression on the nParticle object:

goalU=parentU;
goalV=parentV;



 6. Assign the geometry mesh as a goal for the nParticles. Set the Goal Smoothness to 0 and Goal Weight to 1.0




 Now you should have some particles sticking to the mesh.

7. Create a fluid container. You can use auto-resize if you want.

8. Select the fluid and the nParticles and create a fluid emitter.


 9. Set the emission to zero for Density, Heat and Fuel. Set the emission speed attributes to 'Add' and the Inherit Velocity to a value greater than zero.



That's it. You should now have the nParticles emitting velocity in the fluid. You can visualise the velocity field with the Velocity Draw option on the Fluid shape node.

You can use the velocities generated by this method to drive other simulations - nCloth, particles or fluids.