8

i'm trying to use a SKVideoNode as a video texture source for a SCNSphere within my SCNView

I'm following this answer:

SKVideoNode (embedded in SKScene) as texture for for Scene Kit Node not working

And with my code (pasted at the end of the question) I do get a video and an audio playing.

Issue is, the mapping only occurs on a quarter of the sphere (the all xy-positive quarter).

The cameraNode is inside (0,0,0) the sphere and independent of the sphereNode.

I do apply a scale to the sphere node, just to reverse the nodes of the texture:

    sphereNode.scale = SCNVector3Make(-1, 1, 1)

but commenting that out has no effect.

This is all tested on the device (iphone 6+, using iOS 9.1):

  let sphere = SCNSphere(radius: 1)
    .
    .
    .

       func setupView() {

    // setup the sphere
    sphere.segmentCount = 55

    // sphere material
    sceneMaterial = SCNMaterial()


    // setup the sphereNode
    sphereNode = SCNNode(geometry: sphere)
    sphereNode.position = SCNVector3Make(0, 0, 0)
    sphereNode.scale = SCNVector3Make(-1, 1, 1)

    let apperture = 75.0

    // setup the camera
    camera = SCNCamera()
    camera.xFov = apperture
    camera.zFar = 10000
    camera.yFov = apperture
    camera.zNear = 0.5
    camera.aperture = 1/10
    cameraNode.position = SCNVector3Make(0, 0, 0)
    cameraNode.camera = camera

    // light node
    let lightNode = SCNNode()
    lightNode.position = SCNVector3Make(0, 0, 0)

    // light
    let ambientLight = SCNLight()
    ambientLight.type = SCNLightTypeAmbient
    ambientLight.color = UIColor(white: 0.7, alpha: 1)
    lightNode.light = ambientLight


    // add top sceneView
    topScene.scene = scene
    bottomScene.scene = scene

    // setup the sceneView
    scene.rootNode.addChildNode(sphereNode)
    scene.rootNode.addChildNode(cameraNode)



    // video reader
    let path = NSBundle.mainBundle().pathForResource("tb", ofType: "mp4")
    let url  = NSURL(fileURLWithPath: path!)
    let asset = AVURLAsset(URL: url,options: nil)
    let playerItem = AVPlayerItem(asset: asset)
    let player = AVPlayer(playerItem: playerItem)
    let videoNode = SKVideoNode(AVPlayer: player)

    // check the sizes
    let size = CGFloat(1000.0)
    let spriteScene = SKScene(size: CGSizeMake(size,size))
    videoNode.size.width = size
    videoNode.size.height = size
    spriteScene.addChild(videoNode)

    // the image
    sceneMaterial.specular.contents = UIColor.whiteColor()
    sceneMaterial.doubleSided = true
    sceneMaterial.shininess = 1
    sceneMaterial.diffuse.contents = spriteScene


    sphere.materials = [sceneMaterial]
    videoNode.play()


}
Community
  • 1
  • 1
David Homes
  • 2,725
  • 8
  • 33
  • 53
  • Hi. I'm the guy who wrote the answer you're following. If you post your code in its entirety, it would be easier to test. – jglasse Jun 14 '16 at 16:20

0 Answers0