2015-09-26 7 views
6

Sto tentando di mappare un video come texture a un cilindro primitivo per un progetto VR utilizzando Scenekit: un SKVideoNode incorporato in un SKScene come texture per un oggetto SCNTube di SceneKit e non riesco a visualizzare il video come farebbe un'immagine statica. Codice parco giochi sotto dovrebbe comportare un video in movimento mappato a cilindro, ma la mappatura non funziona:SKVideoNode (incorporato in SKScene) come trama per il nodo del Kit scena non funzionante

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 
+0

"mapping non funziona"? -> tutto nero? hai provato a impostare la larghezza di SKScene su 1024? hai provato a forzare il renderer GL (vedi le impostazioni del builder dell'interfaccia SCNView)? – Toyos

+0

Tutto nero, anche quando skscene è impostato su 1024. L'audio viene riprodotto, quindi so che il film è in riproduzione, ma nessuna mappatura della trama sulla superficie – jglasse

+0

Generatore di interfacce? Sto generando la vista da zero nel codice. – jglasse

risposta

4

ho postato il mio codice (e alcuni contenuti panoramica del campione) su github per chi vuole avere un codice di esempio di lavoro o è interessato a collaborare su un lettore video panoramico opensource:

https://github.com/jglasse/OSVR

come si è visto, sembra che il simulatore (e campi da gioco) non supporta questa funzione. Spostando il codice precedente su un progetto e eseguendolo su un dispositivo, finalmente ce l'ho.

Quindi la morale della storia è - se si sta utilizzando SKVideoNodes come texture per Scenekit, utilizzare un dispositivo reale per il test.

+1

Sembra che l'abbiamo scoperto nello stesso periodo. Ben fatto :) –

+0

Ora sembra che la trama si aggiorni solo quando l'oggetto si muove - quando non c'è movimento, mentre l'audio continua a suonare, la trama non si aggiorna. hai visto questo? – jglasse

+0

@jglasse hai mai risolto quell'altro problema? che la trama si aggiorna solo quando l'oggetto è in movimento? – Travis

Problemi correlati