Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to add particles to existing cloth object
#9
(10-10-2018, 02:47 AM)arrnav96 Wrote: Apologies, my last video did not show the mouse pointer. 

This is the updated video showing the exact problem.

Hi,

I've taken a closer look at your code. Currently it will set the particle position, but will not set its velocity or prevent the rest of the particles from acting upon it. So what you're getting is the cloth still pulling from the particle when you try to set its position, then drifting away due to non-zero velocity.

To get it working as you want, you need to:
- When the particle is picked, set its inverse mass to zero (that is equivalent to setting its mass to infinite, so that constraints cannot act upon it -->the rest of the cloth will not pull it back). Also set its velocity to zero (so that it does not drift off from whatever position we drag it to).
- When dragging the particle, set its position to the cursor position.
- When releasing the particle, set its inverse mass to whatever it was prior to being picked. This will allow it to be affected by the cloth constraints once again.

Code:
Code:
      float oldInvMass;
      void Picker_OnParticlePicked(object sender, NewPicker.ParticlePickEventArgs e)
      {
          oldInvMass = picker.Cloth.invMasses[e.particleIndex] * picker.Cloth.areaContribution[e.particleIndex];
          Oni.SetParticlePositions(picker.Cloth.Solver.OniSolver, new Vector4[] { e.worldPosition }, 1, e.particleIndex);
          Oni.SetParticleVelocities(picker.Cloth.Solver.OniSolver,new Vector4[] { Vector4.zero },1,e.particleIndex);
          Oni.SetParticleInverseMasses(picker.Cloth.Solver.OniSolver,new float[]{0},1,e.particleIndex);
      }

      void Picker_OnParticleDragged (object sender, NewPicker.ParticlePickEventArgs e)
      {
          Oni.SetParticlePositions(picker.Cloth.Solver.OniSolver, new Vector4[] { e.worldPosition }, 1, e.particleIndex);      
      }

      void Picker_OnParticleReleased (object sender, NewPicker.ParticlePickEventArgs e)
      {
          Oni.SetParticleInverseMasses(picker.Cloth.Solver.OniSolver,new float[]{oldInvMass},1,e.particleIndex);
      }

Note that in your code, the picker's OnParticleDragged won't be called as long as the user is dragging (which is exactly the opposite of what you want). You need to get it out of the else clause after Input.GetMouseButton(0).

Also, I've noted that depending on what type the slime is, you set the particle inverse mass to 0.5f or 0 when the user releases it. Setting it to 0.5f will have the effect of making the point released by the user heavier/lighter than the rest of the cloth, which is something you probably want to avoid. Setting it to 0 will disable constraint simulation for that particle (leaving it driven by inertia), which does not make much sense in this context.
Reply


Messages In This Thread
RE: How to add particles to existing cloth object - by josemendez - 10-10-2018, 12:12 PM