Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Scripting rod forces
#3
Qriva0 Wrote:Hi, I have got several quesions about scripting rods.
Is there valid way to calculate rod tension? For example I need to know if rod is pressed against the wall and it's being compressed. I tried to compare compressed distances, but with chain constraint it does not work.

Hi!

Most constraint types have a "lambda" value associated to each of them. These are lagrange multipliers, outputted by the simulation, that can be converted to forces dividing by the timestep squared. These lambda values are stored in an array, in each constraint batch. In ObiRope.cs you have an example of this in the ApplyTear() method: it iterates trough all lagrange multipliers for distance constraints, then breaks those constraints whose force exceeds a threshold.

Bend/Twist and Stretch/Shear constraints used in rods also have lambda values, that you can use to calculate deformation. Chain constraints however don't, since they're not really physically based - more of a geometrical constraint.

Qriva0 Wrote:Is there a way to calculate pressure against softbody or get it from softbody directly?

You can calculate softbody deformation gradient/magnitude using the current linear transform matrix for each shape matching constraint. Using its Frobenius norm usually works well if you just want to measure amount of deformation. See the "DeformationGradient" softbody sample scene as well as the "DeformationToColors.cs" sample script.

Note however that pressure is force per area unit, mostly decoupled from deformation (pressure may or may not lead to deformation). That's a lot more complex to calculate accurately and would require processing individual contacts.

Qriva0 Wrote:Is it possible to make different parts of rod have different elasticity? There is rotational mass, but it's hard to balance and there can't be huge difference in mass (1:10). Sometimes even if difference is not huge, the rod becomes wiggly and can't stop.

Not currently. We want to expose bend/twist/shear compliances in the path editor, as a per-control point property just like mass and rotational mass. This should arrive in Obi 7.2.

Qriva0 Wrote:Is there way to damp rod without touching solver main parameter (damping)? I guess I could write script just for rod to reduce velocities every step, but it also affects other forces.


Not currently. You can do this yourself for each separate actor, the formula used for an individual particle is simply: velocity *= pow(saturate(1-damping), deltaTime).

Note that damping affects particle velocities after all constraints have been applied, at the end of each simulation step. If you are hoping for a per-constraint damping parameter, the situation is complicated: XPBD has built-in damping, but only works for compliant constraints. Infinitely stiff constraints (compliance = 0) apply the maximum positional correction possible, and this means the simulation will gain energy if the correction is too large.

(08-08-2025, 06:33 PM)Qriva0 Wrote: What is difference between changing particle velocity and externalForces?

Force and Velocity are not the same thing. Force results in a mass-dependent acceleration (F=ma), so the same force results in smaller acceleration (less change in velocity) when applied to a heavier object.

(08-08-2025, 06:33 PM)Qriva0 Wrote: Is it possible to change rod default (initial) shape during runtime?


Yes, by taking it out of the solver, modifying its blueprint and then bringing it back in. But this of course means re-loading the rod. What's your use case for this?


(08-08-2025, 06:33 PM)Qriva0 Wrote: There are various properties like startPositions, endPositions, restPositions, any many other, but some of them has no effect and others are not what would be expected.

"startPositions" and "endPositions" are particle positions at the start and end of the whole simulation step, respectively.
"prevPositions" and "positions" are particle positions at the start and end of the current substep, respectively.
"restPositions" are the positions at rest (used to determine whether particles self-intersect at rest, and deactivate self collisions for those that do). "renderablePositions" are the values actually rendered to the screen (which may be interpolated or extrapolated from start/end positions depending on your solver interpolation settings).

Usually, you'd work with positions and renderable positions. These are conceptually equivalent to rigidbody.positon and transform.position in Unity.

(08-08-2025, 06:33 PM)Qriva0 Wrote: I would expect particle delta to show something, but I think they are reset during simulation.


position/orientation deltas store the change in position/orientation applied during each constraint projection. These are reset to zero after each constraint type has been projected (so that the next constraint type has a clean slate), they aren't useful unless you're writing custom constraints.



(08-08-2025, 06:33 PM)Qriva0 Wrote: Is there way to "pin" my burst job to main job queue? I wish I could just add my job handle to be executed with all other stuff without need to complete job instantly.

This is not something that's exposed, but you could modify ObiSolver's source code to give yourself access to the simulation job handle. Note that the lifetime of the job is rather complex and varies depending on the synchronization method used (see "Bolting Obi onto Unity's timestepping": https://obi.virtualmethodstudio.com/manu...eloop.html). It's very easy to break things if you're not intimately familiar with how and when physics should be updated.

kind regards,
Reply


Messages In This Thread
Scripting rod forces - by Qriva0 - 08-08-2025, 06:33 PM
RE: Scripting rod forces - by chenji - Yesterday, 03:18 AM
RE: Scripting rod forces - by josemendez - Yesterday, 08:31 AM
RE: Scripting rod forces - by Qriva0 - Yesterday, 11:14 AM
RE: Scripting rod forces - by josemendez - Yesterday, 11:26 AM
RE: Scripting rod forces - by Qriva0 - Yesterday, 12:25 PM
RE: Scripting rod forces - by josemendez - Yesterday, 12:48 PM
RE: Scripting rod forces - by Qriva0 - 11 hours ago