Exemple #1
0
 def set_clipboard(self,
                   callback=None,
                   obj_type=arena.Shape.sphere,
                   scale=(0.05, 0.05, 0.05),
                   position=(0, 0, -CLIP_RADIUS),
                   color=(255, 255, 255),
                   url=""):
     self.clipboard = arena.Object(  # show item to be created
         objName=(self.camname + "_clipboard"),
         objType=obj_type,
         location=position,
         color=color,
         parent=self.camname,
         scale=scale,
         transparency=arena.Transparency(True, 0.4),
         url=url,
         clickable=True,
         callback=callback)
     self.cliptarget = arena.Object(  # add helper target object to find true origin
         objName=(self.camname + "_cliptarget"),
         objType=arena.Shape.circle,
         location=position,
         parent=self.camname,
         scale=(0.005, 0.005, 0.005),
         transparency=arena.Transparency(True, 0.4),
         clickable=True,
         callback=callback)
Exemple #2
0
def target3_handler(event=None):
    global target3
    if event.event_type == arena.EventType.mouseenter:
        target3.update(color=(0, 255, 0),
                       transparency=arena.Transparency(True, 0.5))
    if event.event_type == arena.EventType.mouseleave:
        target3.update(transparency=arena.Transparency(True, 0.0))
    if event.event_type == arena.EventType.mousedown:
        draw_ray(event.click_pos, event.position)
        target3.update(transparency=arena.Transparency(True, 0.0))
Exemple #3
0
def dir_clickers(object_id,
                 axis,
                 direction,
                 delim,
                 location,
                 color,
                 cones,
                 callback,
                 parent=""):
    if parent:
        location = (location[0] * 10, location[1] * 10, location[2] * 10)
    loc = location
    npos = 0.1
    if direction == "p":
        npos = -0.1
    if axis == "x":
        loc = (location[0] + npos, location[1], location[2])
    elif axis == "y":
        loc = (location[0], location[1] + npos, location[2])
    elif axis == "z":
        loc = (location[0], location[1], location[2] + npos)
    name = (object_id + delim + axis + "p_" + direction)
    CONTROLS[object_id][name] = (
        arena.Object(  # click object positive
            objType=arena.Shape.cone,
            objName=name,
            color=color,
            clickable=True,
            location=location,
            rotation=cones[axis + direction][0],
            scale=(0.05, 0.09, 0.05),
            transparency=arena.Transparency(True, arblib.OPC_CLINE),
            ttl=arblib.TTL_TEMP,
            parent=parent,
            callback=callback))
    name = (object_id + delim + axis + "n_" + direction)
    CONTROLS[object_id][name] = (
        arena.Object(  # click object negative
            objType=arena.Shape.cone,
            objName=name,
            color=color,
            clickable=True,
            location=loc,
            rotation=cones[axis + direction][1],
            scale=(0.05, 0.09, 0.05),
            transparency=arena.Transparency(True, arblib.OPC_CLINE),
            ttl=arblib.TTL_TEMP,
            parent=parent,
            callback=callback))
Exemple #4
0
    def __init__(self,
                 objName="error",
                 objType=arena.Shape.sphere,
                 color=(200, 0, 0),
                 scale=(0.2, 0.2, 0.2),
                 opacity=0.7,
                 pose_source=None,
                 target_source=None):

        self.base_opacity = opacity
        self.target_source = target_source
        self.target_location = (0, 0, 0)
        self.active = False

        self.service = rospy.Service(objName + "/toggle", Empty,
                                     self.toggle_viz)

        super().__init__(objName=objName,
                         objType=objType,
                         color=color,
                         scale=scale,
                         pose_source=pose_source)

        self.update(transparency=arena.Transparency(True, 0))

        self.register_sources()
