Canvatorium Visio Lab 5038
Back Anchors for Ornaments in Volumes.
Ornaments are now supported in Volumes in visionOS 2. This includes new back anchor points where content will face in toward the volume content.
struct Lab5038: View {
var body: some View {
ZStack(alignment: Alignment(horizontal: .center, vertical: .bottom)) {
RealityView { content, attachments in
if let root = try? await Entity(named: "GestureLab", in: realityKitContentBundle) {
root.position = [0, -0.45, 0]
root.scale = [2.5, 2.5, 2.5]
content.add(root)
if let attachmentEntity = attachments.entity(for: "Label") {
attachmentEntity.position = [0, -0.3, 0]
content.add(attachmentEntity)
}
}
} update: { content, attachments in
// Not using update in this lab
} attachments: {
// Create an attachment for the text label
Attachment(id: "Label", {
Text("Attachment Text")
})
}
.toolbar {
ToolbarItemGroup(placement: .bottomOrnament) {
Text("Wow a tool bar")
}
}
.ornament(attachmentAnchor: .scene(.leadingBack)) {
VStack(alignment: .leading, spacing: 8) {
Text("leadingBack")
.font(.extraLargeTitle2)
Spacer()
}
.padding(48)
.frame(width: 360, height: 600)
.glassBackgroundEffect()
.offset(x: -40)
.offset(z: 60)
.rotation3DEffect(
Angle(degrees: 25),
axis: (x: 0, y: 1, z: 0)
)
}
.ornament(attachmentAnchor: .scene(.back)) {
VStack(alignment: .leading, spacing: 8) {
Text("Ornament anchor: .scene(.back)")
.font(.extraLargeTitle2)
Text("This one is using `.scene(.back)) to place a view on the inside of the back surface of the volume.")
Text("I plan on using this in Project Graveyard to replace the card system use on version 1.")
Spacer()
}
.padding(48)
.frame(width: 700, height: 600)
.glassBackgroundEffect()
}
.ornament(attachmentAnchor: .scene(.trailingBack)) {
VStack(alignment: .leading, spacing: 8) {
Text("trailingBack")
.font(.extraLargeTitle2)
Spacer()
}
.padding(48)
.frame(width: 360, height: 600)
.glassBackgroundEffect()
.offset(x: 40)
.offset(z: 60)
.rotation3DEffect(
Angle(degrees: -25),
axis: (x: 0, y: 1, z: 0)
)
}
}
}
}