init commit
This commit is contained in:
112
workflows/simbox/tools/rigid_obj/asset_usd_converter.py
Normal file
112
workflows/simbox/tools/rigid_obj/asset_usd_converter.py
Normal file
@@ -0,0 +1,112 @@
|
||||
# pylint: skip-file
|
||||
# flake8: noqa
|
||||
# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
||||
# and proprietary rights in and to this software, related documentation
|
||||
# and any modifications thereto. Any use, reproduction, disclosure or
|
||||
# distribution of this software and related documentation without an express
|
||||
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
||||
#
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from isaacsim import SimulationApp
|
||||
|
||||
|
||||
async def convert(in_file, out_file, load_materials=False):
|
||||
# This import causes conflicts when global
|
||||
import omni.kit.asset_converter
|
||||
|
||||
def progress_callback(progress, total_steps):
|
||||
pass
|
||||
|
||||
converter_context = omni.kit.asset_converter.AssetConverterContext()
|
||||
# setup converter and flags
|
||||
converter_context.ignore_materials = not load_materials
|
||||
# converter_context.ignore_animation = False
|
||||
# converter_context.ignore_cameras = True
|
||||
# converter_context.single_mesh = True
|
||||
# converter_context.smooth_normals = True
|
||||
# converter_context.preview_surface = False
|
||||
# converter_context.support_point_instancer = False
|
||||
# converter_context.embed_mdl_in_usd = False
|
||||
# converter_context.use_meter_as_world_unit = True
|
||||
# converter_context.create_world_as_default_root_prim = False
|
||||
instance = omni.kit.asset_converter.get_instance()
|
||||
task = instance.create_converter_task(in_file, out_file, progress_callback, converter_context)
|
||||
success = True
|
||||
while True:
|
||||
success = await task.wait_until_finished()
|
||||
if not success:
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
break
|
||||
return success
|
||||
|
||||
|
||||
def asset_convert(args):
|
||||
supported_file_formats = ["stl", "obj", "fbx"]
|
||||
# for folder in args.folders:
|
||||
# local_asset_output = folder + "_converted"
|
||||
# result = omni.client.create_folder(f"{local_asset_output}")
|
||||
|
||||
for folder in args.folders:
|
||||
print(f"\nConverting folder {folder}...")
|
||||
|
||||
(result, models) = omni.client.list(folder)
|
||||
for i, entry in enumerate(models):
|
||||
if i >= args.max_models:
|
||||
print(f"max models ({args.max_models}) reached, exiting conversion")
|
||||
break
|
||||
|
||||
model = str(entry.relative_path)
|
||||
model_name = os.path.splitext(model)[0]
|
||||
model_format = (os.path.splitext(model)[1])[1:]
|
||||
# Supported input file formats
|
||||
if model_format in supported_file_formats:
|
||||
input_model_path = folder + "/" + model
|
||||
# converted_model_path = folder + "_converted/" + model_name + "_" + model_format + ".usd"
|
||||
converted_model_path = folder + "/" + "Aligned_obj.usd"
|
||||
if not os.path.exists(converted_model_path):
|
||||
status = asyncio.get_event_loop().run_until_complete(
|
||||
convert(input_model_path, converted_model_path, True)
|
||||
)
|
||||
if not status:
|
||||
print(f"ERROR Status is {status}")
|
||||
print(f"---Added {converted_model_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
kit = SimulationApp()
|
||||
|
||||
import omni
|
||||
from omni.isaac.core.utils.extensions import enable_extension
|
||||
|
||||
enable_extension("omni.kit.asset_converter")
|
||||
|
||||
parser = argparse.ArgumentParser("Convert OBJ/STL assets to USD")
|
||||
parser.add_argument(
|
||||
"--folders", type=str, nargs="+", default=None, help="List of folders to convert (space seperated)."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max-models", type=int, default=50, help="If specified, convert up to `max-models` per folder."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--load-materials", action="store_true", help="If specified, materials will be loaded from meshes"
|
||||
)
|
||||
args, unknown_args = parser.parse_known_args()
|
||||
|
||||
import glob
|
||||
import os
|
||||
|
||||
if args.folders is not None:
|
||||
# Ensure Omniverse Kit is launched via SimulationApp before asset_convert() is called
|
||||
asset_convert(args)
|
||||
else:
|
||||
print(f"No folders specified via --folders argument, exiting")
|
||||
|
||||
# cleanup
|
||||
kit.close()
|
||||
@@ -0,0 +1,13 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl _texture.019
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 1.000000 1.000000 1.000000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 1
|
||||
map_Kd Scan.jpg
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 89 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 375 KiB |
57
workflows/simbox/tools/rigid_obj/make_collider.py
Normal file
57
workflows/simbox/tools/rigid_obj/make_collider.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# pylint: skip-file
|
||||
# flake8: noqa
|
||||
|
||||
import argparse
|
||||
|
||||
from isaacsim import SimulationApp
|
||||
|
||||
simulation_app = SimulationApp({"headless": True})
|
||||
|
||||
from omni.physx.scripts import physicsUtils, utils
|
||||
from pxr import Usd
|
||||
|
||||
|
||||
def process(
|
||||
usd_file,
|
||||
create_physics_mat=True,
|
||||
):
|
||||
"""Add collision properties to a USD file using convex decomposition.
|
||||
|
||||
Args:
|
||||
usd_file: Path to the USD file.
|
||||
create_physics_mat: Whether to create physics material.
|
||||
"""
|
||||
stage = Usd.Stage.Open(usd_file)
|
||||
aligned_prim = stage.GetPrimAtPath("/World/Aligned")
|
||||
child_prim = aligned_prim.GetAllChildren()[0]
|
||||
|
||||
utils.setCollider(child_prim, "convexDecomposition")
|
||||
child_prim.GetAttribute("physxConvexDecompositionCollision:maxConvexHulls").Set(64)
|
||||
child_prim.GetAttribute("physxConvexDecompositionCollision:hullVertexLimit").Set(64)
|
||||
child_prim.GetAttribute("physxConvexDecompositionCollision:minThickness").Set(0.001)
|
||||
child_prim.GetAttribute("physxConvexDecompositionCollision:shrinkWrap").Set(True)
|
||||
child_prim.GetAttribute("physxConvexDecompositionCollision:errorPercentage").Set(0.1)
|
||||
if create_physics_mat:
|
||||
static_friction = 1.0
|
||||
dynamic_friction = 1.0
|
||||
utils.addRigidBodyMaterial(
|
||||
stage,
|
||||
"/World/Physics_Materials",
|
||||
staticFriction=static_friction,
|
||||
dynamicFriction=dynamic_friction,
|
||||
)
|
||||
physicsUtils.add_physics_material_to_prim(
|
||||
stage,
|
||||
aligned_prim,
|
||||
"/World/Physics_Materials",
|
||||
)
|
||||
stage.Save()
|
||||
print(f"Successfully processed: {usd_file}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Add collision properties to USD file using convex decomposition")
|
||||
parser.add_argument("--usd_path", type=str, required=True, help="Path to the USD file")
|
||||
args = parser.parse_args()
|
||||
|
||||
process(args.usd_path, create_physics_mat=True)
|
||||
45
workflows/simbox/tools/rigid_obj/make_rigid.py
Normal file
45
workflows/simbox/tools/rigid_obj/make_rigid.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import argparse
|
||||
|
||||
from pxr import Usd, UsdPhysics
|
||||
|
||||
|
||||
def process(
|
||||
usd_file,
|
||||
add_rigid_body=True,
|
||||
):
|
||||
"""Add rigid body physics properties to a USD file.
|
||||
|
||||
Args:
|
||||
usd_file: Path to the USD file.
|
||||
add_rigid_body: Whether to add rigid body properties.
|
||||
"""
|
||||
stage = Usd.Stage.Open(usd_file)
|
||||
editor = Usd.NamespaceEditor(stage)
|
||||
root_prim = stage.GetDefaultPrim()
|
||||
aligned_prim = root_prim.GetAllChildren()[1]
|
||||
try:
|
||||
editor.RenamePrim(aligned_prim, "Aligned")
|
||||
editor.ApplyEdits()
|
||||
except Exception:
|
||||
# If rename fails (e.g., already renamed), continue with existing prim
|
||||
aligned_prim = stage.GetPrimAtPath("/World/Aligned")
|
||||
|
||||
aligned_prim = stage.GetPrimAtPath("/World/Aligned")
|
||||
|
||||
if add_rigid_body:
|
||||
UsdPhysics.RigidBodyAPI.Apply(aligned_prim)
|
||||
|
||||
UsdPhysics.MassAPI.Apply(aligned_prim)
|
||||
mass_attr = aligned_prim.GetAttribute("physics:mass")
|
||||
mass_attr.Set(0.1)
|
||||
|
||||
stage.Save()
|
||||
print(f"Successfully processed: {usd_file}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Add rigid body physics properties to USD file")
|
||||
parser.add_argument("--usd_path", type=str, required=True, help="Path to the USD file")
|
||||
args = parser.parse_args()
|
||||
|
||||
process(args.usd_path, True)
|
||||
Reference in New Issue
Block a user