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

Detect glTF 2.0 and change forward to match Cesium's convention. #6632

Merged
merged 9 commits into from
Jun 11, 2018
18 changes: 18 additions & 0 deletions Apps/SampleData/models/DracoCompressed/CesiumMilkTruck.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
"children": [
3,
1
],
"matrix": [
0,
0,
1,
0,
0,
1,
0,
0,
-1,
0,
0,
0,
0,
0,
0,
1
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Physically-Based Materials.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
viewer.scene.globe.depthTestAgainstTerrain = true;

var position = new Cesium.Cartesian3(-1371108.6511167218, -5508684.080096612, 2901825.449865087);
var heading = Cesium.Math.toRadians(90);
var heading = Cesium.Math.toRadians(180);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point of trivia, this change actually puts the heading back to what is was prior to #6592, which is not a coincidence. The model was updated to the correct glTF 2.0 orientation in that PR, but Cesium wasn't yet handling the 2.0 orientations correctly, so this was a workaround that is now being removed.

var pitch = Cesium.Math.toRadians(2);
var roll = Cesium.Math.toRadians(-6);
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
Expand Down
32 changes: 32 additions & 0 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ define([
this._ignoreCommands = defaultValue(options.ignoreCommands, false);
this._requestType = options.requestType;
this._upAxis = defaultValue(options.upAxis, Axis.Y);
this._forwardAxis = defaultValue(options.upAxis, Axis.Z);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be:

this._forwardAxis = defaultValue(options.forwardAxis, Axis.Z);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


/**
* @private
Expand Down Expand Up @@ -973,6 +974,25 @@ define([
}
},

/**
* Gets the model's forward axis.
* By default, glTF 2.0 models are z-forward according to the glTF spec, however older
* glTF (1.0, 0.8) models used x-forward. Note that only Axis.X and Axis.Z are supported.
*
* @memberof Model.prototype
*
* @type {Number}
* @default Axis.Z
* @readonly
*
* @private
*/
forwardAxis : {
get : function() {
return this._forwardAxis;
}
},

/**
* Gets the model's triangle count.
*
Expand Down Expand Up @@ -1361,6 +1381,10 @@ define([
} else if (model._upAxis === Axis.X) {
BoundingSphere.transformWithoutScale(boundingSphere, Axis.X_UP_TO_Z_UP, boundingSphere);
}
if (model._forwardAxis === Axis.Z) {
// glTF 2.0 has a Z-forward convention that must be adapted here to X-forward.
BoundingSphere.transformWithoutScale(boundingSphere, Axis.Z_UP_TO_X_UP, boundingSphere);
}
return boundingSphere;
}

Expand Down Expand Up @@ -4303,6 +4327,10 @@ define([
};
frameState.brdfLutGenerator.update(frameState);
updateVersion(this.gltf);
if (defined(this.gltf.asset) && defined(this.gltf.asset.extras) &&
this.gltf.asset.extras.gltf_pipeline_upgrade_10to20) {
this._forwardAxis = Axis.X;
}
ModelUtility.checkSupportedExtensions(this.extensionsRequired);
addPipelineExtras(this.gltf);
addDefaults(this.gltf);
Expand Down Expand Up @@ -4437,6 +4465,10 @@ define([
} else if (this._upAxis === Axis.X) {
Matrix4.multiplyTransformation(computedModelMatrix, Axis.X_UP_TO_Z_UP, computedModelMatrix);
}
if (this._forwardAxis === Axis.Z) {
// glTF 2.0 has a Z-forward convention that must be adapted here to X-forward.
Matrix4.multiplyTransformation(computedModelMatrix, Axis.Z_UP_TO_X_UP, computedModelMatrix);
}
}

// Update modelMatrix throughout the graph as needed
Expand Down
4 changes: 4 additions & 0 deletions Source/ThirdParty/GltfPipeline/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,12 @@ define([
if (!defined(gltf.asset)) {
gltf.asset = {};
}
if (!defined(gltf.asset.extras)) {
gltf.asset.extras = {};
}
var asset = gltf.asset;
asset.version = '2.0';
asset.extras.gltf_pipeline_upgrade_10to20 = true;
// material.instanceTechnique properties should be directly on the material. instanceTechnique is a gltf 0.8 property but is seen in some 1.0 models.
updateInstanceTechniques(gltf);
// animation.samplers now refers directly to accessors and animation.parameters should be removed
Expand Down
4 changes: 2 additions & 2 deletions Specs/Data/Models/DracoCompression/CesiumMan/CesiumMan.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
1
],
"matrix": [
1,
0,
0,
1,
0,
1,
0,
0,
-1,
0,
0,
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
"children": [
3,
1
],
"matrix": [
0,
0,
1,
0,
0,
1,
0,
0,
-1,
0,
0,
0,
0,
0,
0,
1
]
},
{
Expand Down