Post

Replies

Boosts

Views

Activity

Reply to RealityKit Crash with Orthographic Camera
Updated: In Xcode 16.3 beta, the unprojection of a point from screen to world is already better. However, the values are still wrong (very large values). Because of this, interaction with entities using InputTargetComponent is not possible. import SwiftUI import RealityKit struct ContentView: View { @State var tapPoint: CGPoint? = nil var body: some View { RealityView { content in var camera = Entity() var component = OrthographicCameraComponent() component.scale = 5 camera.position = [0, 0, 5] camera.components.set(component) content.add(camera) let model = ModelEntity(mesh: .generateSphere(radius: 1)) model.name = "Model" model.components.set(InputTargetComponent()) model.generateCollisionShapes(recursive: false) content.add(model) } update: { content in if let p = tapPoint { let planeMatrix = simd_float4x4( SIMD4<Float>( 1, 0, 0, 0), SIMD4<Float>( 0, 0, 1, 0), SIMD4<Float>( 0, -1, 0, 0), SIMD4<Float>( 0, 0, 0, 1) ) if let u = content.unproject(p, from: .global, to: .scene, ontoPlane: planeMatrix) { print("Tapped at \(u)") } } } .simultaneousGesture( SpatialTapGesture() .onEnded({value in tapPoint = value.location }) ) .simultaneousGesture( SpatialTapGesture() .targetedToAnyEntity() .onEnded({value in print(value.entity.name) }) ) } }
Topic: Graphics & Games SubTopic: RealityKit Tags:
Feb ’25
Reply to RealityKit Crash with Orthographic Camera
Hello! I had a similar issue. Adding OrthographicCameraComponent does not crash anymore, but it crashed for me when computing a projection from the world coordinates to screen coordinates or another way around. import SwiftUI import RealityKit struct ContentView: View { var body: some View { RealityView { content in var camera = Entity() var component = OrthographicCameraComponent() component.scale = 5 camera.position = [0, 0, 5] camera.components.set(component) content.add(camera) content.add(ModelEntity(mesh: .generateSphere(radius: 1))) } update: { content in if let p = content.project(point: [0, 0, 0], to: .local) { print(p) } } } } #Preview { ContentView() }
Topic: Graphics & Games SubTopic: RealityKit Tags:
Feb ’25