SKVideoNode 只在 SCNSphere 的一小部分

SKVideoNode only on a small part of SCNSphere

我使用 SKVideoNode 作为我的 360 度视频球体的 material,但它只在球体的 xy 正向部分渲染视频,我正在从 URL 这是一个 .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; 在球体左侧渲染视频,但会拉伸纹理/视频。

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

它为单视场和立体球形 360 度视频使用 SKVideoNode。

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