Skip to content

Commit

Permalink
Added other axes conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Feb 8, 2017
1 parent ccb04b7 commit 289903f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
41 changes: 40 additions & 1 deletion Source/Scene/Axis.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/*global define*/
define([
'../Core/Check',
'../Core/freezeObject',
'../Core/Math',
'../Core/Matrix3',
'../Core/Matrix4'
], function(
Check,
freezeObject,
CesiumMath,
Matrix3,
Expand Down Expand Up @@ -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
Expand All @@ -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];
}
};
Expand Down
36 changes: 23 additions & 13 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
});

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
11 changes: 6 additions & 5 deletions Specs/Scene/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand All @@ -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);
});
});
Expand All @@ -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);
});
});
Expand Down

0 comments on commit 289903f

Please sign in to comment.