IOS How to take a custom resizable SKVideoNode to reference a custom resizable ARImageAnchor SCNPlane's position and size

122 views Asked by At

Currently, when I build to my phone I see the SCNPlane pop over an image the camera is detecting. The SCNPlane does not have an issue adjusting to the size of the image it detects. What I am having trouble with is taking the SCNPlane and replacing it with a SKVideoNode and its SKScene that can also auto adjust its size to the image.

Any Ideas?

Thank You!

 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
0

There are 0 answers