我使用SKVideoNode作为我的360度视频球体的素材,但它只在xy正面的球体上呈现视频,我是从一个网址流式传输视频的。 sa .m3u8
供参考,请参阅 - SKVideoNode as texture for SCNSphere
多人似乎和我有同样的问题
func makeSphere() {
let sceneView = SCNView(frame: self.view.frame);
self.view.addSubview(sceneView);
var screenSize: CGRect = UIScreen.mainScreen().bounds;
var screenWidth = screenSize.width;
var screenHeight = screenSize.height;
sceneView.frame.size.height = screenHeight * 1;
sceneView.frame.size.width = screenWidth * 1;
sceneView.center.x = screenWidth * 0.5;
let scene = SCNScene();
sceneView.scene = scene;
sphereGeometry = SCNSphere(radius: 5);
sphereNode = SCNNode(geometry: sphereGeometry);
sphereNode.position = SCNVector3(x: 0, y: 0, z: 0);
sphereGeometry.segmentCount = 55;
constraint = SCNLookAtConstraint(target: sphereNode);
let camera = SCNCamera();
let cameraNode = SCNNode();
cameraNode.camera = camera;
cameraNode.position = SCNVector3(x: 0, y: 0, z: 0);
let light = SCNLight();
light.type = SCNLightTypeOmni;
let lightNode = SCNNode();
lightNode.light = light;
lightNode.position = SCNVector3(x: 0, y: 0, z: 0);
cameraNode.constraints = [constraint];
scene.rootNode.addChildNode(cameraNode);
scene.rootNode.addChildNode(sphereNode);
let videoMaterial = SCNMaterial();
let path = "http://video-url.m3u8";
let url = NSURL(string: path);
let asset = AVURLAsset(URL: url!,options: nil);
let playerItem = AVPlayerItem(asset: asset);
let player = AVPlayer(playerItem: playerItem);
let videoNode = SKVideoNode(AVPlayer: player);
let size = CGFloat(100.0);
let spriteScene = SKScene(size: CGSizeMake(size,size));
videoNode.size.width = size;
videoNode.size.height = size;
spriteScene.addChild(videoNode);
videoMaterial.diffuse.contents = spriteScene;
videoMaterial.specular.contents = UIColor.redColor();
videoMaterial.shininess = 1.0;
videoMaterial.doubleSided = true;
sphereGeometry.materials = [videoMaterial];
videoNode.play();
}
您可以使用上面的代码重现我的问题,如果它有所不同,当我显示图像时,它可以正常工作。
修改
使用videoMaterial.diffuse.contents.transfom(SCNMatrix4MakeScale(0,-1,1));
和videoMaterial.diffuse.wrapT = SCNWrapMode.Repeat;
使得视频是在球体的下半部分的项目,但不是正确显示所有我可以看到被拉伸环,改变WrapMode
,使它使iOS 6屏幕只显示1种颜色。
使用videoMaterial.diffuse.contents.transfom(SCNMatrix4MakeScale(1,0,1));
和videoMaterial.diffuse.wrapT = SCNWrapMode.Repeat;
渲染球体左侧的视频,但会拉伸纹理/视频。
答案 0 :(得分:1)
很难具体说明出了什么问题,但我在这里有一个有效的解决方案:https://github.com/alfiehanssen/ThreeSixtyPlayer
它使用SKVideoNode进行单视场和立体球形360视频。
我注意到您没有设置SKScene的position
或anchorPoint
,我认为您必须这样做才能让SKVideoNode(素材)正确定位。