Skip to content

Commit

Permalink
refactor(parser): re-write Matrix4#setMatrix3().
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jul 2, 2020
1 parent 259b38d commit 532a687
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/Parser/CameraCalibrationParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ import OrientedImageCamera from 'Renderer/OrientedImageCamera';
* @module CameraCalibrationParser
*/

THREE.Matrix4.prototype.setMatrix3 = function setMatrix3(m) {
this.elements[0] = m.elements[0];
this.elements[1] = m.elements[1];
this.elements[2] = m.elements[2];
this.elements[4] = m.elements[3];
this.elements[5] = m.elements[4];
this.elements[6] = m.elements[5];
this.elements[8] = m.elements[6];
this.elements[9] = m.elements[7];
this.elements[10] = m.elements[8];
return this;
};

const xAxis = new THREE.Vector3();
const yAxis = new THREE.Vector3();
const zAxis = new THREE.Vector3();
const textureLoader = new THREE.TextureLoader();
const matrix3 = new THREE.Matrix3();

THREE.Matrix4.prototype.makeBasisFromMatrix = function makeBasisFromMatrix(m) {
m.extractBasis(xAxis, yAxis, zAxis);
return this.makeBasis(xAxis, yAxis, zAxis);
};

// the json format encodes the following transformation:
// extrinsics: p_local = rotation * (p_world - position)
// intrinsics: p_pixel = projection * p_local
Expand All @@ -45,7 +41,7 @@ function parseCalibration(calibration, options = {}) {
camera.position.fromArray(calibration.position);
// calibration.rotation is row-major but fromArray expects a column-major array, yielding the transposed matrix
const rotationInverse = matrix3.fromArray(calibration.rotation);
camera.matrix.setMatrix3(rotationInverse);
camera.matrix.makeBasisFromMatrix(rotationInverse);
camera.quaternion.setFromRotationMatrix(camera.matrix);

// local axes for cameras is (X right, Y up, Z back) rather than (X right, Y down, Z front)
Expand Down

0 comments on commit 532a687

Please sign in to comment.