I'm still looking for an answer!
Post
Replies
Boosts
Views
Activity
Thanks for your quick reply!
So basically, the attachment is currently behind the visible window, but I would like to have it visible in front of the window. If you look at the screenshots, you can see that the "Hello World" attachment will always be behind the window, whether I move the window closer or further away. So, I'm assuming that it is a layering issue within the space?
Thank you for your answer!
Maybe as a follow-up question. To me, it does not seem to be entirely clear why, when I'm trying to display my attachment, no matter the positioning, it will always be hidden/covered by the window. I'm trying to achieve displaying the attachment one layer above/in front of the window.
Thank you for your help!
ContentView.swift
import SwiftUI
import RealityKit
struct ContentView: View {
@Environment(\.openImmersiveSpace) private var openImmersiveSpace
public var body: some View {
VStack {
Text("Hello World")
.font(.largeTitle)
Button("Start") {
Task {
await openImmersiveSpace(id: "AppSpace")
}
}
}
}
}
ImmersiveView.swift
import SwiftUI
import RealityKit
struct ImmersiveView: View {
var loader: EnvironmentLoader
public var body: some View {
RealityView { content, attachments in
content.add(try! await loader.getEntity())
let headEntity = AnchorEntity(.head)
content.add(headEntity)
if let text = attachments.entity(for: "at01") {
text.position = [0, 0, -0.25]
headEntity.addChild(text)
}
}
attachments: {
Attachment(id: "at01") {
Text("Hello World!")
.font(.extraLargeTitle)
.padding()
}
}
}
}
App.swift
import SwiftUI
@main
private struct App: App {
@State var loader = EnvironmentLoader()
public var body: some Scene {
WindowGroup {
ContentView()
}
ImmersiveSpace(id: "AppSpace") {
ImmersiveView(loader: loader)
}
.immersionStyle(selection: .constant(.progressive), in: .progressive)
}
}
I'm still looking for an optimal solution, so I would be thankful for any response!
In case of any ambiguity in the question: It would be important that the Mac Virtual Display would appear IN the app window, not as a seperate view.
Hi Michael @Vision Pro Engineer
First of all, thank you for your quick answer. I appreciate your effort!
I think it goes in the right direction. To maybe give you a better idea of what I aim to achieve. The goal is basically to have a state of "distraction," which is the case if the user won't have the app window in front of it's vision/orientation of the AVP.
Unfortunately, as far as I understood, ScenePhase only tells me if, let's say, the user closes the app window, it is now in the background, and if reopening the app, it is active, etc. What I was hoping for would be something that I can access that could tell me if the window of the app is either within the visible space of the user (e.g., I just started the app, and the window is in front of me and my AVP is also directed towards the window) or not (e.g., my window is still at the initial spawn space when I started the app but I've turned around so the window would be behind my back, not visible anymore for me).
Furthermore, now that I'm able to track the spatial positioning of the window as you suggested, would there be a way to either be able to track if the window is within the space of the AVP's orientation (e.g., as long as I have the window in my vision or even only a corner of it) OR attach the AVP's originFromAnchorTransform property to the window, so that eventually the app launches and the AVP's orientation rotation data angles are set to 0, having the window basically as the center of orientation, and then making the AVP's orientation depending on the window, speaking of if I would move the window and then look perfectly centered at the new positioned window, I would be back at the 0 values.