Events are ways to interact with user input in the ARENA.
To handle events in ARENA-py, you must set a function to the
When you attach an
evt_handler to an
Object, you will receive
Event objects in your handler.
Below is how you access attributes of the
# [scene] is the Scene that called the callback # [evt] will be an Event instance # [msg] is the raw JSON message as a dict def click_handler(scene, evt, msg): ## Get Event type evt.type # == "mousedown", "mouseup", "mouseenter", "mouseleave", etc. ## Get Event data evt.data.clickPos evt.data.position evt.data.source # etc. box = Box(..., evt_handler=click_handler) # note the use of "evt_handler=click_handler" # could also do box.evt_handler = click_handler # or box.update_attributes(evt_handler=click_handler)
There are several types of click events that you can generate (
scene.generate_click_event(obj, type, ...) # add a click listener to an object to be able to click it obj.update_attributes(clickable=True) # generate a "fake" click event from ARENA-py scene.generate_click_event( obj, type="mouseup" ) # ARENA-py will "click" obj with mouseup. In JSON, "source" will be defined as "arena_lib_[some random ID here]".
You can also move a user’s camera and/or make it look at a specific location or object:
scene.manipulate_camera(obj, type, ...) # move camera: scene.manipulate_camera( camera, position=(rando(),1.6,rando()), rotation=(0,0,0,1) ) # make camera look at something/some position: scene.look_at( camera, target=box # can also do a position: (0,0,0) )
If there is an event that does not exist yet, you can use this to have more freedom in the event type:
# define custom event evt = Event(type="my_custom_event", position=(3,4,5), target=sphere) # generate custom event with ARENA-py client scene.generate_custom_event(evt, action="clientEvent")
Event(object_id, action, type, ...)