Tôi đang cố gắng ánh xạ video dưới dạng kết cấu tới hình trụ nguyên thủy cho dự án VR bằng cách sử dụng Scenekit: SKVideoNode được nhúng trong SKScene dưới dạng kết cấu cho một đối tượng SceneKit SCNTube và tôi không thể hiển thị video như một hình ảnh tĩnh. Sân chơi mã dưới đây sẽ tạo ra di chuyển video ánh xạ tới xi lanh, nhưng các bản đồ không hoạt động:SKVideoNode (được nhúng trong SKScene) làm texture cho Scene Kit Node không hoạt động
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
"ánh xạ không hoạt động"? -> tất cả màu đen? bạn đã cố gắng thiết lập chiều rộng của SKScene thành 1024? bạn đã cố gắng để buộc các renderer GL (xem cài đặt trình xây dựng giao diện SCNView)? – Toyos
Tất cả màu đen, ngay cả khi skscene được đặt thành 1024. Phát âm thanh, vì vậy tôi biết phim đang phát, nhưng không có ánh xạ nào của kết cấu lên bề mặt – jglasse
Trình tạo giao diện? Tôi đang tạo chế độ xem từ đầu trong mã. – jglasse