Canvatorium Visio Lab 5037
Revisit Surroundings Effect
We can use preferredSurroundingsEffect to dim or tint the passthrough video feed while presenting an immersive space.
This API received some updates in visionOS 2. There are three new presets as well as a colorMultiply option.
struct Lab5037: View {
@State var effect: SurroundingsEffect? = nil
var body: some View {
RealityView { content, attachments in
let model = ModelEntity(
mesh: .generateBox(size: 0.3, cornerRadius: 8.0),
materials: [SimpleMaterial(color: .black, isMetallic: false)])
model.position = SIMD3(x: 0, y: 1.3, z: -1)
content.add(model)
if let attachmentEntity = attachments.entity(for: "controls") {
attachmentEntity.position = model.position + [0, 0.26, 0]
model.addChild(attachmentEntity)
content.add(attachmentEntity)
}
} update: { content, attachments in
print("do nothing")
} attachments: {
Attachment(id: "controls", {
HStack {
Button(action: {
effect = nil
}, label: {
Text("None")
})
Button(action: {
effect = .semiDark
}, label: {
Text("Semi Dark")
})
Button(action: {
effect = .dark
}, label: {
Text("Dark")
})
Button(action: {
effect = .ultraDark
}, label: {
Text("Ultra Dark")
})
Button(action: {
effect = .colorMultiply(Color(red: 10, green: 1.0, blue: 1.0))
}, label: {
Text("Color Multiply")
})
}
.padding()
.glassBackgroundEffect()
.presentationCornerRadius(24)
})
}
.preferredSurroundingsEffect(effect)
}
}