Labs 001, 002, and 003

These three labs were used during project setup to test the process of opening windows, volumes, and spaces.

Each lab presents only a small amount of content.

Lab 001 contains a VStack with some text. This will be opened as a Window.

struct Lab001: View {
    var body: some View {
        VStack {
            Text("A Regular Window")
                .font(.title)
            Text("2D content made with SwiftUI")
        }
    }
}

Lab 002 creates a RealityView with a simple sphere, and a toolbar that will appear at the bottom of the volume.

struct Lab002: View {
    var body: some View {
        RealityView { content in
            let model = ModelEntity(
                mesh: .generateSphere(radius: 0.1),
                materials: [SimpleMaterial(color: .black, isMetallic: false)])
            content.add(model)
        }
        .toolbar {
            ToolbarItem(placement: .bottomOrnament, content: {
                Text("A Volume")
                    .font(.title)
            })
        }
    }
}

Lab 003 will present an immersive space that will position a sphere and a SwiftUI attachment.

struct Lab003: View {

    let count: Int = 12
    let radius: Float = 160

    var body: some View {
        RealityView { content, attachments in
            let model = ModelEntity(
                mesh: .generateSphere(radius: 0.1),
                materials: [SimpleMaterial(color: .black, isMetallic: false)])
            model.position = SIMD3(x: 0.8, y: 1, z: -2)
            content.add(model)

            if let attachmentEntity = attachments.entity(for: "SphereLabel") {
                attachmentEntity.position = model.position + [0, 0.16, 0]
                model.addChild(attachmentEntity)
                content.add(attachmentEntity)
            }

        } update: { content, attachments in
            // ...
        } attachments: {
            Attachment(id: "SphereLabel") {
                Text("An Immersive Space")
                    .font(.largeTitle)
                    .padding(18)
                    .background(.black)
                    .cornerRadius(12)
            }
        }
    }
}

You can read more about the navigation and scene presentation process Building Step Into Labs.

Support our work so we can continue to bring you new examples and articles.

Download the Xcode project with this and many more labs from Step Into Vision.

Questions or feedback?