Recursively rescales an entire subtree of an MJCF model.
(body, position_factor, size_factor)
| 19 | |
| 20 | |
| 21 | def rescale_subtree(body, position_factor, size_factor): |
| 22 | """Recursively rescales an entire subtree of an MJCF model.""" |
| 23 | for child in body.all_children(): |
| 24 | if child.tag == 'sensor': |
| 25 | continue |
| 26 | if getattr(child, 'fromto', None) is not None: |
| 27 | new_pos = position_factor * 0.5 * (child.fromto[3:] + child.fromto[:3]) |
| 28 | new_size = size_factor * 0.5 * (child.fromto[3:] - child.fromto[:3]) |
| 29 | child.fromto[:3] = new_pos - new_size |
| 30 | child.fromto[3:] = new_pos + new_size |
| 31 | if getattr(child, 'pos', None) is not None: |
| 32 | child.pos *= position_factor |
| 33 | if getattr(child, 'size', None) is not None: |
| 34 | child.size *= size_factor |
| 35 | if child.tag == 'body' or child.tag == 'worldbody': |
| 36 | rescale_subtree(child, position_factor, size_factor) |
| 37 | |
| 38 | |
| 39 | def rescale_humanoid(walker, position_factor, size_factor=None, mass=None): |
no test coverage detected
searching dependent graphs…