refactor(convert): Add physx_max_convex_hulls, max_vertices, max_voxel_res to MeshtoUSDConverter. (#57)

This commit is contained in:
Xinjie 2025-11-10 11:45:44 +08:00 committed by GitHub
parent a256674bf2
commit fb637f9afc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 36 deletions

View File

@ -45,8 +45,8 @@ with gr.Blocks(delete_cache=(43200, 43200), theme=custom_theme) as demo:
## ***EmbodiedGen***: Image-to-3D Asset
**🔖 Version**: {VERSION}
<p style="display: flex; gap: 10px; flex-wrap: nowrap;">
<a href="https://horizonrobotics.github.io/robot_lab/embodied_gen/index.html">
<img alt="🌐 Project Page" src="https://img.shields.io/badge/🌐-Project_Page-blue">
<a href="https://horizonrobotics.github.io/EmbodiedGen">
<img alt="📖 Documentation" src="https://img.shields.io/badge/📖-Documentation-blue">
</a>
<a href="https://arxiv.org/abs/2506.10600">
<img alt="📄 arXiv" src="https://img.shields.io/badge/📄-arXiv-b31b1b">

View File

@ -45,8 +45,8 @@ with gr.Blocks(delete_cache=(43200, 43200), theme=custom_theme) as demo:
## ***EmbodiedGen***: Text-to-3D Asset
**🔖 Version**: {VERSION}
<p style="display: flex; gap: 10px; flex-wrap: nowrap;">
<a href="https://horizonrobotics.github.io/robot_lab/embodied_gen/index.html">
<img alt="🌐 Project Page" src="https://img.shields.io/badge/🌐-Project_Page-blue">
<a href="https://horizonrobotics.github.io/EmbodiedGen">
<img alt="📖 Documentation" src="https://img.shields.io/badge/📖-Documentation-blue">
</a>
<a href="https://arxiv.org/abs/2506.10600">
<img alt="📄 arXiv" src="https://img.shields.io/badge/📄-arXiv-b31b1b">

View File

@ -55,8 +55,8 @@ with gr.Blocks(delete_cache=(43200, 43200), theme=custom_theme) as demo:
## ***EmbodiedGen***: Texture Generation
**🔖 Version**: {VERSION}
<p style="display: flex; gap: 10px; flex-wrap: nowrap;">
<a href="https://horizonrobotics.github.io/robot_lab/embodied_gen/index.html">
<img alt="🌐 Project Page" src="https://img.shields.io/badge/🌐-Project_Page-blue">
<a href="https://horizonrobotics.github.io/EmbodiedGen">
<img alt="📖 Documentation" src="https://img.shields.io/badge/📖-Documentation-blue">
</a>
<a href="https://arxiv.org/abs/2506.10600">
<img alt="📄 arXiv" src="https://img.shields.io/badge/📄-arXiv-b31b1b">

View File

@ -479,8 +479,8 @@ with gr.Blocks(
**🔖 Version**: {VERSION}
<p style="display: flex; gap: 10px; flex-wrap: nowrap;">
<a href="https://horizonrobotics.github.io/robot_lab/embodied_gen/index.html">
<img alt="🌐 Project Page" src="https://img.shields.io/badge/🌐-Project_Page-blue">
<a href="https://horizonrobotics.github.io/EmbodiedGen">
<img alt="📖 Documentation" src="https://img.shields.io/badge/📖-Documentation-blue">
</a>
<a href="https://arxiv.org/abs/2506.10600">
<img alt="📄 arXiv" src="https://img.shields.io/badge/📄-arXiv-b31b1b">

View File

@ -488,8 +488,8 @@ class MeshtoUSDConverter(AssetConverterBase):
DEFAULT_BIND_APIS = [
"MaterialBindingAPI",
# "PhysicsMeshCollisionAPI",
"PhysxDecompositionCollisionAPI",
"PhysicsMeshCollisionAPI",
"PhysxConvexDecompositionCollisionAPI",
"PhysicsCollisionAPI",
"PhysxCollisionAPI",
"PhysicsMassAPI",
@ -515,10 +515,10 @@ class MeshtoUSDConverter(AssetConverterBase):
if simulation_app is not None:
self.simulation_app = simulation_app
if "exit_close" in kwargs:
self.exit_close = kwargs.pop("exit_close")
else:
self.exit_close = True
self.exit_close = kwargs.pop("exit_close", True)
self.physx_max_convex_hulls = kwargs.pop("physx_max_convex_hulls", 32)
self.physx_max_vertices = kwargs.pop("physx_max_vertices", 16)
self.physx_max_voxel_res = kwargs.pop("physx_max_voxel_res", 10000)
self.usd_parms = dict(
force_usd_conversion=force_usd_conversion,
@ -548,12 +548,12 @@ class MeshtoUSDConverter(AssetConverterBase):
def __exit__(self, exc_type, exc_val, exc_tb):
"""Context manager exit, closes simulation app if created."""
# Close the simulation app if it was created here
if hasattr(self, "app_launcher") and self.exit_close:
self.simulation_app.close()
if exc_val is not None:
logger.error(f"Exception occurred: {exc_val}.")
if hasattr(self, "app_launcher") and self.exit_close:
self.simulation_app.close()
return False
def convert(self, urdf_path: str, output_file: str):
@ -601,11 +601,9 @@ class MeshtoUSDConverter(AssetConverterBase):
# Add convex decomposition collision and set ShrinkWrap.
elif prim.GetName() == "mesh":
approx_attr = prim.GetAttribute("physics:approximation")
if not approx_attr:
approx_attr = prim.CreateAttribute(
"physics:approximation", Sdf.ValueTypeNames.Token
)
approx_attr = prim.CreateAttribute(
"physics:approximation", Sdf.ValueTypeNames.Token
)
approx_attr.Set("convexDecomposition")
physx_conv_api = (
@ -613,6 +611,15 @@ class MeshtoUSDConverter(AssetConverterBase):
prim
)
)
physx_conv_api.GetMaxConvexHullsAttr().Set(
self.physx_max_convex_hulls
)
physx_conv_api.GetHullVertexLimitAttr().Set(
self.physx_max_vertices
)
physx_conv_api.GetVoxelResolutionAttr().Set(
self.physx_max_voxel_res
)
physx_conv_api.GetShrinkWrapAttr().Set(True)
api_schemas = prim.GetMetadata("apiSchemas")
@ -639,8 +646,8 @@ class PhysicsUSDAdder(MeshtoUSDConverter):
DEFAULT_BIND_APIS = [
"MaterialBindingAPI",
# "PhysicsMeshCollisionAPI",
"PhysxDecompositionCollisionAPI",
"PhysicsMeshCollisionAPI",
"PhysxConvexDecompositionCollisionAPI",
"PhysicsCollisionAPI",
"PhysxCollisionAPI",
"PhysicsRigidBodyAPI",
@ -675,18 +682,23 @@ class PhysicsUSDAdder(MeshtoUSDConverter):
if "lightfactory" in prim.GetName().lower():
continue
approx_attr = prim.GetAttribute(
"physics:approximation"
approx_attr = prim.CreateAttribute(
"physics:approximation", Sdf.ValueTypeNames.Token
)
if not approx_attr:
approx_attr = prim.CreateAttribute(
"physics:approximation",
Sdf.ValueTypeNames.Token,
)
approx_attr.Set("convexDecomposition")
physx_conv_api = PhysxSchema.PhysxConvexDecompositionCollisionAPI.Apply(
prim
)
physx_conv_api.GetMaxConvexHullsAttr().Set(
self.physx_max_convex_hulls
)
physx_conv_api.GetHullVertexLimitAttr().Set(
self.physx_max_vertices
)
physx_conv_api.GetVoxelResolutionAttr().Set(
self.physx_max_voxel_res
)
physx_conv_api.GetShrinkWrapAttr().Set(True)
rigid_body_api = UsdPhysics.RigidBodyAPI.Apply(prim)
@ -790,11 +802,9 @@ class URDFtoUSDConverter(MeshtoUSDConverter):
with Usd.EditContext(stage, layer):
for prim in stage.Traverse():
if prim.GetName() == "collisions":
approx_attr = prim.GetAttribute("physics:approximation")
if not approx_attr:
approx_attr = prim.CreateAttribute(
"physics:approximation", Sdf.ValueTypeNames.Token
)
approx_attr = prim.CreateAttribute(
"physics:approximation", Sdf.ValueTypeNames.Token
)
approx_attr.Set("convexDecomposition")
physx_conv_api = (
@ -802,6 +812,9 @@ class URDFtoUSDConverter(MeshtoUSDConverter):
prim
)
)
physx_conv_api.GetMaxConvexHullsAttr().Set(32)
physx_conv_api.GetHullVertexLimitAttr().Set(16)
physx_conv_api.GetVoxelResolutionAttr().Set(10000)
physx_conv_api.GetShrinkWrapAttr().Set(True)
api_schemas = prim.GetMetadata("apiSchemas")