ARKit Показывает сломанный UIWebView - PullRequest
0 голосов
/ 09 октября 2019

Я пытаюсь определить изображение с помощью ARImageTrackingConfiguration, и при обнаружении изображения вместо сканированного изображения появляется UIWebView. Я прочитал много проблем, связанных с новым WBWebView, но он тоже не работает.

Кажется, проблема в том, что UIWebView не обновляется из основного потока, даже если я использую DispatchMain.

В смежной теме (код, который я использую, почти такой же), если я попытаюсь поставить SKVideoNode вместо UIWebView, видео будет проигрываться очень медленно с некоторыми большими пикселями сверху, если я установлю plane.cornerRadius =0,25

Код следующий


func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let imageAnchor = anchor as? ARImageAnchor else { return }

        updateQueue.async {
            let physicalWidth = imageAnchor.referenceImage.physicalSize.width
            let physicalHeight = imageAnchor.referenceImage.physicalSize.height

            // Create a plane geometry to visualize the initial position of the detected image
            let mainPlane = SCNPlane(width: physicalWidth, height: physicalHeight)

            mainPlane.firstMaterial?.colorBufferWriteMask = .alpha

            // Create a SceneKit root node with the plane geometry to attach to the scene graph
            // This node will hold the virtual UI in place
            let mainNode = SCNNode(geometry: mainPlane)
            mainNode.eulerAngles.x = -.pi / 2
            mainNode.renderingOrder = -1
            mainNode.opacity = 1

            // Add the plane visualization to the scene
            node.addChildNode(mainNode)

            // Perform a quick animation to visualize the plane on which the image was detected.
            // We want to let our users know that the app is responding to the tracked image.
            self.highlightDetection(on: mainNode, width: physicalWidth, height: physicalHeight, completionHandler: {

            DispatchQueue.main.async {
            let request = URLRequest(url: URL(string: "https://www.facebook.com/")!)
            let webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 400, height: 672))
            webView.loadRequest(request)

            let webViewPlane = SCNPlane(width: xOffset, height: xOffset * 1.4)
            webViewPlane.cornerRadius = 0.25

            let webViewNode = SCNNode(geometry: webViewPlane)
            webViewNode.geometry?.firstMaterial?.diffuse.contents = webView
            webViewNode.position.z -= 0.5
            webViewNode.opacity = 0

            rootNode.addChildNode(webViewNode)
            webViewNode.runAction(.sequence([
                .wait(duration: 3.0),
                .fadeOpacity(to: 1.0, duration: 1.5),
                .moveBy(x: xOffset * 1.1, y: 0, z: -0.05, duration: 1.5),
                .moveBy(x: 0, y: 0, z: -0.05, duration: 0.2)
                ])
            )
        }


            })
        }
    }


VIDEO VERSION

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let imageAnchor = anchor as? ARImageAnchor else { return }

        updateQueue.async {
            let physicalWidth = imageAnchor.referenceImage.physicalSize.width
            let physicalHeight = imageAnchor.referenceImage.physicalSize.height

            // Create a plane geometry to visualize the initial position of the detected image
            let mainPlane = SCNPlane(width: physicalWidth, height: physicalHeight)

            mainPlane.firstMaterial?.colorBufferWriteMask = .alpha

            // Create a SceneKit root node with the plane geometry to attach to the scene graph
            // This node will hold the virtual UI in place
            let mainNode = SCNNode(geometry: mainPlane)
            mainNode.eulerAngles.x = -.pi / 2
            mainNode.renderingOrder = -1
            mainNode.opacity = 1

            // Add the plane visualization to the scene
            node.addChildNode(mainNode)

            // Perform a quick animation to visualize the plane on which the image was detected.
            // We want to let our users know that the app is responding to the tracked image.
            self.highlightDetection(on: mainNode, width: physicalWidth, height: physicalHeight, completionHandler: {

                let size = imageAnchor.referenceImage.physicalSize

                var videoNode = SKVideoNode()

                switch imageAnchor.name {
                case "Elephant-PostCard":
                    videoNode = SKVideoNode(fileNamed: "Movies/cat.mp4")

                case "puppy":
                    videoNode = SKVideoNode(fileNamed: "puppy.mov")
                default:
                    break
                }
                // invert our video so it does not look upside down
                videoNode.yScale = -1.0

                videoNode.play()

                let videoScene = SKScene(size: CGSize(width: 1280, height: 720))

                videoScene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
                videoScene.addChild(videoNode)

                let plane = SCNPlane(width: size.width, height: size.height)
                plane.cornerRadius = 0.25
                plane.firstMaterial?.diffuse.contents = videoScene

                let planeNode = SCNNode(geometry: plane)
                plane.firstMaterial?.isDoubleSided = true

                mainNode.addChildNode(planeNode)

            })
        }
    }



...