def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'hs:', ['scene=']) except getopt.GetoptError: printhelp() sys.exit(1) scene = None for opt, arg in opts: if opt == '-h': printhelp() sys.exit(1) elif opt in ('-s', '--scene'): scene = arg else: printhelp() sys.exit(1) if scene is None: printhelp() sys.exit(1) print('Scene:', scene) arena.init(BROKER, REALM, scene) print('Go to URL: https://xr.andrew.cmu.edu/?networkedTagSolver=true&scene=' + scene + '&fixedCamera=<username>') arena.add_topic(TOPIC, on_tag_detect) arena.handle_events()
def arena_init(): arena.init("arena.andrew.cmu.edu", "realm", "patrick_scene", scene_callback) temperature_text = arena.Object(objName="temperature_text", objType=arena.Shape.text, color=(255, 0, 0), location=(-1, 2, -3), text="Hello world! The temperature is: 0") humidity_text = arena.Object(objName="humidity_text", objType=arena.Shape.text, color=(255, 0, 0), location=(-1, 1, -3), text="Hello world! The humidity is: 0") start_serial(temperature_text, humidity_text) arena.handle_events()
def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'hs:u:', ['scene=', 'userfile=']) except getopt.GetoptError: printhelp() sys.exit(1) scene = None userfile = None for opt, arg in opts: if opt == '-h': printhelp() sys.exit(1) elif opt in ('-s', '--scene'): scene = arg elif opt in ('-u', '--userfile'): userfile = arg else: printhelp() sys.exit(1) if scene is None or userfile is None: printhelp() sys.exit(1) with open(userfile, 'r') as f: config = json.load(f, object_hook=dict_to_sns) arena.init(BROKER, REALM, scene) for user in config: arenanames[user.uwbname] = user.arenaname if user.static: users[user.client_id] = StaticUser(user) else: users[user.client_id] = SyncUser(user) print( "Go to URL: https://xr.andrew.cmu.edu/?networkedTagSolver=true&scene=" + scene + "&fixedCamera=" + user.arenaname) scene.add_topic(TOPIC_DETECT, on_tag_detect) scene.add_topic(TOPIC_VIO, on_vio) scene.add_topic(TOPIC_UWB, on_uwb) arena.handle_events()
def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'hs:', ['scene=']) except getopt.GetoptError: printhelp() sys.exit(1) scene = None for opt, arg in opts: if opt == '-h': printhelp() sys.exit(1) elif opt in ('-s', '--scene'): scene = arg else: printhelp() sys.exit(1) if scene is None or userfile is None: printhelp() sys.exit(1) arena.init(BROKER, REALM, scene) print("Go to URL: https://xr.andrew.cmu.edu/?scene=" + scene) arena.handle_events()
return # Check for mouseenter events # the obj vars are arena objects # the state vars are just ints that hold if the light is on/off if jsonMsg["type"] == "mouseenter": name = jsonMsg["object_id"] numname = name.split("_") #1 is x, 2 is y x = int(numname[1]) y = int(numname[2]) icon_select(x, y) # Check for mouseleve events if jsonMsg["type"] == "mouseleave": name = jsonMsg["object_id"] numname = name.split("_") #1 is x, 2 is y x = int(numname[1]) y = int(numname[2]) icon_unselect(x, y) if jsonMsg["type"] == "mousedown": name = jsonMsg["object_id"] numname = name.split("_") #1 is x, 2 is y x = int(numname[1]) y = int(numname[2]) icon_click(x, y) arena.init(HOST, REALM, SCENE, scene_callback) print("starting main loop") draw_board() arena.handle_events()
import arena arena.init("oz.andrew.cmu.edu", "realm", "hello") arena.Object(arena.Shape.cube) arena.handle_events()
# hello2.py # demonstrate receiving ARENA callback (JSON) messages import arena def scene_callback(msg): print("scene_callback: ", msg) arena.init("arena.andrew.cmu.edu", "realm", "example", scene_callback) # synchronous draw commands cube = arena.Object(objType=arena.Shape.cube, clickable=True) # our main event loop arena.handle_events()
def remove_objects(): print("Cleaning up objects") for entity in objects: print("Removing {}".format(entity.objName)) entity.delete() if __name__ == '__main__': rospy.init_node('RArena_node') # rospy.on_shutdown(remove_objects) # # Instatiate the MQTT client class print("Connecting to broker: ", mqtt_broker) arena.init(mqtt_broker, "realm", "drone", cleanup=remove_objects) remove_objects() generate_objects() if status_topic: rospy.Subscriber(status_topic, NetworkStatusMsg, status_callback) rospy.loginfo("Subscribed to: {}".format(status_topic)) rate = rospy.Rate(10) while not rospy.is_shutdown(): # Hack to deal with areana.handle_events blocking. while len(arena.messages) > 0: arena.process_message(arena.messages.pop(0)) update_objects() rate.sleep()
if jsonMsg["type"] == "mousedown": name = jsonMsg["object_id"] if name == "pendant": # The "3" is the lutron id for that light pendant_state = light_toggle(pendant_obj, pendant_state, "2") if name == "pantry": # The "4" is the lutron id for that light pantry_state = light_toggle(pantry_obj, pantry_state, "4") if name == "cabinet": cabinet_state = light_toggle(cabinet_obj, cabinet_state, "7") # open a telnet (sigh) connection to to lutron caseta system lutron_connect() arena.init(HOST, "realm", SCENE, scene_callback) print("setting up objects") arena.Object(objType=arena.Shape.cube, objName="origin", location=(0, 0, 0), color=(0, 0, 255), scale=(0.1, 0.1, 0.1), persist=True) arena.Object(objType=arena.Shape.cube, objName="wall1", location=(1.5, 1.25, -3.90), color=(100, 100, 100), scale=(0.3, 3.0, 6.2), persist=True, data='{"material":{"colorWrite": false}, "render-order": "0"}')
print("solved") animate_win() draw_board() 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}}'
elif USERS[camname].mode == Mode.OCCLUDE: arblib.occlude_obj(REALM, SCENE, objid, USERS[camname].target_style) elif USERS[camname].mode == Mode.RENAME or USERS[ camname].mode == Mode.PARENT: if len(USERS[camname].typetext) > 0: # edits already made new_id = USERS[camname].typetext USERS[camname].typetext = "" if USERS[camname].mode == Mode.PARENT: arblib.parent_obj(REALM, SCENE, objid, new_id) else: do_rename(camname, objid, new_id) else: # no edits yet, load previous name to change USERS[camname].typetext = objid USERS[camname].set_textright(USERS[camname].typetext) # parse args and wait for events init_args() random.seed() if DEMO: arena.init(BROKER, REALM, SCENE, port=PORT, callback=scene_callback, democlick=(400, -250)) else: arena.init(BROKER, REALM, SCENE, port=PORT, callback=scene_callback) arena.handle_events()
for opt, arg in opts: if opt == '-h': print("tracer.py -s <scene> -u <fixedCamera> -c <r,g,b> ") print(" ex: python3 tracer.py -s myScene -u myCamera -c 255,0,0") sys.exit() elif opt in ("-s", "--scene"): SCENE = arg elif opt in ("-u", "--user"): fixedCamera = arg elif opt in ("-c", "--color"): cam_color = arg.split(',') print("Scene: " + SCENE) print("fixedCamera: " + fixedCamera) print("color: " + str(cam_color)) arena.init("arena.andrew.cmu.edu", "realm", SCENE) cameraStr = "camera_" + fixedCamera + "_" + fixedCamera my_camera = arena.Object(objName=cameraStr, transparency=arena.Transparency(True, 0), callback=camera_callback, persist=False) print("Go to URL: https://arena.andrew.cmu.edu/?scene=" + SCENE + "&fixedCamera=" + fixedCamera) # our main event loop arena.handle_events()
# balls.py # import arena arena.init("arena.andrew.cmu.edu", "realm", "example") arena.Object(objType=arena.Shape.cone, location=(1, 0, -3)) arena.handle_events()
# Size Update (Larger = More moist) size_output = 1.0 + output size_output = max(min(size_output, 1.5), 1.0) map_cube.update(scale=(size_output, size_output, size_output)) time.sleep(0.1) ser.close() def scene_callback(msg): print("scene_callback: ", msg) arena.init("arena.andrew.cmu.edu", "realm", "patrick_scene") #, scene_callback) ''' Stove ''' ''' Turns the stove on and off ''' stove_status = False def stove_button_callback(event): global stove_status global stove_cube global stove_light global stove_text if event.event_type == arena.EventType.mousedown:
import arena arena.init("arena.andrew.cmu.edu", "realm", "headsup-dev-test") testUI = arena.Object(objName="a-testUI") testUI.delete()
x = int(name.split("_")[1]) y = int(name.split("_")[2]) if grid[(x - 1)][(y - 1)] != -1: return counter = counter + 1 grid[(x - 1)][(y - 1)] = counter % 2 colstring = '#%02x%02x%02x' % color cubes[(x,y)].update(physics=arena.Physics.static, data='{"impulse": {"on": "mouseup","force":"0 40 0","position":"10 1 1"},"material": {"color":"'+ colstring+'", "transparent": false, "opacity": 1}}', clickable=True, location=(x,y,-3), scale=(0.6, 0.6, 0.6)) if solved(): print("solved") animate_win() draw_board() if stalemate(): print("stalemate") animate_loss() draw_board() else: return # start the fun shall we? arena.init(HOST, REALM, SCENE, process_message) print("starting main loop") draw_board() arena.handle_events()
All: https://arenaxr.org/volatile ''' # [TODO] update this to 0.1.0! import arena def tag_callback(event=None): ''' Since we expect the position/rotation updates, we can react here. ''' if event.event_action == arena.EventAction.update and \ event.event_type == arena.EventType.object: print("Tag position: " + str(event.position)) print("Tag rotation: " + str(event.rotation)) arena.init("arenaxr.org", "realm", "example") # apriltag_450 will receive position/rotation updates so don't set them TAG = arena.Object(objName="apriltag_450", transparency=arena.Transparency(True, 0), callback=tag_callback, persist=True) # duck as child to it can can be rotated relative to apriltag arena.Object(objName="duck", objType=arena.Shape.gltf_model, scale=(0.1, 0.1, 0.1), rotation=(0.7, 0, 0, 0.7), parent=TAG.objName, url="models/Duck.glb", persist=True) # our main event loop
import sys import time import arena arena.init("oz.andrew.cmu.edu", "realm", "render") # Draw origin cube rotation = (0.0, 0.0, 0.0, 0.0) scale = (0.1, 0.1, 0.1) color = (255, 0, 0) location = (0, 0, 0) originCube = arena.Object(location=location, rotation=rotation, scale=scale, color=color) color = (0, 255, 0) # Draw UWB tag locations location = (1.079, 0.789, 0.071) arena.Object(location=location, rotation=rotation, scale=scale, color=color) location = (1.079, 0.789, 0.778) arena.Object(location=location, rotation=rotation, scale=scale, color=color) location = (2.674, 0.789, 0.071) arena.Object(location=location, rotation=rotation, scale=scale, color=color) location = (2.674, 0.789, 0.778) arena.Object(location=location, rotation=rotation, scale=scale, color=color) arena.handle_events()
# shapes.py # # MQTT message format: x,y,z,rotX,rotY,rotZ,rotW,scaleX,scaleY,scaleZ,#colorhex,on/off import arena import random import time import signal HOST = "oz.andrew.cmu.edu" SCENE = "shapes" arena.init(HOST, "realm", SCENE) def randmove(): rando = random.random() * 10 - 5 return rando def rando(val): rando = random.random() * val return round(rando, 3) def randrot(): return round((random.random() * 2 - 1), 3) def randcolor(): x = random.randint(0,255) y = random.randint(0,255) z = random.randint(0,255) return(x,y,z)
"," + REALM + "," + MQTTH + "," + MID) MID = MID + '-' else: print( "You need to set SCENE, MQTTH, MID and REALM as environmental variables to specify the program target" ) print("JSONCFG is optional for setting multiple screens and loications.") print("\nFor bash you can copy paste the following before running:") print("export MID=dir") print("export MQTTH=arena.andrew.cmu.edu") print("export REALM=realm") print("export SCENE=example") print("export JSONCFG=directory_cfg.json") exit(-1) arena.init(MQTTH, REALM, SCENE) if os.environ.get('JSONCFG') is not None: # Links is base64 encoded JFILE = os.environ["JSONCFG"] print("JSONCFG:" + JFILE) screensData = None with open(JFILE) as dataFile: screensData = json.load(dataFile) cnt = 0 for key in screensData: print("Key:" + key) value = screensData[key] if key == "projector": print("Projector") projector_start = arena.Object(persist=True,
blink) + '" },' morphStr += '"gltf-morph__7": {"morphtarget": "shapes.browOuterUp_L", "value": "' + str( browOuterUp_L) + '" },' morphStr += '"gltf-morph__8": {"morphtarget": "shapes.browOuterUp_R", "value": "' + str( browOuterUp_R) + '" },' morphStr += '"gltf-morph__9": {"morphtarget": "shapes.mouthPucker", "value": "' + str( mouthPucker) + '" }' morphStr += '}' rotChange = distance.euclidean(face.rot, last_face_state['rotation']) if rotChange < 0.03: face.rot = last_face_state['rotation'] last_face_state['rotation'] = face.rot # print(morphStr) if face.counter % 2 == 0: obj = arena.Object( rotation=face.rot, # location=(face.trans[0]/10, face.trans[1]/10+3, (face.trans[2]+50)/10-5), # rotation=(0,0,0.6-openness,1), # quaternion value roughly between -.05 and .05 objName=OBJECT, # url="models/Facegltf/sampledata.gltf", objType=arena.Shape.gltf_model, scale=(15, 15, 15), location=(0, 2, -5), data=morphStr) arena.init(HOST, "realm", SCENE, callback=callback) arena.handle_events()
import arena arena.init("arena.andrew.cmu.edu", "realm", "sprng-changeme") prnum = arena.Object(objName="a-prnum") prnum.delete()
import sys sys.path.append("../") import time import arena arena.init("oz.andrew.cmu.edu", "realm", "demo") arena.start() # Draw origin cube scale = (0.1, 0.1, 0.1) color = (255, 0, 0) location = (0, 0, 0) originCube = arena.Object(persist=True, location=location, scale=scale, color=color) # Draw UWB tag locations color = (255, 0, 0) location = (-2.183, 1.407, -6.194) arena.Object(persist=True, location=location, scale=scale, color=color) color = (0, 255, 0) location = (-1.739, 1.159, -6.155) arena.Object(persist=True, location=location, scale=scale, color=color) color = (0, 0, 255) location = (-2.229, 0.280, -6.011) arena.Object(persist=True, location=location, scale=scale, color=color)
print(msg) if jsonMsg["type"] != "mouseup": return is_video_playing = not is_video_playing if is_video_playing: video_play_timestamp = time.time() - (video_pause_timestamp - video_play_timestamp) else: video_pause_timestamp = time.time() video_paused_by = jsonMsg["data"]["source"] arena.init( "oz.andrew.cmu.edu", "realm", "synchvideoscene", callback = callback, ) screen = arena.Object( objName = "videoscreen", objType = arena.Shape.cube, scale = (16, 9, 0.1), location = (0, 7.2, -15), data = '{"material": {"src": "//commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"}}', clickable = True ) status = arena.Object( objName = "videostatus", objType = arena.Shape.text,
# balls.py # # spray a bunch of spheres into the scene, test physics import arena import random import time import signal arena.init("arena.andrew.cmu.edu", "realm", "systest-balls") def rando(): return float(random.randint(0, 10000)) / 1000 def randcolor(): x = random.randint(0, 255) y = random.randint(0, 255) z = random.randint(0, 255) return (x, y, z) def signal_handler(sig, frame): exit() signal.signal(signal.SIGINT, signal_handler) counter = 0 while True:
# transCubes.py # # draw a symmetric structure of transparent mostly red blue (yellow) rectangles import arena import random import time import signal arena.init("arena.andrew.cmu.edu", "realm", "systest-transCubes") def randmove(): rando = random.random() * 10 - 5 return rando def rando(val): rand = random.random() * val return round(rand, 3) def randrot(): return round((random.random() * 2 - 1), 3) def unhex(a): return int(a, 16) def randgold():
ref_tag_rotq[2], ref_tag_rotq[3] }) else: # Solving for client rig, default localization operation print("Localizing", client_id, "on", str(detected_tag.id)) ref_tag_pose = TAGS.get(detected_tag.id) if ref_tag_pose is None: # Tag not found. TODO: query ATLAS for it print("Tag not found, not in build mode") return rig_pose = ref_tag_pose @ np.linalg.inv(dtag_pose) @ np.linalg.inv( vio_pose) rig_pos = rig_pose[0:3, 3] rig_rotq = Rotation.from_matrix(rig_pose[0:3, 0:3]).as_quat() RIGS[client_id] = rig_pose arena.updateRig( client_id, (rig_pos[0], rig_pos[1], rig_pos[2]), (rig_rotq[0], rig_rotq[1], rig_rotq[2], rig_rotq[3])) # mqtt_response = { # "new_pose": { # 'position': { 'x': new_pos[0], 'y': new_pos[1], 'z': new_pos[2]}, # 'rotation': { 'x': new_rotq[0],'y': new_rotq[1],'z': new_rotq[2],'w': new_rotq[3]} # } # } arena.init(HOST, "realm", TOPIC, on_tag_detect) arena.handle_events()
# hello2.py # demonstrate receiving ARENA callback (JSON) messages import arena def scene_callback(msg): print("scene_callback: ", msg) arena.init("oz.andrew.cmu.edu", "realm", "hello", scene_callback) # synchronous draw commandds cube = arena.Object(arena.Shape.cube, clickable=True) # our main event loop arena.handle_events()
counter = counter + 1 grid[(x - 1)][(y - 1)] = counter % 2 colstring = '#%02x%02x%02x' % color cubes[(x, y)].update( physics=arena.Physics.static, data= '{"impulse": {"on": "mouseup","force":"0 40 0","position":"10 1 1"},"material": {"color":"' + colstring + '", "transparent": false, "opacity": 1}}', clickable=True, location=(x, y, -3), scale=(0.6, 0.6, 0.6)) if solved(): print("solved") animate_win() draw_board() if stalemate(): print("stalemate") animate_loss() draw_board() else: return # start the fun shall we? arena.init(HOST, REALM, SCENE, process_message, port=3003) print("starting main loop") draw_board() arena.handle_events()
# shapes.py # # MQTT message format: x,y,z,rotX,rotY,rotZ,rotW,scaleX,scaleY,scaleZ,#colorhex,on/off import arena import random import time import signal arena.init("arena.andrew.cmu.edu", "realm", "systest-shapes") def randmove(): rando = random.random() * 10 - 5 return rando def rando(val): rando = random.random() * val return round(rando, 3) def randrot(): return round((random.random() * 2 - 1), 3) def randcolor(): x = random.randint(0, 255) y = random.randint(0, 255) z = random.randint(0, 255) return (x, y, z)