Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Remove three js import from Libraries, ban it in the future via eslint
Browse files Browse the repository at this point in the history
Summary: Three is a runtime dependency, we can't count on it being available in the core library. Added an eslint rule so it doesn't accidentally get imported later on.

Reviewed By: mikearmstrong001

Differential Revision: D5140278

fbshipit-source-id: 1f1c1dc
  • Loading branch information
andrewimm authored and facebook-github-bot committed May 30, 2017
1 parent b07a803 commit 5594c53
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Libraries/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
rules: {
'no-restricted-modules': ['error', 'three'],
'no-restricted-imports': ['error', 'three'],
},
}
9 changes: 4 additions & 5 deletions Libraries/Utilities/VrHeadModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
const MatrixMath = require('MatrixMath');
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
const VrMath = require('VrMath');
import * as THREE from 'three';

/**
* VrHeadModel is a util module that simplifies obtaining the current orientation of the headset
Expand Down Expand Up @@ -87,7 +86,7 @@ class VrHeadModelImpl {
* [rotation about X axis, rotation about Y axis, rotation about Z axis]
*/
rotation() {
return this.rotationInRadians().map(THREE.Math.radToDeg);
return this.rotationInRadians().map(VrMath.radToDeg);
}

/**
Expand All @@ -112,7 +111,7 @@ class VrHeadModelImpl {
* [Y axis, X axis, Z axis]
*/
yawPitchRoll() {
return this.yawPitchRollInRadians().map(THREE.Math.radToDeg);
return this.yawPitchRollInRadians().map(VrMath.radToDeg);
}

/**
Expand Down Expand Up @@ -148,14 +147,14 @@ class VrHeadModelImpl {
* Return the horizontal field of view of the camera in radians.
*/
horizontalFovInRadians() {
return THREE.Math.degToRad(this.horizontalFov());
return VrMath.degToRad(this.horizontalFov());
}

/**
* Return the vertical field of view of the camera in radians.
*/
verticalFovInRadians() {
return THREE.Math.degToRad(this.verticalFov());
return VrMath.degToRad(this.verticalFov());
}
/**
* Return Head matrix as array of numbers
Expand Down
11 changes: 11 additions & 0 deletions Libraries/Utilities/VrMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
const clamp = require('clamp');
const MatrixMath = require('MatrixMath');

const RAD_TO_DEG = 180 / Math.PI;
const DEG_TO_RAD = Math.PI / 180;

/**
* Math utilities for React VR
*/
Expand Down Expand Up @@ -145,6 +148,14 @@ const VrMath = {
getMatrixUp: function(m) {
return MatrixMath.v3Normalize([m[4], m[5], m[6]]);
},

radToDeg: function(rad) {
return rad * RAD_TO_DEG;
},

degToRad: function(deg) {
return deg * DEG_TO_RAD;
},
};

module.exports = VrMath;

0 comments on commit 5594c53

Please sign in to comment.