I wanna make a spring to joint objects

Hello.


I wanna use “apply_force_at_pos” or “apply_body_force” but I can’t.
Both lines 29 and 30 fail to execute.
I would like to implement it myself without using the joints provided by Omnivese.
I am new to Python as well as Omniverse.
Please tell me what I am doing wrong.

You want to apply force through omni physics interface, like this:

import omni.physx

        position = Gf.Vec3d(0.0, 0.0, 0.0)
        force = carb.Float3(1000.0, 1000.0, 1000.0)
        get_physx_interface().apply_force_at_pos("/xform", force, position)

Note that the apply body force function does not exist on this interface, only apply_force_at_pos

Thank you! I followed your advice and was able to implement the spring.
But now I can only apply the force at the moment I press the Run button. How can I make it run automatically every frame?
Also, I would like to know if there is a function to apply torque.

You would have to register to an update in your extension, so use a code like this:

        def _on_update(self, e):
              pass

        self._update_sub = omni.kit.app.get_app().get_update_event_stream().create_subscription_to_pop(self._on_update, name="my update")

Torque is unfortunately not yet exposed, we are working on exposing this through new PhysxForceAPI, this should available in next release.

I could run every frame!
What I want to do next is to place this spring function on a stage like Omnivese’s Joint (Create>Physics>Joint) and select two objects on the GUI to use the spring.
If this is difficult to explain, please provide documentation to which I should refer.

You can create your own custom widget in the Property window, but this is not well documented at the moment, same goes for adding items to the Create menu. I’ll try to give you a list of code examples, but if you are new to Python this might be a bit rough :)

You would need to create your own extension for that (Window → Extensions, green plus on the top left is a new extension template wizard) that will register and deregister the widget and the menu item on startup/shutdown. That widget would need to show two relationship subwidgets which will enable you to set the rel targets through the GUI.

As an example for the implementation of a custom property widget you can have a look at custom widgets injected by the physics vehicle extension - the easiest way to find the source would be to open Window → Extensions, search for omni.physx.vehicles and there’s a folder icon button on the right side that will open the folder with the extension’s sources. There you will find omni\physxvehicle\scripts\properties\propertyWidgetManager.py and start from there. For some more complex property widget code see the sources of the omni.kit.property.physx.

As for the menu, an example can be how the main physxui extension registers its menu items → search for “physx ui” in the extensions window, open its folder and have a look at omni\physxui\scripts\menu.py, the _refresh_create_menu registers those menu items.

You would probably also need to read on how omni.ui works to better understand how the UI is written. The best way is to use the omni.ui docs app, that’s runnable from the main menu Help → Omni UI Docs.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.