I create a SKScene with SKVideoNode, then apply to sphere geometry.
Here is the key code:
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"2222" ofType:@"mp4"];
NSURL* sourceMovieURL = [NSURL fileURLWithPath:filePath];
AVPlayer* player = [AVPlayer playerWithURL:sourceMovieURL];
SKVideoNode* videoNode = [SKVideoNode videoNodeWithAVPlayer:player];
CGSize size = [UIScreen mainScreen].bounds.size;
videoNode.size = size;
videoNode.position = CGPointMake(size.width/2.0, size.height/2.0);
SKScene* spriteScene = [SKScene sceneWithSize:size];
[spriteScene addChild:videoNode];
SCNMaterial* material = [SCNMaterial material];
material.doubleSided = true;
material.diffuse.contents = spriteScene;
[sphereNode.geometry replaceMaterialAtIndex:0 withMaterial:material];
[videoNode play];
[_scnScene.rootNode addChildNode:sphereNode];
_renderer = [SCNRenderer rendererWithContext:cardboardView.context options:nil];
_renderer.scene = _scnScene;
_renderer.pointOfView = _scnCameraNode;
In the drawEye function:
- (void)cardboardView:(GVRCardboardView *)cardboardView drawEye:(GVREye)eye withHeadTransform:(GVRHeadTransform *)headTransform
{
const GLKMatrix4 head_from_start_matrix = [headTransform headPoseInStartSpace];
GLKMatrix4 projection_matrix = [headTransform projectionMatrixForEye:eye near:_scnCamera.zNear far:_scnCamera.zFar];
GLKMatrix4 eye_from_head_matrix = [headTransform eyeFromHeadMatrix:eye];
GLKMatrix4 view_projection_matrix = GLKMatrix4Multiply(
projection_matrix, GLKMatrix4Multiply(eye_from_head_matrix, head_from_start_matrix));
[_scnCamera setProjectionTransform:SCNMatrix4FromGLKMatrix4(view_projection_matrix)];
[_renderer renderAtTime:0];
}
When you run the code, it will be broken into
[_renderer renderAtTime:0]
and output:
Failed to create IOSurface image (texture)
Assertion failed: (result), function create_texture_from_IOSurface, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Jet/Jet-2.6.1/Jet/jet_context_OpenGL.mm, line 570.
When I remove SKVideoNode from SKScene, everything is fine.
Any help? Thank.
source
share