Convert RealityView Attachment View Coordinate to Scene Coordinates

74 views Asked by At

Just starting out with RealityKit and RealityView. Imagine trying to put a view onto a table instead of vertical in a window. So I have an immersive space with a simple plane entity and an attachment.

Simple SwiftUI view as an attachment that picks up touches and interaction. In SwiftUI I can get the touch events and their coordinates in the view space. I'm now trying to do something in the scene space with where that coordinate relates to.

I can't seem to figure out how to convert from view space to entity space to scene space.

In the update: block of the reality view I am adding a simple sphere where my calculations dictate, and the spacing and orientation is correct but they're not where the tap occurred.

let convertedPoint = content.convert(Point3D(x: screenPoint.x, y: 0, z: screenPoint.y), from: .local, to: .scene)

Also tried using:

attachmentEntity.convert(position: SIMD3(x: Float(point.x), y: 0, z: Float(point.y)), to: nil)

Neither result in correct placement when adding a ball as so:

                    let ballEntity = ModelEntity(mesh: .generateSphere(radius: 0.02), materials: [SimpleMaterial(color: .red, isMetallic: true)])
                    // move it up vertically 
                    ballEntity.position = convertedPoint
                    content.add(ballEntity)

Basically I'd like to go from tap on an attachment view to a scene point of that tap. Is that possible? There are a lot of convert functions but most are from entity to entity, I don't see any relating to attachment space to entity space.

0

There are 0 answers