-
Notifications
You must be signed in to change notification settings - Fork 745
Expand file tree
/
Copy patharenas.py
More file actions
99 lines (86 loc) · 2.92 KB
/
arenas.py
File metadata and controls
99 lines (86 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright 2018 The dm_control Authors.
#
# 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.
# ============================================================================
"""Suite-specific arena class."""
from dm_control import composer
class Standard(composer.Arena):
"""Suite-specific subclass of the standard Composer arena."""
def _build(self, name=None):
"""Initializes this arena.
Args:
name: (optional) A string, the name of this arena. If `None`, use the
model name defined in the MJCF file.
"""
super()._build(name=name)
# Add visual assets.
self.mjcf_model.asset.add(
'texture',
type='skybox',
builtin='gradient',
rgb1=(0.4, 0.6, 0.8),
rgb2=(0., 0., 0.),
width=100,
height=100)
groundplane_texture = self.mjcf_model.asset.add(
'texture',
name='groundplane',
type='2d',
builtin='checker',
rgb1=(0.2, 0.3, 0.4),
rgb2=(0.1, 0.2, 0.3),
width=300,
height=300,
mark='edge',
markrgb=(.8, .8, .8))
groundplane_material = self.mjcf_model.asset.add(
'material',
name='groundplane',
texture=groundplane_texture,
texrepeat=(5, 5),
texuniform='true',
reflectance=0.2)
# Add ground plane.
self.mjcf_model.worldbody.add(
'geom',
name='ground',
type='plane',
material=groundplane_material,
size=(1, 1, 0.1),
friction=(0.4,),
solimp=(0.95, 0.99, 0.001),
solref=(0.002, 1))
# Add lighting
self.mjcf_model.worldbody.add(
'light',
pos=(0, 0, 1.5),
dir=(0, 0, -1),
diffuse=(0.7, 0.7, 0.7),
specular=(.3, .3, .3),
directional='false',
castshadow='true')
# Always initialize the free camera so that it points at the origin.
self.mjcf_model.statistic.center = (0., 0., 0.)
def attach_offset(self, entity, offset, attach_site=None):
"""Attaches another entity at a position offset from the attachment site.
Args:
entity: The `Entity` to attach.
offset: A length 3 array-like object representing the XYZ offset.
attach_site: (optional) The site to which to attach the entity's model.
If not set, defaults to self.attachment_site.
Returns:
The frame of the attached model.
"""
frame = self.attach(entity, attach_site=attach_site)
frame.pos = offset
return frame