SmartBody can be customized to respond to events that occur during the simulation through its own event system. Events can be triggered via a BML message, from markers associated with animations, or through scripting.
An event can be called at any time by creating one from the Event Manager:
eventManager = scene.getEventManager() event = eventManager.createEvent(type, parameters)
where 'type' is the event type, and 'parameters' is a string describing the parameters associated with the event. Once an event has been triggered in SmartBody, it will look for an event handler that can process that type of event. An event handler can be created by extending the SBEventHandler class as follows:
class MyEventHandler(SBEventHandler): def executeAction(self, event): str = event.getParameters() print "Now executing event with parameters " + str
then add the handler to the Event Manager:
myHandler = MyEventHandler() eventManager = scene.getEventManager() eventManager .addEventHandler("myevents", myHandler)
In this example, a handler called 'MyEventHandler' is created, and will respond to 'myevents' events. The handler will extract the parameters from the event, and then print out to the screen some text. The event processing can be more complex, of course, and could perform actions such as play a sound, send a BML request to a character, change the position of the camera, and so forth.
Triggering Events Automatically From Animations
Animations can automatically trigger events when they are played by marking the time, type and parameters on the motion as follows:
motion = scene.getMotion(motionName) motion.addEvent(time, type, parameters, onlyOnce)
where 'time' is the local time when the event will occur, 'type' is the event type, 'parameters' is a string describing the event parameters, and 'onlyOnce' is a boolean that determines whether this event will be triggered only once, or every time the motion passes the local time mark. Such animation event markers can be used to play a footstepping sound when the character's foot hits the ground, or to trigger an external event when a motion reaches a certain point, and so forth.