How can I apply the Force Fields (Wind) extension to multiple rigid bodies using the Python API? I am using Isaac 2022.2.1 for now.
Hi matters,
Here is some sample Python script that I copied from the tests.py file in the ForceFields PhysX tests.
By default, this force field will apply forces to ALL rigid bodies in the scene.
Also, force fields will not currently be applied to links in an articulation. This will be fixed in a future release.
Please let me know if you have any questions about the following script.
Good Luck,
Rick
# Create the force field prim
xformPrim = UsdGeom.Xform.Define(stage, primPathName)
xformPrim.AddTranslateOp().Set(Gf.Vec3f(0.0, 500.0, 0.0))
prim = xformPrim.GetPrim()
# Add the wind force fields to the prim
windApi = ForceFieldSchema.PhysxForceFieldWindAPI.Apply(prim, "wind")
windApi.CreateDragAttr(1000.0)
windApi.CreateAverageSpeedAttr(500.0)
windApi.CreateSpeedVariationAttr(2.0)
windApi.CreateSpeedVariationFrequencyAttr(3.0)
windApi.CreateAverageDirectionAttr(Gf.Vec3f(0.0, 0.0, 1.0))
windApi.CreateDirectionVariationAttr(Gf.Vec3f(0.707, 0.707, 0.0))
windApi.CreateDirectionVariationFrequencyAttr(Gf.Vec3f(2.0, 2.0, 2.0))
forceFieldApi = ForceFieldSchema.PhysxForceFieldAPI(windApi, "wind")
forceFieldApi.CreateEnabledAttr(True)
forceFieldApi.CreatePositionAttr(Gf.Vec3f(0.0, 0.0, 0.0))
forceFieldApi.CreateRangeAttr(Gf.Vec2f(-1.0, -1.0))
forceFieldApi.CreateSurfaceSampleDensityAttr(surfaceSampleDensity)
Thank you!
So using USD schema directly was the way.
I thought it that I would have to import the extension (how? I donāt know) and then apply it.
One last question, if I need to apply different wind conditions, is there an optimized way to do it, or do I need to set the attribute every time? Also, just to save time, do you know how can I apply a force field to some and another field to other prims?
Iām sorry that I didnāt mention it, but you also have to enable the Force Fields extension if it isnāt enabled. Search for āForceā in the Window > Extensions window and then click on the AutoLoad switch to load it every time.
Tuning the wind takes some experimentation. Itās broken into two parts. A steady state wind that blows at a set velocity from a set direction. The second part is turbulence which has a set frequency and set amplitude. Try to tune one thing at a time and then combine them. That might be easiest.
Yes, there is a way to specify which prims to apply forces to for each Force Field. Select a Force Field and look in the Property tab. There is a setting called Force Field Bodies where you can specify which prims to Include and which prims to Exclude. By default, there is one entry on the Include list, ā/Worldā which includes ALL rigid bodies because the Expansion Rule is expandPrims which includes all descendents. You can delete ā/Worldā by clicking on the red āXā. Then click Add Targetā¦ next to Includes and select the prims you want to apply forces to.
Hope That Helps,
Rick
Thank you for a complete answer and insights Rick!
That will help me a lot, so much to do, but no time to dive in everything in detail by myself.
That will make my development quicker, I appreciate your help!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.