I am experimenting with RealityKit to set up a portal. Everything works, but I was wondering where the scene's origin is with respect to the front of the portal window?
From experiments, the origin's X and Y appear to be at the center of the portal window, while the origin's Z appearing to be about a meter behind the portal window.
Is this (at least roughly) correct? Is it documented anywhere?
PS. I began with the standard visionOS app and edited the Reality Composer Pro file to create the scene.
Hi @THeberlein
It sounds like you are asking for the origin of the world entity (with WorldComponent
) relative to the plain entity (with the PortalComponent
). I "believe" the plane and world origins will always intersect. By default, the origin of an entity is its center. So by default, the center of the world should intersect the center of the plane (in all dimensions).
I ran an experiment to confirm this. Note the comments.
struct PortalView: View {
@Environment(\.physicalMetrics) private var physicalMetrics
let portalSize:Float = 1.0
var body: some View {
RealityView { content in
var worldMaterial = SimpleMaterial(color: .blue, isMetallic: false)
worldMaterial.faceCulling = .front
let world = ModelEntity(
mesh: .generateBox(size: portalSize),
materials: [worldMaterial])
world.components.set(WorldComponent())
// Since the world origin relative to the portal plane
// is the center of the plane, pushing the world
// back 1/2 the depth of the world plus 0.1m causes
// a 0.1m gap between the portal opening and the world.
// Comment out the next line and observe the world move to the center.
world.position.z = -portalSize / 2.0 - 0.1
content.add(world)
let portal = ModelEntity(
mesh: .generatePlane(width: portalSize, height: portalSize),
materials: [PortalMaterial()]
)
portal.components.set(PortalComponent(target: world))
content.add(portal)
}
.frame(
width: physicalMetrics.convert(CGFloat(portalSize), from: .meters),
height: physicalMetrics.convert(CGFloat(portalSize), from: .meters)
)
}
}
I couldn't find any documentation on this. Please accept this answer if this answers your question. Otherwise please followup. I want to help you achieve your goal.