Exemple #5
0
def agent_handler(event=None):
    global agent1
    global agentParent
    print("agent handler callback!")
    if event.event_type == arena.EventType.mouseenter:
        # Make it transparent on hover over
        agent1.update(transparency=arena.Transparency(True, 0.1))
    if event.event_type == arena.EventType.mouseleave:
        # Make it opaque, you can add color or other properties in the list
        agent1.update(transparency=arena.Transparency(True, 1.0))
    if event.event_type == arena.EventType.mousedown:
        # On click, draw a ray
        draw_ray(event.click_pos, event.position)
        agent1.update(transparency=arena.Transparency(True, 1.0))
        agentParent.update(location=(random.randrange(-10, 10), 0,
                                     random.randrange(-10, 1)))
Exemple #6
0
def temp_loc_marker(location, color):
    return arena.Object(objType=arena.Shape.sphere,
                        ttl=120,
                        color=color,
                        transparency=arena.Transparency(True, 0.5),
                        location=location,
                        scale=(0.02, 0.02, 0.02),
                        clickable=True)
Exemple #7
0
def projector_stop(event=None):
    global screens
    if event.event_type == arena.EventType.mouseup:
        local_screens = screens.copy()
        print("Start")
        for i in range(len(local_screens)):
            screen = local_screens.pop()
            print(screen)
            screen.update(transparency=arena.Transparency(True, 0.0))
Exemple #8
0
def handle_clickline_event(event, mode):
    # naming order: objectname_clicktype_axis_direction
    click_id = event.object_id.split("_" + mode.value + "_")
    object_id = click_id[0]
    direction = (click_id[1])[0:2]
    move = (click_id[1])[1:4]
    if event.event_type == arena.EventType.mouseenter:
        CONTROLS[object_id][event.object_id].update(
            transparency=arena.Transparency(True, arblib.OPC_CLINE_HOVER))
    elif event.event_type == arena.EventType.mouseleave:
        CONTROLS[object_id][event.object_id].update(
            transparency=arena.Transparency(True, arblib.OPC_CLINE))
    # allow any user to change an object
    if event.event_type != arena.EventType.mousedown:
        return None, None, None
    if USERS[event.source].mode != mode:
        return None, None, None
    pobjs = arena.get_network_persisted_obj(object_id, BROKER, SCENE)
    if not pobjs:
        return None, None, None
    obj = arblib.ObjectPersistence(pobjs[0])
    return (obj, direction, move)
Exemple #9
0
    def __init__(self,
                 objName="cube",
                 objType=arena.Shape.cube,
                 location=(0, 0, 0),
                 rotation=(0, 0, 0, 0),
                 location_offset=(0, 0, 0),
                 rotation_offset=(0, 0, 0, 1),
                 scale=(1, 1, 1),
                 color=(200, 200, 200),
                 hoverColor=(0, 200, 0),
                 activeColor=(200, 200, 0),
                 opacity=1,
                 url=None,
                 pose_source=None,
                 active_source=None,
                 ros_callback=None,
                 group_callback=None,
                 clickable=False):

        self.location = location
        self.rotation = rotation
        self.location_offset = location_offset
        self.rotation_offset = rotation_offset
        self.baseColor = color
        self.hoverColor = hoverColor
        self.activeColor = activeColor
        self.opacity = opacity
        self.pose_source = pose_source
        self.active_source = active_source
        self.ros_callback = ros_callback
        self.group_callback = group_callback
        self.hover = False
        self.active = False

        super().__init__(objName=objName,
                         objType=objType,
                         location=location,
                         rotation=rotation,
                         scale=scale,
                         color=color,
                         url=url,
                         ttl=2,
                         clickable=clickable,
                         callback=self.arena_callback)

        self.update(transparency=arena.Transparency(True, self.opacity))

        self.register_sources()
        self.register_services()
