yshrkt / VuforiaSampleSwift

Vuforia sample code with SceneKit using Swift
MIT License
123 stars 24 forks source link

Playing video #16

Open ghost opened 7 years ago

ghost commented 7 years ago

Hey, lovely project, have been using it to work with Vuforia for a few weeks. Do you have any guidelines on how this project could be used to display a video instead of where you'd display a SCNode? Vuforia has a sample for playing video but it's a bit over my head, maybe you could give me some directions. Thanks!

markleeyw commented 7 years ago

Yes i agree. I'm trying to do this and would like some advice if possible :) This project has been really helpful!

yshrkt commented 7 years ago

@Angryhead

I fixes minor issue in 32ec7d8f. So, if you are using iOS9, You can display video using SKVideoNode. But iOS10 not work PrefersOpenGL. it seems to be used Metal for rendering SKVideoNode in iOS10.


fileprivate func createStonesScene(with view: VuforiaEAGLView) -> SCNScene {
        let scene = SCNScene()

        let lightNode = SCNNode()
        lightNode.light = SCNLight()
        lightNode.light?.type = .omni
        lightNode.light?.color = UIColor.lightGray
        lightNode.position = SCNVector3(x:0, y:10, z:10)
        scene.rootNode.addChildNode(lightNode)

        let ambientLightNode = SCNNode()
        ambientLightNode.light = SCNLight()
        ambientLightNode.light?.type = .ambient
        ambientLightNode.light?.color = UIColor.darkGray
        scene.rootNode.addChildNode(ambientLightNode)

        let videoWidth: CGFloat = 1280
        let videoHeight: CGFloat = 720

        let urlStr = Bundle.main.path(forResource: "sample", ofType: "mov")
        let url = URL(fileURLWithPath: urlStr!)

        let asset = AVURLAsset(url: url, options: nil)
        let playerItem = AVPlayerItem(asset: asset)
        let player = AVPlayer(playerItem: playerItem)

        let videoNode = SKVideoNode(avPlayer: player)
        videoNode.position = CGPoint(x: videoWidth/2.0, y: videoHeight/2.0)
        videoNode.yScale = -1.0

        let sprite = SKScene(size: CGSize(width: videoWidth, height: videoHeight))
        videoNode.size.width = sprite.size.width
        videoNode.size.height = sprite.size.height
        sprite.addChild(videoNode)

        let planeNode = SCNNode()
        planeNode.name = "plane"
        planeNode.geometry = SCNPlane(width: 247.0/view.objectScale, height: 173.0/view.objectScale)
        planeNode.position = SCNVector3Make(0, 0, -2)
        planeNode.transform = SCNMatrix4MakeScale(1.0, 9.0/16.0, 1.0)
        let planeMaterial = SCNMaterial()
        planeMaterial.diffuse.contents = sprite
        planeNode.geometry?.firstMaterial = planeMaterial
        scene.rootNode.addChildNode(planeNode)
        videoNode.play()
}
markleeyw commented 7 years ago

for iOS 10 as mentioned cannot see.

Any advice how to slove this as most user now as slowly moving to iOS 10?

Thank you!

2016-10-16 17:40:32.786630 VuforiaSampleSwift[502:60027] Created new image data buffer @ 0x10ae7c000 w/ 1382400 bytes stones scene Failed to create IOSurface image (texture) after EAGLView renderFrameVuforia() glError (0x506) after EAGLView renderFrameVuforia() glError (0x506)

yshrkt commented 7 years ago

@markleeyw I'm trying to use Vuforia with Metal instead of OpenGLES. But it does not work well now...

markleeyw commented 7 years ago

Thank you. Hope there is some update soon :)

byroncoetsee commented 7 years ago

Hey @yshrkt - any news on that update? 😃

markleeyw commented 7 years ago

Any update ? :)

markleeyw commented 7 years ago

Any update :)