fixing frame rate bug in demo file

This commit is contained in:
Abhishek Joshi
2024-07-04 15:06:25 -05:00
parent 59303bb161
commit c79ae6f242
6 changed files with 41 additions and 46 deletions
+2 -1
View File
@@ -18,7 +18,8 @@ from pxr import Gf
from pxr import Usd from pxr import Usd
from pxr import UsdGeom from pxr import UsdGeom
import mujoco.usd.utils as utils_component # import mujoco.usd.utils as utils_component
import utils as utils_component
class USDCamera: class USDCamera:
"""Class that handles the cameras in the USD scene""" """Class that handles the cameras in the USD scene"""
+19 -31
View File
@@ -1,26 +1,14 @@
# 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.
# ==============================================================================
import argparse import argparse
from pathlib import Path
from tqdm import tqdm from tqdm import tqdm
from pathlib import Path
import mujoco import mujoco
from mujoco.usd import exporter
# from mujoco.usd import exporter
import exporter
def generate_usd_trajectory(args): def generate_usd_trajectory(args):
"""Generates a USD file from a mujoco trajectory."""
# load a model to mujoco # load a model to mujoco
model_path = args.model_path model_path = args.model_path
m = mujoco.MjModel.from_xml_path(model_path) m = mujoco.MjModel.from_xml_path(model_path)
@@ -32,11 +20,11 @@ def generate_usd_trajectory(args):
output_directory_root=args.output_directory_root, output_directory_root=args.output_directory_root,
camera_names=args.camera_names) camera_names=args.camera_names)
# step through the model for length steps # step through the simulation for the given duration of time
for _ in tqdm(range(args.length)): while d.time < args.duration:
for _ in range(args.steps_per_frame): mujoco.mj_step(m, d)
mujoco.mj_step(m, d) if exp.frame_count < d.time * args.framerate:
exp.update_scene(d) exp.update_scene(data=d)
exp.save_scene(filetype=args.export_extension) exp.save_scene(filetype=args.export_extension)
@@ -49,10 +37,15 @@ if __name__ == "__main__":
required=True, required=True,
help='path to mjcf xml model') help='path to mjcf xml model')
parser.add_argument('--length', parser.add_argument('--duration',
type=int, type=int,
default=100, default=5,
help='length of trajectory to render') help='duration in seconds for the generated video')
parser.add_argument('--framerate',
type=int,
default=60,
help='frame rate of the generated video')
parser.add_argument('--output_directory_root', parser.add_argument('--output_directory_root',
type=str, type=str,
@@ -67,12 +60,7 @@ if __name__ == "__main__":
parser.add_argument('--export_extension', parser.add_argument('--export_extension',
type=str, type=str,
default="usd", default="usd",
help='extension of exported file (usd, usda, or usdc)') help='extension of exported file (can be usd, usda, or usdc)')
parser.add_argument('--steps_per_frame',
type=int,
default=1,
help='number of frames to skip for each rendering step')
args = parser.parse_args() args = parser.parse_args()
generate_usd_trajectory(args) generate_usd_trajectory(args)
+8 -5
View File
@@ -29,10 +29,14 @@ from pxr import UsdGeom
import mujoco import mujoco
import mujoco.usd.shapes as shapes_module # import mujoco.usd.shapes as shapes_module
import mujoco.usd.objects as object_module # import mujoco.usd.objects as object_module
import mujoco.usd.lights as light_module # import mujoco.usd.lights as light_module
import mujoco.usd.camera as camera_module # import mujoco.usd.camera as camera_module
import shapes as shapes_module
import objects as object_module
import lights as light_module
import camera as camera_module
class USDExporter: class USDExporter:
@@ -293,7 +297,6 @@ class USDExporter:
self.geom_refs[geom_name] = usd_geom self.geom_refs[geom_name] = usd_geom
def _update_geoms(self): def _update_geoms(self):
# iterate through all geoms in the scene and makes update # iterate through all geoms in the scene and makes update
for i in range(self.scene.ngeom): for i in range(self.scene.ngeom):
geom = self.scene.geoms[i] geom = self.scene.geoms[i]
+1 -1
View File
@@ -59,7 +59,7 @@ class ExporterTest(absltest.TestCase):
exporter.save_scene("export.usda") exporter.save_scene("export.usda")
with open(os.path.join( with open(os.path.join(
output_dir, "mujoco_usdpkg/frames", "frame_1_.export.usda"), "r") as f: output_dir, "mujoco_usdpkg/frames", "frame_1.export.usda"), "r") as f:
golden_path = os.path.join( golden_path = os.path.join(
epath.resource_path("mujoco"), "testdata", "usd_golden.usda") epath.resource_path("mujoco"), "testdata", "usd_golden.usda")
with open(golden_path, "r") as golden_file: with open(golden_path, "r") as golden_file:
+5 -2
View File
@@ -27,8 +27,11 @@ from pxr import Vt
import mujoco import mujoco
import mujoco.usd.utils as utils_component # import mujoco.usd.utils as utils_component
import mujoco.usd.shapes as shapes_component # import mujoco.usd.shapes as shapes_component
import utils as utils_component
import shapes as shapes_component
class USDObject(ABC): class USDObject(ABC):
""" Abstract interface for all USD objects including meshes and primitives. """ Abstract interface for all USD objects including meshes and primitives.