Exemple #10
0
def create_obj(camname, clipboard, location):
    randstr = str(random.randrange(0, 1000000))
    # make a copy of static object in place
    new_obj = arena.Object(
        persist=True,
        objName=clipboard.objType.name + "_" + randstr,
        objType=clipboard.objType,
        location=location,
        rotation=(0, 0, 0, 1),  # undo clipboard rotation for visibility
        scale=clipboard.scale,
        color=clipboard.color,
        transparency=arena.Transparency(False),
        url=clipboard.url,
        clickable=True)
    USERS[camname].target_id = new_obj.objName
    print("Created " + new_obj.objName)
Exemple #11
0
def initCube(x, y, color):
    name = "cube_" + str(x) + "_" + str(y)
    cubes[(x, y)] = childObject(
        objType=arena.Shape.cube,
        persist=True,
        objName=name,
        # messes up child-follow-parent pose
        # physics=arena.Physics.static,
        collision_listener=True,
        transparency=arena.Transparency(True,0.5),
        impulse=arena.Impulse("mouseup",(0,40,0),(10,1,1)),
        location=(x, y, -3),
        color=color,
        scale=(0.6, 0.6, 0.6),
        clickable=True,
        callback=guac_callback,
    )
Exemple #12
0
def show_redpill_scene(enabled):
    # any scene changes must not persist
    # show gridlines
    glen = arblib.GRIDLEN
    y = arblib.FLOOR_Y
    hcolor = arblib.rgb2hex(arblib.CLR_GRID)
    for z in range(-glen, glen + 1):
        name = "grid_z" + str(z)
        if enabled:
            arena.Object(objName=name,
                         objType=arena.Shape.line,
                         line=arena.Line((-glen, y, z), (glen, y, z), 1,
                                         hcolor))
        else:
            arblib.delete_obj(REALM, SCENE, name)
    for x in range(-glen, glen + 1):
        name = "grid_x" + str(x)
        if enabled:
            arena.Object(objName=name,
                         objType=arena.Shape.line,
                         line=arena.Line((x, y, -glen), (x, y, glen), 1,
                                         hcolor))
        else:
            arblib.delete_obj(REALM, SCENE, name)
    pobjs = arena.get_network_persisted_scene(BROKER, SCENE)
    for pobj in pobjs:
        obj = arblib.ObjectPersistence(pobj)
        # show occluded objects
        if obj.transparent_occlude:
            name = "redpill_" + obj.object_id
            if enabled:
                arena.Object(
                    objName=name,
                    objType=obj.object_type,
                    location=obj.position,
                    rotation=obj.rotation,
                    scale=obj.scale,
                    color=obj.color,
                    clickable=True,
                    url=obj.url,
                    transparency=arena.Transparency(True, 0.5),
                )
                print("Wrapping occlusion " + name)
            else:
                arblib.delete_obj(REALM, SCENE, name)
Exemple #13
0
def guac_callback(event=None):  # gets a GenericEvent

    global counter

    # only mousedown messages
    if event.event_type == arena.EventType.mousedown:

        # draw a ray from clicker to cube
        draw_ray(event.click_pos, event.position)

        color = redblue[counter % 2]
        x = int(event.object_id.split("_")[1])
        y = int(event.object_id.split("_")[2])
        if grid[(x - 1)][(y - 1)] != -1:
            return
        counter = counter + 1
        grid[(x - 1)][(y - 1)] = counter % 2
        cubes[(x, y)].update(
            #physics=arena.Physics.static,
            color=color,
            impulse=arena.Impulse("mouseup", (0, 10, 0), (10, 1, 1)),
            transparency=arena.Transparency(False, 1),
            clickable=True,
            location=(x, y, -3),
            scale=(0.6, 0.6, 0.6),
        )

        winColor = solved()
        if winColor != -1:
            draw_hud(winColor)
            print("solved")
            animate_win()
            draw_board()
        if stalemate():
            draw_hud(-1)
            print("stalemate")
            animate_loss()
            draw_board()

    else:
        return
Exemple #14
0
        if stalemate():
            draw_hud(-1)
            print("stalemate")
            animate_loss()
            draw_board()

    else:
        return


