通过 Vision
Vision
也许你们中有人知道我做错了什么。
let rect = CGPoint(x: barcode.boundingBox.origin.x, y: barcode.boundingBox.origin.y) let hitTestResults = sceneView.hitTest(rect, types: [.existingPlaneUsingExtent, .existingPlane]) if let hitResult = hitTestResults.first { //TODO: change to width and height let plane = SCNPlane(width: 0.1, height: 0.1) let material = SCNMaterial() material.diffuse.contents = UIColor.red plane.materials = [material] let node = SCNNode() node.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0) node.position = SCNVector3(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z) node.geometry = plane sceneView.scene.rootNode.addChildNode(node) }
编辑:
添加了当前情况的图片。红色平面添加在左上角。然而,该平面必须精确地添加到te QRCode上。
使用中心点而不是原点对我有效:
let center2 = CGPoint(x: result.boundingBox.midX, y: result.boundingBox.midY) let hitTestResults2 = frame.hitTest(center2, types: [.featurePoint/*, .estimatedHorizontalPlane, .existingPlane, .existingPlaneUsingExtent*/] )