Skip to content

Commit

Permalink
Merge pull request #1714 from abhihjoshi:tendons
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 651048034
Change-Id: If5b7cb55ff0007c3c6f932e62f068d1168778a33
  • Loading branch information
Copybara-Service committed Jul 10, 2024
2 parents 7f9f8b5 + e734527 commit 60afda9
Show file tree
Hide file tree
Showing 9 changed files with 1,092 additions and 969 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*.egg-info/
build/
build_cmake/
python/dist/

# Exclude macOS folder attributes
.DS_Store
Expand Down
53 changes: 53 additions & 0 deletions python/mujoco/usd/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2024 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Camera handling for USD exporter."""

import mujoco.usd.utils as utils_component

import numpy as np

from pxr import Gf
from pxr import Usd
from pxr import UsdGeom


class USDCamera:
"""Class that handles the cameras in the USD scene."""

def __init__(self, stage: Usd.Stage, obj_name: str):
self.stage = stage

xform_path = f"/World/Camera_Xform_{obj_name}"
camera_path = f"{xform_path}/Camera_{obj_name}"
self.usd_xform = UsdGeom.Xform.Define(stage, xform_path)
self.usd_camera = UsdGeom.Camera.Define(stage, camera_path)
self.usd_prim = stage.GetPrimAtPath(camera_path)

# defining ops required by update function
self.transform_op = self.usd_xform.AddTransformOp()

self.usd_camera.CreateFocalLengthAttr().Set(12)
self.usd_camera.CreateFocusDistanceAttr().Set(400)

self.usd_camera.GetHorizontalApertureAttr().Set(12)

self.usd_camera.GetClippingRangeAttr().Set(Gf.Vec2f(1e-4, 1e6))

def update(self, cam_pos: np.ndarray, cam_mat: np.ndarray, frame: int):
"""Updates the position and orientation of the camera in the scene."""
transformation_mat = utils_component.create_transform_matrix(
rotation_matrix=cam_mat, translation_vector=cam_pos
).T
self.transform_op.Set(Gf.Matrix4d(transformation_mat.tolist()), frame)
Loading

0 comments on commit 60afda9

Please sign in to comment.