# start the fun shall we?

arena.init(HOST, REALM, SCENE)
# make a parent scene object
sceneParent = arena.Object(persist=False,
                           objName="sceneParent",
                           objType=arena.Shape.cube,
                           location=ORIGIN,
                           scale=(0.01, 0.01, 0.01),
                           transparency=arena.Transparency(True, 0))
print("starting main loop")
draw_board()
for x in range(-10, 10):
    for z in range(-10, 10):
        draw_ray(ORIGIN, (x, 10, z))
sceneParent.update(
    data=
    '{"animation": {"property": "scale","to": "0.1 0.1 0.1","easing": "linear","dur": 1000}}'
)
arena.handle_events()
Exemple #15
0
    def __init__(self, camname, panel_callback):
        self.camname = camname
        self.mode = Mode.NONE
        self.clipboard = self.cliptarget = None
        self.target_id = self.location = self.rotation = None
        self.target_style = self.typetext = ""
        self.locky = LOCK_YOFF
        self.lockx = LOCK_XOFF
        self.wloc_start = self.wloc_end = None
        self.wrot_start = self.wrot_end = None
        self.lamp = None
        init_origin()

        # set HUD to each user
        self.hudtext_left = self.make_hudtext("hudTextLeft",
                                              (-0.15, 0.15, -0.5),
                                              str(self.mode))
        self.hudtext_right = self.make_hudtext("hudTextRight",
                                               (0.1, 0.15, -0.5), "")
        self.hudtext_status = self.make_hudtext("hudTextStatus",
                                                (0.02, -0.15, -0.5),
                                                "")  # workaround x=0 bad?

        # AR Control Panel
        self.follow_lock = False
        self.follow = arena.Object(
            objName=("follow_" + camname),
            objType=arena.Shape.cube,
            parent=camname,
            transparency=arena.Transparency(True, 0),
            location=(0, 0, -PANEL_RADIUS * 0.1),
            scale=(0.1, 0.01, 0.1),
            rotation=(0.7, 0, 0, 0.7),
        )
        self.redpill = False
        self.panel = {}  # button dictionary
        followname = self.follow.objName
        self.dbuttons = {}
        buttons = [
            # top row
            [Mode.ROTATE, -2, 1, True, ButtonType.ACTION],
            [Mode.NUDGE, -1, 1, True, ButtonType.ACTION],
            [Mode.SCALE, 0, 1, True, ButtonType.ACTION],
            [Mode.STRETCH, 1, 1, True, ButtonType.ACTION],
            [Mode.MODEL, 2, 1, True, ButtonType.ACTION],
            [Mode.CREATE, 3, 1, True, ButtonType.ACTION],
            # center row
            [Mode.REDPILL, -2, 0, True, ButtonType.TOGGLE],
            [Mode.MOVE, -1, 0, True, ButtonType.ACTION],
            [Mode.LOCK, 0, 0, True, ButtonType.TOGGLE],
            [Mode.DELETE, 1, 0, True, ButtonType.ACTION],
            [Mode.PARENT, 2, 0, True, ButtonType.ACTION],
            # bottom row
            [Mode.WALL, -2, -1, True, ButtonType.ACTION],
            [Mode.OCCLUDE, -1, -1, True, ButtonType.ACTION],
            [Mode.RENAME, 0, -1, True, ButtonType.ACTION],
            [Mode.COLOR, 1, -1, True, ButtonType.ACTION],
            [Mode.LAMP, 2, -1, True, ButtonType.TOGGLE],
        ]
        for but in buttons:
            pbutton = Button(camname,
                             but[0],
                             but[1],
                             but[2],
                             enable=but[3],
                             btype=but[4],
                             parent=followname,
                             callback=panel_callback)
            self.panel[pbutton.button.objName] = pbutton
Exemple #16
0
 def deactivate(self):
     self.active = False
     self.update(transparency=arena.Transparency(True, 0))
