Skip to content

Commit 68e156b

Browse files
fix(DeviceService): Fixed _updateForWebVR logic
Added fallback to default left/right bounds Modified viewport size to be based on vrDisplay parameters
1 parent 4fdd657 commit 68e156b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/device.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,28 +376,43 @@ export class DeviceService {
376376
orientation: new ConstantProperty(Quaternion.IDENTITY)
377377
});
378378

379+
private _defaultLeftBounds = [ 0.0, 0.0, 0.5, 1.0 ];
380+
private _defaultRightBounds = [ 0.5, 0.0, 0.5, 1.0 ];
381+
379382
private _updateForWebVR() {
380383

381384
const frameState = this.frameState;
382385

383386
const vrDisplay:VRDisplay = currentVRDisplay;
384387

385-
const element = this.viewService.element;
388+
// const element = this.viewService.element;
389+
390+
var leftEye = vrDisplay.getEyeParameters("left");
391+
var rightEye = vrDisplay.getEyeParameters("right");
386392

387393
const viewport = frameState.viewport;
388394
viewport.x = 0;
389395
viewport.y = 0;
390-
viewport.width = element && element.clientWidth || 0;
391-
viewport.height = element && element.clientHeight || 0;
396+
viewport.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
397+
viewport.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
392398

393399
const vrFrameData : VRFrameData = this._vrFrameData =
394400
this._vrFrameData || new VRFrameData();
395401
if (!vrDisplay['getFrameData'](vrFrameData))
396402
return this.frameState;
397403

398404
const layers = vrDisplay.getLayers();
399-
const leftBounds = layers[0].leftBounds!;
400-
const rightBounds = layers[0].rightBounds!;
405+
let leftBounds = layers[0].leftBounds;
406+
let rightBounds = layers[0].rightBounds;
407+
408+
if ( layers.length ) {
409+
var layer = layers[ 0 ]!;
410+
leftBounds = layer.leftBounds && layer.leftBounds.length === 4 ? layer.leftBounds : this._defaultLeftBounds;
411+
rightBounds = layer.rightBounds && layer.rightBounds.length === 4 ? layer.rightBounds : this._defaultRightBounds;
412+
} else {
413+
leftBounds = this._defaultLeftBounds;
414+
rightBounds = this._defaultRightBounds;
415+
}
401416

402417
const subviews = frameState.subviews = frameState.subviews || [];
403418
subviews.length = 2;

0 commit comments

Comments
 (0)