-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_rods.py
More file actions
83 lines (66 loc) · 3.32 KB
/
Copy pathtest_rods.py
File metadata and controls
83 lines (66 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# SPDX-FileCopyrightText: Copyright (c) 2025 The Newton Developers
# SPDX-License-Identifier: Apache-2.0
import math
import unittest
from pxr import Plug, Usd, UsdShade
import newton_usd_schemas # noqa: F401
USD_HAS_LIMITS = Usd.GetVersion() >= (0, 25, 11)
class TestNewtonCurvesDeformableMaterialAPI(unittest.TestCase):
def setUp(self):
self.stage: Usd.Stage = Usd.Stage.CreateInMemory()
self.material = UsdShade.Material.Define(self.stage, "/CableMaterial").GetPrim()
def test_api_registered(self):
plug_type = Plug.Registry().FindTypeByName("NewtonPhysicsCurvesDeformableMaterialAPI")
self.assertEqual(plug_type.typeName, "NewtonPhysicsCurvesDeformableMaterialAPI")
schema_type = Usd.SchemaRegistry().GetSchemaTypeName("NewtonPhysicsCurvesDeformableMaterialAPI")
self.assertEqual(schema_type, "NewtonCurvesDeformableMaterialAPI")
def test_api_application(self):
self.assertFalse(self.material.HasAPI("NewtonCurvesDeformableMaterialAPI"))
self.material.ApplyAPI("NewtonCurvesDeformableMaterialAPI")
self.assertTrue(self.material.HasAPI("PhysicsMaterialAPI"))
self.assertTrue(self.material.HasAPI("NewtonCurvesDeformableMaterialAPI"))
for name in (
"newton:stretchDamping",
"newton:shearDamping",
"newton:bendDamping",
"newton:twistDamping",
):
self.assertTrue(self.material.HasAttribute(name), name)
def test_api_limitations(self):
prim = self.stage.DefinePrim("/NotMaterial", "Xform")
self.assertFalse(prim.CanApplyAPI("NewtonCurvesDeformableMaterialAPI"))
self.assertTrue(self.material.CanApplyAPI("NewtonCurvesDeformableMaterialAPI"))
def test_material_parameter_defaults(self):
self.material.ApplyAPI("NewtonCurvesDeformableMaterialAPI")
self.assertEqual(self.material.GetAttribute("newton:stretchDamping").Get(), -math.inf)
self.assertEqual(self.material.GetAttribute("newton:shearDamping").Get(), -math.inf)
self.assertEqual(self.material.GetAttribute("newton:bendDamping").Get(), -math.inf)
self.assertEqual(self.material.GetAttribute("newton:twistDamping").Get(), -math.inf)
def test_material_parameter_roundtrip(self):
self.material.ApplyAPI("NewtonCurvesDeformableMaterialAPI")
values = {
"newton:stretchDamping": 0.01,
"newton:shearDamping": 0.02,
"newton:bendDamping": 0.03,
"newton:twistDamping": 0.04,
}
for name, value in values.items():
attr = self.material.GetAttribute(name)
self.assertTrue(attr.Set(value), name)
self.assertAlmostEqual(attr.Get(), value)
def test_limits(self):
if not USD_HAS_LIMITS:
self.skipTest("USD build does not expose schema limits")
self.material.ApplyAPI("NewtonCurvesDeformableMaterialAPI")
for name in (
"newton:stretchDamping",
"newton:shearDamping",
"newton:bendDamping",
"newton:twistDamping",
):
limits = self.material.GetAttribute(name).GetSoftLimits()
self.assertTrue(limits.IsValid(), name)
self.assertEqual(limits.GetMinimum(), 0.0)
self.assertIsNone(limits.GetMaximum())
if __name__ == "__main__":
unittest.main()