SKVideoNode 仅在节点或相机移动时在 SCNScene 中渲染
SKVideoNode only rendering in SCNScene when the node or camera moves
我正在使用一种非常简单的方法来设置 SKVideoNode 并通过几何体的漫反射内容将其放置在 SCNNode 中。当我这样做时,仅纹理更新并正确显示视频的时间是相机或节点移动时。当两者都静止时,纹理永远不会更新(就像视频甚至没有播放一样)但声音会播放。
显然它仍在播放视频,但渲染不正确。我不知道为什么。
func setupAndPlay() {
// create the asset & player and grab the dimensions
let path = NSBundle.mainBundle().pathForResource("indycar", ofType: "m4v")!
let asset = AVAsset(URL: NSURL(fileURLWithPath: path))
let size = asset.tracksWithMediaType(AVMediaTypeVideo)[0].naturalSize
let player = AVPlayer(playerItem: AVPlayerItem(asset: asset))
// setup the video SKVideoNode
let videoNode = SKVideoNode(AVPlayer: player)
videoNode.size = size
videoNode.position = CGPoint(x: size.width * 0.5, y: size.height * 0.5)
// setup the SKScene that will house the video node
let videoScene = SKScene(size: size)
videoScene.addChild(videoNode)
// create a wrapper ** note that the geometry doesn't matter, it happens with spheres and planes
let videoWrapperNode = SCNNode(geometry: SCNSphere(radius: 10))
videoWrapperNode.position = SCNVector3(x: 0, y: 0, z: 0)
// set the material's diffuse contents to be the video scene we created above
videoWrapperNode.geometry?.firstMaterial?.diffuse.contents = videoScene
videoWrapperNode.geometry?.firstMaterial?.doubleSided = true
// reorient the video properly
videoWrapperNode.scale.y = -1
videoWrapperNode.scale.z = -1
// add it to our scene
scene.rootNode.addChildNode(videoWrapperNode)
// if I uncomment this, the video plays correctly; if i comment it, the texture on the videoWrapperNode only
// get updated when I'm moving the camera around. the sound always plays properly.
videoWrapperNode.runAction( SCNAction.repeatActionForever( SCNAction.rotateByAngle(CGFloat(M_PI * 2.0), aroundAxis: SCNVector3(x: 0, y: 1, z: 0), duration: 15.0 )))
videoNode.play()
}
有没有人遇到过类似的事情?任何帮助将不胜感激。
听起来您需要在 SCNView
上设置 .playing = true
。
来自docs.
If the value of this property is NO (the default), SceneKit does not
increment the scene time, so animations associated with the scene do
not play. Change this property’s value to YES to start animating the
scene.
我在 Xcode 7.0 或 7.1 中获取 SKVideoNode 以显示视频不成功。如果我 运行 我的代码或硬件设备上的其他示例 iPad 或 iPhone 视频显示正常,但在模拟器上只能播放音频。相同的代码在 xCode 6.4 的模拟器中运行良好。
我有来自 Ray Wenderlich iOS 和 tvOS Games 教程的 CatNap 示例 (iOS 9),它在 [=20] 附带的模拟器 9.1 中没有 运行 =] 7.1。我相信模拟器坏了并且已经向 Apple 提交了错误,但一个月内没有任何回应。
有没有人有 SKVideoNode 的示例代码,可以在 xCode 7.1 的模拟器上运行??
我还发现在渲染器(例如 scnView)上将 rendersContinously
设置为 true 将使视频播放。
如果您记录 SCNRendererDelegate
的 update
调用,您可以看到绘制帧的时间
我正在使用一种非常简单的方法来设置 SKVideoNode 并通过几何体的漫反射内容将其放置在 SCNNode 中。当我这样做时,仅纹理更新并正确显示视频的时间是相机或节点移动时。当两者都静止时,纹理永远不会更新(就像视频甚至没有播放一样)但声音会播放。
显然它仍在播放视频,但渲染不正确。我不知道为什么。
func setupAndPlay() {
// create the asset & player and grab the dimensions
let path = NSBundle.mainBundle().pathForResource("indycar", ofType: "m4v")!
let asset = AVAsset(URL: NSURL(fileURLWithPath: path))
let size = asset.tracksWithMediaType(AVMediaTypeVideo)[0].naturalSize
let player = AVPlayer(playerItem: AVPlayerItem(asset: asset))
// setup the video SKVideoNode
let videoNode = SKVideoNode(AVPlayer: player)
videoNode.size = size
videoNode.position = CGPoint(x: size.width * 0.5, y: size.height * 0.5)
// setup the SKScene that will house the video node
let videoScene = SKScene(size: size)
videoScene.addChild(videoNode)
// create a wrapper ** note that the geometry doesn't matter, it happens with spheres and planes
let videoWrapperNode = SCNNode(geometry: SCNSphere(radius: 10))
videoWrapperNode.position = SCNVector3(x: 0, y: 0, z: 0)
// set the material's diffuse contents to be the video scene we created above
videoWrapperNode.geometry?.firstMaterial?.diffuse.contents = videoScene
videoWrapperNode.geometry?.firstMaterial?.doubleSided = true
// reorient the video properly
videoWrapperNode.scale.y = -1
videoWrapperNode.scale.z = -1
// add it to our scene
scene.rootNode.addChildNode(videoWrapperNode)
// if I uncomment this, the video plays correctly; if i comment it, the texture on the videoWrapperNode only
// get updated when I'm moving the camera around. the sound always plays properly.
videoWrapperNode.runAction( SCNAction.repeatActionForever( SCNAction.rotateByAngle(CGFloat(M_PI * 2.0), aroundAxis: SCNVector3(x: 0, y: 1, z: 0), duration: 15.0 )))
videoNode.play()
}
有没有人遇到过类似的事情?任何帮助将不胜感激。
听起来您需要在 SCNView
上设置 .playing = true
。
来自docs.
If the value of this property is NO (the default), SceneKit does not increment the scene time, so animations associated with the scene do not play. Change this property’s value to YES to start animating the scene.
我在 Xcode 7.0 或 7.1 中获取 SKVideoNode 以显示视频不成功。如果我 运行 我的代码或硬件设备上的其他示例 iPad 或 iPhone 视频显示正常,但在模拟器上只能播放音频。相同的代码在 xCode 6.4 的模拟器中运行良好。
我有来自 Ray Wenderlich iOS 和 tvOS Games 教程的 CatNap 示例 (iOS 9),它在 [=20] 附带的模拟器 9.1 中没有 运行 =] 7.1。我相信模拟器坏了并且已经向 Apple 提交了错误,但一个月内没有任何回应。
有没有人有 SKVideoNode 的示例代码,可以在 xCode 7.1 的模拟器上运行??
我还发现在渲染器(例如 scnView)上将 rendersContinously
设置为 true 将使视频播放。
如果您记录 SCNRendererDelegate
的 update
调用,您可以看到绘制帧的时间