fix: avoid remote Gazebo model lookups

This commit is contained in:
2026-08-05 16:51:21 +09:00
parent 37eeca2c83
commit 4da46838bf
@@ -21,6 +21,18 @@ HOUSE_FURNITURE_BOXES = {
'table_marble/': ('1.40 0.86 0.76', None), 'table_marble/': ('1.40 0.86 0.76', None),
} }
LOCAL_GROUND_PLANE_MODEL = ''' <model name="ground_plane">
<static>1</static>
<link name="link">
<collision name="collision"><geometry><plane><normal>0 0 1</normal><size>100 100</size></plane></geometry></collision>
<visual name="visual"><cast_shadows>false</cast_shadows><geometry><plane><normal>0 0 1</normal><size>100 100</size></plane></geometry><material><ambient>0.24 0.27 0.32 1</ambient><diffuse>0.24 0.27 0.32 1</diffuse></material></visual>
</link>
</model>'''
LOCAL_SUN_LIGHT = ''' <light type="directional" name="sun">
<cast_shadows>false</cast_shadows><pose>0 0 10 0 0 0</pose><diffuse>0.8 0.8 0.8 1</diffuse><specular>0.2 0.2 0.2 1</specular><direction>-0.5 0.1 -0.9</direction>
</light>'''
def replace_house_visual_meshes_with_boxes(house_model): def replace_house_visual_meshes_with_boxes(house_model):
"""Keep physical mesh collisions, but render furniture as inexpensive boxes.""" """Keep physical mesh collisions, but render furniture as inexpensive boxes."""
@@ -109,7 +121,14 @@ def create_flat_house_world(gazebo_dir):
) )
with open(world_path, 'r', encoding='utf-8') as source: with open(world_path, 'r', encoding='utf-8') as source:
flat_world = source.read().replace('model://turtlebot3_house', 'model://turtlebot3_house_flat') flat_world = source.read()
flat_world = flat_world.replace(
' <include>\n <uri>model://ground_plane</uri>\n </include>',
LOCAL_GROUND_PLANE_MODEL,
).replace(
' <include>\n <uri>model://sun</uri>\n </include>',
LOCAL_SUN_LIGHT,
).replace('model://turtlebot3_house', 'model://turtlebot3_house_flat')
flat_world_path = os.path.join(tempfile.gettempdir(), 'nav2_turtlebot3_house_flat.world') flat_world_path = os.path.join(tempfile.gettempdir(), 'nav2_turtlebot3_house_flat.world')
with open(flat_world_path, 'w', encoding='utf-8') as destination: with open(flat_world_path, 'w', encoding='utf-8') as destination:
@@ -119,6 +138,7 @@ def create_flat_house_world(gazebo_dir):
os.environ['GAZEBO_MODEL_PATH'] = os.pathsep.join( os.environ['GAZEBO_MODEL_PATH'] = os.pathsep.join(
part for part in (flat_models_dir, existing_model_path) if part part for part in (flat_models_dir, existing_model_path) if part
) )
os.environ['GAZEBO_MODEL_DATABASE_URI'] = ''
return flat_world_path return flat_world_path