Skip to content

[Development] Define scale for usd conversion #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: bulk_usd_conversion
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions habitat-lab/habitat/isaacsim/scene_instance_json_to_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,16 @@ def add_habitat_visual_to_usd_root(
)


def add_xform_scale(object_xform: "UsdGeom.Xform") -> None:
def add_xform_scale(
obj_instance_json: Dict[str, Any], object_xform: "UsdGeom.Xform"
) -> None:
"""Add object scale value into xform class for scene instance json.

:param object_xform: The Xform class containing scene object information.
"""
# Ensure scale op exists, default value
scale = [
1.0,
1.0,
1.0,
] # obj_instance_json.get("non_uniform_scale", [1.0, 1.0, 1.0])
hab_scale = obj_instance_json.get("non_uniform_scale", [1.0, 1.0, 1.0])
usd_scale = habitat_to_usd_scale(hab_scale)

scale_op = next(
(
Expand All @@ -361,7 +360,20 @@ def add_xform_scale(object_xform: "UsdGeom.Xform") -> None:
)
if scale_op is None:
scale_op = object_xform.AddScaleOp()
scale_op.Set(Gf.Vec3f(*scale))
scale_op.Set(Gf.Vec3f(*usd_scale))


def habitat_to_usd_scale(scale: List[float]) -> List[float]:
"""
Convert a position from Habitat (Y-up) to USD (Z-up) coordinate system. Habitat (-x, z, y) -> Isaac (x, y, z)

:param position: Habitat coordinates
:return: Isaac coordinates
"""

abs_scale = [abs(num) for num in scale]
x, y, z = abs_scale
return [x, z, y]


def add_xform_rotation(
Expand Down Expand Up @@ -558,7 +570,7 @@ def convert_hab_scene(

# Operation are performed in the order listed, change as desired
# Current order is scale at global origin, local rotation at global origin, then translate from global origin
add_xform_scale(object_xform)
add_xform_scale(obj_instance_json, object_xform)
add_xform_rotation(obj_instance_json, object_xform)
add_xform_translation(obj_instance_json, object_xform)

Expand Down
37 changes: 25 additions & 12 deletions test/test_isaac_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@


## Helper functions
def usd_to_habitat_scale(scale: List[float]) -> List[float]:
"""
Convert a scale from USD (Z-up) to Habitat (Y-up) coordinate system.

Issac (x, y, z) -> Habitat (x, z, y)
"""
x, y, z = scale
return [x, z, y]


def usd_to_habitat_position(position: List[float]) -> List[float]:
"""
Convert a position from USD (Z-up) to Habitat (Y-up) coordinate system.
Expand Down Expand Up @@ -140,14 +150,15 @@ def test_example2_scene_instance():
xform_prim.GetAttribute("xformOp:orient").Get().imaginary
)
usda_orient_real = xform_prim.GetAttribute("xformOp:orient").Get().real
# usda_scale = list(xform_prim.GetAttribute("xformOp:scale").Get())
usda_scale = list(xform_prim.GetAttribute("xformOp:scale").Get())
usda_translate = list(xform_prim.GetAttribute("xformOp:translate").Get())

# change usd coords back to habitat coords

usda_translate_hab_coord = usd_to_habitat_position(usda_translate)
hab_translate_from_usd = usd_to_habitat_position(usda_translate)
usda_rotation = [usda_orient_real] + usda_orient_im
usda_rotation_hab_coord = usd_to_habitat_rotation(usda_rotation)
hab_rotation_from_usd = usd_to_habitat_rotation(usda_rotation)
hab_scale_from_usd = usd_to_habitat_scale(usda_scale)

with open(scene_filepath, "r") as file:
scene_instance_json_data = json.load(file)
Expand All @@ -158,17 +169,19 @@ def test_example2_scene_instance():
scene_instance_rotation = scene_instance_json_data["object_instances"][0][
"rotation"
]
# scene_instance_uniform_scale = scene_instance_json_data[
# "object_instances"
# ][0]["non_uniform_scale"]
scene_instance_uniform_scale = scene_instance_json_data[
"object_instances"
][0]["non_uniform_scale"]

abs_val_scene_instance_uniform_scale = [
abs(num) for num in scene_instance_uniform_scale
]

assert usda_translate_hab_coord == pytest.approx(
scene_instance_translation
assert hab_translate_from_usd == pytest.approx(scene_instance_translation)
assert hab_rotation_from_usd == pytest.approx(scene_instance_rotation)
assert hab_scale_from_usd == pytest.approx(
abs_val_scene_instance_uniform_scale
)
assert usda_rotation_hab_coord == pytest.approx(scene_instance_rotation)
# TODO: Add Scale to show values are equal, looks like most objects are (1, 1, 1) for the (x, y, z) coordinates in hab space.
# Not sure, but pxr space is has values from 0 to infinity, and 1 is default, but hab space has
# -1 values? Don't know what hab space scaling is.


## urdf_to_usd.py unit tests
Expand Down
Loading