Hi, for anyone looking for similar thing, this solution worked nice for me:
import SwiftUI
import RealityKit
import MapKit
struct SwiftUIView: View {
@PhysicalMetric(from: .meters) private var oneMeter = 1
@State var mainEntity = Entity()
var body: some View {
RealityView { content, attachments in
// Create and configure the 3D shape entity
let shapeEntity = ModelEntity(mesh: .generateCylinder(height: 0.03, radius: 0.45))
mainEntity.addChild(shapeEntity)
content.add(shapeEntity)
mainEntity.addChild(shapeEntity)
if let mapAttachment = attachments.entity(for: "mapAttachment") {
// Adjust the map attachment's transformation to the same size and orientation as the 3D shape entity
mapAttachment.transform = Transform(pitch: -.pi / 2, yaw: 0, roll: 0)
// Position the map slightly above the 3D shape entity
let shapeDimensions = shapeEntity.visualBounds(relativeTo: nil).extents
mapAttachment.setPosition(SIMD3<Float>(0, shapeDimensions.y / 2 + 0.0001, 0), relativeTo: shapeEntity)
mainEntity.addChild(mapAttachment)
}
content.add(mainEntity)
}
attachments: {
// Create and add a map attachment to the RealityKit scene
Attachment(id: "mapAttachment") {
Map()
.frame(width: oneMeter * 0.45 * 2, height: oneMeter * 0.45 * 2)
.mask(Circle())
}
}
}
}