From 289903fc64ec9fa08b36a399627c073f80780d96 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 8 Feb 2017 13:49:25 -0500 Subject: [PATCH] Added other axes conversions --- Source/Scene/Axis.js | 41 +++++++++++++++++++++++++++++++++++++++- Source/Scene/Model.js | 36 ++++++++++++++++++++++------------- Specs/Scene/ModelSpec.js | 11 ++++++----- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/Source/Scene/Axis.js b/Source/Scene/Axis.js index 457d101d0bd7..948f2cddeba9 100644 --- a/Source/Scene/Axis.js +++ b/Source/Scene/Axis.js @@ -1,10 +1,12 @@ /*global define*/ define([ + '../Core/Check', '../Core/freezeObject', '../Core/Math', '../Core/Matrix3', '../Core/Matrix4' ], function( + Check, freezeObject, CesiumMath, Matrix3, @@ -50,13 +52,46 @@ define([ */ Y_UP_TO_Z_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationX(CesiumMath.PI_OVER_TWO)), + /** + * Matrix used to convert from z-up to y-up + * + * @type {Matrix4} + * @constant + */ + Z_UP_TO_Y_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationX(-CesiumMath.PI_OVER_TWO)), + /** * Matrix used to convert from x-up to z-up * * @type {Matrix4} * @constant */ - X_UP_TO_Z_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationY(CesiumMath.PI_OVER_TWO)), + X_UP_TO_Z_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationY(-CesiumMath.PI_OVER_TWO)), + + /** + * Matrix used to convert from z-up to x-up + * + * @type {Matrix4} + * @constant + */ + Z_UP_TO_X_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationY(CesiumMath.PI_OVER_TWO)), + + /** + * Matrix used to convert from x-up to y-up + * + * @type {Matrix4} + * @constant + */ + X_UP_TO_Y_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationZ(CesiumMath.PI_OVER_TWO)), + + /** + * Matrix used to convert from y-up to x-up + * + * @type {Matrix4} + * @constant + */ + Y_UP_TO_X_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationZ(-CesiumMath.PI_OVER_TWO)), + /** * Gets the axis by name @@ -65,6 +100,10 @@ define([ * @returns {Number} The axis enum. */ fromName : function(name) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.string('name', name); + //>>includeEnd('debug'); + return Axis[name]; } }; diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 885fd6e3dced..98f23b653444 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -624,15 +624,7 @@ define([ this._pickFragmentShaderLoaded = options.pickFragmentShaderLoaded; this._pickUniformMapLoaded = options.pickUniformMapLoaded; this._ignoreCommands = defaultValue(options.ignoreCommands, false); - - - /** - * By default models are y-up according to the glTF spec, however geo-referenced models will typically be z-up - * - * @private - * @readonly - */ - this.upAxis = defaultValue(options.upAxis, Axis.Y); + this._upAxis = defaultValue(options.upAxis, Axis.Y); /** * @private @@ -966,6 +958,24 @@ define([ //>>includeEnd('debug'); this._distanceDisplayCondition = DistanceDisplayCondition.clone(value, this._distanceDisplayCondition); } + }, + + /** + * Gets the model's up-axis. + * By default models are y-up according to the glTF spec, however geo-referenced models will typically be z-up. + * + * @memberof Model.prototype + * + * @type {Number} + * @default Axis.Y + * @readonly + * + * @private + */ + upAxis : { + get : function() { + return this._upAxis; + } } }); @@ -1299,9 +1309,9 @@ define([ } var boundingSphere = BoundingSphere.fromCornerPoints(min, max); - if (model.upAxis === Axis.Y) { + if (model._upAxis === Axis.Y) { BoundingSphere.transformWithoutScale(boundingSphere, Axis.Y_UP_TO_Z_UP, boundingSphere); - } else if (model.upAxis === Axis.X) { + } else if (model._upAxis === Axis.X) { BoundingSphere.transformWithoutScale(boundingSphere, Axis.X_UP_TO_Z_UP, boundingSphere); } return boundingSphere; @@ -4330,9 +4340,9 @@ define([ var scale = getScale(this, frameState); var computedModelMatrix = this._computedModelMatrix; Matrix4.multiplyByUniformScale(modelMatrix, scale, computedModelMatrix); - if (this.upAxis === Axis.Y) { + if (this._upAxis === Axis.Y) { Matrix4.multiplyTransformation(computedModelMatrix, Axis.Y_UP_TO_Z_UP, computedModelMatrix); - } else if (this.upAxis === Axis.X) { + } else if (this._upAxis === Axis.X) { Matrix4.multiplyTransformation(computedModelMatrix, Axis.X_UP_TO_Z_UP, computedModelMatrix); } } diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index 92d726eb6603..271643969cde 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -324,14 +324,14 @@ defineSuite([ it('Renders x-up model', function() { return loadJson(boxEcefUrl).then(function(gltf) { // Model data is z-up. Edit the transform to be z-up to x-up. - var zUpToXUp = Matrix4.fromRotationTranslation(Matrix3.fromRotationY(-CesiumMath.PI_OVER_TWO)); - gltf.nodes.node_transform.matrix = Matrix4.pack(zUpToXUp, new Array(16)); + gltf.nodes.node_transform.matrix = Matrix4.pack(Axis.Z_UP_TO_X_UP, new Array(16)); return loadModelJson(gltf, { modelMatrix : Matrix4.IDENTITY, upAxis : Axis.X }).then(function(m) { verifyRender(m); + expect(m.upAxis).toBe(Axis.X); primitives.remove(m); }); }); @@ -340,14 +340,14 @@ defineSuite([ it('Renders y-up model', function() { return loadJson(boxEcefUrl).then(function(gltf) { // Model data is z-up. Edit the transform to be z-up to y-up. - var zUpToYUp = Matrix4.fromRotationTranslation(Matrix3.fromRotationX(-CesiumMath.PI_OVER_TWO)); - gltf.nodes.node_transform.matrix = Matrix4.pack(zUpToYUp, new Array(16)); + gltf.nodes.node_transform.matrix = Matrix4.pack(Axis.Z_UP_TO_Y_UP, new Array(16)); return loadModelJson(gltf, { modelMatrix : Matrix4.IDENTITY, upAxis : Axis.Y }).then(function(m) { verifyRender(m); + expect(m.upAxis).toBe(Axis.Y); primitives.remove(m); }); }); @@ -360,9 +360,10 @@ defineSuite([ return loadModelJson(gltf, { modelMatrix : Matrix4.IDENTITY, - upAxis : Axis.Y + upAxis : Axis.Z }).then(function(m) { verifyRender(m); + expect(m.upAxis).toBe(Axis.Z); primitives.remove(m); }); });