|
1 | 1 | # SPDX-FileCopyrightText: Copyright (c) 2025 The Newton Developers |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
| 4 | +import math |
4 | 5 | import unittest |
5 | 6 |
|
6 | 7 | from pxr import Plug, Usd, UsdPhysics, UsdShade |
@@ -30,6 +31,10 @@ def test_api_application(self): |
30 | 31 |
|
31 | 32 | self.assertTrue(self.material.HasAttribute("physics:dynamicFriction")) # from PhysicsMaterialAPI |
32 | 33 | self.assertTrue(self.material.HasAttribute("newton:torsionalFriction")) # from NewtonMaterialAPI |
| 34 | + self.assertTrue(self.material.HasAttribute("newton:contactStiffness")) # from NewtonMaterialAPI |
| 35 | + self.assertTrue(self.material.HasAttribute("newton:contactDamping")) # from NewtonMaterialAPI |
| 36 | + self.assertTrue(self.material.HasAttribute("newton:contactFrictionStiffness")) # from NewtonMaterialAPI |
| 37 | + self.assertTrue(self.material.HasAttribute("newton:contactAdhesion")) # from NewtonMaterialAPI |
33 | 38 |
|
34 | 39 | def test_api_limitations(self): |
35 | 40 | prim: Usd.Prim = self.stage.DefinePrim("/NotMaterial", "Xform") |
@@ -75,6 +80,86 @@ def test_rolling_friction(self): |
75 | 80 | self.assertAlmostEqual(hard.GetMinimum(), 0.0) |
76 | 81 | self.assertIsNone(hard.GetMaximum()) |
77 | 82 |
|
| 83 | + def test_contact_stiffness(self): |
| 84 | + self.assertFalse(self.material.HasAttribute("newton:contactStiffness")) |
| 85 | + |
| 86 | + self.material.ApplyAPI("NewtonMaterialAPI") |
| 87 | + attr = self.material.GetAttribute("newton:contactStiffness") |
| 88 | + self.assertIsNotNone(attr) |
| 89 | + self.assertFalse(attr.HasAuthoredValue()) |
| 90 | + self.assertEqual(attr.Get(), -math.inf) |
| 91 | + |
| 92 | + success = attr.Set(5000.0) |
| 93 | + self.assertTrue(success) |
| 94 | + self.assertTrue(attr.HasAuthoredValue()) |
| 95 | + self.assertAlmostEqual(attr.Get(), 5000.0) |
| 96 | + |
| 97 | + if USD_HAS_LIMITS: |
| 98 | + soft = attr.GetSoftLimits() |
| 99 | + self.assertTrue(soft.IsValid()) |
| 100 | + self.assertAlmostEqual(soft.GetMinimum(), 0.0) |
| 101 | + self.assertIsNone(soft.GetMaximum()) |
| 102 | + |
| 103 | + def test_contact_damping(self): |
| 104 | + self.assertFalse(self.material.HasAttribute("newton:contactDamping")) |
| 105 | + |
| 106 | + self.material.ApplyAPI("NewtonMaterialAPI") |
| 107 | + attr = self.material.GetAttribute("newton:contactDamping") |
| 108 | + self.assertIsNotNone(attr) |
| 109 | + self.assertFalse(attr.HasAuthoredValue()) |
| 110 | + self.assertEqual(attr.Get(), -math.inf) |
| 111 | + |
| 112 | + success = attr.Set(200.0) |
| 113 | + self.assertTrue(success) |
| 114 | + self.assertTrue(attr.HasAuthoredValue()) |
| 115 | + self.assertAlmostEqual(attr.Get(), 200.0) |
| 116 | + |
| 117 | + if USD_HAS_LIMITS: |
| 118 | + soft = attr.GetSoftLimits() |
| 119 | + self.assertTrue(soft.IsValid()) |
| 120 | + self.assertAlmostEqual(soft.GetMinimum(), 0.0) |
| 121 | + self.assertIsNone(soft.GetMaximum()) |
| 122 | + |
| 123 | + def test_contact_friction_stiffness(self): |
| 124 | + self.assertFalse(self.material.HasAttribute("newton:contactFrictionStiffness")) |
| 125 | + |
| 126 | + self.material.ApplyAPI("NewtonMaterialAPI") |
| 127 | + attr = self.material.GetAttribute("newton:contactFrictionStiffness") |
| 128 | + self.assertIsNotNone(attr) |
| 129 | + self.assertFalse(attr.HasAuthoredValue()) |
| 130 | + self.assertEqual(attr.Get(), -math.inf) |
| 131 | + |
| 132 | + success = attr.Set(2000.0) |
| 133 | + self.assertTrue(success) |
| 134 | + self.assertTrue(attr.HasAuthoredValue()) |
| 135 | + self.assertAlmostEqual(attr.Get(), 2000.0) |
| 136 | + |
| 137 | + if USD_HAS_LIMITS: |
| 138 | + soft = attr.GetSoftLimits() |
| 139 | + self.assertTrue(soft.IsValid()) |
| 140 | + self.assertAlmostEqual(soft.GetMinimum(), 0.0) |
| 141 | + self.assertIsNone(soft.GetMaximum()) |
| 142 | + |
| 143 | + def test_contact_adhesion(self): |
| 144 | + self.assertFalse(self.material.HasAttribute("newton:contactAdhesion")) |
| 145 | + |
| 146 | + self.material.ApplyAPI("NewtonMaterialAPI") |
| 147 | + attr = self.material.GetAttribute("newton:contactAdhesion") |
| 148 | + self.assertIsNotNone(attr) |
| 149 | + self.assertFalse(attr.HasAuthoredValue()) |
| 150 | + self.assertEqual(attr.Get(), -math.inf) |
| 151 | + |
| 152 | + success = attr.Set(0.05) |
| 153 | + self.assertTrue(success) |
| 154 | + self.assertTrue(attr.HasAuthoredValue()) |
| 155 | + self.assertAlmostEqual(attr.Get(), 0.05) |
| 156 | + |
| 157 | + if USD_HAS_LIMITS: |
| 158 | + soft = attr.GetSoftLimits() |
| 159 | + self.assertTrue(soft.IsValid()) |
| 160 | + self.assertAlmostEqual(soft.GetMinimum(), 0.0) |
| 161 | + self.assertIsNone(soft.GetMaximum()) |
| 162 | + |
78 | 163 |
|
79 | 164 | if __name__ == "__main__": |
80 | 165 | unittest.main() |
0 commit comments