This commit is contained in:
Blair MacIntyre 2018-03-18 20:17:35 -04:00
Родитель 51778bdaf1
Коммит 2cd13d8819
3 изменённых файлов: 61 добавлений и 6 удалений

Просмотреть файл

@ -107,10 +107,7 @@ class XRExampleBase {
this.session.addEventListener('blur', ev => { this.handleSessionBlur(ev) })
this.session.addEventListener('end', ev => { this.handleSessionEnded(ev) })
// if this session is getting video frames, lets set up a callback.
// EVENTUALLY should look at properties on the session to see if user
// approved it, but the app doesn't let us know this yet
this.session.requestVideoFrames(ev => { this.handleVideoFrame(ev) })
this.newSession();
if(this.shouldStartPresenting){
// VR Displays need startPresenting called due to input events like a click
@ -122,6 +119,11 @@ class XRExampleBase {
})
}
/*
Clients should override to be called when a new session is created
*/
newSession() {}
/*
Empties this.el, adds a div with the message text, and shows a button to test rendering the scene to this.el
*/
@ -167,7 +169,18 @@ class XRExampleBase {
handleLayerFocus(ev){}
handleLayerBlur(ev){}
handleVideoFrame(ev){}
/*
* set up the video processing
*/
setVideoWorker(worker){
//
// NOTE: not a worker, a callback! Couldn't get workers working!
//
// if this session is getting video frames, lets set up a callback.
// EVENTUALLY should look at properties on the session to see if user
// approved it, but the app doesn't let us know this yet
this.session.requestVideoFrames(worker)
}
/*
Extending classes should override this to set up the scene during class construction

Просмотреть файл

@ -68,6 +68,10 @@
this.el.appendChild(this.textBox)
}
newSession() {
this.setVideoWorker(ev => { this.handleVideoFrame(ev) })
}
// Called during construction
initializeScene(){
// Add a box at the scene origin
@ -121,7 +125,7 @@
var camera = ev.detail.camera
switch (frame.pixelFormat) {
case "YUV420P":
this.averageIntensity(frame.buffers[0])
this.averageIntensity(frame.buffers[0])
}
}

Просмотреть файл

@ -0,0 +1,38 @@
// could not get workers working, so am not using this.
//
// Tried to use Transferable ArrayBuffers but kept getting DOM Error 25.
//
averageIntensity = function (buffer) {
var w = buffer.size.width;
var h = buffer.size.height;
var pad = buffer.size.bytesPerRow - w;
var pixels = buffer.buffer;
var intensity = 0.0;
var p = 0;
for (var r = 0; r < h; r++) {
var v = 0;
for (var i = 0; i < w; i++) {
if (p < pixels.length) {
v += pixels[p++]
} else {
console.error("overflow pixel buffer")
}
}
intensity += v / w;
p += pad;
}
postMessage ((intensity / h) / 255.0);
}
onMessage = function (ev) {
var frame = ev.detail.frame
var camera = ev.detail.camera
switch (frame.pixelFormat) {
case "YUV420P":
this.averageIntensity(frame.buffers[0])
}
}