Exemple #17
0
 def activate(self):
     self.active = True
     self.update(transparency=arena.Transparency(True, self.base_opacity))
Exemple #18
0
def make_wall(camname):
    # Wall theory: capture two poses and use them to place a wall object.
    # Also assumes first corner easier to capture accurate rotation than last.
    # Click 1: Capture the position and rotation.
    # Click 2: Capture the position only.
    sloc = USERS[camname].wloc_start
    eloc = USERS[camname].wloc_end
    srot = USERS[camname].wrot_start
    erot = USERS[camname].wrot_end
    print("S POS " + str((sloc[0], sloc[1], sloc[2])))
    print("E POS " + str((eloc[0], eloc[1], eloc[2])))
    # center point (blue)
    locx = arena.agran(statistics.median([sloc[0], eloc[0]]))
    locy = arena.agran(statistics.median([sloc[1], eloc[1]]))
    locz = arena.agran(statistics.median([sloc[2], eloc[2]]))
    arblib.temp_loc_marker((locx, locy, locz), (0, 0, 255))
    print("wall position " + str((locx, locy, locz)))
    # rotation
    print("S ROT " + str((srot[0], srot[1], srot[2], srot[3])))
    print("E ROT " + str((erot[0], erot[1], erot[2], erot[3])))
    rotx = arblib.probable_quat(srot[0])
    roty = arblib.probable_quat(srot[1])
    rotz = arblib.probable_quat(srot[2])
    rotw = arblib.probable_quat(srot[3])
    rot = (rotx, roty, rotz, rotw)
    arblib.temp_rot_marker((locx, locy, locz), rot)
    print("wall rotation " + str(rot))
    # which axis to use for wall? use camera gaze
    # TODO: rotation still off
    if rot in arblib.GAZES[0]:
        height = abs(sloc[1] - eloc[1])
        width = abs(sloc[0] - eloc[0])
    elif rot in arblib.GAZES[1]:
        height = abs(sloc[1] - eloc[1])
        width = abs(sloc[2] - eloc[2])
    elif rot in arblib.GAZES[2]:
        height = abs(sloc[2] - eloc[2])
        width = abs(sloc[0] - eloc[0])
    else:
        # TODO: (placeholder) add direction and hypotenuse
        height = abs(sloc[1] - eloc[1])
        width = abs(sloc[0] - eloc[0])
        print("Non-axis parallel rotation: " + str(rot))
    # scale
    scax = width
    scay = height
    scaz = arblib.WALL_WIDTH
    print("wall scale " + str((scax, scay, scaz)))
    # make wall
    randstr = str(random.randrange(0, 1000000))
    new_wall = arena.Object(
        persist=True,
        clickable=True,
        objName="wall_" + randstr,
        objType=arena.Shape.cube,
        location=(locx, locy, locz),
        rotation=(rotx, roty, rotz, rotw),
        scale=(scax, scay, scaz),
        color=(200, 200, 200),
        transparency=arena.Transparency(True, 0.5),
    )
    USERS[camname].target_id = new_wall.objName
    print("Created " + new_wall.objName + " r" +
          str((rotx, roty, rotz, rotw)) + " s" + str((scax, scay, scaz)))
Exemple #19
0
def signal_handler(sig, frame):
    exit()


signal.signal(signal.SIGINT, signal_handler)

cube = arena.Object(
    objName="cube_1", objType=arena.Shape.cube, location=(1, 1, -1), color=(255, 0, 0)
)
input("")

cube.update(color=(0, 255, 0))
input("")

cube.update(transparency=arena.Transparency(True, 0.5))
input("")

cube.update(location=(2, 2, -1))
input("")

cube.update(rotation=(0.4, 0.4, 0.4, 0.4))
input("")

cube.update(
    data='{"animation": {"property":"rotation", "to":"0 360 0", "loop":"true", "dur":10000}}'
)
input("")

cube.delete()
input("")