旋转后未正确检测到SCNNode平面

时间:2019-03-18 19:34:32

标签: swift augmented-reality scnnode

我有一个水平面被检测到。一旦检测到,我希望该平面(矩形)始终显示为水平(宽度>高度)。 这是我用来创建此SCNNode的代码:

  func createFloorNode(anchor: ARPlaneAnchor) ->SCNNode {
    let geometry = SCNPlane(width: CGFloat(anchor.extent.x), height: CGFloat(anchor.extent.z))
    let floorNode = SCNNode(geometry: geometry)
    floorNode.position = SCNVector3(anchor.center.x, 0, anchor.center.z)
    floorNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red 
    floorNode.geometry?.firstMaterial?.isDoubleSided = true
    floorNode.eulerAngles = SCNVector3(-Double.pi/2, 0, 0)
    if geometry.width < geometry.height {
      floorNode.eulerAngles = SCNVector3(-Double.pi/2, -Double.pi/2, 0)
    }
    floorNode.name = floorNodeName
    return floorNode
  } 

此后,我添加了一个轻击手势功能,如果希望我在SCNNode内轻击,我希望它告诉我:

  @objc func tapped(sender: UITapGestureRecognizer) {
    guard let sceneView = sender.view as? ARSCNView else { return }
    let tapLocation = sender.location(in: sceneView)

    let hitTest = sceneView.hitTest(tapLocation, types: .existingPlaneUsingExtent)
    guard !hitTest.isEmpty else {
      print("Not a plane")
      return
    }
    print("Touched on the plane")
  }

问题是,在我旋转了scnnode之后,该功能会继续检测该平面是否为旧平面(在被检测之前)。如果我不旋转它,效果很好。

有什么想法吗?

0 个答案:

没有答案