SKVideoNode仅限于SCNSphere的一小部分

我'm using SKVideoNode as a material for my sphere for 360 video, but it only renders the video on the xy positive part of the sphere, I' m从一个网址流式传输视频 .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();

    }

您可以使用上面的代码重现我的问题,如果它有所不同,当我显示一个图像时,它工作得很好 .

EDIT

使用 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; 渲染球体左侧的视频,但会拉伸纹理/视频 .

回答(1)

2 years ago

它出错了,但我在这里有一个有效的解决方案:https://github.com/alfiehanssen/ThreeSixtyPlayer

它使用SKVideoNode进行单视场和立体球形360视频 .

我注意到你没有设置你的SKScene的 positionanchorPoint ,这是我认为你必须做的事情才能让SKVideoNode(材质)正确定位 .