2
votes

SCNMaterialProperty's contents property on SCNMaterial is unable to render when assigned a AVPlayerLayer. Note this is only a issue on a physical device, works fine on the simulator (Xcode 6.0.1).

I am creating my SCNode as such:

SCNNode *videoBall = [SCNNode node];
videoBall.position = SCNVector3Make(-5, 5, -18);
videoBall.geometry = [SCNSphere sphereWithRadius:5];
videoBall.geometry.firstMaterial.locksAmbientWithDiffuse = YES;
videoBall.geometry.firstMaterial.diffuse.contents = [self videoLayer];
videoBall.geometry.firstMaterial.diffuse.contentsTransform = SCNMatrix4MakeScale(2, 1, 1);
videoBall.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeMirror;
[[scene rootNode] addChildNode:videoBall];

I am creating the video layer as such:

- (AVPlayerLayer *)videoLayer {
  if (_videoLayer == nil) {
    AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://devstreaming.apple.com/videos/wwdc/2014/609xxkxq1v95fju/609/609_sd_whats_new_in_scenekit.mov"]];
    _videoLayer = [AVPlayerLayer layer];
    [_videoLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    _videoLayer.frame = CGRectMake(0, 0, 1000, 1000);
    _videoLayer.player = player;

    [player play];
  }
return _videoLayer;
}

So this works fine in the simulator. However on a iPhone 6 running iOS 8.0.2, I can hear the audio but the node is invisible.

Is this a bug or am I doing something wrong?

If the goal is to map a movie on a 3D object you can try to use a SKVideoNode in a SKScene instead. - Toyos
I have the same problem except I'm trying to render the video on a plane, my code is written in Swift, and I'm running it on an iPAd (running 8.0.2 as well). So it's probably a bug :-(. - Guillaume Laurent
@Toyos , I need to render my layer onto a 3d scene. AFAIK I can't take a SKNode and push it onto a SCNScene, or otherwise manipulate the camera show that the the SKNode has depth - Cezar
you can set the contents of your SCNMaterialProperty to be an SKScene :) - mnuages
@Cezar, did you get to solve this? I'm facing the same issue - David Homes