我用 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)cardboardViewGVRCardboardView *)cardboardView drawEyeGVREye)eye withHeadTransformGVRHeadTransform *)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 时,一切正常。
有什么帮助吗?谢谢。
Best Answer-推荐答案 strong>
更新:这适用于低质量的视频,但高质量的视频在复制这么多字节时表现不佳。我还没有尝试过,但我的下一个方法是使用带有 CVPixelBuffer 的 OpenGL 纹理以获得更好的性能。
-
我不知道您是否仍在寻找解决方案,但我很幸运能够在 iOS 9.3 上的 6s 和 iOS 8 sim 上使用 SceneKit/GVR 的视频球体。但我不能保证所有平台!
我完全放弃了 SpriteKit,转而使用 CALayer,我将其内容设置为 CVPixelBuffer 中的 CGImage。
视频代码:(最初基于this OpenGL 360 video tutorial)
|