Component System

From ANVEL Wiki
Jump to: navigation, search

Introduction

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 component, or the ability to store user provided data with the Tag component. Developers can also create new components via plugins that can 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

New types of Components can be added 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. Select ComponentType 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 in ANVEL.

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 New Component Types