I am loading a 3D object using SceneView
in SwiftUI:
SceneView(
scene: scene,
pointOfView: cameraNode,
options: [.autoenablesDefaultLighting]
)
I have removed .allowsCameraControl
property from options
to handle gestures manually. I want to be able to rotate the object horizontally. In UIKit I was able to do so using UIPanGestureRecognizer
like this:
func rotateObject(_ gesture: UIPanGestureRecognizer) {
var currentAngleY: Float = 0.0
guard let nodeToRotate = scene?.rootNode else { return }
let translation = gesture.translation(in: gesture.view!)
var newAngleY = (Float)(translation.x) * (Float)(Double.pi) / 180.0
newAngleY += currentAngleY
nodeToRotate.eulerAngles.y = newAngleY
if(gesture.state == .ended) { currentAngleY = newAngleY }
}
But in SwiftUI I am not sure how can do it, any help would be appreciated.