FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
duobench/scripts/scale_gray_microwave.py at master · RobotControlStack/duobench · GitHub
RobotControlStack
/
duobench
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
19
Code
Issues
2
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
duobench
/
scripts
/
scale_gray_microwave.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (52 loc) · 1.97 KB
Breadcrumbs
duobench
/
scripts
/
scale_gray_microwave.py
Copy path
File metadata and controls
68 lines (52 loc) · 1.97 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
"""Scale MuJoCo size values and local positional offsets in gray_microwave.xml."""
import
argparse
import
xml
.
etree
.
ElementTree
as
ET
from
pathlib
import
Path
DEFAULT_INPUT
=
Path
(
"assets/objects/spring_door/gray_microwave_original.xml"
)
DEFAULT_OUTPUT
=
Path
(
"assets/objects/spring_door/gray_microwave.xml"
)
def
parse_args
()
->
argparse
.
Namespace
:
parser
=
argparse
.
ArgumentParser
(
description
=
(
"Parse gray_microwave.xml, scale local geometry values, and write "
"the output XML."
)
)
parser
.
add_argument
(
"scale_float"
,
type
=
float
,
help
=
"Scale factor applied to every number in each `size` attribute."
,
)
parser
.
add_argument
(
"--input"
,
type
=
Path
,
default
=
DEFAULT_INPUT
,
help
=
f"Input XML path. Defaults to
{
DEFAULT_INPUT
}
."
,
)
parser
.
add_argument
(
"--output"
,
type
=
Path
,
default
=
DEFAULT_OUTPUT
,
help
=
f"Output XML path. Defaults to
{
DEFAULT_OUTPUT
}
."
,
)
return
parser
.
parse_args
()
def
scale_vector_value
(
vector_value
:
str
,
scale_float
:
float
)
->
str
:
scaled
=
[
f"
{
float
(
part
)
*
scale_float
:.9g
}
"
for
part
in
vector_value
.
split
()]
return
" "
.
join
(
scaled
)
def
main
()
->
None
:
args
=
parse_args
()
tree
=
ET
.
parse
(
args
.
input
)
root
=
tree
.
getroot
()
pos_tags
=
{
"body"
,
"geom"
,
"joint"
,
"inertial"
,
"site"
,
"camera"
,
"light"
}
for
element
in
root
.
iter
():
size_value
=
element
.
get
(
"size"
)
if
size_value
is
not
None
:
element
.
set
(
"size"
,
scale_vector_value
(
size_value
,
args
.
scale_float
))
pos_value
=
element
.
get
(
"pos"
)
if
pos_value
is
not
None
and
element
.
tag
in
pos_tags
:
element
.
set
(
"pos"
,
scale_vector_value
(
pos_value
,
args
.
scale_float
))
ET
.
indent
(
tree
,
space
=
" "
)
args
.
output
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
tree
.
write
(
args
.
output
,
encoding
=
"utf-8"
,
xml_declaration
=
False
)
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL