Skip to content

Commit 2faffca

Browse files
committed
update urdf loader
1 parent 9853fc5 commit 2faffca

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

manualtest/gpu_viewer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def main():
3232

3333
robots: list[sapien.physx.PhysxArticulation] = []
3434
for scene in scenes:
35-
scene.load_widget_from_package("demo_arena", "DemoArena")
35+
# scene.load_widget_from_package("demo_arena", "DemoArena")
3636
builder.set_scene(scene)
3737
robot = builder.build()
3838
robots.append(robot)
@@ -180,13 +180,13 @@ def slow_way():
180180
viewer.set_scenes(scenes)
181181
vs = viewer.window._internal_scene
182182
vs.set_ambient_light([0.1, 0.1, 0.1])
183-
vs.set_cubemap(scenes[0].render_system.get_cubemap()._internal_cubemap)
183+
# vs.set_cubemap(sapien.render.RenderCubemap()._internal_cubemap)
184184

185185
viewer.render()
186186

187187
while not viewer.closed:
188188
px.step()
189-
px.sync_poses_gpu_to_cpu()
189+
# px.sync_poses_gpu_to_cpu()
190190
viewer.window.update_render()
191191
viewer.render()
192192

python/py_package/wrapper/actor_builder.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .coacd import do_coacd
88

99

10+
1011
def preprocess_mesh_file(filename: str):
1112
"""
1213
Process input mesh file to a SAPIEN supported format
@@ -16,7 +17,7 @@ def preprocess_mesh_file(filename: str):
1617
filename for the generated file or original filename
1718
"""
1819

19-
from .geometry.usd import convert_usd_to_glb
20+
from sapien.wrapper.geometry.usd import convert_usd_to_glb
2021

2122
if any(filename.lower().endswith(s) for s in [".usd", ".usda", ".usdc", ".usdz"]):
2223
glb_filename = filename + ".sapien.glb"
@@ -62,6 +63,7 @@ class CollisionShapeRecord:
6263
decomposition_params: Union[Dict[str, Any], None] = None
6364

6465

66+
6567
@dataclass
6668
class VisualShapeRecord:
6769
type: Literal["file", "plane", "box", "capsule", "sphere", "cylinder"]
@@ -97,7 +99,9 @@ def __init__(self):
9799
self._cmass_local_pose = sapien.Pose()
98100
self._inertia = np.zeros(3)
99101
self._auto_inertial = True
100-
102+
self.disable_gravity: bool = False
103+
self.linear_damping: float = 0.0
104+
self.angular_damping: float = 0.0
101105
self.initial_pose = sapien.Pose()
102106

103107
def set_initial_pose(self, pose):
@@ -132,8 +136,7 @@ def build_render_component(self):
132136
else:
133137
assert r.material is None or isinstance(
134138
r.material, sapien.render.RenderMaterial
135-
)
136-
139+
) # gravity property is temporarily placed here.
137140
if r.type == "plane":
138141
shape = sapien.render.RenderShapePlane(r.scale, r.material)
139142
elif r.type == "box":
@@ -168,13 +171,22 @@ def build_physx_component(self, link_parent=None):
168171

169172
if self.physx_body_type == "dynamic":
170173
component = sapien.physx.PhysxRigidDynamicComponent()
174+
component.set_linear_damping(self.linear_damping)
175+
component.set_angular_damping(self.angular_damping)
176+
component.set_disable_gravity(self.disable_gravity)
171177
elif self.physx_body_type == "kinematic":
172178
component = sapien.physx.PhysxRigidDynamicComponent()
179+
component.set_linear_damping(self.linear_damping)
180+
component.set_angular_damping(self.angular_damping)
181+
component.set_disable_gravity(self.disable_gravity)
173182
component.kinematic = True
174183
elif self.physx_body_type == "static":
175184
component = sapien.physx.PhysxRigidStaticComponent()
176185
elif self.physx_body_type == "link":
177186
component = sapien.physx.PhysxArticulationLinkComponent(link_parent)
187+
component.set_linear_damping(self.linear_damping)
188+
component.set_angular_damping(self.angular_damping)
189+
component.set_disable_gravity(self.disable_gravity)
178190
else:
179191
raise Exception(f"invalid physx body type [{self.physx_body_type}]")
180192

@@ -280,7 +292,7 @@ def build(self, name=None):
280292

281293
entity = self.build_entity()
282294
entity.name = self.name
283-
entity.pose = self.initial_pose # set pose before adding to scene
295+
entity.set_pose(self.initial_pose) # set pose before adding to scene
284296
self.scene.add_entity(entity)
285297
return entity
286298

python/py_package/wrapper/articulation_builder.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from ..pysapien.physx import PhysxArticulation, PhysxRigidDynamicComponent, PhysxArticulationLinkComponent
44
from typing import Optional
55
import numpy as np
6+
from numpy.typing import NDArray
67
from dataclasses import dataclass
7-
from typing import List, Tuple
8-
8+
from typing import List, Tuple, Union
99

1010
@dataclass
1111
class MimicJointRecord:
@@ -19,19 +19,20 @@ class MimicJointRecord:
1919
class JointRecord:
2020
joint_type: str = "undefined" # "fixed", "prismatic", "revolute"
2121
limits: Tuple[float] = (-np.inf, np.inf)
22-
pose_in_parent:Pose = Pose()
22+
pose_in_parent: Pose = Pose()
2323
pose_in_child: Pose = Pose()
2424
friction: float = 0
2525
damping: float = 0
26+
armature: Union[NDArray[np.float32], float] = 0.01
2627
name: str = ""
2728

2829

2930
class LinkBuilder(ActorBuilder):
3031
def __init__(self, index: int, parent):
3132
super().__init__()
32-
self.parent = parent
33-
self.index = index
34-
self.joint_record = JointRecord()
33+
self.parent:LinkBuilder = parent
34+
self.index:int = index
35+
self.joint_record = JointRecord() # Joint record of the parent joint.
3536
self.physx_body_type = "link"
3637

3738
def set_joint_name(self, name):
@@ -117,11 +118,13 @@ def build_entities(self, fix_root_link=None)->List[Entity]:
117118
]:
118119
link_component.joint.limit = np.array(b.joint_record.limits).flatten()
119120
link_component.joint.set_drive_property(0, b.joint_record.damping)
121+
link_component.joint.set_armature(b.joint_record.armature * np.ones_like(link_component.joint.get_armature(), dtype=np.float32))
120122

121123
links.append(link_component)
122124
entities.append(entity)
123125

124126
if fix_root_link is not None:
127+
# The first component should be sapien.physx.PhysxArticulationLinkComponent
125128
entities[0].components[0].joint.type = (
126129
"fixed" if fix_root_link else "undefined"
127130
)

0 commit comments

Comments
 (0)