def draw_ray(click_pos, position): line = arena.Object( ttl=1, objType=arena.Shape.thickline, thickline=arena.Thickline( # slightly below camera so you can see line vs head-on { (click_pos[0],click_pos[1]-0.2,click_pos[2]), (position[0],position[1],position[2]) },5,"#FF00FF") )
def make_hudtext(self, label, location, text): return arena.Object( objName=(label + "_" + self.camname), objType=arena.Shape.text, parent=self.camname, text=text, location=location, color=CLR_HUDTEXT, scale=(0.1, 0.1, 0.1), )
def __init__(self, config): self.hud = arena.Object(objName='circle_' + config.arenaname, parent=config.client_id, objType=arena.Shape.circle, location=(0, 0, -0.5), rotation=(0, 0, 0, 1), scale=(0.02, 0.02, 0.02), persist=True) self.arenaname = config.arenaname self.reset()
def make_followspot(object_id, position, delim, color): name = (object_id + delim + "spot") CONTROLS[object_id][name] = (arena.Object( # follow spot on ground objType=arena.Shape.circle, objName=name, scale=(0.1, 0.1, 0.1), color=color, ttl=arblib.TTL_TEMP, location=(position[0], arblib.FLOOR_Y, position[2]), rotation=(-0.7, 0, 0, 0.7), data='{"material":{"transparent":true,"opacity":0.4,"shader":"flat"}}'))
def initCube(x, y, color): name = "cube_" + str(x) + "_" + str(y) cubes[(x,y)]=arena.Object(objType=arena.Shape.cube, persist=True, objName=name, physics=arena.Physics.static, data='{"collision-listner":"", "material": {"transparent":true,"opacity": 0.5},"impulse":{"on":"mouseup","force":"0 40 0","position": "10 1 1"}}', location=(x,y,-3), color=color, scale=(0.6,0.6,0.6), clickable=True);
def do_rename(camname, old_id, new_id): if new_id == old_id: return pobjs = arena.get_network_persisted_obj(old_id, BROKER, SCENE) if not pobjs: return data = json.dumps(pobjs[0]["attributes"]) arena.Object(objName=new_id, persist=True, data=data) USERS[camname].target_id = new_id print("Duplicating " + old_id + " to " + new_id) arblib.delete_obj(REALM, SCENE, old_id)
def signs(): arena.Object( objName="signpost1", url="store/users/wiselab/models/signpost/scene.gltf", objType=arena.Shape.gltf_model, scale=(0.1, 0.1, 0.1), rotation=(0, 0.3, 0, 1), location=(-18.2, 0.2, -2.3), clickable=True, persist=True )
def create_line(self, pts1, pts2, name): x1 = pts1[0] y1 = pts1[1] + 2 x2 = pts2[0] y2 = pts2[1] + 2 line = arena.Line((x1, y1, -0.5), (x2, y2, -0.5), 2, "#ffffff") arena.Object(objName=name, objType=arena.Shape.line, line=line, persist=False)
def set_lamp(self, enabled): if enabled: self.lamp = arena.Object( objName=self.camname + "_lamp", objType=arena.Shape.light, parent=self.camname, color=(144, 144, 173), data='{"light":{"type":"point","intensity":"0.75"}}', ) elif self.lamp: self.lamp.delete()
def got_click(location): for name in drones: if drones[name].active == True: arena.Object(objName="line1", objType=arena.Shape.line, line=arena.Line(start=drones[name].location, end=location, color=(206, 0, 255)), ttl=2) break print("No drone selected")
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 = arblib.get_network_persisted_scene(BROKER, SCENE) for pobj in pobjs: obj = arblib.ObjectPersistence(pobj) # show occulded 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)
def camera_callback(event=None): global last_position global cam_color cam_moved = distance.euclidean(event.position, last_position) if cam_moved > 0.25: last_position = event.position arena.Object(objType=arena.Shape.sphere, location=event.position, scale=(0.1, 0.1, 0.1), color=cam_color) print("Draw Marker")
def create_line(self, pts1, pts2, name): x1 = float(pts1[0]) * self.width y1 = float(pts1[1]) * self.height + self.height x2 = float(pts2[0]) * self.width y2 = float(pts2[1]) * self.height + self.height line = arena.Line((x1, y1, -0.5), (x2, y2, -0.5), 2, users[self.ID]["color"]) arena.Object(objName=name, objType=arena.Shape.line, line=line, persist=False)
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))
def icon_select(x, y): global icons global grid global wineNames if (grid[y][x] == 0): #idk yet. enter text? wineDisp = arena.Object(objType=arena.Shape.text, objName="wine_name", persist=True, data='{"text":"empty"}', location=(0, 1.8, -0.4), color=color[1], scale=(1, 1, 1)) else: icons[(x, y)].update(color=color[1]) wineDisp = arena.Object(objType=arena.Shape.text, objName="wine_name", persist=True, data='{"text":"' + wineNames[y][x] + '"}', location=(0, 1.8, -0.4), color=color[1], scale=(1, 1, 1))
def init_origin(): """Origin object, construction cone, so user knows ARB is running.""" size = [0.2, 0.4, 0.2] arena.Object( # 370mm x 370mm # 750mm objType=arena.Shape.cone, objName="arb-origin", data='{"material":{"transparent":true,"opacity":0.5,"shader":"flat"}}', color=(255, 114, 33), location=(0, size[1] / 2, 0), scale=(size[0] / 2, size[1], size[2] / 2)) arena.Object(objType=arena.Shape.cone, objName="arb-origin-hole", data='{"material":{"colorWrite":false},"render-order":"0"}', location=(0, size[1] - (size[1] / 2 / 15), 0), scale=(size[0] / 15, size[1] / 10, size[2] / 15)) arena.Object( objType=arena.Shape.cube, objName="arb-origin-base", data='{"material":{"transparent":true,"opacity":0.5,"shader":"flat"}}', color=(0, 0, 0), location=(0, size[1] / 20, 0), scale=(size[0], size[1] / 10, size[2]))
def draw_ray(click_pos, position): global clock_objects boing = arena.Object( location=(pinata_loc[0], pinata_loc[1], pinata_loc[2]), data= '{"sound":{"positional":true,"poolSize":8,"src":"store/users/wiselab/audio/glass.oga","autoplay":"true"}}' ) boing.delete() random_number = random.randint(0, 16777215) rand_color = str(hex(random_number)) rand_color = '#' + rand_color[2:] line = arena.Object( #ttl=1, DON'T USE THIS FOR high traffic objects since it uses the DB! # Have a harvester thread above instead objType=arena.Shape.thickline, thickline=arena.Thickline( # slightly below camera so you can see line vs head-on { (click_pos[0],click_pos[1]-0.2,click_pos[2]), (position[0],position[1],position[2]) },5,rand_color) ) click_objects.append(line)
def arm_click_handler(event=None): global animateState print("ARM event handler") if event.event_type == arena.EventType.mousedown: draw_ray(event.click_pos, event.position) print("ARM click!") if animateState == False: animateStr = '{"animation-mixer": {"clip": "Armature.002|Armature.002Action.001"}}' arm1 = arena.Object( objName="arm1", url="store/models/factory_robot_arm/scene.gltf", objType=arena.Shape.gltf_model, # scale=(0.001,0.001,0.001), # location=(0,0,-4), rotation=(0.7, 0, 0, 0.7), scale=(robot1Scale, robot1Scale, robot1Scale), location=(0, 0, 0), data=animateStr, clickable=True, callback=arm_click_handler) animateState = True else: animateStr = '{"animation-mixer": {"clip": "pause"}}' arm1 = arena.Object( objName="arm1", url="store/models/factory_robot_arm/scene.gltf", objType=arena.Shape.gltf_model, # scale=(0.001,0.001,0.001), # location=(0,0,-4), rotation=(0.7, 0, 0, 0.7), scale=(robot1Scale, robot1Scale, robot1Scale), location=(0, 0, 0), data=animateStr, clickable=True, callback=arm_click_handler) animateState = False
def game_thread(): global vi global t global fire_impulse global gravity_enabled global kill_flag #cnt = 0 while True: if kill_flag==1: print("Kill Flat!") return #if gravity_enabled is True: # pinataParent.update(location=(pinata_loc[0],pinata_loc[1],pinata_loc[2])) if(fire_impulse>0): print("Hit!") t=0.1 vi=20.0 H = pinata_loc[1] fire_impulse=0 if gravity_enabled is True: pinata_loc[1] = H + vi * t + 0.5*GRAVITY*(t*t) #if cnt%4==0 and pinata_loc[1]>6.0: if pinata_loc[1]>6.0: pinata_loc[0] += random.uniform(-1,1) pinata_loc[2] += random.uniform(-1,1) t=t+0.1 # print( "H, Vi,t,y: " + str(H) + "," + str(vi) + "," + str(t) + "," + str(pinata_loc[1])) if( pinata_loc[1]<=0): pinata_loc[1]=0 vi= (-1*GRAVITY*t) / 5 if(vi<2.0): vi=0.0 else: boing = arena.Object( location=(pinata_loc[0],pinata_loc[1],pinata_loc[2]),data='{"sound":{"positional":true,"poolSize":8,"src":"store/users/wiselab/audio/boing.wav","autoplay":"true"}}') boing.delete() t=0.1 H = 0.0 # pinata_loc[0]=random.uniform(0,10) # pinata_loc[1]=random.uniform(0,10) # pinata_loc[2]=random.uniform(0,10) # Tweening Move... if gravity_enabled is True and vi>0: pinataParent.update(location=(pinata_loc[0],pinata_loc[1],pinata_loc[2])) pinataParent.update(data='{"animation": {"property": "position","to": "' + str(pinata_loc[0]) + ' ' + str(pinata_loc[1]) + ' ' + str(pinata_loc[2]) + '","easing": "linear","dur": 100}}') time.sleep(0.1)
def regline(object_id, axis, direction, delim, suffix, start, end, line_width, color=(255, 255, 255), parent=""): if parent: end = ((end[0] - start[0]) * 10, (end[1] - start[1]) * 10, (end[2] - start[2]) * 10) start = (0, 0, 0) name = (object_id + delim + axis + direction + "_" + suffix) CONTROLS[object_id][name] = (arena.Object( objType=arena.Shape.line, objName=name, color=color, ttl=arblib.TTL_TEMP, parent=parent, line=arena.Line(start, end, line_width, color)))
def draw_landmarks(self): arena.Object(objName="origin", objType=arena.Shape.sphere, scale=(0.01, 0.01, 0.01), location=(0, 2, -0.5), persist=False) for i in range(0, len(self.jawPts) - 1): draw_line(self.jawPts[i], self.jawPts[i + 1], "jaw" + str(i)) for i in range(0, len(self.eyebrowLPts) - 1): draw_line(self.eyebrowLPts[i], self.eyebrowLPts[i + 1], "browL" + str(i)) for i in range(0, len(self.eyebrowRPts) - 1): draw_line(self.eyebrowRPts[i], self.eyebrowRPts[i + 1], "browR" + str(i)) for i in range(0, len(self.noseBridgePts) - 1): draw_line(self.noseBridgePts[i], self.noseBridgePts[i + 1], "noseB" + str(i)) for i in range(0, len(self.noseLowerPts) - 1): draw_line(self.noseLowerPts[i], self.noseLowerPts[i + 1], "noseL" + str(i)) draw_line(self.noseLowerPts[0], self.noseLowerPts[-1], "noseL" + str(i + 1)) for i in range(0, len(self.eyeLPts) - 1): draw_line(self.eyeLPts[i], self.eyeLPts[i + 1], "eyeL" + str(i)) draw_line(self.eyeLPts[0], self.eyeLPts[-1], "eyeL" + str(i + 1)) for i in range(0, len(self.eyeRPts) - 1): draw_line(self.eyeRPts[i], self.eyeRPts[i + 1], "eyeR" + str(i)) draw_line(self.eyeRPts[0], self.eyeRPts[-1], "eyeR" + str(i + 1)) for i in range(0, len(self.lipOuterPts) - 1): draw_line(self.lipOuterPts[i], self.lipOuterPts[i + 1], "lipO" + str(i)) draw_line(self.lipOuterPts[0], self.lipOuterPts[-1], "lipO" + str(i + 1)) for i in range(0, len(self.lipInnerPts) - 1): draw_line(self.lipInnerPts[i], self.lipInnerPts[i + 1], "lipI" + str(i)) draw_line(self.lipInnerPts[0], self.lipInnerPts[-1], "lipI" + str(i + 1))
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)
def initIcons(): global Xcoords, Ycoords global icons for x in range(0, 6): for y in range(0, 10): #print("x: " + str(x) + " y: " + str(y)) name = "icon_" + str(x) + "_" + str(y) icons[(x, y)] = arena.Object( objType=arena.Shape.sphere, persist=True, objName=name, physics=arena.Physics.static, data= '{"collision-listner":"", "material": {"transparent":true,"opacity": 0.8},"impulse":{"on":"mouseup","force":"0 40 0","position": "10 1 1"}}', location=(Xcoords[x], Ycoords[y], 0.2), color=color[2], scale=(0.02, 0.02, 0.02), clickable=True)
def draw_hud(score): global reds global blues global draws if score == -1: draws = draws + 1 if score == 1: reds = reds + 1 if score == 0: blues = blues + 1 hud = arena.Object( persist=True, objName="hudText", objType=arena.Shape.text, text="red:"+str(reds)+" blue:"+str(blues)+" draw:"+str(draws), location=(0, 0.4, -0.5), parent="myCamera", scale=(0.2, 0.2, 0.2), )
def arena_callback(self, msg): if msg.event_action != arena.EventAction.clientEvent: return if msg.event_type == arena.EventType.mouseenter: self.hover = True elif msg.event_type == arena.EventType.mouseleave: self.hover = False elif msg.event_type == arena.EventType.mouseup: location = tuple(float(num) for num in msg.position) arena.Object(location=location + self.offset, objType=arena.Shape.cylinder, scale=(.1, .1, .1), color=(200, 0, 0), ttl=1) if self.ros_callback: self.ros_callback(location)
import arena arena.init("arena.andrew.cmu.edu", "realm", "sprng-changeme") prnum = arena.Object(objName="a-prnum") prnum.delete()
def on_tag_detect(msg): json_msg = None try: json_msg = json.loads(msg.payload.decode("utf-8"), object_hook=dict_to_sns) except ValueError: pass if hasattr(json_msg, 'vio'): client_id = msg.topic.split('/')[-1] scene = json_msg.scene # Only take first marker for now, later iterate and avg all markers detected_tag = json_msg.detections[0] pos = json_msg.vio.position rot = json_msg.vio.rotation vio_pose = np.identity(4) vio_pose[0:3, 0:3] = Rotation.from_quat([rot._x, rot._y, rot._z, rot._w]).as_matrix() vio_pose[0:3, 3] = [pos.x, pos.y, pos.z] dtag_pose = np.identity(4) R_correct = np.array(detected_tag.pose.R).T dtag_pose[0:3, 0:3] = R_correct dtag_pose[0:3, 3] = detected_tag.pose.t dtag_pose = np.array(FLIP) @ dtag_pose @ np.array(FLIP) update_type = "" if (hasattr(json_msg, "localize_tag") and json_msg.localize_tag and detected_tag.id != 0): print("Solve for tag", str(detected_tag.id)) # Solve for tag, not client rig_pose = RIGS.get(client_id) if rig_pose is None: # Don't have client RIG offset, can't solve print("Don't have client rig pose:", client_id) else: ref_tag_pose = rig_pose @ vio_pose @ dtag_pose ref_tag_pos = ref_tag_pose[0:3, 3] ref_tag_rotq = Rotation.from_matrix( ref_tag_pose[0:3, 0:3]).as_quat() TAGS[detected_tag.id] = ref_tag_pose # Store as reference arena.Object(objId="apriltag_" + str(detected_tag.id), position=(ref_tag_pos[0], ref_tag_pos[1], ref_tag_pos[2]), rotation={ ref_tag_rotq[0], ref_tag_rotq[1], 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]))
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, objName="projector_start", objType=arena.Shape.cube, clickable=True, color=(0, 255, 0), location=value["location"], scale=value["scale"], rotation=value["rotation"], callback=projector_start) stop_location = value["location"] stop_location[1] = stop_location[1] - value["button_distance"] projector_stop = arena.Object(persist=True, objName="projector_stop", objType=arena.Shape.cube, clickable=True, location=stop_location, color=(255, 0, 0), scale=value["scale"], rotation=value["rotation"], callback=projector_stop)
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: obj_id = str(counter) name = "sphere" + "_" + obj_id counter += 1 obj = arena.Object(physics=arena.Physics.dynamic, objName=obj_id, objType=arena.Shape.sphere, location=(rando(), 0, rando()), color=randcolor(), ttl=40) time.sleep(0.1)
# 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()