I would like to change the parameter of physics materials from python using kit.comands. However, the code does not work and there is no error output. The simulation is launched by KitHelper(). The code example is given below. It is should be noted that code works in python Editor.
stage = self.omni_kit.get_stage()
path = ‘/World/ZeroFrictionMaterial’
omni.kit.commands.execute(‘AddMaterialCommand’,
stage=stage,
path=path,
density=1000,
staticFriction=0.0,
dynamicFriction=0.0,
restitution=0.0)
bug_materials.mkv (6.6 MB)
I have recorded the short video in which you can see that script changes the property of material if this property was changed manually once, otherwise, the command does not work. Please give me the feedback on how to avoid that issue.
The alternative method to setting the property is using something like:
import omni
from pxr import Sdf, UsdPhysics, PhysxSchema
stage = omni.usd.get_context().get_stage()
prim = PhysxSchema.PhysxMaterialAPI(stage.GetPrimAtPath("/World/PhysicsMaterial"))
prim.CreateFrictionCombineModeAttr(PhysxSchema.Tokens.min)
Unfortunately I think there is a bug in the ui which will not update properly unless you manually change something. If you set the value using the above code it should be correct when queried however.
Will follow up with the omniverse team to see if this can be resolved.
In addition, I have tried to get the attribute value:
stage = omni.usd.get_context().get_stage()
prim = PhysxSchema.PhysxMaterialAPI(stage.GetPrimAtPath("/ZeroFrictionMaterial"))
att = prim.GetFrictionCombineModeAttr()
Here is a slightly better answer that fixes the UI not updating issue, the PhysxMaterialAPI needs to be applied first before the rest will update in the ui.
import omni
from pxr import Sdf, UsdPhysics, PhysxSchema
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/PhysicsMaterial")
pma = PhysxSchema.PhysxMaterialAPI.Apply(prim)
pma.CreateFrictionCombineModeAttr(PhysxSchema.Tokens.min)
Note that the attribute has to be created first before you can access it which is why