Component System

From ANVEL Wiki
Jump to: navigation, search


The ANVEL Component System is based on the Entity-Component-System architecture found in many simulation and game development engines. A component adds a bit of functionality to an object present in the ANVEL simulation. These can include custom behavior logic with the PythonScript component, sound content with the AudioSource component, tailored animation or material properties with the AnimationController or MaterialOverride components, or the ability to store user provided data with the Tag component. Developers can also create new components via plugins to quickly extend and customize the simulation capabilities of an object.

The Component System represents a fundamental shift in approach for future ANVEL development. New behaviors and functionality will generally be provided by extending the set of available components.

Included Components

The following component types are included with ANVEL:

  • Lifetime component: Removes the associated object after a specified amount of time elapses to trigger delayed deletion
  • Tag component: Adds a collection of name and value pair entries associated to the object. It appends instance-specific data that can be queried by other systems within ANVEL, or user-defined plugins and scripts
  • PythonScript component: Adds dynamic Python code that will be executed per simulation step, render step, or after reception of messages, etc. It can be used to add custom logic without having to create plugins
  • MaterialOverride component: Allows control over the material used to render an object
  • Label component: Add customized labels to objects for easy tracking during simulation play
  • AnimationController component: Allow direct control over the animation that an object has defined for it
  • TriggerVolume component: Allows detection of objects within a given volume. Sends an ANVEL message or command when an object enters or leaves the volume
  • AudioSource component: Allows the association of a sound file with an object. Can specify the .wav file, the volume, and looping state of the sound
Anvel-new-icon.png Particle and MotionController components are new in version 3.5.
  • Particle component: Allows the visualization of particles through a prebuilt Ogre particle script
  • MotionController component: Allows the application of automatic position updates to an object that does not already include physics simulation

Adding New Component Types

Add new component types through ANVEL plugins. See Creating New Component Types.

Attach a Component to an Object

  1. Drag an object into the simulation.
  2. Right-click on the object and select World Object > Add component.
    Add component.png
  3. Confirm that the AddComponent dialog appears.
    Add component dialog.png
  4. In the drop-down, select LifetimeComponent. Click OK.
  5. Click on the Properties tab.
  6. Navigate to the object to confirm LifetimeComponent is attached to it.
    Add component properties.png

Attaching a Component Using the Built-in Python

In the example below, the Lifetime component is added to a cube.

import Anvel

# Create object
myCubeID = Anvel.Assets.CreateInstance('Cube (Cyan)', 'Cube-Cyan-1', 0, (0,0,0), (1, 0, 0, 0), (1, 1, 1), False) 

# Look up the Type ID for LifetimeComponent
ComponentTypeID = Anvel.GetTypeIdByName('LifetimeComponent')

# Add the component to the object
ComponentID = Anvel.World.AddComponent(myCubeID,ComponentTypeID)

# Verify component was created
if ComponentID is not None:
	# Get IDs for components attached to object
	myComponents = Anvel.World.GetComponentsOfType( myCubeID, ComponentTypeID)

See Also

Creating a Plugin

Creating New Component Types