SKVideoNode(嵌入在SKScene中)作为Scene Kit Node无法正常工作的纹理 [英] SKVideoNode (embedded in SKScene) as texture for for Scene Kit Node not working

查看:235
本文介绍了SKVideoNode(嵌入在SKScene中)作为Scene Kit Node无法正常工作的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Scenekit将视频作为纹理映射到VR项目的原始柱面:一个嵌入在SKScene中的SKVideoNode作为SceneKit SCNTube对象的纹理,我只是无法显示视频作为静止图像会。下面的PLayground代码应生成映射到柱面的移动视频,但映射不起作用:

I'm attempting to map a video as texture to a primitive cylinder for a VR project by using Scenekit: an SKVideoNode embedded in an SKScene as a texture for a SceneKit SCNTube object, and I just can't get video to display as a still image would. PLayground code below should generate moving video mapped to cylinder, but the mapping does not work:

编辑:在上市结束时添加单行修复。下面的代码应该工作

import UIKit
import SceneKit      // for 3D mapping
import SpriteKit     // for SKVideoNode
import QuartzCore    // for basic animation
import XCPlayground  // for live preview
import AVFoundation  // for video playback engine

// create a scene view with an empty scene
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
var scene = SCNScene()
sceneView.scene = scene


// start a live preview of that view
XCPShowView("The Scene View", view: sceneView)

// default lighting
sceneView.autoenablesDefaultLighting = true

// a geometry object
var tube = SCNTube(innerRadius: 1.99, outerRadius: 2, height: 3)
var tubeNode = SCNNode(geometry: tube)
scene.rootNode.addChildNode(tubeNode)

// video scene


let urlStr = NSBundle.mainBundle().pathForResource("sample", ofType: "mp4")
let url = NSURL(fileURLWithPath: urlStr!)

let asset = AVURLAsset(URL: url, options: nil)
let playerItem = AVPlayerItem(asset: asset)
let player = AVPlayer(playerItem: playerItem)
let videoNode = SKVideoNode(AVPlayer: player)
let spritescene = SKScene(size: CGSize(width: 1211, height: 431))



videoNode.size.width=spritescene.size.width
videoNode.size.height=spritescene.size.height
spritescene.addChild(videoNode)


// configure the geometry object

var myImage = UIImage.init(named: "BandImage.jpeg")

tube.firstMaterial?.diffuse.contents  = spritescene


// set a rotation axis (no angle) to be able to
// use a nicer keypath below and avoid needing
// to wrap it in an NSValue
tubeNode.rotation = SCNVector4(x: 0.0, y: 1.0, z: 0.0, w: 0.0)

// animate the rotation of the torus
var spin = CABasicAnimation(keyPath: "rotation.w") // only animate the angle
spin.toValue = 2.0*M_PI
spin.duration = 3
spin.repeatCount = HUGE // for infinity
tubeNode.addAnimation(spin, forKey: "spin around")

// starts the video, solving the issue
    sceneView.playing = true


推荐答案

我已经在github上发布了我的代码(以及一些示例全景内容)给任何想要有一个工作示例代码或者有兴趣在开源全景上进行协作的人视频播放器:

I've posted my code (and some sample panoramic content) on github for anyone who wants to have a working sample code or is interested in collaborating on an opensource panoramic video player:

https://github.com/ jglasse / OSVR

事实证明,模拟器(和游乐场)似乎不支持此功能。将上面的代码移动到项目并在设备上运行,我终于让它工作了。

As it turns out, it looks like simulator (and playgrounds) doesn't support this feature. Moving the above code to a project and running on a device, I finally have it working.

故事的寓意是 - 如果您使用SKVideoNodes作为Scenekit的纹理,请使用实际设备进行测试。

So the moral of the story is - if you're using SKVideoNodes as textures for Scenekit, use an actual device for testing.

这篇关于SKVideoNode(嵌入在SKScene中)作为Scene Kit Node无法正常工作的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