Skip to content

Commit 5b6ef2d

Browse files
yuvaltassacopybara-github
authored andcommitted
Add soccer pitch textures to pitch entity.
PiperOrigin-RevId: 304382332 Change-Id: Ibf1ec412f4343480156d24bfa321b879dd679e29
1 parent 8aaec9c commit 5b6ef2d

11 files changed

Lines changed: 28 additions & 5 deletions

File tree

dm_control/entities/props/position_detector.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from dm_control import mjcf
2424
import numpy as np
2525

26-
_RENDERED_HEIGHT_IN_2D_MODE = 0.1
26+
_RENDERED_HEIGHT_IN_2D_MODE = 0.01
2727

2828

2929
def _ensure_3d(pos):
@@ -62,7 +62,8 @@ def _build(self,
6262
size,
6363
inverted=False,
6464
visible=False,
65-
rgba=(1, 0, 0, 0.25),
65+
rgba=(1, 1, 1, 1),
66+
material=None,
6667
detected_rgba=(0, 1, 0, 0.25),
6768
name='position_detector'):
6869
"""Builds the detector.
@@ -81,6 +82,7 @@ def _build(self,
8182
but can be toggled on (e.g. in `dm_control.viewer`) for debugging
8283
purposes.
8384
rgba: (optional) The color to render when nothing is detected.
85+
material: (optional) The material of the position detector.
8486
detected_rgba: (optional) The color to render when an entity is detected.
8587
name: (optional) XML element name of this position detector.
8688
@@ -114,7 +116,7 @@ def _build(self,
114116
self._mjcf_root = mjcf.RootElement(model=name)
115117
self._site = self._mjcf_root.worldbody.add(
116118
'site', name='detection_zone', type='box',
117-
pos=render_pos, size=render_size, rgba=self._rgba)
119+
pos=render_pos, size=render_size, rgba=self._rgba, material=material)
118120
self._lower_site = self._mjcf_root.worldbody.add(
119121
'site', name='lower', pos=self._lower_3d, size=[0.05],
120122
rgba=self._rgba)
133 KB
Loading
61.4 KB
Loading
72.9 KB
Loading
33.1 KB
Loading
16 KB
Loading
9.13 KB
Loading
28.8 KB
Loading
14.2 KB
Loading

dm_control/locomotion/soccer/pitch.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,26 @@
1919
from __future__ import division
2020
from __future__ import print_function
2121

22+
import os
23+
2224
from absl import logging
2325
from dm_control import composer
26+
from dm_control import mjcf
2427
from dm_control.composer.variation import distributions
2528
from dm_control.entities import props
2629
from dm_control.locomotion.soccer import team
2730
import numpy as np
2831

32+
from dm_control.utils import io as resources
33+
34+
_ASSETS_PATH = os.path.join(os.path.dirname(__file__), 'assets', 'pitch')
35+
36+
37+
def _get_texture(name):
38+
contents = resources.GetResource(
39+
os.path.join(_ASSETS_PATH, '{}.png'.format(name)))
40+
return mjcf.Asset(contents, '.png')
41+
2942

3043
_TOP_CAMERA_Y_PADDING_FACTOR = 1.1
3144
_TOP_CAMERA_DISTANCE = 100.
@@ -168,11 +181,19 @@ def _build(self,
168181
self.attach(self._away_goal)
169182

170183
# Build inverted field position detectors.
184+
self._field_texture = self._mjcf_root.asset.add(
185+
'texture',
186+
type='2d',
187+
file=_get_texture('pitch_nologo_s'),
188+
name='fieldplane')
189+
self._field_material = self._mjcf_root.asset.add(
190+
'material', name='fieldplane', texture=self._field_texture)
191+
171192
self._field = props.PositionDetector(
172193
pos=(0, 0),
173194
size=(self._size[0] - 2 * goal_size[0],
174195
self._size[1] - 2 * goal_size[0]),
175-
rgba=(1, 0, 0, 0.1),
196+
material=self._field_material,
176197
inverted=True,
177198
visible=True,
178199
name='field')

0 commit comments

Comments
 (0)