createPortal(world:portalEntity:style:enableClipping:enableCrossing:)
Creates a portal targeting an existing world entity.
Declaration
static func createPortal(world: Entity, portalEntity: Entity? = nil, style: PortalFactory.Style, enableClipping: Bool = true, enableCrossing: Bool = false) -> PortalFactory.PortalSetupParameters
- world:
An entity with
WorldComponent. This entity must already have aWorldComponentattached, or the method will fail with a precondition. - portalEntity:
An optional entity to configure as the portal. If
nil, a new entity is created. If provided, any existingModelComponentandPortalComponentwill be replaced. Default isnil. - style:
The visual style and geometry of the portal.
- enableClipping:
When
true, content is clipped at the portal boundary. Default istrue. - enableCrossing:
When
true, enables portal crossing for entities withPortalCrossingComponent. Default isfalse.
Return Value
A PortalSetup containing the root entity with configured portal and world.
Discussion
Use this method when you want multiple portals to view the same world, or when you need to configure the world entity before creating the portal.
Example
// Create a shared world
let sharedWorld = Entity()
sharedWorld.components.set(WorldComponent())
// Create two portals viewing the same world
let portal1 = PortalFactory.createPortal(
world: sharedWorld,
style: .plane(width: 1.0, height: 1.0)
)
let portal2 = PortalFactory.createPortal(
world: sharedWorld,
style: .plane(width: 1.5, height: 1.5)
)
// Add both portals to scene
content.add(portal1.rootEntity)
content.add(portal2.rootEntity)