Вот ближайшее, к которому я добираюсь, и он действительно перемещается в 3D, но
плохо отвечает на местоположение пальца. < /p>
Код: Выделить всё
import SwiftUI
import RealityKit
struct ContentView: View {
@State var box = Entity()
@State var lastPanTouchPosition: CGPoint = .zero
var body: some View {
RealityView{ content in
let item = ModelEntity(mesh: .generateBox(size: .init(0.25, 0.25, 0.25)), materials: [SimpleMaterial(color: .blue, isMetallic: true)])
box.addChild(item)
content.add(box)
}
.gesture(dragThis)
}
var dragThis: some Gesture {
DragGesture()
.onChanged { value in
print(value.translation)
print(value.location)
let dragRatio: Float = 0.0001
box.position.x += Float(value.translation.width) * dragRatio
box.position.y -= Float(value.translation.height) * dragRatio
}
.onEnded{_ in
box.position = [0, 0, 0]
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ag-gesture