10

我正在使用 SKVideoNode 作为 360 视频球体的材料,但它只在球体的 xy 正部分渲染视频,我正在从一个 URL 流式传输视频,它是一个.m3u8参考,请参阅 - SKVideoNode 作为 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;渲染球体左侧的视频,但拉伸纹理/视频。

4

1 回答 1

1

很难说具体出了什么问题,但我在这里有一个可行的解决方案:https ://github.com/alfiehanssen/ThreeSixtyPlayer

它对单视场和立体球面 360 视频都使用 SKVideoNode。

我确实注意到您没有设置 SKScene 的positionor anchorPoint,这是我相信您必须做的事情才能正确定位 SKVideoNode (材料)。

于 2016-10-09T18:06:50.540 回答