Slots, Geometry and Effects

Slot Transformation

Each slot is assigned a local transformation, in relation to its parent. This allows for offsetting the slot geometry from the entity it is attached to, and is especially useful when dealing with multiple slots in one entity.

Function nameDescription
IEntity::GetSlotWorldTMGets the transformation of the slot in world coordinates.
IEntity::GetSlotLocalTMGets the transformation of the slot in relation to its parent.
IEntity::SetSlotLocalTMSets the relative transformation of the slot.

Camera-Space Rendering

Camera space rendering allows for drawing an entity slot in the Camera's local space - always making it relative to the camera, and avoiding that other objects are on top. This is most commonly used for first person shooter weaponry and hands.

This is achieved by setting the ENTITY_SLOT_RENDER_NEAREST flag instead of ENTITY_SLOT_RENDER, and then setting the camera-space relative position of the object:

Function nameDescription
IEntity::SetSlotCameraSpacePosSets the camera space position of the slot, used when the ENTITY_SLOT_RENDER_NEAREST is applied to the slot.
IEntity::GetSlotCameraSpacePosGets the camera space position of the slot, used when the ENTITY_SLOT_RENDER_NEAREST is applied to the slot.

Slot Material

By default, a slot contains a null material - resulting in the rendered form of a slot using the default material for the object assigned to it. However, it is often useful to override the material of the slot, allowing custom effects on individual entity geometry.

This can be achieved with the IEntity::GetSlotMaterial and IEntity::SetSlotMaterial functions.

Slot Flags

The EEntitySlotFlags enum can be used to change the behavior of individual slots, for example to disable rendering entirely - something that can be useful when a slot is only meant for physical interaction.

Function nameDescription
IEntity:;SetSlotFlagsUsed to set the flags for this slot, note that this completely overrides the flags.
IEntity::GetSlotFlagsRetrieves the specified slot's flags.

The currently available slot flags are:

Flag nameDescription
ENTITY_SLOT_RENDERSet by default. If cleared, the entity will no longer be rendered to the screen.
ENTITY_SLOT_RENDER_NEARESTIf set, the entity will be rendered in camera space. See IEntity::SetSlotCameraSpacePos and IEntity::GetSlotCameraSpacePos.
ENTITY_SLOT_CAST_SHADOWIf set, the entity slot will cast a shadow.

Slot Types

There are several types of objects that can be applied to an entity slot:

Characters

Interaction with characters on an entity is limited to:

Function nameDescription
IEntity::GetCharacterRetrieves the character instance at the specified slot, if any.
IEntity::SetCharacterApplies an existing character instance (.CDF, .CHR, .CGA) to the specified slot.
IEntity::LoadCharacterLoads specified character from disk and applies it to the specified slot.

For more information on characters, and how to approach animating them, see Characters and Animations.

Static Geometry

Static geometry is represented by the CGF format, and is known in code as IStatObj.

Interaction with static geometry on an entity is limited to:

Function nameDescription
IEntity::GetStatObjRetrieves the static geometry at the specified slot, if any.
IEntity::SetStatObjApplies the specified static geometry (.CGF) to the specified slot.
IEntity::LoadGeometryLoads specified static geometry (.CGF) from disk and applies it to the specified slot.

Particle Emitters

Particles can be loaded into emitters, a construct that will continuously emit effects from a point. When assigned to an entity, a particle emitter will follow an entity and thus allow creating very complex effects with ease. Emitters are represented in code by the IParticleEmitter interface, while the underlying particle effect (.pfx, .pfx2) is known in code as IParticleEffect.

Interaction with particle emitters on an entity is limited to:

Function nameDescription
IEntity::GetParticleEmitterRetrieves the particle emitter at the specified slot, if any.
IEntity::SetParticleEmitterApplies the specified particle emitter to the specified slot.
IEntity::LoadParticleEmitterCreates an emitter in the specified slot out of the specified effect.

Lights

Very often useful, lights can be loaded into entities to create dynamic light sources that can move around the level at run-time. This is useful to create entities that provide point lights, projected lights or even environment probes.

Lights are loaded into entity slots using the IEntity::LoadLight function, with the accompanying CDLight structure defining the behavior of the light. This allows for creating point lights, projector lights and environment probes. An example is available here.

Fog Volume

Entities can also load fog volumes into slots, allowing the use of dynamic fog effects around logical entities.

Fog volumes can be loaded into entity slots using the IEntity::LoadFogVolume function, with the accompanying SFogVolumeProperties structure defining the behavior of the volume.

Geom Cache / Alembic

Geom Caches can be loaded into entities, allowing the playback of arbitrarily animated geometry. This can allow for complex destruction, complicated cloth motion and other special effects that would otherwise be too expensive to calculate in real-time.

Geom Cache can be loaded into entity slots using the IEntity::LoadGeomCache function, and can subsequently be manipulated by calling IEntity::GetGeomCacheRenderNode.

Render Nodes

Low-level Render nodes can be added directly to entities, allowing the dynamic rendering of effects on entities. Keep in mind that all the constructs above are also render nodes, but direct helpers for creating the render node are available to simplify ease of use.

Examples of render nodes that could be attached to entities are: IRoadRenderNode, IDecalRenderNode and IWaterVolumeRenderNode, IRopeRenderNode. It is also possible to directly query the render node attached to a slot, even in the case of using the helpers above, using IEntity::GetSlotRenderNode.

Otherwise, render nodes can be applied directly to a specific slot using the IEntity::SetSlotRenderNode function.

Conclusion

That concludes this article on Entity Slots. You may be interested in: