HoverExample

If you have the VastPark Player installed, download the example IMML file below and open the demo in the VastPark Player.

Overview

A beginner script which demonstrates the mouse-over trigger in IMML primitives, this serves as a foundation for many interactive features in IMML and will teach the designer how nesting triggers in Primitives can turn them into buttons

Instructions

Mouse over the squares to have them change in colour.

Walkthrough

The purpose of this walkthrough is not to explain every line of code but to highlight the code which is important in it's function.

1 <Primitive Name="box2" Type="Box" Complexity="VeryLow" Position="-0.8855561,2.075658,7.400005" Size="1,1,1">
2     <MaterialGroup Id="-1">
3       <Material Ambient="#4c4c4c" Diffuse="#cccccc" Emissive="#68ff00" Specular="#000000" EnableTextures="True" />
4     </MaterialGroup>
5     <Physics Enabled="False" Movable="False" />
6     <Trigger Name="trigger21" Event="MouseEnter" Target="onMouseEnter" Enabled="True" />
7     <Trigger Name="trigger3" Event="MouseLeave" Target="onMouseLeave" Enabled="True" />
8 </Primitive>

Pay special attention to lines 6 and 7 Where the triggers are nested within the primitive. The trigger's events are MouseEnter and MouseLeave. Since the triggers are nested within the primitive, those triggers will only apply to that primitive.

 1  <Script Name="onMouseEnter" Language="Lua">function main(obj, args)
 2         scene.ui:writeline('MOUSE ENTER')
 3         -- **** SET THE VARIALBE 'objColour' TO THE OBJECT WE ARE CURRENTLY HOVERING OVER
 4         scene:set('objColour', obj.material.emissive)
 5 
 6         -- ****  CHANGE THE COLOUR OF THE CURRENT OBJECT 
 7         obj.material.emissive = rgb('#FFC500')
 8 
 9         -- CHANGE THE CURSOR TO A HAND. THIS WILL HELP USERS IDENTIFY CLICKABLE OBJECTS
10         cursorplugin:setcursor('Hand')
11 
12         end</Script>

In the above snippet there is quite a few things happening.

1 scene:set('objColour', obj.material.emissive) 

In this line the scene's dictionary data structure is setting a key-value pair for future retrieval. Which in this case is the Primitive's Emissive colour value. Using the dictionary can allow different scripts to pass variables to one another.

1 cursorplugin:setcursor('Hand')

This line of code is calling a different method than those called of the scene, it is calling a plugin which is separate code from the VastPark Player entirely. Plugins have to be added as elements within IMML.

hoverExample.imml (3.3 kB) Ian Tan, 02/23/2011 01:23 am