unify interactive assets loading
This commit is contained in:
parent
98fc2bece6
commit
43784014da
|
@ -7,13 +7,13 @@
|
|||
<!-- One maintainer tag required, multiple allowed, one person per tag -->
|
||||
<!-- Example: -->
|
||||
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
|
||||
<maintainer email="fei@todo.todo">fei</maintainer>
|
||||
<maintainer email="feixia@stanford.edu">Fei Xia</maintainer>
|
||||
|
||||
|
||||
<!-- One license tag required, multiple allowed, one license per tag -->
|
||||
<!-- Commonly used license strings: -->
|
||||
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
|
||||
<license>TODO</license>
|
||||
<license>MIT</license>
|
||||
|
||||
|
||||
<!-- Url tags are optional, but multiple are allowed, one per tag -->
|
||||
|
|
|
@ -75,19 +75,6 @@ class StadiumScene(Scene):
|
|||
def reset_floor(self, floor=0, additional_elevation=0.05, height=None):
|
||||
return
|
||||
|
||||
# TODO: Merge InteractiveBuildingScene into BuildingScene
|
||||
class InteractiveBuildingScene(Scene):
|
||||
"""
|
||||
A simple stadium scene for debugging
|
||||
"""
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def load(self):
|
||||
filename = self.path
|
||||
body_id = p.loadURDF(filename, flags=p.URDF_USE_SELF_COLLISION_EXCLUDE_ALL_PARENTS)
|
||||
return [body_id]
|
||||
|
||||
|
||||
class BuildingScene(Scene):
|
||||
|
@ -128,6 +115,7 @@ class BuildingScene(Scene):
|
|||
self.num_waypoints = num_waypoints
|
||||
self.waypoint_interval = int(waypoint_resolution / trav_map_resolution)
|
||||
self.mesh_body_id = None
|
||||
self.floor_body_ids = []
|
||||
self.pybullet_load_texture = pybullet_load_texture
|
||||
|
||||
def load_floor_metadata(self):
|
||||
|
@ -174,7 +162,6 @@ class BuildingScene(Scene):
|
|||
textureUniqueId=texture_id)
|
||||
|
||||
def load_floor_planes(self):
|
||||
self.floor_body_ids = []
|
||||
if self.is_interactive:
|
||||
for f in range(len(self.floors)):
|
||||
# load the floor plane with the original floor texture for each floor
|
||||
|
@ -273,26 +260,37 @@ class BuildingScene(Scene):
|
|||
self.scene_objects = []
|
||||
self.scene_objects_pos = []
|
||||
scene_path = get_model_path(self.model_id)
|
||||
urdf_files = [item for item in os.listdir(scene_path) if item[-4:] == 'urdf']
|
||||
urdf_files = [item for item in os.listdir(scene_path) if item[-4:] == 'urdf' and item != 'scene.urdf']
|
||||
position_files = [item[:-4].replace('alignment_centered', 'pos') + 'txt' for item in urdf_files]
|
||||
for urdf_file, position_file in zip(urdf_files, position_files):
|
||||
print('loading urdf file {}'.format(urdf_file))
|
||||
with open(os.path.join(scene_path, position_file)) as f:
|
||||
pos = np.array([float(item) for item in f.readlines()[0].strip().split()])
|
||||
# filter out duplicate annotations for the same object
|
||||
if len(self.scene_objects_pos) == 0 or \
|
||||
np.min(np.linalg.norm(np.array(self.scene_objects_pos) - pos, axis=1)) > 0.5:
|
||||
obj = InteractiveObj(os.path.join(scene_path, urdf_file))
|
||||
obj.load()
|
||||
self.scene_objects.append(obj)
|
||||
self.scene_objects_pos.append(pos)
|
||||
#if len(self.scene_objects_pos) == 0 or \
|
||||
# np.min(np.linalg.norm(np.array(self.scene_objects_pos) - pos, axis=1)) > 0.5:
|
||||
obj = InteractiveObj(os.path.join(scene_path, urdf_file))
|
||||
obj.load()
|
||||
self.scene_objects.append(obj)
|
||||
self.scene_objects_pos.append(pos)
|
||||
|
||||
def load_scene_urdf(self):
|
||||
self.mesh_body_id = p.loadURDF(os.path.join(get_model_path(self.model_id), 'scene.urdf'))
|
||||
|
||||
def has_scene_urdf(self):
|
||||
return os.path.exists(os.path.join(get_model_path(self.model_id), 'scene.urdf'))
|
||||
|
||||
def load(self):
|
||||
"""
|
||||
Initialize scene
|
||||
"""
|
||||
self.load_floor_metadata()
|
||||
self.load_scene_mesh()
|
||||
self.load_floor_planes()
|
||||
if self.has_scene_urdf():
|
||||
self.load_scene_urdf()
|
||||
else:
|
||||
self.load_scene_mesh()
|
||||
self.load_floor_planes()
|
||||
|
||||
self.load_trav_map()
|
||||
self.load_scene_objects()
|
||||
self.reset_scene_objects()
|
||||
|
|
|
@ -184,7 +184,10 @@ class Simulator:
|
|||
if type == p.GEOM_MESH:
|
||||
filename = filename.decode('utf-8')
|
||||
# print(filename, self.visual_objects)
|
||||
self.renderer.load_object(filename)
|
||||
self.renderer.load_object(filename,
|
||||
transform_orn=rel_orn,
|
||||
transform_pos=rel_pos,
|
||||
scale=np.array(dimensions))
|
||||
self.visual_objects[filename] = len(self.renderer.visual_objects) - 1
|
||||
self.renderer.add_instance(len(self.renderer.visual_objects) - 1,
|
||||
pybullet_uuid=new_object,
|
||||
|
|
|
@ -8,11 +8,12 @@ import pybullet as p
|
|||
import numpy as np
|
||||
import os
|
||||
import gibson2
|
||||
from gibson2.utils.assets_utils import download_data
|
||||
from gibson2.utils.assets_utils import download_assets,download_demo_data
|
||||
|
||||
class Demo(object):
|
||||
def __init__(self):
|
||||
download_data()
|
||||
download_assets()
|
||||
download_demo_data()
|
||||
|
||||
def run_demo(self):
|
||||
config = parse_config(os.path.join(gibson2.assets_path, '../../examples/configs/turtlebot_demo.yaml'))
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
import yaml
|
||||
from gibson2.core.physics.robot_locomotors import Turtlebot
|
||||
from gibson2.core.simulator import Simulator
|
||||
from gibson2.core.physics.scene import BuildingScene, StadiumScene, InteractiveBuildingScene
|
||||
from gibson2.core.physics.scene import BuildingScene, StadiumScene
|
||||
from gibson2.utils.utils import parse_config
|
||||
import pytest
|
||||
import pybullet as p
|
||||
import numpy as np
|
||||
import os
|
||||
import gibson2
|
||||
from gibson2.utils.assets_utils import download_data
|
||||
from gibson2.utils.assets_utils import download_assets,download_demo_data
|
||||
|
||||
class DemoInteractive(object):
|
||||
def __init__(self):
|
||||
download_data()
|
||||
download_assets()
|
||||
download_demo_data()
|
||||
|
||||
def run_demo(self):
|
||||
config = parse_config(os.path.join(gibson2.assets_path, '../../examples/configs/turtlebot_demo.yaml'))
|
||||
s = Simulator(mode='gui', image_width=700, image_height=700)
|
||||
model_path = os.path.join(gibson2.dataset_path, 'Rs_interactive', 'rs_interactive.urdf')
|
||||
scene = InteractiveBuildingScene(model_path)
|
||||
scene = BuildingScene('Rs_interactive', is_interactive=True)
|
||||
s.import_scene(scene)
|
||||
turtlebot = Turtlebot(config)
|
||||
s.import_robot(turtlebot)
|
||||
|
|
|
@ -25,6 +25,14 @@ def get_texture_file(mesh_file):
|
|||
|
||||
return texture_file
|
||||
|
||||
def download_data():
|
||||
download_assets()
|
||||
if not os.path.exists(gibson2.dataset_path):
|
||||
os.makedirs(gibson2.dataset_path)
|
||||
if not os.path.exists(os.path.join(gibson2.dataset_path, 'Rs')):
|
||||
os.system('wget https://storage.googleapis.com/gibson_scenes/Rs.tar.gz -O /tmp/Rs.tar.gz')
|
||||
os.system('tar -zxf /tmp/Rs.tar.gz --directory {}'.format(gibson2.dataset_path))
|
||||
|
||||
def download_assets():
|
||||
if not os.path.exists(gibson2.assets_path):
|
||||
os.system('wget https://storage.googleapis.com/gibson_scenes/assets_igibson.tar.gz -O /tmp/assets_igibson.tar.gz')
|
||||
|
|
Loading…
Reference in New Issue