我用 SKVideoNode 创建了一个 SKScene,然后应用于球体几何。
这是关键代码:
// Create a SKScene to play video
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 = CGSizeMake(512, 512);
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];
// create a material with SKScene
SCNMaterial* material = [SCNMaterial material];
material.doubleSided = true;
material.diffuse.contents = spriteScene;
[sphereNode.geometry replaceMaterialAtIndex:0 withMaterial:material];
[videoNode play];
[_scnScene.rootNode addChildNode:sphereNode];
// create SCNRenderer to render the scene
_renderer = [SCNRenderer rendererWithContext:cardboardView.context options:nil];
_renderer.scene = _scnScene;
_renderer.pointOfView = _scnCameraNode;
在drawEye函数中:
- (void)cardboardView:(GVRCardboardView *)cardboardView drawEye:(GVREye)eye withHeadTransform:(GVRHeadTransform *)headTransform
{
//CGRect viewport = [headTransform viewportForEye:eye];
// Get the head matrix.
const GLKMatrix4 head_from_start_matrix = [headTransform headPoseInStartSpace];
// Get this eye's matrices.
GLKMatrix4 projection_matrix = [headTransform projectionMatrixForEye:eye near:_scnCamera.zNear far:_scnCamera.zFar];
GLKMatrix4 eye_from_head_matrix = [headTransform eyeFromHeadMatrix:eye];
// Compute the model view projection matrix.
GLKMatrix4 view_projection_matrix = GLKMatrix4Multiply(
projection_matrix, GLKMatrix4Multiply(eye_from_head_matrix, head_from_start_matrix));
// Set the projection matrix to camera
[_scnCamera setProjectionTransform:SCNMatrix4FromGLKMatrix4(view_projection_matrix)];
// Render the scene
[_renderer renderAtTime:0];
}
运行代码时,它将中断
[_renderer renderAtTime:0]
输出是:
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.
当我从 SKScene 中删除 SKVideoNode 时,一切正常。
有什么帮助吗?谢谢。