Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix small screen issue #228

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "videojs-vr",
"version": "1.7.2",
"name": "videojs-vr-sd",
"version": "1.7.3",
"description": "A plugin to add 360 and VR video support to video.js.",
"author": {
"name": "James Broberg",
Expand Down Expand Up @@ -40,7 +40,7 @@
"build:lang": "vjslang --dir dist/lang",
"clean": "shx rm -rf ./dist ./test/dist && shx mkdir -p ./dist ./test/dist",
"lint": "vjsstandard",
"prepublishOnly": "npm-run-all build-prod && vjsverify --verbose",

"start": "npm-run-all -p server watch",
"server": "karma start scripts/karma.conf.js --singleRun=false --auto-watch",
"test": "npm run build-test && karma start scripts/karma.conf.js",
Expand Down
45 changes: 35 additions & 10 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import OmnitoneController from './omnitone-controller';
// import controls so they get regisetered with videojs
import './cardboard-button';
import './big-vr-play-button';
import {doubleSizeForSmallScreen} from './utils';

// Default options for the plugin.
const defaults = {
debug: false,
omnitone: false,
forceCardboard: false,
omnitoneOptions: {},
projection: 'AUTO'
projection: 'AUTO',
sphereDetail: 32
};

const errors = {
Expand Down Expand Up @@ -126,7 +128,7 @@ class VR extends Plugin {
}
return this.changeProjection_('NONE');
} else if (projection === '360') {
this.movieGeometry = new THREE.SphereBufferGeometry(256, 32, 32);
this.movieGeometry = new THREE.SphereBufferGeometry(256, this.options_.sphereDetail, this.options_.sphereDetail);
this.movieMaterial = new THREE.MeshBasicMaterial({ map: this.videoTexture, overdraw: true, side: THREE.BackSide });

this.movieScreen = new THREE.Mesh(this.movieGeometry, this.movieMaterial);
Expand All @@ -137,7 +139,11 @@ class VR extends Plugin {
this.scene.add(this.movieScreen);
} else if (projection === '360_LR' || projection === '360_TB') {
// Left eye view
let geometry = new THREE.SphereGeometry(256, 32, 32);
let geometry = new THREE.SphereGeometry(
256,
this.options_.sphereDetail,
this.options_.sphereDetail
);

let uvs = geometry.faceVertexUvs[ 0 ];

Expand All @@ -163,7 +169,11 @@ class VR extends Plugin {
this.scene.add(this.movieScreen);

// Right eye view
geometry = new THREE.SphereGeometry(256, 32, 32);
geometry = new THREE.SphereGeometry(
256,
this.options_.sphereDetail,
this.options_.sphereDetail
);

uvs = geometry.faceVertexUvs[ 0 ];

Expand Down Expand Up @@ -224,7 +234,13 @@ class VR extends Plugin {

this.scene.add(this.movieScreen);
} else if (projection === '180') {
let geometry = new THREE.SphereGeometry(256, 32, 32, Math.PI, Math.PI);
let geometry = new THREE.SphereGeometry(
256,
this.options_.sphereDetail,
this.options_.sphereDetail,
Math.PI,
Math.PI
);

// Left eye view
geometry.scale(-1, 1, 1);
Expand All @@ -247,7 +263,13 @@ class VR extends Plugin {
this.scene.add(this.movieScreen);

// Right eye view
geometry = new THREE.SphereGeometry(256, 32, 32, Math.PI, Math.PI);
geometry = new THREE.SphereGeometry(
256,
this.options_.sphereDetail,
this.options_.sphereDetail,
Math.PI,
Math.PI
);
geometry.scale(-1, 1, 1);
uvs = geometry.faceVertexUvs[0];

Expand Down Expand Up @@ -565,8 +587,9 @@ void main() {
}

handleResize_() {
const width = this.player_.currentWidth();
const height = this.player_.currentHeight();
const size = doubleSizeForSmallScreen();
const width = size.width;
const height = size.height;

this.effect.setSize(width, height, false);
this.camera.aspect = width / height;
Expand Down Expand Up @@ -653,10 +676,12 @@ void main() {
}
};

this.renderer.setSize(this.player_.currentWidth(), this.player_.currentHeight(), false);
const size = doubleSizeForSmallScreen();

this.renderer.setSize(size.width, size.height, false);
this.effect = new VREffect(this.renderer);

this.effect.setSize(this.player_.currentWidth(), this.player_.currentHeight(), false);
this.effect.setSize(size.width, size.height, false);
this.vrDisplay = null;

// Previous timestamps for gamepad updates
Expand Down
17 changes: 17 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@ export const getInternalProjectionName = function(projection) {
}

};

// double currentWidth/Height for small screen device, for better quality
// also need a high sphereDetail like 128 (https://github.com/videojs/videojs-vr/pull/225)
// this is just a workaround
export const doubleSizeForSmallScreen = function() {
let width = this.player_.currentWidth();
let height = this.player_.currentHeight();

if (this.player_.videoWidth() > this.player_.currentWidth() * 2) {
width = this.player_.currentWidth() * 2;
height = this.player_.currentHeight() * 2;
}
return {
width,
height
};
};