Created
December 11, 2014 22:10
-
-
Save glaurent/aad82c4185f3c92f21dc to your computer and use it in GitHub Desktop.
adding a video in a SceneKit scene using a SpriteKit SKVideoNode
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 spriteKitScene = SKScene(size: CGSize(width: 1276.0 / 2.0, height: 712.0 / 2.0)) | |
var videoSpriteKitNode:SKVideoNode? | |
let videoNode = SCNNode() | |
videoNode.geometry = SCNPlane(width: videoNodeWidth, height: videoNodeHeight) | |
// using SpriteKit scene with videonode inside | |
// | |
spriteKitScene.scaleMode = .AspectFit | |
videoSpriteKitNode?.position = CGPoint(x: spriteKitScene.size.width / 2.0, y: spriteKitScene.size.height / 2.0) | |
videoSpriteKitNode?.size = spriteKitScene.size | |
spriteKitScene.addChild(videoSpriteKitNode!) | |
videoNode.geometry?.firstMaterial?.diffuse.contents = spriteKitScene | |
videoNode.geometry?.firstMaterial?.doubleSided = true | |
// flip video upside down, so that it's shown in the right position | |
// | |
var transform = SCNMatrix4MakeRotation(Float(M_PI), 0.0, 0.0, 1.0) | |
transform = SCNMatrix4Translate(transform, 1.0, 1.0, 0) | |
videoNode.geometry?.firstMaterial?.diffuse.contentsTransform = transform | |
videoNode.position = SCNVector3(x: 0, y: 30, z: 7) | |
aSceneKitNode.addChildNode(videoNode) | |
videoSpriteKitNode?.play() |
Any idea why is it shown upside down?
I was doing something similar and getting upside down labels. Try this:
videoNode.geometry?.firstMaterial?.diffuse.contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0)
(From this post: https://stackoverflow.com/questions/33284781/scenekit-flip-direction-of-scnmaterial)
@guoye-zhang's suggestion using videoSpriteKitNode?.yScale = -1
works great for me
contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0) doesn't seem to do anything on iOS 13.4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or you can just use: