0

目前,当我在手机上构建时,我看到 SCNPlane 出现在相机正在检测的图像上。SCNPlane 在调整到它检测到的图像大小时没有问题。我遇到的问题是使用 SCNPlane 并将其替换为 SKVideoNode 及其 SKScene ,它还可以根据图像自动调整其大小。

有任何想法吗?

谢谢你!

 if let imageAnchor = anchor as? ARImageAnchor
        {

            //get plane
            let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)

            plane.firstMaterial?.diffuse.contents = UIColor(white: 1, alpha: 0.8)

            let planeNode = SCNNode(geometry: plane)
            planeNode.eulerAngles.x = -.pi / 2


            // get container
            guard let container = ARSceneView.scene.rootNode.childNode(withName: "Container", recursively: false) else {return}


            container.removeFromParentNode()

            container.position.y = planeNode.position.y + Float(CGFloat (0.25))
            container.position.z = planeNode.position.z + Float(CGFloat (0.1))

            planeNode.addChildNode(container)
            node.addChildNode(planeNode)

            container.isHidden = false



            //VIDEO SCENE
            let videoURL = Bundle.main.url(forResource: "video", withExtension: "mp4")!
            let videoPlayer = AVPlayer(url:videoURL)

            let videoPlane = SKScene(size: CGSize(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height))
            //videoPlane = SKScene(size: CGSize(width: 720.0, height: 1280.0))
            let videoNode = SKVideoNode(avPlayer: videoPlayer)

            videoNode.play()
            videoPlane.addChild(videoNode)

            guard let video = container.childNode(withName: "Video", recursively: true) else {return}

            video.geometry?.firstMaterial?.diffuse.contents = videoPlane
4

0 回答 0