Ejemplo n.º 1
0
def stretch_obj(scene: Scene, object_id, scale, position):
    if object_id in scene.all_objects:
        scene.update_object(
            scene.all_objects[object_id], scale=scale, position=position)
        print(f"Stretched {object_id}")
Ejemplo n.º 2
0
def opaque_obj(scene: Scene, object_id, opacity):
    if object_id in scene.all_objects:
        scene.update_object(scene.all_objects[object_id],
                            material=Material(transparent=True, opacity=opacity))
        print(f"Opaqued {object_id}")
Ejemplo n.º 3
0
def color_obj(scene: Scene, object_id, color):
    if object_id in scene.all_objects:
        scene.update_object(
            scene.all_objects[object_id], material=Material(color=color))
        print(f"Colored {object_id}")
Ejemplo n.º 4
0
# errors.py
#
# test printing tracebacks from exceptions when an error occurs
# should continue running mqtt loop, but print traceback

from arena import Scene

scene = Scene(host="arena.andrew.cmu.edu", realm="realm", scene="example")


@scene.run_once
def main():
    print("hello")
    print(1 / 0)  # should print traceback here!
    print("world")


@scene.run_forever
def forever():
    print("goodbye")
    print(iDontExist()
          )  # should print traceback here and stop running this task!
    print("planet")


scene.run_tasks()
Ejemplo n.º 5
0
 def __init__(self, scene: Scene, camname, mode, x=0, y=0, label="", parent=None,
              drop=None, color=CLR_BUTTON, enable=True, callback=None,
              btype=ButtonType.ACTION):
     self.scene = scene
     if label == "":
         label = mode.value
     if parent is None:
         parent = camname
         scale = Scale(0.1, 0.1, 0.01)
     else:
         scale = Scale(1, 1, 1)
     self.type = btype
     self.enabled = enable
     if enable:
         self.colorbut = color
     else:
         self.colorbut = CLR_BUTTON_DISABLED
     self.colortxt = CLR_BUTTON_TEXT
     if len(label) > 8:  # easier to read
         self.label = f"{label[:6]}..."
     else:
         self.label = label
     self.mode = mode
     self.dropdown = drop
     self.active = False
     if drop is None:
         obj_name = f"{camname}_button_{mode.value}"
     else:
         obj_name = f"{camname}_button_{mode.value}_{drop}"
     shape = Box.object_type
     if btype == ButtonType.TOGGLE:
         shape = Cylinder.object_type
         scale = Scale(scale.x / 2, scale.y, scale.z / 2)
     self.button = Object(  # box is main button
         object_id=obj_name,
         object_type=shape,
         parent=parent,
         material=Material(
             color=self.colorbut,
             transparent=True,
             opacity=OPC_BUTTON,
             shader="flat"),
         position=Position(x * 1.1, PANEL_RADIUS, y * -1.1),
         scale=scale,
         clickable=True,
         evt_handler=callback,
     )
     scene.add_object(self.button)
     scale = Scale(1, 1, 1)
     if btype == ButtonType.TOGGLE:
         scale = Scale(scale.x * 2, scale.y * 2, scale.z)
     self.text = Text(  # text child of button
         object_id=f"{self.button.object_id}_text",
         parent=self.button.object_id,
         text=self.label,
         # position inside to prevent ray events
         position=Position(0, -0.1, 0),
         rotation=Rotation(-0.7, 0, 0, 0.7),
         scale=scale,
         color=self.colortxt,
     )
     scene.add_object(self.text)
Ejemplo n.º 6
0
def parent_obj(scene: Scene, object_id, parent_id):
    if object_id in scene.all_objects:
        scene.update_object(scene.all_objects[object_id], parent=parent_id)
        print(f"{parent_id} adopted {object_id}")
Ejemplo n.º 7
0
def delete_obj(scene: Scene, object_id):
    if object_id in scene.all_objects:
        scene.delete_object(scene.all_objects[object_id])
        print(f"Deleted {object_id}")
Ejemplo n.º 8
0
def rotate_obj(scene: Scene, object_id, rotation):
    if object_id in scene.all_objects:
        scene.update_object(scene.all_objects[object_id], rotation=rotation)
        print(f"Rotated {object_id}")
Ejemplo n.º 9
0
def move_obj(scene: Scene, object_id, position):
    if object_id in scene.all_objects:
        scene.update_object(scene.all_objects[object_id], position=position)
        print(f"Relocated {object_id}")
Ejemplo n.º 10
0
def scale_obj(scene: Scene, object_id, scale):
    if object_id in scene.all_objects:
        scene.update_object(scene.all_objects[object_id], scale=scale)
        print(f"Scaled {object_id}")
Ejemplo n.º 11
0
                USERS[camname].set_textright(USERS[camname].typetext)


def end_program_callback(_scene):
    for camname in USERS:
        USERS[camname].delete()
    show_redpill_scene(False)
    # TODO: remove origin marker
    for objid in CONTROLS:
        for ctrl in CONTROLS[objid]:
            _scene.delete_object(CONTROLS[objid][ctrl])


# parse args and wait for events
init_args()
random.seed()
kwargs = {}
if PORT:
    kwargs["port"] = PORT
if NAMESPACE:
    kwargs["namespace"] = NAMESPACE
if DEBUG:
    kwargs["debug"] = DEBUG
scene = Scene(host=BROKER,
              realm=REALM,
              scene=SCENE,
              on_msg_callback=scene_callback,
              end_program_callback=end_program_callback,
              **kwargs)
scene.run_tasks()
Ejemplo n.º 12
0
# errors.py
#
# test printing tracebacks from exceptions when an error occurs
# should continue running mqtt loop, but print traceback

from arena import Scene

scene = Scene(host="arenaxr.org", scene="example")


@scene.run_once
def main():
    print("hello")
    print(1 / 0)  # should print traceback here!
    print("world")


@scene.run_forever
def forever():
    print("goodbye")
    print(iDontExist()
          )  # should print traceback here and stop running this task!
    print("planet")


scene.run_tasks()