-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSVSCommands.py
84 lines (70 loc) · 3.5 KB
/
SVSCommands.py
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
"""
This module defines a set of methods that generate SVS string commands
"""
class SVSCommands:
""" Contains static methods that generate SVS string commands
These can then be passed to agent.SendSVSCommands
Note that all transforms (pos, rot, scale) should be lists of 3 floats
"""
@staticmethod
def pos_to_str(pos):
""" Returns a string of 3 space-separated position values """
return "{:f} {:f} {:f}".format(pos[0], pos[1], pos[2])
@staticmethod
def rot_to_str(rot):
""" Returns a string of 3 space-separated rotation values """
return "{:f} {:f} {:f}".format(rot[0], rot[1], rot[2])
@staticmethod
def scl_to_str(scl):
""" Returns a string of 3 space-separated scale values """
return "{:f} {:f} {:f}".format(scl[0], scl[1], scl[2])
@staticmethod
def bbox_verts():
""" Returns a string of 8 vertices (24 numbers) forming a bounding box
It is of unit size centered at the origin
"""
return "0.5 0.5 0.5 0.5 0.5 -0.5 0.5 -0.5 0.5 0.5 -0.5 -0.5 -0.5 0.5 0.5 -0.5 0.5 -0.5 -0.5 -0.5 0.5 -0.5 -0.5 -0.5"
@staticmethod
def add_node(node_id, pos=None, rot=None, scl=None, parent="world"):
""" Returns an SVS command for adding a graph node to the scene (no geometry) """
cmd = "add {:s} {:s} ".format(node_id, parent)
if pos: cmd += " p {:s}".format(SVSCommands.pos_to_str(pos))
if rot: cmd += " r {:s}".format(SVSCommands.rot_to_str(rot))
if scl: cmd += " s {:s}".format(SVSCommands.scl_to_str(scl))
return cmd
@staticmethod
def add_box(obj_id, pos=None, rot=None, scl=None, parent="world"):
""" Returns an SVS command for adding a bounding box object to the scene """
cmd = "add {:s} {:s} v {:s}".format(obj_id, parent, SVSCommands.bbox_verts())
if pos: cmd += " p {:s}".format(SVSCommands.pos_to_str(pos))
if rot: cmd += " r {:s}".format(SVSCommands.rot_to_str(rot))
if scl: cmd += " s {:s}".format(SVSCommands.scl_to_str(scl))
return cmd
@staticmethod
def change_pos(obj_id, pos):
""" Returns an SVS command for changing the position of an svs object """
return "change {:s} p {:s}".format(obj_id, SVSCommands.pos_to_str(pos))
@staticmethod
def change_rot(obj_id, rot):
""" Returns an SVS command for changing the rotation of an svs object """
return "change {:s} r {:s}".format(obj_id, SVSCommands.rot_to_str(rot))
@staticmethod
def change_scl(obj_id, scl):
""" Returns an SVS command for changing the scale of an svs object """
return "change {:s} s {:s}".format(obj_id, SVSCommands.scl_to_str(scl))
@staticmethod
def delete(obj_id):
""" Returns an SVS command for deleting an object """
return "delete {:s}".format(obj_id)
@staticmethod
def add_tag(obj_id, tag_name, tag_value):
""" Returns an SVS command for adding a tag to an object (^name value) """
return "tag add {:s} {:s} {:s}".format(obj_id, tag_name, tag_value)
@staticmethod
def change_tag(obj_id, tag_name, tag_value):
""" Returns an SVS command for changing a tag on an object (^name value) """
return "tag change {:s} {:s} {:s}".format(obj_id, tag_name, tag_value)
@staticmethod
def delete_tag(obj_id, tag_name):
""" Returns an SVS command for deleting a tag with the given name from an object """
return "tag delete {:s} {:s}".format(obj_id, tag_name)