We have a plane model (basecircle)without physics and rigid body components, and no gestures are implemented. However, when tapped, the model unexpectedly falls into infinity.
func fetchEnvResource(){
var simpleMaterial = SimpleMaterial()
env = try! Entity.loadModel(named: "bgMain5")
env.position += [0,0,-10]
envTexture = PhysicallyBasedMaterial()
envTextureUnlit = UnlitMaterial()
envTexture.baseColor = .init(texture: .init(try! .load(named: "bgMain5")))
envTextureUnlit.color = .init(texture: .init(try! .load(named: "bgMain5")))
env.isEnabled = false
let anchor = AnchorEntity(world: [0, 0, -3])
baseCircle = ModelEntity(mesh: .generatePlane(width: 1.5, depth: 1.5, cornerRadius: 0.75), materials: [SimpleMaterial(color: .green, isMetallic: false)])
env.components.set(InputTargetComponent())
baseMaterial = PhysicallyBasedMaterial()
baseMaterialUnlit = UnlitMaterial()
baseMaterial.baseColor = .init(texture: .init(try! .load(named: "groundTexture")))
baseMaterial.baseColor.tint = UIColor(white: 1.0, alpha: CGFloat(textureOpacity))
baseCircle.model?.materials = [baseMaterial]
baseCircle.generateCollisionShapes(recursive: false)
baseCircle.components.set(InputTargetComponent())
baseCircle.components[PhysicsBodyComponent.self] = .init(PhysicsBodyComponent(massProperties: .default, mode: .static))
baseCircle.physicsBody = PhysicsBodyComponent(
mode: .kinematic
)
anchorEntity.addChild(baseCircle)
baseCircle.position = [0,0,-3]
baseCircle.isEnabled = false
let cylinder = ModelEntity(mesh: .generateCylinder(height: 0.2, radius: 0.5), materials: [SimpleMaterial(color: .blue, isMetallic: false)])
cylinder.position = [0,-0.1,0]
cylinder.generateCollisionShapes(recursive: false)
cylinder.components[PhysicsBodyComponent.self] = .init(PhysicsBodyComponent(massProperties: .default, mode: .static))
cylinder.physicsBody = nil
cylinder.scale = [500, 100, 100]
anchor.addChild(cylinder)
}
The plane model in this issue is the BaseCircle. Any suggestions on how to solve this or potential fixes would be greatly appreciated
Post
Replies
Boosts
Views
Activity
We are encountering an issue with our app on Vision Pro with OS version 1.3. The app runs perfectly in the VisionOS Simulator, but when tested on the actual device, no content is displayed.
Here’s the expected behavior: When the app launches, a video should play in a window. Once the video ends, another information window should open. After a series of these information windows, we will load to an immersive space to handle 3D elements.
We've set the "Preferred Default Scene Session Role" to "Window Application Session Role" in info.plist, but the issue persists.
Below is the code we're using. Any advice or suggestions would be greatly appreciated.
import SwiftUI
@main
struct myApp: App {
@StateObject var sharedData = SharedDataModel()
@State private var isFactoryEnabled = false
var body: some Scene {
WindowGroup(id: "LaunchScreen", content: {
LaunchScreen()
})
.windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup(id: "LoginView", content: {
ZStack {
let _ = UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
let _ = print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.path)
LoginView()
}
}).windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup(id: "TrainingSelection", content: {
if !sharedData.showNavigationHintView{
NavigationHintView()
.glassBackgroundEffect()
.cornerRadius(30)
}
else {
TrainingSelection()
}
}).windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup(id: "Salutations", content: {
Salutations()
}).windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup {
ContentView()
}
.environmentObject(sharedData)
ImmersiveSpace(id: "myImmersiveSpace") {
ImmersiveView(viewModel: .init())
}
.environmentObject(sharedData)
}
}
import SwiftUI
import AVFoundation
import RealityKit
import RealityKitContent
struct LaunchScreen: View {
@State private var player: AVPlayer?
@State private var navigateToContentView = false
@EnvironmentObject var audioPlayer: AudioPlayer
var body: some View {
ZStack {
ZStack {
if navigateToContentView {
WarningView()
.transition(.opacity)
.glassBackgroundEffect()
.cornerRadius(15)
} else {
if let player = player {
AVPlayerView(player: player)
.onAppear {
player.play()
addObserver()
}
.cornerRadius(30)
} else {
Text("Unable to Load the Video")
.foregroundColor(.white)
.onAppear {
loadVideo()
}
}
}
}
.edgesIgnoringSafeArea(.all)
.animation(.easeIn, value: 1)
}
.glassBackgroundEffect()
}
private func loadVideo() {
if let videoUrl = Bundle.main.url(forResource: "launchScreen", withExtension: "mp4") {
player = AVPlayer(url: videoUrl)
} else {
print("Unable to Load the Video")
}
}
private func addObserver() {
NotificationCenter.default.addObserver(
forName: .AVPlayerItemDidPlayToEndTime,
object: player?.currentItem,
queue: .main
) { _ in
self.navigateToContentView = true
}
}
}