Created
December 16, 2019 13:25
-
-
Save ozgurshn/49f282db17c39340a71363d57664cce8 to your computer and use it in GitHub Desktop.
add video as a plane node to SCNView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let videoNode = SKVideoNode(url: URL(string: "https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4")!) | |
| videoNode.play() | |
| // set the size (just a rough one will do) | |
| let videoScene = SKScene(size: CGSize(width: 480, height: 360)) | |
| // center our video to the size of our video scene | |
| videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2) | |
| // invert our video so it does not look upside down | |
| videoNode.yScale = -1.0 | |
| // videoNode.xScale = -1.0 | |
| // add the video to our scene | |
| videoScene.addChild(videoNode) | |
| // create a plan that has the same real world height and width as our detected image | |
| let plane = SCNPlane(width: 0.35, height: 0.35) | |
| // set the first materials content to be our video scene | |
| plane.firstMaterial?.diffuse.contents = videoScene | |
| // create a node out of the plane | |
| let planeNode = SCNNode(geometry: plane) | |
| // since the created node will be vertical, rotate it along the x axis to have it be horizontal or parallel to our detected image | |
| // planeNode.eulerAngles.x = -Float.pi / 2 | |
| // finally add the plane node (which contains the video node) to the added node | |
| node.addChildNode(planeNode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment