Skip to content

Instantly share code, notes, and snippets.

@nampereira
Last active December 9, 2020 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nampereira/90becd40681ec4da46c5cd0388f72c64 to your computer and use it in GitHub Desktop.
Save nampereira/90becd40681ec4da46c5cd0388f72c64 to your computer and use it in GitHub Desktop.
Create a demo wall in the ARENA
# demo wall placement
#
import argparse
import time
import arena
import random
import os
import json
def createDemoWall(dname, location, rotation):
"""Create a demo wall
args:
dname
demo name, used for the names of objects created in the scene
location
x, y, z position of wall
rotation
rotation quaternion of the wall
"""
# some defaults
persist=True # False=objects will disappear after a reload (and only appear to clients already viewing the scene when they are created)
wallcolor = (100, 100, 130) # color of the poster wall
# these will be the name of the objects in the scene
rootName = dname + '_root'
wallName = dname + '_wall'
imgName = dname + '_img'
lightName = dname + '_light'
lblName = dname + '_lbl'
siteLnkName = dname + '_sitelink'
videoLnkName = dname + '_videolink'
# invisible root object; all other objects children of this object
root = arena.Object(
objName=rootName,
objType=arena.Shape.cube,
location=location, # change the location of this object to move the poster wall
transparency=arena.Transparency(True, 0), # invisible
rotation=rotation,
clickable=False,
persist=persist)
# back wall
wall = arena.Object(
objName=wallName,
objType=arena.Shape.cube,
location=(0, 0, 0),
scale=(8, 9, .5),
rotation=(0, 0.7071, 0, 0.7071),
color=wallcolor,
parent=rootName,
clickable=False,
persist=persist)
# image on the wall
img = arena.Object(
objName=imgName,
url='https://arena.andrew.cmu.edu/store/users/ececapstone/slides_imgs/Slide1.jpeg',
objType=arena.Shape.image,
scale=(5.5, 4, 4),
location=(-0.3, 2.2, 0),
rotation=(0, 0.7071, 0, -0.7071),
clickable=False,
parent=rootName,
persist=persist)
# button with link to the demo website
sitelink = arena.Object(
objName=siteLnkName,
url='https://arena.andrew.cmu.edu/store/users/ececapstone/button_imgs/site.jpeg',
objType=arena.Shape.image,
scale=(.5, .5, .5),
location=(-.3, 3.3, 3.3),
rotation=(0, 0.7071, 0, -0.7071),
clickable=True,
parent=rootName,
persist=persist,
data='{"goto-url": { "dest":"popup", "on": "mousedown", "url": "http://course.ece.cmu.edu/~ece500/projects/f19-teama1/"} } ') # some random link
# button with link to the demo video
videolink = arena.Object(
objName=videoLnkName,
url='https://arena.andrew.cmu.edu/store/users/ececapstone/button_imgs/video.jpeg',
objType=arena.Shape.image,
scale=(.5, .5, .5),
location=(-.3, 2.5, 3.3),
rotation=(0, 0.7071, 0, -0.7071),
clickable=True,
parent=rootName,
persist=persist,
data='{"goto-url": { "dest":"popup", "on": "mousedown", "url": "https://youtu.be/S3_ZNI6a8e0"} } ') # some youtube video :-)
# top label
plbl = arena.Object(
objName=lblName,
objType=arena.Shape.text,
scale=(0.5,0.5,0.5),
location=(-0.35, 4.3, 0),
rotation=(0, 0.7071, 0, -0.7071),
clickable=False,
data='{"text":"ECE Capstone 2020!"}',
color=(252, 132, 3),
parent=rootName,
persist=persist)
# light for the demo wall
plight = arena.Object(
objName=lightName,
objType=arena.Shape.light,
location=(-2, 2, 0),
rotation=(0, 0, 1, 0),
data='{"light":{"type":"point","distance":"10", "decay":".3"}}',
clickable=False,
parent=rootName,
persist=persist)
if __name__ == '__main__':
# a scene is the name of the 3d environment/room; can be anything
# scene can be passed as argument or environment variable (SCENE)
# open the scene in the browser: https://arena.andrew.cmu.edu/ececapstone
dft_scene="ececapstone"
parser = argparse.ArgumentParser(description=(
"ARENA python program"))
parser.add_argument('--host', dest='host', default=os.environ.get('MQTTH', "arena.andrew.cmu.edu"),
help='MQTT host')
parser.add_argument('--scene', dest='scene', default=os.environ.get('SCENE', dft_scene),
help='ARENA Scene')
parser.add_argument('--realm', dest='realm', default= os.environ.get('REALM', "realm"),
help='ARENA realm')
args = parser.parse_args()
if args.scene == None:
print('Please provide a scene name (environment variable SCENE, or --scene [scene_name])')
exit(1)
# init the ARENA library
print("Starting ARENA lib:" + args.scene + "," + args.realm + "," + args.host)
arena.init(args.host, args.realm, args.scene)
# create the wall objects; args: demo name; x, y, z position; rotation (quaternion)
createDemoWall('demo1', (0, 0, -5), (0, -0.7071, 0, -0.7071))
# This is the main ARENA event handler
# Everything after this should be in callbacks
print("starting main loop")
time.sleep(5) # need to allow some time if not entering handle_events()
#arena.handle_events()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment