PortalComponent
A Component that enables entity surfaces to act as portals to a target world (the targetEntity EC tree) and should be used in conjunction with PortalMaterial.
Terminologies:
PortalEntity: An entity that the PortalComponent is added to.
PortalWorldEntity: An entity that the PortalWorldComponent is added to.
PortalCrossableEntity: An entity that the PortalCrossableComponent is added to.
To achieve the desired portal effect, you should adhere to the following design principles:
PortalEntity should have a PortalMaterial linked to its ModelComponent.
PortalEntity must be either a sibling or parent node to PortalWorldEntity, not a child.
PortalCrossableEntity must be a child node within a PortalWorldEntity and cannot be isolated outside of it.
The system can display up to 8 pairs of Portal-World relationships simultaneously. This supports up to 8 such pairs.
Background Settings
The portal background can be configured with panelColor and backgroundMode:
PortalBackgroundMode.SOLID_COLOR: Displays a solid color background (default). The color is controlled by panelColor.
PortalBackgroundMode.PASSTHROUGH: Shows the real world (passthrough) behind the portal.
These properties are experimental and require ExperimentalSpatialApi to be enabled.
Usage Example
// Create world entity and crossing entity
val worldEntity = Entity()
worldEntity.components.set(PortalWorldComponent())
val willCrossingEntity = Entity()
willCrossingEntity.components.set(PortalCrossableComponent())
worldEntity.addChild(willCrossingEntity)
// Create portal entity
val portalEntity = Entity()
portalEntity.components.set(
PortalComponent(
targetEntity = worldEntity,
allowClipping = true,
doubleSide = false,
allowEntityCrossing = true
)
)
// Attach required visual components
portalEntity.components.set(ModelComponent(mesh, PortalMaterial()))See also
Constructors
Constructs a PortalComponent with the specified parameters.
Constructs a PortalComponent with the specified parameters, including experimental background settings.
Properties
Whether clipping is allowed for the PortalComponent. The default value is true.
Whether entities are allowed to cross through the PortalComponent. The default value is true.
The background mode of the portal. The default value is PortalBackgroundMode.SOLID_COLOR.
Whether both sides (forward and backward) of the PortalComponent are rendered. The default value is false.
The enabled state of the PortalComponent. The default value is true, indicating enabled.
The color of the portal panel. The default value is black (0, 0, 0). The panel color is used when backgroundMode is set to PortalBackgroundMode.SOLID_COLOR.
The target entity representing the world visible through the portal. If targetEntity is null, the portal will not be rendered. To render the portal correctly, set targetEntity to a valid Entity object.