Hi!
I wanna know that if it's possible that loading Immersive Scene after scanning(recognizing) preregistered images or objects? I tried to load the Immersive scene after scanning image and objects, it didn't work well. Please let me know about the solution if it's possible. Here the ImmersiveView.swift code i tried.
// ImmersiveView.swift
import SwiftUI
import RealityKit
import RealityKitContent // Using the RealityKitContent module
struct ImmersiveView: View {
@ObservedObject var viewModel: TrackingViewModel
@State private var immersiveScene: Entity?
@State private var isToggleOn: Bool = false // Variable for toggle state
var body: some View {
ZStack { // Overlay RealityView and UI elements
RealityView { content in
if let scene = immersiveScene {
content.add(scene)
print("Immersive scene successfully added.")
if let moneyGunsEntity = scene.findEntity(named: "MoneyGuns") {
NotificationCenter.default.post(
name: Notification.Name("RealityKit.NotificationTrigger"),
object: nil,
userInfo: [
"RealityKit.NotificationTrigger.Scene": scene,
"RealityKit.NotificationTrigger.Identifier": "PlayTimeline"
]
)
print("PlayTimeline notification sent.")
} else {
print("MoneyGuns entity not found.")
}
}
}
.onAppear {
Task {
if let scene = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
immersiveScene = scene
} else {
print("Failed to load immersive scene.")
}
}
}
VStack {
Spacer()
Toggle(isOn: $isToggleOn) { // Add toggle button
Text("Toggle Option")
.foregroundColor(.white)
}
.padding()
.background(Color.black.opacity(0.7))
.cornerRadius(8)
.padding()
}
}
}
}