Skip to content

Entity and Component

The core of Orillusion is inspired by the ECS structure, and follows the principle of Composition over inheritance. Implemented own component system. We divide the traditional complex logic into independent and reusable parts. Each part can be encapsulated and run independently. Then, by flexible combination, multiple simple components are combined to perform complex functions and logic.

ECS

Entity

Entity is a container for components to connect various components. It doesn't have actual function and will not render or express any functions if no components are added to it. In practice, we will not operate Entity directly. Usually, we use Object3D and Scene3D as scene container nodes to connect various components.

Compnent

Component is a series of reusable modules or data. All the functions of Entity are implemented by loading Component. By defining the logic callback and lifecycle of the component, we can freely combine different components to make the Entity have different functions, such as:

  • a camera = Position + Rotation + Camera3D
  • a bulb = Position + Rotation + PointLight + Shadow
  • a box = Position + Rotation + Scale + BoxGeometry + Material

Among them, all components are independent and equal, and each performs a single function. This split makes the Position and Rotation modules reusable, and they can be combined as needed, which greatly improves the efficiency of code reuse, and also effectively reduces the coupling between modules.

Built-in Components

We have built-in a lot of basic components in the Orillusion engine, which encapsulates a lot of basic functions. For example, Object3D has already built-in the Transform component, which contains the Position, Rotation, Scale and other related functions. Make it convenient for users to operate the spatial transformation of Object3D.

These are the commonly used built-in components in the Orillusion engine:

NameDescription
Camera3DCamera component, set the camera node
TransformTransform component, used to control the matrix coordinate transformation of the object
HoverCameraControllerCamera controlort, used to control the position and orientation of the camera
MeshRendererMesh renderer component, used to render meshes and materials
DirectLightDirectional light, set the type and parameters of the directional light
PointLightPoint light source, set the type and parameters of the point light
SpotLightSpotlight, set the type and parameters of the spotlight
ColliderComponentCollider component, used to detect collisions
SkeletonAnimationComponentSkeleton animation component, used to control animation playback
AtmosphericComponentAtmospheric skybox component

And more built-in components can be found in Components

Basic Usage

ts
//Create a new entity
let obj = new Object3D();
//Add the entity to scene
scene.addChild(obj);

Add Component

ts
let obj = new Object3D();
let light = obj.addComponent(DirectLight)

Delete Component

ts
let obj = new Object3D();
let light = obj.removeComponent(DirectLight)

Disable Component

ts
let obj = new Object3D();
let light = obj.getComponent(DirectLight)
light.enable = false

Enable Component

ts
let obj = new Object3D();
let light = obj.getComponent(DirectLight)
light.enable = true

Lifecycle of Component

The component extends from the CompnentBase, which defines several basic lifecycles:

LifecycleDescription
initComponent initialization, only run once when the component is created
startComponent starts running, only called before the first onUpdate
stopComponent runs before destruction
onUpdateComponent runs every frame
onBeforeUpdateComponent runs before rendering update
onLateUpdateComponent runs after rendering update
onEnableWork when enable = true , component joins the main loop update
onDisableWork when enable = false , component will no longer trigger loop

Users can extend different custom functions by inheriting the ComponentBase base class, see Script Component for details.

Released under the MIT License