Contents

immersiveSpace

The named coordinate space that represents the currently opened Immersivespace scene. If no immersive space is currently opened, this CoordinateSpace provides the same behavior as the .global coordinate space.

Declaration

static var immersiveSpace: NamedCoordinateSpace { get }

Discussion

Use this to convert transforms from a window to an immersive space. The following sample converts the top-leading-back origin of a Model3D view to coordinates in the immersive space.

Model3D(url: URL(string: "https://example.com/robot.usdz")!)
    .onGeometryChange3D(for: AffineTransform3D.self) { proxy in
        // Convert the view's transform to the immersive space
        return proxy.transform(in: .immersiveSpace) ?? .identity
    } action: { transform in
        appModel.immersiveSpaceFromCuboid = transform
    }
}

Then, apply it to a corresponding Model3D in the immersive space.

if let transform = appModel.immersiveSpaceFromRobot {
    Model3D(url: URL(string: "https://example.com/robot.usdz")!)
        // Align the origin of this Model3D to its top-leading-back
        .visualEffect3D({ effect, proxy in
            effect
                .offset(x: proxy.size.width/2, y: proxy.size.height/2)
                .offset(z: proxy.size.depth/2)
        })
        // Apply the transform in SRT order
       .scaleEffect(transform.scale)
       .rotation3DEffect(transform.rotation ?? .identity)
       .transform3DEffect(AffineTransform3D(
           translation: transform.translation))
}

To apply scale and rotation relative to a view’s origin, don’t set them at the same time using transform3DEffect(_:). Instead, set them separately using scaleEffect(_:anchor:) together with rotation3DEffect(_:anchor:).

See Also

Getting built-in coordinate spaces