我有一个扩展名为.scn的3D模型。如何在没有来自iOS示例放置对象应用程序的 virtualobject 文件的情况下使用捏合手势进行缩放。
如果从.scj文件转换后,捏合手势适用于.scn' s。但它不适用于.dae模型。
func addPinchGestureToSceneView() {
pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(scale))
pinchGesture.scale = 1.0;
pinchGesture.delegate = self
self.sceneView.addGestureRecognizer(pinchGesture)
}
private func node(at position: CGPoint) -> SCNNode? {
var hitTestOptions = [SCNHitTestOption: Any]()
hitTestOptions[SCNHitTestOption.boundingBoxOnly] = true
return sceneView.hitTest(position, options: hitTestOptions)
.first(where: { self.getOnlyModelName(name: $0.node.name ?? "") == self.currentmodel.modelname})?
.node
}
@objc func scale(_ gesture: UIPinchGestureRecognizer) {
if self.currentmodel.isZoomEnabled == false{
return
}
let location = gesture.location(in: sceneView)
guard let node = node(at: location)else{return}
// guard let node = node(at: location) else { return }
switch gesture.state {
case .began:
originalScale = node.scale
gesture.scale = CGFloat(node.scale.x)
print("Begin:: \(originalScale)")
case .changed:
guard var originalScale = originalScale else { return }
if gesture.scale > 2.0{
return
}
originalScale.x = Float(gesture.scale)
originalScale.y = Float(gesture.scale)
originalScale.z = Float(gesture.scale)
node.scale = originalScale
case .ended:
guard var originalScale = originalScale else { return }
if gesture.scale > 2.0{
return
}
originalScale.x = Float(gesture.scale)
originalScale.y = Float(gesture.scale)
originalScale.z = Float(gesture.scale)
node.scale = originalScale
gesture.scale = CGFloat(node.scale.x)
default:
gesture.scale = 1.0
originalScale = nil
}
答案 0 :(得分:0)
当它是一个dae时,你可能需要尝试抓住命中测试中捕获的节点的父节点。我和dae有类似的问题,通过获得孩子的父母,甚至有时是孩子的祖父母来解决问题。