ARItem

From Blue Mars Developer Guidebook

Jump to: navigation, search
There are security restrictions on this article

Contents

Overview

The ARItem entity is a clickable object which highlights when the mouse is over the model. The supplied model must have collision proxy. Upon selecting the item, the avatar will automatically walk toward the item if located farther than 5 meters away.

Image:ARItem_entity.png


In the CityEditor, drag the ARItem entity into the level. Use the FlowGraph setup to trigger events on MouseOver, MouseOut and Select (clicking the object).


Properties

Image:ARItem_props.png

Animated
determines whether to play .cga default animation upon clicking item
DisableSeeThrough
determines whether the see-through effect is used when this object is between the camera and local avatar
Model
specify the .cgf model or .cga model with animation. The model must have collision proxy to detect mouse events
Previewable
enables the item preview mode, bringing the model to focus, and allowing the user to right-drag rotate and left-drag zoom; left-click will exit this mode (used for purchasable items)


FlowGraph setup in CityEditor

Image:ARItem_fg.png

Distance
distance between the item and the avatar triggered on Select, MouseOver or MouseOut
MouseOut
triggered upon cursor moving out of the area marked by the item's collision proxy
MouseOver
triggered upon cursor moving over the area marked by the item's collision proxy
Select
triggered upon clicking the item
Use
not used for the ARItem (only for synchronized items like the ARChair which can only be used if not used by another avatar)


Creating a FlowGraph for the item

  • select the item, scroll down in the RollupBar and click Create in the FlowGraph section
  • specifying a group name is optional; click OK
  • right-click in the gray area of the FlowGraph and choose Add Graph Default Entity
  • Or, alternatively, the item can be added to an existing FlowGraph by selecting it, right-clicking in the gray area of the FlowGraph and choosing Add Selected Entity.


FlowGraph Tips

  • connect ports by clicking and dragging. E.g., the connection in the example above was made by clicking on the Select Output and dragging to the Trigger Input.
  • to temporarily disable a connection, mouse-over the center point until the cursor changes, right-click and select Disable.
  • more details can be found on the FlowGraph Editor page


Spawning in Lua

Spawning an ARItem

If you need to spawn an ARItem, rather than placing one in the Editor, here's an example to follow:

function MyScript:SpawnItem()
  local props = {fileModel = "",};
  local spawnParams_item = { 
        class = "ARItem",
        position = self:GetWorldPos(),
        orientation = self:GetDirectionVector(),
        properties = props,
      };
  self.my_item = System.SpawnEntity(spawnParams_item);

end

This is all you need to do to spawn an ARItem. The options for the properties table include:

  • fileModel, supply a path to the model, beginning one level under the Game directory
  • bAnimated, bDisableSeeThrough and bPreviewable, the flags shown in the Properties section above (set to 1 or 0 as described here, rather than true or false)



Overwriting OnSelect

Furthermore, if you need to overwrite the item's OnSelect callback for use in your script, you can store the original callback and overwrite it with a function that calls the original and adds to it. This is shown in the example below:

--(continuation of function MyScript.SpawnItem)

  self.originalSelect = self.my_item.OnSelect;  --store original OnSelect callback function
  local origself = self;
  self.my_item.OnSelect =                       --overwrite OnSelect
         function(...)
            origself.originalSelect(...);       --call the original OnSelect function
            origself:HandleItemSelect();        --add your custom code
         end

When the system calls OnSelect, the arguments passed in are (1) the item entity, (2) the avatar entity, (3) the avatar distance from item, and (4) the position of the selected entity.

We overwrite the callback with a vararg function to pass the arguments "..." through (the Lua manual includes further details about variable arguments, used here as a placeholder).

Finally, your custom code is executed:

function MyScript:HandleItemSelect()
  --your custom code
end
Problems with this wiki page? Contact us either by: Support Email or Support Ticket System

Blue Mars Guidebook Privacy Policy
Blue Mars Guidebook Community Guidelines

Personal tools