I have a very basic test scene set up: one camera, default lighting and one slowly rotating cube.
I am attempting to add a video as the texture of the cube and have been following the example here to do so.
Here is the specific block of code that is supposed to add an AVPlayerLayer
as the material for a node's geometry:
NSURL *url = [[NSBundle mainBundle] URLForResource:@"testVid" withExtension:@"mp4"];
AVAsset *asset = [AVAsset assetWithURL:url];
if (!asset.playable) {
NSLog(@"Err 1");
return;
}
AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:asset];
AVPlayerLayer *layer = [[AVPlayerLayer alloc] init];
layer.player = [AVPlayer playerWithPlayerItem:item];
layer.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[layer.player play];
layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
layer.frame = CGRectMake(0, 0, 600, 800);
CALayer *backLayer = [CALayer layer];
backLayer.backgroundColor = [[UIColor blackColor] CGColor];
backLayer.frame = CGRectMake(0, 0, 600, 800);
[backLayer addSublayer:layer];
self.cubeNode.geometry.firstMaterial.diffuse.contents = backLayer;
//[self.sceneView.layer addSublayer:backLayer];
If I add the layer to a UIView (see commented out line) then I get nice playback fine. However, if I add it to the node I just get a black spinning cube (i.e. the backLayer
shows up but not the video).
Is there something I'm missing? Or is this actually not possible?