Using volume baseplates

visionOS 2 brought us a new way to show users an indicator for the bottom of a Volume.

This baseplate indicator can be very helpful for finding the edge of a volume. It is especially useful when the user wants to use the resize controls. Volumes will show baseplates by default, but we can hide them if needed.

The volumeBaseplateVisibility modifier can be added to a view inside a volume to control visibility.

struct ContentView: View {

    @State var showBasePlate = true

    var body: some View {
        RealityView { content in

            var groundMat = PhysicallyBasedMaterial()
            groundMat.baseColor.tint = .init(.stepGreen)
            groundMat.roughness = 0.5
            groundMat.metallic = 0.0

            let groundModel = ModelEntity(
                mesh: .generateBox(size: 1, cornerRadius: 0.1),
                materials: [groundMat])
            groundModel.scale = .init(x: 0.8, y: 0.025, z: 0.8)
            groundModel.position = .init(x: 0, y: -0.44, z: 0)
            content.add(groundModel)

        } update: { content in
        }
        .toolbar() {
            ToolbarItem(placement: .bottomOrnament, content: {
                Button(action: {
                    showBasePlate.toggle()
                }, label: {
                    Image(systemName: showBasePlate ? "rectangle" : "rectangle.slash" )
                    Text("Toggle Baseplate")
                })
            })
        }
        .volumeBaseplateVisibility(showBasePlate ? .visible : .hidden)

    }
}

Simulator video showing volume baseplates hidden and visible.

https://developer.apple.com/documentation/SwiftUI/View/volumeBaseplateVisibility(_:)

Sample code is available in Garden11 in the Step Into Example Projects repo.

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

Download the Xcode project with this and many more examples from Step Into Vision.
Some examples are provided as standalone Xcode projects. You can find those here.

Questions or feedback?