From a409bb4975d4b3c33271dba5a458254e0b1af73f Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 7 Feb 2017 13:40:41 -0500 Subject: [PATCH 1/5] Load z-up models --- Source/Scene/Model.js | 16 +- Specs/Data/Models/Box-ECEF/ecef-y-up.gltf | 312 ++++++++++++++++++++++ Specs/Data/Models/Box-ECEF/ecef-z-up.gltf | 288 ++++++++++++++++++++ Specs/Data/Models/Boxes-ECEF/ecef.glb | Bin 5693 -> 0 bytes Specs/Scene/ModelSpec.js | 18 +- 5 files changed, 627 insertions(+), 7 deletions(-) create mode 100644 Specs/Data/Models/Box-ECEF/ecef-y-up.gltf create mode 100644 Specs/Data/Models/Box-ECEF/ecef-z-up.gltf delete mode 100644 Specs/Data/Models/Boxes-ECEF/ecef.glb diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 7f1443d9e048..a7fcf0ada9a6 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -624,6 +624,9 @@ define([ 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 + this._zUp = defaultValue(options.zUp, false); + /** * @private * @readonly @@ -1233,7 +1236,7 @@ define([ }; } - function computeBoundingSphere(gltf) { + function computeBoundingSphere(model, gltf) { var gltfNodes = gltf.nodes; var gltfMeshes = gltf.meshes; var rootNodes = gltf.scenes[gltf.scene].nodes; @@ -1289,7 +1292,10 @@ define([ } var boundingSphere = BoundingSphere.fromCornerPoints(min, max); - return BoundingSphere.transformWithoutScale(boundingSphere, yUpToZUp, boundingSphere); + if (!model._zUp) { + BoundingSphere.transformWithoutScale(boundingSphere, yUpToZUp, boundingSphere); + } + return boundingSphere; } /////////////////////////////////////////////////////////////////////////// @@ -4192,7 +4198,7 @@ define([ this._state = ModelState.LOADING; - this._boundingSphere = computeBoundingSphere(this.gltf); + this._boundingSphere = computeBoundingSphere(this, this.gltf); this._initialRadius = this._boundingSphere.radius; checkSupportedExtensions(this); @@ -4315,7 +4321,9 @@ define([ var scale = getScale(this, frameState); var computedModelMatrix = this._computedModelMatrix; Matrix4.multiplyByUniformScale(modelMatrix, scale, computedModelMatrix); - Matrix4.multiplyTransformation(computedModelMatrix, yUpToZUp, computedModelMatrix); + if (!this._zUp) { + Matrix4.multiplyTransformation(computedModelMatrix, yUpToZUp, computedModelMatrix); + } } // Update modelMatrix throughout the graph as needed diff --git a/Specs/Data/Models/Box-ECEF/ecef-y-up.gltf b/Specs/Data/Models/Box-ECEF/ecef-y-up.gltf new file mode 100644 index 000000000000..eae2d497647a --- /dev/null +++ b/Specs/Data/Models/Box-ECEF/ecef-y-up.gltf @@ -0,0 +1,312 @@ +{ + "accessors": { + "accessor_position": { + "bufferView": "bufferView_0", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC3", + "min": [ + 1215011.25, + -4736310, + 4081601.25 + ], + "max": [ + 1215012.625, + -4736308.5, + 4081602.75 + ] + }, + "accessor_normal": { + "bufferView": "bufferView_0", + "byteOffset": 288, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC3", + "min": [ + -0.968635618686676, + -0.7415555715560913, + -0.7655670642852783 + ], + "max": [ + 0.968635618686676, + 0.7415555715560913, + 0.7655670642852783 + ] + }, + "accessor_uv": { + "bufferView": "bufferView_0", + "byteOffset": 576, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC2", + "min": [ + 0, + 0 + ], + "max": [ + 1, + 1 + ] + }, + "accessor_index_0": { + "bufferView": "bufferView_1", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5123, + "count": 36, + "type": "SCALAR", + "min": [ + 0 + ], + "max": [ + 23 + ] + } + }, + "asset": { + "generator": "3d-tiles-generator", + "version": "1.1", + "premultipliedAlpha": true, + "profile": { + "api": "WebGL", + "version": "1.0.3" + } + }, + "buffers": { + "bufferView_0_buffer": { + "type": "arraybuffer", + "byteLength": 840, + "u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AMABAAFAAYABwAEAAYACAAJAAoACAAKAAsADAANAA4ADwAMAA4AEAARABIAEwAQABIAFAAVABYAFAAWABcA" + } + }, + "bufferViews": { + "bufferView_0": { + "buffer": "bufferView_0_buffer", + "byteLength": 768, + "byteOffset": 0, + "target": 34962 + }, + "bufferView_1": { + "buffer": "bufferView_0_buffer", + "byteLength": 72, + "byteOffset": 768, + "target": 34963 + } + }, + "extensionsRequired": [ + "KHR_materials_common" + ], + "images": {}, + "materials": { + "material_0": { + "extensions": {}, + "technique": "technique0", + "values": { + "ambient": [ + 0.1, + 0.1, + 0.1, + 1 + ], + "diffuse": [ + 1, + 1, + 1, + 1 + ], + "emission": [ + 0, + 0, + 0, + 1 + ], + "specular": [ + 0, + 0, + 0, + 1 + ], + "shininess": 0, + "transparency": 1 + } + } + }, + "meshes": { + "mesh": { + "primitives": [ + { + "attributes": { + "POSITION": "accessor_position", + "NORMAL": "accessor_normal", + "TEXCOORD_0": "accessor_uv" + }, + "indices": "accessor_index_0", + "material": "material_0", + "mode": 4 + } + ] + } + }, + "nodes": { + "rootNode": { + "children": [], + "meshes": [ + "mesh" + ], + "matrix": [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1 + ] + }, + "node_transform": { + "children": [ + "rootNode" + ], + "matrix": [ + 1, + 0, + 0, + 0, + 0, + 0, + -1, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 1 + ], + "name": "Y_UP_Transform" + } + }, + "samplers": {}, + "scene": "scene", + "scenes": { + "scene": { + "nodes": [ + "node_transform" + ] + } + }, + "textures": {}, + "animations": {}, + "cameras": {}, + "programs": { + "program0": { + "attributes": [ + "a_position", + "a_normal", + "a_texcoord_0" + ], + "fragmentShader": "fragmentShader0", + "vertexShader": "vertexShader0" + } + }, + "shaders": { + "vertexShader0": { + "type": 35633, + "uri": "data:text/plain;base64,YXR0cmlidXRlIHZlYzIgYV90ZXhjb29yZF8wOwpwcmV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B2ZWMzIGVtaXNzaW9uID0gdV9lbWlzc2lvbi5yZ2I7CiAgdmVjMyBhbWJpZW50ID0gdV9hbWJpZW50LnJnYjsKICB2ZWMzIHZpZXdEaXIgPSAtbm9ybWFsaXplKHZfcG9zaXRpb25FQyk7CiAgdmVjMyBhbWJpZW50TGlnaHQgPSB2ZWMzKDAuMCwgMC4wLCAwLjApOwogIGFtYmllbnRMaWdodCArPSB2ZWMzKDAuMiwgMC4yLCAwLjIpOwogIHZlYzMgbCA9IG5vcm1hbGl6ZShjem1fc3VuRGlyZWN0aW9uRUMpOwogIGRpZmZ1c2VMaWdodCArPSB2ZWMzKDEuMCwgMS4wLCAxLjApICogbWF4KGRvdChub3JtYWwsbCksIDAuKTsKICB2ZWMzIGNvbG9yID0gdmVjMygwLjAsIDAuMCwgMC4wKTsKICBjb2xvciArPSBkaWZmdXNlLnJnYiAqIGRpZmZ1c2VMaWdodDsKICBjb2xvciArPSBlbWlzc2lvbjsKICBjb2xvciArPSBhbWJpZW50ICogYW1iaWVudExpZ2h0OwogIGdsX0ZyYWdDb2xvciA9IHZlYzQoY29sb3IgKiBkaWZmdXNlLmEsIGRpZmZ1c2UuYSAqIHVfdHJhbnNwYXJlbmN5KTsKfQo=" + } + }, + "skins": {}, + "techniques": { + "technique0": { + "attributes": { + "a_position": "position", + "a_normal": "normal", + "a_texcoord_0": "texcoord_0" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + }, + "normalMatrix": { + "semantic": "MODELVIEWINVERSETRANSPOSE", + "type": 35675 + }, + "ambient": { + "type": 35666 + }, + "diffuse": { + "type": 35666, + "semantic": "_3DTILESDIFFUSE" + }, + "emission": { + "type": 35666 + }, + "specular": { + "type": 35666 + }, + "shininess": { + "type": 5126 + }, + "transparency": { + "type": 5126 + }, + "position": { + "semantic": "POSITION", + "type": 35665 + }, + "normal": { + "semantic": "NORMAL", + "type": 35665 + }, + "texcoord_0": { + "semantic": "TEXCOORD_0", + "type": 5126 + } + }, + "program": "program0", + "states": { + "enable": [ + 2884, + 2929 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix", + "u_normalMatrix": "normalMatrix", + "u_ambient": "ambient", + "u_diffuse": "diffuse", + "u_emission": "emission", + "u_specular": "specular", + "u_shininess": "shininess", + "u_transparency": "transparency" + } + } + }, + "extensions": {}, + "extensionsUsed": [] +} diff --git a/Specs/Data/Models/Box-ECEF/ecef-z-up.gltf b/Specs/Data/Models/Box-ECEF/ecef-z-up.gltf new file mode 100644 index 000000000000..155373ca5ed3 --- /dev/null +++ b/Specs/Data/Models/Box-ECEF/ecef-z-up.gltf @@ -0,0 +1,288 @@ +{ + "accessors": { + "accessor_position": { + "bufferView": "bufferView_0", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC3", + "min": [ + 1215011.25, + -4736310, + 4081601.25 + ], + "max": [ + 1215012.625, + -4736308.5, + 4081602.75 + ] + }, + "accessor_normal": { + "bufferView": "bufferView_0", + "byteOffset": 288, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC3", + "min": [ + -0.968635618686676, + -0.7415555715560913, + -0.7655670642852783 + ], + "max": [ + 0.968635618686676, + 0.7415555715560913, + 0.7655670642852783 + ] + }, + "accessor_uv": { + "bufferView": "bufferView_0", + "byteOffset": 576, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC2", + "min": [ + 0, + 0 + ], + "max": [ + 1, + 1 + ] + }, + "accessor_index_0": { + "bufferView": "bufferView_1", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5123, + "count": 36, + "type": "SCALAR", + "min": [ + 0 + ], + "max": [ + 23 + ] + } + }, + "asset": { + "generator": "3d-tiles-generator", + "version": "1.1", + "premultipliedAlpha": true, + "profile": { + "api": "WebGL", + "version": "1.0.3" + } + }, + "buffers": { + "bufferView_0_buffer": {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ACAPwAAAAAAAIA/AAABAAIAAAACAAMABAAFAAYABwAEAAYACAAJAAoACAAKAAsADAANAA4ADwAMAA4AEAARABIAEwAQABIAFAAVABYAFAAWABcA" + } + }, + "bufferViews": { + "bufferView_0": { + "buffer": "bufferView_0_buffer", + "byteLength": 768, + "byteOffset": 0, + "target": 34962 + }, + "bufferView_1": { + "buffer": "bufferView_0_buffer", + "byteLength": 72, + "byteOffset": 768, + "target": 34963 + } + }, + "extensionsRequired": [ + "KHR_materials_common" + ], + "images": {}, + "materials": { + "material_0": { + "extensions": {}, + "technique": "technique0", + "values": { + "ambient": [ + 0.1, + 0.1, + 0.1, + 1 + ], + "diffuse": [ + 1, + 1, + 1, + 1 + ], + "emission": [ + 0, + 0, + 0, + 1 + ], + "specular": [ + 0, + 0, + 0, + 1 + ], + "shininess": 0, + "transparency": 1 + } + } + }, + "meshes": { + "mesh": { + "primitives": [ + { + "attributes": { + "POSITION": "accessor_position", + "NORMAL": "accessor_normal", + "TEXCOORD_0": "accessor_uv" + }, + "indices": "accessor_index_0", + "material": "material_0", + "mode": 4 + } + ] + } + }, + "nodes": { + "rootNode": { + "children": [], + "meshes": [ + "mesh" + ], + "matrix": [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1 + ] + } + }, + "samplers": {}, + "scene": "scene", + "scenes": { + "scene": { + "nodes": [ + "rootNode" + ] + } + }, + "textures": {}, + "animations": {}, + "cameras": {}, + "programs": { + "program0": { + "attributes": [ + "a_position", + "a_normal", + "a_texcoord_0" + ], + "fragmentShader": "fragmentShader0", + "vertexShader": "vertexShader0" + } + }, + "shaders": { + "vertexShader0": { + "type": 35633, + "uri": "data:text/plain;base64,YXR0cmlidXRlIHZlYzIgYV90ZXhjb29yZF8wOwpwcmVjaXNpb24gaGlnaHAgZmxvYXQ7CnVuaWZvcm0gbWF0NCB1X21vZGVsVmlld01hdHJpeDsKdW5pZm9ybSBtYXQ0IHVfcHJvam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zIHZpZXdEaXIgPSAtbm9ybWFsaXplKHZfcG9zaXRpb25FQyk7CiAgdmVjMyBhbWJpZW50TGlnaHQgPSB2ZWMzKDAuMCwgMC4wLCAwLjApOwogIGFtYmllbnRMaWdodCArPSB2ZWMzKDAuMiwgMC4yLCAwLjIpOwogIHZlYzMgbCA9IG5vcm1hbGl6ZShjem1fc3VuRGlyZWN0aW9uRUMpOwogIGRpZmZ1c2VMaWdodCArPSB2ZWMzKDEuMCwgMS4wLCAxLjApICogbWF4KGRvdChub3JtYWwsbCksIDAuKTsKICB2ZWMzIGNvbG9yID0gdmVjMygwLjAsIDAuMCwgMC4wKTsKICBjb2xvciArPSBkaWZmdXNlLnJnYiAqIGRpZmZ1c2VMaWdodDsKICBjb2xvciArPSBlbWlzc2lvbjsKICBjb2xvciArPSBhbWJpZW50ICogYW1iaWVudExpZ2h0OwogIGdsX0ZyYWdDb2xvciA9IHZlYzQoY29sb3IgKiBkaWZmdXNlLmEsIGRpZmZ1c2UuYSAqIHVfdHJhbnNwYXJlbmN5KTsKfQo=" + } + }, + "skins": {}, + "techniques": { + "technique0": { + "attributes": { + "a_position": "position", + "a_normal": "normal", + "a_texcoord_0": "texcoord_0" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + }, + "normalMatrix": { + "semantic": "MODELVIEWINVERSETRANSPOSE", + "type": 35675 + }, + "ambient": { + "type": 35666 + }, + "diffuse": { + "type": 35666, + "semantic": "_3DTILESDIFFUSE" + }, + "emission": { + "type": 35666 + }, + "specular": { + "type": 35666 + }, + "shininess": { + "type": 5126 + }, + "transparency": { + "type": 5126 + }, + "position": { + "semantic": "POSITION", + "type": 35665 + }, + "normal": { + "semantic": "NORMAL", + "type": 35665 + }, + "texcoord_0": { + "semantic": "TEXCOORD_0", + "type": 5126 + } + }, + "program": "program0", + "states": { + "enable": [ + 2884, + 2929 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix", + "u_normalMatrix": "normalMatrix", + "u_ambient": "ambient", + "u_diffuse": "diffuse", + "u_emission": "emission", + "u_specular": "specular", + "u_shininess": "shininess", + "u_transparency": "transparency" + } + } + }, + "extensions": {}, + "extensionsUsed": [] +} diff --git a/Specs/Data/Models/Boxes-ECEF/ecef.glb b/Specs/Data/Models/Boxes-ECEF/ecef.glb deleted file mode 100644 index 5ce9b416c51edda2290285a0bfc086b6bc2892b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5693 zcmb_gTW=&s749S?gb4`{V3D{etqw?D(jN6?Znm{+8GDvE@!E^+-GD4>RPO1SsiZHH z?w-kdEhBhChzF1mKLp;_?}%rf@;~4q5BW}YcXjoQv))9p<>~5kPM!Pts>b8s_}&Ye zrro)vX`jB11%56J=6Qaa#z|_dS1*HUobrsv5fRU3qmiFH;{GSby7Drx4AVF}&-{bY zDD^XA-O68&vV;$P@#@9lG>-fzJ3gO+(zczBX?XE0g0#~zjZBb@NBwOVxI0;$sWrA^f zy{{#lRjawy>2=(8$L`_T>2^$zx-GknpDsQ-)|%}KS_dy(tJ89NZKvCFWvI&vY1c}^qoMy8J@kwQv%f-vxw64r#85QY(e~Ef z)?wwAbjop0FDXr_Xy6ND>_>jWvN%DfyTjFt2Y$L*5lv(6C#e_9t`9p0SHvNEu%N`941?d1783Jb^%|kZ! zsajAk`IOc2B`;lNITy`*ZxZp3XJ|D;t_hpxESL#>1`E$PP#9iXP1`L0Y}g#~(P)-p z>j~zQe#z^Qr+Jf~V1V&U#B}O=vw&eRRN{n3Ji_rI&^}98lulXVN8Y)yjx13eemcp0 zpcMr(O?Zf-Wlq!+%tnUe;%t`XLJtm(c8_-t_7O^XE>%a7Y3v^y-rw3&nFX+$#&Q3* z+Xn}SJCvhpFJKQ&0BSf6Ih9eOPnBtKl{|wU(;?Qn6aW$7g(_ntah&Z7&V}JkcrZk? zhyw{KBRvr-swdP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 +++ Source/Scene/Model.js | 21 +- Specs/Data/Models/Box-ECEF/ecef-x-up.gltf | 312 ++++++++++++++++++++++ Specs/Scene/ModelSpec.js | 31 ++- 4 files changed, 396 insertions(+), 8 deletions(-) create mode 100644 Source/Scene/Axis.js create mode 100644 Specs/Data/Models/Box-ECEF/ecef-x-up.gltf diff --git a/Source/Scene/Axis.js b/Source/Scene/Axis.js new file mode 100644 index 000000000000..eacf8314247a --- /dev/null +++ b/Source/Scene/Axis.js @@ -0,0 +1,40 @@ +/*global define*/ +define([ + '../Core/freezeObject' +], function( + freezeObject) { + 'use strict'; + + /** + * An enum describing the x, y, z axes. + * + * @exports Axis + */ + var Axis = { + /** + * Denotes the x-axis. + * + * @type {String} + * @constant + */ + X : 'X', + + /** + * Denotes the y-axis. + * + * @type {String} + * @constant + */ + Y : 'Y', + + /** + * Denotes the z-axis. + * + * @type {String} + * @constant + */ + Z : 'Z' + }; + + return freezeObject(Axis); +}); diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index a7fcf0ada9a6..30ebe72b24d0 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -52,6 +52,7 @@ define([ '../ThirdParty/gltfDefaults', '../ThirdParty/Uri', '../ThirdParty/when', + './Axis', './BlendingState', './ColorBlendMode', './getAttributeOrUniformBySemantic', @@ -118,6 +119,7 @@ define([ gltfDefaults, Uri, when, + Axis, BlendingState, ColorBlendMode, getAttributeOrUniformBySemantic, @@ -140,6 +142,7 @@ define([ } var yUpToZUp = Matrix4.fromRotationTranslation(Matrix3.fromRotationX(CesiumMath.PI_OVER_TWO)); + var xUpToZUp = Matrix4.fromRotationTranslation(Matrix3.fromRotationY(CesiumMath.PI_OVER_TWO)); var boundingSphereCartesian3Scratch = new Cartesian3(); var ModelState = { @@ -624,8 +627,14 @@ define([ 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 - this._zUp = defaultValue(options.zUp, 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); /** * @private @@ -1292,8 +1301,10 @@ define([ } var boundingSphere = BoundingSphere.fromCornerPoints(min, max); - if (!model._zUp) { + if (model.upAxis === Axis.Y) { BoundingSphere.transformWithoutScale(boundingSphere, yUpToZUp, boundingSphere); + } else if (model.upAxis === Axis.X) { + BoundingSphere.transformWithoutScale(boundingSphere, xUpToZUp, boundingSphere); } return boundingSphere; } @@ -4321,8 +4332,10 @@ define([ var scale = getScale(this, frameState); var computedModelMatrix = this._computedModelMatrix; Matrix4.multiplyByUniformScale(modelMatrix, scale, computedModelMatrix); - if (!this._zUp) { + if (this.upAxis === Axis.Y) { Matrix4.multiplyTransformation(computedModelMatrix, yUpToZUp, computedModelMatrix); + } else if (this.upAxis === Axis.X) { + Matrix4.multiplyTransformation(computedModelMatrix, xUpToZUp, computedModelMatrix); } } diff --git a/Specs/Data/Models/Box-ECEF/ecef-x-up.gltf b/Specs/Data/Models/Box-ECEF/ecef-x-up.gltf new file mode 100644 index 000000000000..7f9e89f2a012 --- /dev/null +++ b/Specs/Data/Models/Box-ECEF/ecef-x-up.gltf @@ -0,0 +1,312 @@ +{ + "accessors": { + "accessor_position": { + "bufferView": "bufferView_0", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC3", + "min": [ + 1215011.25, + -4736310, + 4081601.25 + ], + "max": [ + 1215012.625, + -4736308.5, + 4081602.75 + ] + }, + "accessor_normal": { + "bufferView": "bufferView_0", + "byteOffset": 288, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC3", + "min": [ + -0.968635618686676, + -0.7415555715560913, + -0.7655670642852783 + ], + "max": [ + 0.968635618686676, + 0.7415555715560913, + 0.7655670642852783 + ] + }, + "accessor_uv": { + "bufferView": "bufferView_0", + "byteOffset": 576, + "byteStride": 0, + "componentType": 5126, + "count": 24, + "type": "VEC2", + "min": [ + 0, + 0 + ], + "max": [ + 1, + 1 + ] + }, + "accessor_index_0": { + "bufferView": "bufferView_1", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5123, + "count": 36, + "type": "SCALAR", + "min": [ + 0 + ], + "max": [ + 23 + ] + } + }, + "asset": { + "generator": "3d-tiles-generator", + "version": "1.1", + "premultipliedAlpha": true, + "profile": { + "api": "WebGL", + "version": "1.0.3" + } + }, + "buffers": { + "bufferView_0_buffer": { + "type": "arraybuffer", + "byteLength": 840, + "uri": "data:application/octet-stream;base64,HVGUSWyKkMoIH3lKJVGUSWyKkMoIH3lKI1GUSWuKkMoLH3lKHFGUSWuKkMoLH3lKIlGUSWmKkMoIH3lKI1GUSWqKkMoFH3lKG1GUSWuKkMoFH3lKGlGUSWqKkMoIH3lKI1GUSWqKkMoFH3lKIlGUSWmKkMoIH3lKI1GUSWuKkMoLH3lKJVGUSWyKkMoIH3lKHFGUSWuKkMoLH3lKGlGUSWqKkMoIH3lKG1GUSWuKkMoFH3lKHVGUSWyKkMoIH3lKI1GUSWuKkMoLH3lKIlGUSWmKkMoIH3lKGlGUSWqKkMoIH3lKHFGUSWuKkMoLH3lKG1GUSWuKkMoFH3lKI1GUSWqKkMoFH3lKJVGUSWyKkMoIH3lKHVGUSWyKkMoIH3lKP8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/gfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAjLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjPpGIH780/EO/jLMjPpGIH780/EO/jLMjPpGIH780/EO/jLMjPpGIH780/EO/AAAAAAAAAAAAAIA/AAAAAAAAgD8AAIA/AAAAAAAAgD8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAIA/AAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAACAPwAAgD8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAIA/AAABAAIAAAACAAMABAAFAAYABwAEAAYACAAJAAoACAAKAAsADAANAA4ADwAMAA4AEAARABIAEwAQABIAFAAVABYAFAAWABcA" + } + }, + "bufferViews": { + "bufferView_0": { + "buffer": "bufferView_0_buffer", + "byteLength": 768, + "byteOffset": 0, + "target": 34962 + }, + "bufferView_1": { + "buffer": "bufferView_0_buffer", + "byteLength": 72, + "byteOffset": 768, + "target": 34963 + } + }, + "extensionsRequired": [ + "KHR_materials_common" + ], + "images": {}, + "materials": { + "material_0": { + "extensions": {}, + "technique": "technique0", + "values": { + "ambient": [ + 0.1, + 0.1, + 0.1, + 1 + ], + "diffuse": [ + 1, + 1, + 1, + 1 + ], + "emission": [ + 0, + 0, + 0, + 1 + ], + "specular": [ + 0, + 0, + 0, + 1 + ], + "shininess": 0, + "transparency": 1 + } + } + }, + "meshes": { + "mesh": { + "primitives": [ + { + "attributes": { + "POSITION": "accessor_position", + "NORMAL": "accessor_normal", + "TEXCOORD_0": "accessor_uv" + }, + "indices": "accessor_index_0", + "material": "material_0", + "mode": 4 + } + ] + } + }, + "nodes": { + "rootNode": { + "children": [], + "meshes": [ + "mesh" + ], + "matrix": [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1 + ] + }, + "node_transform": { + "children": [ + "rootNode" + ], + "matrix": [ + 0, + 0, + 1, + 0, + 0, + 1, + 0, + 0, + -1, + 0, + 0, + 0, + 0, + 0, + 0, + 1 + ], + "name": "X_UP_Transform" + } + }, + "samplers": {}, + "scene": "scene", + "scenes": { + "scene": { + "nodes": [ + "node_transform" + ] + } + }, + "textures": {}, + "animations": {}, + "cameras": {}, + "programs": { + "program0": { + "attributes": [ + "a_position", + "a_normal", + "a_texcoord_0" + ], + "fragmentShader": "fragmentShader0", + "vertexShader": "vertexShader0" + } + }, + "shaders": { + "vertexShader0": { + "type": 35633, + "uri": "data:text/plain;base64,YXR0cmlidXRlIHZlYzIgYV90ZXhjb29yZF8wOwpwcmVjaXNpb24gaGlnaHAgZmxvYXQ7CnVuaWZvcm0gbWF0NCB1X21vZGVsVmlld01hdHJpeDsKdW5pZm9ybSBtYXQ0IHVfcHJvamVjdGlvbk1hdHJpeDsKdW5pZm9ybSBtYXQzIHVfbm9ybWFsTWF0cml4OwphdHRyaWJ1dGUgdmVjMyBhX3Bvc2l0aW9uOwp2YXJ5aW5nIHZlYzMgdl9wb3NpdGlvbkVDOwphdHRyaWJ1dGUgdmVjMyBhX25vcm1hbDsKdmFyeWluZyB2ZWMzIHZfbm9ybWFsOwp2b2lkIG1haW4odm9pZCkgewogIHZlYzQgcG9zID0gdV9tb2RlbFZpZXdNYXRyaXggKiB2ZWM0KGFfcG9zaXRpb24sMS4wKTsKICB2X3Bvc2l0aW9uRUMgPSBwb3MueHl6OwogIGdsX1Bvc2l0aW9uID0gdV9wcm9qZWN0aW9uTWF0cml4ICogcG9zOwogIHZfbm9ybWFsID0gdV9ub3JtYWxNYXRyaXggKiBhX25vcm1hbDsKfQo=" + }, + "fragmentShader0": { + "type": 35632, + "uri": "data:text/plain;base64,cHJlY2lzaW9uIGhpZ2hwIGZsb2F0Owp1bmlmb3JtIHZlYzQgdV9hbWJpZW50Owp1bmlmb3JtIHZlYzQgdV9kaWZmdXNlOwp1bmlmb3JtIHZlYzQgdV9lbWlzc2lvbjsKdW5pZm9ybSB2ZWM0IHVfc3BlY3VsYXI7CnVuaWZvcm0gZmxvYXQgdV9zaGluaW5lc3M7CnVuaWZvcm0gZmxvYXQgdV90cmFuc3BhcmVuY3k7CnZhcnlpbmcgdmVjMyB2X3Bvc2l0aW9uRUM7CnZhcnlpbmcgdmVjMyB2X25vcm1hbDsKdm9pZCBtYWluKHZvaWQpIHsKICB2ZWMzIG5vcm1hbCA9IG5vcm1hbGl6ZSh2X25vcm1hbCk7CiAgdmVjNCBkaWZmdXNlID0gdV9kaWZmdXNlOwogIHZlYzMgZGlmZnVzZUxpZ2h0ID0gdmVjMygwLjAsIDAuMCwgMC4wKTsKICB2ZWMzIGVtaXNzaW9uID0gdV9lbWlzc2lvbi5yZ2I7CiAgdmVjMyBhbWJpZW50ID0gdV9hbWJpZW50LnJnYjsKICB2ZWMzIHZpZXdEaXIgPSAtbm9ybWFsaXplKHZfcG9zaXRpb25FQyk7CiAgdmVjMyBhbWJpZW50TGlnaHQgPSB2ZWMzKDAuMCwgMC4wLCAwLjApOwogIGFtYmllbnRMaWdodCArPSB2ZWMzKDAuMiwgMC4yLCAwLjIpOwogIHZlYzMgbCA9IG5vcm1hbGl6ZShjem1fc3VuRGlyZWN0aW9uRUMpOwogIGRpZmZ1c2VMaWdodCArPSB2ZWMzKDEuMCwgMS4wLCAxLjApICogbWF4KGRvdChub3JtYWwsbCksIDAuKTsKICB2ZWMzIGNvbG9yID0gdmVjMygwLjAsIDAuMCwgMC4wKTsKICBjb2xvciArPSBkaWZmdXNlLnJnYiAqIGRpZmZ1c2VMaWdodDsKICBjb2xvciArPSBlbWlzc2lvbjsKICBjb2xvciArPSBhbWJpZW50ICogYW1iaWVudExpZ2h0OwogIGdsX0ZyYWdDb2xvciA9IHZlYzQoY29sb3IgKiBkaWZmdXNlLmEsIGRpZmZ1c2UuYSAqIHVfdHJhbnNwYXJlbmN5KTsKfQo=" + } + }, + "skins": {}, + "techniques": { + "technique0": { + "attributes": { + "a_position": "position", + "a_normal": "normal", + "a_texcoord_0": "texcoord_0" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + }, + "normalMatrix": { + "semantic": "MODELVIEWINVERSETRANSPOSE", + "type": 35675 + }, + "ambient": { + "type": 35666 + }, + "diffuse": { + "type": 35666, + "semantic": "_3DTILESDIFFUSE" + }, + "emission": { + "type": 35666 + }, + "specular": { + "type": 35666 + }, + "shininess": { + "type": 5126 + }, + "transparency": { + "type": 5126 + }, + "position": { + "semantic": "POSITION", + "type": 35665 + }, + "normal": { + "semantic": "NORMAL", + "type": 35665 + }, + "texcoord_0": { + "semantic": "TEXCOORD_0", + "type": 5126 + } + }, + "program": "program0", + "states": { + "enable": [ + 2884, + 2929 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix", + "u_normalMatrix": "normalMatrix", + "u_ambient": "ambient", + "u_diffuse": "diffuse", + "u_emission": "emission", + "u_specular": "specular", + "u_shininess": "shininess", + "u_transparency": "transparency" + } + } + }, + "extensions": {}, + "extensionsUsed": [] +} diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index 08b95c33eabf..f0ad0ab27a68 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -28,6 +28,7 @@ defineSuite([ 'Renderer/Pass', 'Renderer/RenderState', 'Renderer/ShaderSource', + 'Scene/Axis', 'Scene/ColorBlendMode', 'Scene/HeightReference', 'Scene/ModelAnimationLoop', @@ -63,6 +64,7 @@ defineSuite([ Pass, RenderState, ShaderSource, + Axis, ColorBlendMode, HeightReference, ModelAnimationLoop, @@ -85,7 +87,8 @@ defineSuite([ var texturedBoxCustomUrl = './Data/Models/Box-Textured-Custom/CesiumTexturedBoxTest.gltf'; var texturedBoxKhrBinaryUrl = './Data/Models/Box-Textured-Binary/CesiumTexturedBoxTest.glb'; var boxRtcUrl = './Data/Models/Box-RTC/Box.gltf'; - var boxEcefUrl = './Data/Models/Box-ECEF/ecef-y-up.gltf'; + var boxEcefXUpUrl = './Data/Models/Box-ECEF/ecef-x-up.gltf'; + var boxEcefYUpUrl = './Data/Models/Box-ECEF/ecef-y-up.gltf'; var boxEcefZUpUrl = './Data/Models/Box-ECEF/ecef-z-up.gltf'; var cesiumAirUrl = './Data/Models/CesiumAir/Cesium_Air.gltf'; @@ -288,7 +291,7 @@ defineSuite([ }); it('renders ECEF in 2D', function() { - return loadModel(boxEcefUrl, { + return loadModel(boxEcefYUpUrl, { modelMatrix : Matrix4.IDENTITY, minimumPixelSize : undefined }).then(function(m) { @@ -310,7 +313,7 @@ defineSuite([ }); it('renders ECEF in CV', function() { - return loadModel(boxEcefUrl, { + return loadModel(boxEcefYUpUrl, { modelMatrix : Matrix4.IDENTITY, minimumPixelSize : undefined }).then(function(m) { @@ -320,10 +323,30 @@ defineSuite([ }); }); + it('Renders x-up model', function() { + return loadModel(boxEcefXUpUrl, { + modelMatrix : Matrix4.IDENTITY, + axis : Axis.X + }).then(function(m) { + verifyRender(m); + primitives.remove(m); + }); + }); + + it('Renders x-up model', function() { + return loadModel(boxEcefYUpUrl, { + modelMatrix : Matrix4.IDENTITY, + axis : Axis.Y + }).then(function(m) { + verifyRender(m); + primitives.remove(m); + }); + }); + it('Renders z-up model', function() { return loadModel(boxEcefZUpUrl, { modelMatrix : Matrix4.IDENTITY, - zUp : true + axis : Axis.Z }).then(function(m) { verifyRender(m); primitives.remove(m); From ccb04b74a37a129ab6b0ebc2b5fb5545d2141954 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 8 Feb 2017 13:36:36 -0500 Subject: [PATCH 3/5] Updates --- Source/Scene/Axis.js | 51 ++- Source/Scene/Model.js | 10 +- Specs/Data/Models/Box-ECEF/ecef-x-up.gltf | 312 ------------------ Specs/Data/Models/Box-ECEF/ecef-z-up.gltf | 288 ---------------- .../Box-ECEF/{ecef-y-up.gltf => ecef.gltf} | 0 Specs/Scene/ModelSpec.js | 63 ++-- 6 files changed, 85 insertions(+), 639 deletions(-) delete mode 100644 Specs/Data/Models/Box-ECEF/ecef-x-up.gltf delete mode 100644 Specs/Data/Models/Box-ECEF/ecef-z-up.gltf rename Specs/Data/Models/Box-ECEF/{ecef-y-up.gltf => ecef.gltf} (100%) diff --git a/Source/Scene/Axis.js b/Source/Scene/Axis.js index eacf8314247a..457d101d0bd7 100644 --- a/Source/Scene/Axis.js +++ b/Source/Scene/Axis.js @@ -1,39 +1,72 @@ /*global define*/ define([ - '../Core/freezeObject' + '../Core/freezeObject', + '../Core/Math', + '../Core/Matrix3', + '../Core/Matrix4' ], function( - freezeObject) { + freezeObject, + CesiumMath, + Matrix3, + Matrix4) { 'use strict'; /** - * An enum describing the x, y, z axes. + * An enum describing the x, y, and z axes and helper conversion functions. * * @exports Axis + * @private */ var Axis = { /** * Denotes the x-axis. * - * @type {String} + * @type {Number} * @constant */ - X : 'X', + X : 0, /** * Denotes the y-axis. * - * @type {String} + * @type {Number} * @constant */ - Y : 'Y', + Y : 1, /** * Denotes the z-axis. * - * @type {String} + * @type {Number} * @constant */ - Z : 'Z' + Z : 2, + + /** + * Matrix used to convert from y-up to z-up + * + * @type {Matrix4} + * @constant + */ + Y_UP_TO_Z_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)), + + /** + * Gets the axis by name + * + * @param {String} name The name of the axis. + * @returns {Number} The axis enum. + */ + fromName : function(name) { + return Axis[name]; + } }; return freezeObject(Axis); diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 30ebe72b24d0..885fd6e3dced 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -141,8 +141,6 @@ define([ return {}; } - var yUpToZUp = Matrix4.fromRotationTranslation(Matrix3.fromRotationX(CesiumMath.PI_OVER_TWO)); - var xUpToZUp = Matrix4.fromRotationTranslation(Matrix3.fromRotationY(CesiumMath.PI_OVER_TWO)); var boundingSphereCartesian3Scratch = new Cartesian3(); var ModelState = { @@ -1302,9 +1300,9 @@ define([ var boundingSphere = BoundingSphere.fromCornerPoints(min, max); if (model.upAxis === Axis.Y) { - BoundingSphere.transformWithoutScale(boundingSphere, yUpToZUp, boundingSphere); + BoundingSphere.transformWithoutScale(boundingSphere, Axis.Y_UP_TO_Z_UP, boundingSphere); } else if (model.upAxis === Axis.X) { - BoundingSphere.transformWithoutScale(boundingSphere, xUpToZUp, boundingSphere); + BoundingSphere.transformWithoutScale(boundingSphere, Axis.X_UP_TO_Z_UP, boundingSphere); } return boundingSphere; } @@ -4333,9 +4331,9 @@ define([ var computedModelMatrix = this._computedModelMatrix; Matrix4.multiplyByUniformScale(modelMatrix, scale, computedModelMatrix); if (this.upAxis === Axis.Y) { - Matrix4.multiplyTransformation(computedModelMatrix, yUpToZUp, computedModelMatrix); + Matrix4.multiplyTransformation(computedModelMatrix, Axis.Y_UP_TO_Z_UP, computedModelMatrix); } else if (this.upAxis === Axis.X) { - Matrix4.multiplyTransformation(computedModelMatrix, xUpToZUp, computedModelMatrix); + Matrix4.multiplyTransformation(computedModelMatrix, Axis.X_UP_TO_Z_UP, computedModelMatrix); } } diff --git a/Specs/Data/Models/Box-ECEF/ecef-x-up.gltf b/Specs/Data/Models/Box-ECEF/ecef-x-up.gltf deleted file mode 100644 index 7f9e89f2a012..000000000000 --- a/Specs/Data/Models/Box-ECEF/ecef-x-up.gltf +++ /dev/null @@ -1,312 +0,0 @@ -{ - "accessors": { - "accessor_position": { - "bufferView": "bufferView_0", - "byteOffset": 0, - "byteStride": 0, - "componentType": 5126, - "count": 24, - "type": "VEC3", - "min": [ - 1215011.25, - -4736310, - 4081601.25 - ], - "max": [ - 1215012.625, - -4736308.5, - 4081602.75 - ] - }, - "accessor_normal": { - "bufferView": "bufferView_0", - "byteOffset": 288, - "byteStride": 0, - "componentType": 5126, - "count": 24, - "type": "VEC3", - "min": [ - -0.968635618686676, - -0.7415555715560913, - -0.7655670642852783 - ], - "max": [ - 0.968635618686676, - 0.7415555715560913, - 0.7655670642852783 - ] - }, - "accessor_uv": { - "bufferView": "bufferView_0", - "byteOffset": 576, - "byteStride": 0, - "componentType": 5126, - "count": 24, - "type": "VEC2", - "min": [ - 0, - 0 - ], - "max": [ - 1, - 1 - ] - }, - "accessor_index_0": { - "bufferView": "bufferView_1", - "byteOffset": 0, - "byteStride": 0, - "componentType": 5123, - "count": 36, - "type": "SCALAR", - "min": [ - 0 - ], - "max": [ - 23 - ] - } - }, - "asset": { - "generator": "3d-tiles-generator", - "version": "1.1", - "premultipliedAlpha": true, - "profile": { - "api": "WebGL", - "version": "1.0.3" - } - }, - "buffers": { - "bufferView_0_buffer": { - "type": "arraybuffer", - "byteLength": 840, - "uri": "data:application/octet-stream;base64,HVGUSWyKkMoIH3lKJVGUSWyKkMoIH3lKI1GUSWuKkMoLH3lKHFGUSWuKkMoLH3lKIlGUSWmKkMoIH3lKI1GUSWqKkMoFH3lKG1GUSWuKkMoFH3lKGlGUSWqKkMoIH3lKI1GUSWqKkMoFH3lKIlGUSWmKkMoIH3lKI1GUSWuKkMoLH3lKJVGUSWyKkMoIH3lKHFGUSWuKkMoLH3lKGlGUSWqKkMoIH3lKG1GUSWuKkMoFH3lKHVGUSWyKkMoIH3lKI1GUSWuKkMoLH3lKIlGUSWmKkMoIH3lKGlGUSWqKkMoIH3lKHFGUSWuKkMoLH3lKG1GUSWuKkMoFH3lKI1GUSWqKkMoFH3lKJVGUSWyKkMoIH3lKHVGUSWyKkMoIH3lKP8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/gfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAjLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjPpGIH780/EO/jLMjPpGIH780/EO/jLMjPpGIH780/EO/jLMjPpGIH780/EO/AAAAAAAAAAAAAIA/AAAAAAAAgD8AAIA/AAAAAAAAgD8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAIA/AAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAACAPwAAgD8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAIA/AAABAAIAAAACAAMABAAFAAYABwAEAAYACAAJAAoACAAKAAsADAANAA4ADwAMAA4AEAARABIAEwAQABIAFAAVABYAFAAWABcA" - } - }, - "bufferViews": { - "bufferView_0": { - "buffer": "bufferView_0_buffer", - "byteLength": 768, - "byteOffset": 0, - "target": 34962 - }, - "bufferView_1": { - "buffer": "bufferView_0_buffer", - "byteLength": 72, - "byteOffset": 768, - "target": 34963 - } - }, - "extensionsRequired": [ - "KHR_materials_common" - ], - "images": {}, - "materials": { - "material_0": { - "extensions": {}, - "technique": "technique0", - "values": { - "ambient": [ - 0.1, - 0.1, - 0.1, - 1 - ], - "diffuse": [ - 1, - 1, - 1, - 1 - ], - "emission": [ - 0, - 0, - 0, - 1 - ], - "specular": [ - 0, - 0, - 0, - 1 - ], - "shininess": 0, - "transparency": 1 - } - } - }, - "meshes": { - "mesh": { - "primitives": [ - { - "attributes": { - "POSITION": "accessor_position", - "NORMAL": "accessor_normal", - "TEXCOORD_0": "accessor_uv" - }, - "indices": "accessor_index_0", - "material": "material_0", - "mode": 4 - } - ] - } - }, - "nodes": { - "rootNode": { - "children": [], - "meshes": [ - "mesh" - ], - "matrix": [ - 1, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 1 - ] - }, - "node_transform": { - "children": [ - "rootNode" - ], - "matrix": [ - 0, - 0, - 1, - 0, - 0, - 1, - 0, - 0, - -1, - 0, - 0, - 0, - 0, - 0, - 0, - 1 - ], - "name": "X_UP_Transform" - } - }, - "samplers": {}, - "scene": "scene", - "scenes": { - "scene": { - "nodes": [ - "node_transform" - ] - } - }, - "textures": {}, - "animations": {}, - "cameras": {}, - "programs": { - "program0": { - "attributes": [ - "a_position", - "a_normal", - "a_texcoord_0" - ], - "fragmentShader": "fragmentShader0", - "vertexShader": "vertexShader0" - } - }, - "shaders": { - "vertexShader0": { - "type": 35633, - "uri": "data:text/plain;base64,YXR0cmlidXRlIHZlYzIgYV90ZXhjb29yZF8wOwpwcmVjaXNpb24gaGlnaHAgZmxvYXQ7CnVuaWZvcm0gbWF0NCB1X21vZGVsVmlld01hdHJpeDsKdW5pZm9ybSBtYXQ0IHVfcHJvamVjdGlvbk1hdHJpeDsKdW5pZm9ybSBtYXQzIHVfbm9ybWFsTWF0cml4OwphdHRyaWJ1dGUgdmVjMyBhX3Bvc2l0aW9uOwp2YXJ5aW5nIHZlYzMgdl9wb3NpdGlvbkVDOwphdHRyaWJ1dGUgdmVjMyBhX25vcm1hbDsKdmFyeWluZyB2ZWMzIHZfbm9ybWFsOwp2b2lkIG1haW4odm9pZCkgewogIHZlYzQgcG9zID0gdV9tb2RlbFZpZXdNYXRyaXggKiB2ZWM0KGFfcG9zaXRpb24sMS4wKTsKICB2X3Bvc2l0aW9uRUMgPSBwb3MueHl6OwogIGdsX1Bvc2l0aW9uID0gdV9wcm9qZWN0aW9uTWF0cml4ICogcG9zOwogIHZfbm9ybWFsID0gdV9ub3JtYWxNYXRyaXggKiBhX25vcm1hbDsKfQo=" - }, - "fragmentShader0": { - "type": 35632, - "uri": "data:text/plain;base64,cHJlY2lzaW9uIGhpZ2hwIGZsb2F0Owp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mEsIGRpZmZ1c2UuYSAqIHVfdHJhbnNwYXJlbmN5KTsKfQo=" - } - }, - "skins": {}, - "techniques": { - "technique0": { - "attributes": { - "a_position": "position", - "a_normal": "normal", - "a_texcoord_0": "texcoord_0" - }, - "parameters": { - "modelViewMatrix": { - "semantic": "MODELVIEW", - "type": 35676 - }, - "projectionMatrix": { - "semantic": "PROJECTION", - "type": 35676 - }, - "normalMatrix": { - "semantic": "MODELVIEWINVERSETRANSPOSE", - "type": 35675 - }, - "ambient": { - "type": 35666 - }, - "diffuse": { - "type": 35666, - "semantic": "_3DTILESDIFFUSE" - }, - "emission": { - "type": 35666 - }, - "specular": { - "type": 35666 - }, - "shininess": { - "type": 5126 - }, - "transparency": { - "type": 5126 - }, - "position": { - "semantic": "POSITION", - "type": 35665 - }, - "normal": { - "semantic": "NORMAL", - "type": 35665 - }, - "texcoord_0": { - "semantic": "TEXCOORD_0", - "type": 5126 - } - }, - "program": "program0", - "states": { - "enable": [ - 2884, - 2929 - ] - }, - "uniforms": { - "u_modelViewMatrix": "modelViewMatrix", - "u_projectionMatrix": "projectionMatrix", - "u_normalMatrix": "normalMatrix", - "u_ambient": "ambient", - "u_diffuse": "diffuse", - "u_emission": "emission", - "u_specular": "specular", - "u_shininess": "shininess", - "u_transparency": "transparency" - } - } - }, - "extensions": {}, - "extensionsUsed": [] -} diff --git a/Specs/Data/Models/Box-ECEF/ecef-z-up.gltf b/Specs/Data/Models/Box-ECEF/ecef-z-up.gltf deleted file mode 100644 index 155373ca5ed3..000000000000 --- a/Specs/Data/Models/Box-ECEF/ecef-z-up.gltf +++ /dev/null @@ -1,288 +0,0 @@ -{ - "accessors": { - "accessor_position": { - "bufferView": "bufferView_0", - "byteOffset": 0, - "byteStride": 0, - "componentType": 5126, - "count": 24, - "type": "VEC3", - "min": [ - 1215011.25, - -4736310, - 4081601.25 - ], - "max": [ - 1215012.625, - -4736308.5, - 4081602.75 - ] - }, - "accessor_normal": { - "bufferView": "bufferView_0", - "byteOffset": 288, - "byteStride": 0, - "componentType": 5126, - "count": 24, - "type": "VEC3", - "min": [ - -0.968635618686676, - -0.7415555715560913, - -0.7655670642852783 - ], - "max": [ - 0.968635618686676, - 0.7415555715560913, - 0.7655670642852783 - ] - }, - "accessor_uv": { - "bufferView": "bufferView_0", - "byteOffset": 576, - "byteStride": 0, - "componentType": 5126, - "count": 24, - "type": "VEC2", - "min": [ - 0, - 0 - ], - "max": [ - 1, - 1 - ] - }, - "accessor_index_0": { - "bufferView": "bufferView_1", - "byteOffset": 0, - "byteStride": 0, - "componentType": 5123, - "count": 36, - "type": "SCALAR", - "min": [ - 0 - ], - "max": [ - 23 - ] - } - }, - "asset": { - "generator": "3d-tiles-generator", - "version": "1.1", - "premultipliedAlpha": true, - "profile": { - "api": "WebGL", - "version": "1.0.3" - } - }, - "buffers": { - "bufferView_0_buffer": { - "type": "arraybuffer", - "byteLength": 840, - "uri": "data:application/octet-stream;base64,HVGUSWyKkMoIH3lKJVGUSWyKkMoIH3lKI1GUSWuKkMoLH3lKHFGUSWuKkMoLH3lKIlGUSWmKkMoIH3lKI1GUSWqKkMoFH3lKG1GUSWuKkMoFH3lKGlGUSWqKkMoIH3lKI1GUSWqKkMoFH3lKIlGUSWmKkMoIH3lKI1GUSWuKkMoLH3lKJVGUSWyKkMoIH3lKHFGUSWuKkMoLH3lKGlGUSWqKkMoIH3lKG1GUSWuKkMoFH3lKHVGUSWyKkMoIH3lKI1GUSWuKkMoLH3lKIlGUSWmKkMoIH3lKGlGUSWqKkMoIH3lKHFGUSWuKkMoLH3lKG1GUSWuKkMoFH3lKI1GUSWqKkMoFH3lKJVGUSWyKkMoIH3lKHVGUSWyKkMoIH3lKP8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCPpbWPb/8siQ/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/P8xCvpbWPT/8siS/gfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3P/dyfj4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAgfh3v/dyfr4AAAAAjLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjvpGIHz80/EM/jLMjPpGIH780/EO/jLMjPpGIH780/EO/jLMjPpGIH780/EO/jLMjPpGIH780/EO/AAAAAAAAAAAAAIA/AAAAAAAAgD8AAIA/AAAAAAAAgD8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAIA/AAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAACAPwAAgD8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAIA/AAABAAIAAAACAAMABAAFAAYABwAEAAYACAAJAAoACAAKAAsADAANAA4ADwAMAA4AEAARABIAEwAQABIAFAAVABYAFAAWABcA" - } - }, - "bufferViews": { - "bufferView_0": { - "buffer": "bufferView_0_buffer", - "byteLength": 768, - "byteOffset": 0, - "target": 34962 - }, - "bufferView_1": { - "buffer": "bufferView_0_buffer", - "byteLength": 72, - "byteOffset": 768, - "target": 34963 - } - }, - "extensionsRequired": [ - "KHR_materials_common" - ], - "images": {}, - "materials": { - "material_0": { - "extensions": {}, - "technique": "technique0", - "values": { - "ambient": [ - 0.1, - 0.1, - 0.1, - 1 - ], - "diffuse": [ - 1, - 1, - 1, - 1 - ], - "emission": [ - 0, - 0, - 0, - 1 - ], - "specular": [ - 0, - 0, - 0, - 1 - ], - "shininess": 0, - "transparency": 1 - } - } - }, - "meshes": { - "mesh": { - "primitives": [ - { - "attributes": { - "POSITION": "accessor_position", - "NORMAL": "accessor_normal", - "TEXCOORD_0": "accessor_uv" - }, - "indices": "accessor_index_0", - "material": "material_0", - "mode": 4 - } - ] - } - }, - "nodes": { - "rootNode": { - "children": [], - "meshes": [ - "mesh" - ], - "matrix": [ - 1, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 1 - ] - } - }, - "samplers": {}, - "scene": "scene", - "scenes": { - "scene": { - "nodes": [ - "rootNode" - ] - } - }, - "textures": {}, - "animations": {}, - "cameras": {}, - "programs": { - "program0": { - "attributes": [ - "a_position", - "a_normal", - "a_texcoord_0" - ], - "fragmentShader": "fragmentShader0", - "vertexShader": "vertexShader0" - } - }, - "shaders": { - "vertexShader0": { - "type": 35633, - "uri": "data:text/plain;base64,YXR0cmlidXRlIHZlYzIgYV90ZXhjb29yZF8wOwpwcmVjaXNpb24gaGlnaHAgZmxvYXQ7CnVuaWZvcm0gbWF0NCB1X21vZGVsVmlld01hdHJpeDsKdW5pZm9ybSBtYXQ0IHVfcHJvamVjdGlvbk1hdHJpeDsKdW5pZm9ybSBtYXQzIHVfbm9ybWFsTWF0cml4OwphdHRyaWJ1dGUgdmVjMyBhX3Bvc2l0aW9uOwp2YXJ5aW5nIHZlYzMgdl9wb3NpdGlvbkVDOwphdHRyaWJ1dGUgdmVjMyBhX25vcm1hbDsKdmFyeWluZyB2ZWMzIHZfbm9ybWFsOwp2b2lkIG1haW4odm9pZCkgewogIHZlYzQgcG9zID0gdV9tb2RlbFZpZXdNYXRyaXggKiB2ZWM0KGFfcG9zaXRpb24sMS4wKTsKICB2X3Bvc2l0aW9uRUMgPSBwb3MueHl6OwogIGdsX1Bvc2l0aW9uID0gdV9wcm9qZWN0aW9uTWF0cml4ICogcG9zOwogIHZfbm9ybWFsID0gdV9ub3JtYWxNYXRyaXggKiBhX25vcm1hbDsKfQo=" - }, - "fragmentShader0": { - "type": 35632, - "uri": "data:text/plain;base64,cHJlY2lzaW9uIGhpZ2hwIGZsb2F0Owp1bmlmb3JtIHZlYzQgdV9hbWJpZW50Owp1bmlmb3JtIHZlYzQgdV9kaWZmdXNlOwp1bmlmb3JtIHZlYzQgdV9lbWlzc2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position", - "a_normal": "normal", - "a_texcoord_0": "texcoord_0" - }, - "parameters": { - "modelViewMatrix": { - "semantic": "MODELVIEW", - "type": 35676 - }, - "projectionMatrix": { - "semantic": "PROJECTION", - "type": 35676 - }, - "normalMatrix": { - "semantic": "MODELVIEWINVERSETRANSPOSE", - "type": 35675 - }, - "ambient": { - "type": 35666 - }, - "diffuse": { - "type": 35666, - "semantic": "_3DTILESDIFFUSE" - }, - "emission": { - "type": 35666 - }, - "specular": { - "type": 35666 - }, - "shininess": { - "type": 5126 - }, - "transparency": { - "type": 5126 - }, - "position": { - "semantic": "POSITION", - "type": 35665 - }, - "normal": { - "semantic": "NORMAL", - "type": 35665 - }, - "texcoord_0": { - "semantic": "TEXCOORD_0", - "type": 5126 - } - }, - "program": "program0", - "states": { - "enable": [ - 2884, - 2929 - ] - }, - "uniforms": { - "u_modelViewMatrix": "modelViewMatrix", - "u_projectionMatrix": "projectionMatrix", - "u_normalMatrix": "normalMatrix", - "u_ambient": "ambient", - "u_diffuse": "diffuse", - "u_emission": "emission", - "u_specular": "specular", - "u_shininess": "shininess", - "u_transparency": "transparency" - } - } - }, - "extensions": {}, - "extensionsUsed": [] -} diff --git a/Specs/Data/Models/Box-ECEF/ecef-y-up.gltf b/Specs/Data/Models/Box-ECEF/ecef.gltf similarity index 100% rename from Specs/Data/Models/Box-ECEF/ecef-y-up.gltf rename to Specs/Data/Models/Box-ECEF/ecef.gltf diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index f0ad0ab27a68..92d726eb6603 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -87,9 +87,7 @@ defineSuite([ var texturedBoxCustomUrl = './Data/Models/Box-Textured-Custom/CesiumTexturedBoxTest.gltf'; var texturedBoxKhrBinaryUrl = './Data/Models/Box-Textured-Binary/CesiumTexturedBoxTest.glb'; var boxRtcUrl = './Data/Models/Box-RTC/Box.gltf'; - var boxEcefXUpUrl = './Data/Models/Box-ECEF/ecef-x-up.gltf'; - var boxEcefYUpUrl = './Data/Models/Box-ECEF/ecef-y-up.gltf'; - var boxEcefZUpUrl = './Data/Models/Box-ECEF/ecef-z-up.gltf'; + var boxEcefUrl = './Data/Models/Box-ECEF/ecef.gltf'; var cesiumAirUrl = './Data/Models/CesiumAir/Cesium_Air.gltf'; var cesiumAir_0_8Url = './Data/Models/CesiumAir/Cesium_Air_0_8.gltf'; @@ -291,7 +289,7 @@ defineSuite([ }); it('renders ECEF in 2D', function() { - return loadModel(boxEcefYUpUrl, { + return loadModel(boxEcefUrl, { modelMatrix : Matrix4.IDENTITY, minimumPixelSize : undefined }).then(function(m) { @@ -313,7 +311,7 @@ defineSuite([ }); it('renders ECEF in CV', function() { - return loadModel(boxEcefYUpUrl, { + return loadModel(boxEcefUrl, { modelMatrix : Matrix4.IDENTITY, minimumPixelSize : undefined }).then(function(m) { @@ -324,32 +322,49 @@ defineSuite([ }); it('Renders x-up model', function() { - return loadModel(boxEcefXUpUrl, { - modelMatrix : Matrix4.IDENTITY, - axis : Axis.X - }).then(function(m) { - verifyRender(m); - primitives.remove(m); + 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)); + + return loadModelJson(gltf, { + modelMatrix : Matrix4.IDENTITY, + upAxis : Axis.X + }).then(function(m) { + verifyRender(m); + primitives.remove(m); + }); }); }); - it('Renders x-up model', function() { - return loadModel(boxEcefYUpUrl, { - modelMatrix : Matrix4.IDENTITY, - axis : Axis.Y - }).then(function(m) { - verifyRender(m); - primitives.remove(m); + 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)); + + return loadModelJson(gltf, { + modelMatrix : Matrix4.IDENTITY, + upAxis : Axis.Y + }).then(function(m) { + verifyRender(m); + primitives.remove(m); + }); }); }); it('Renders z-up model', function() { - return loadModel(boxEcefZUpUrl, { - modelMatrix : Matrix4.IDENTITY, - axis : Axis.Z - }).then(function(m) { - verifyRender(m); - primitives.remove(m); + return loadJson(boxEcefUrl).then(function(gltf) { + // Model data is z-up. Edit the transform to be the identity. + gltf.nodes.node_transform.matrix = Matrix4.pack(Matrix4.IDENTITY, new Array(16)); + + return loadModelJson(gltf, { + modelMatrix : Matrix4.IDENTITY, + upAxis : Axis.Y + }).then(function(m) { + verifyRender(m); + primitives.remove(m); + }); }); }); From 289903fc64ec9fa08b36a399627c073f80780d96 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 8 Feb 2017 13:49:25 -0500 Subject: [PATCH 4/5] 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); }); }); From 2161c1fa28e74db6872127d6eb9d9a6acfb095bf Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Wed, 8 Feb 2017 20:24:58 -0500 Subject: [PATCH 5/5] Whitespace --- Source/Scene/Axis.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Scene/Axis.js b/Source/Scene/Axis.js index 948f2cddeba9..e98bf2f81466 100644 --- a/Source/Scene/Axis.js +++ b/Source/Scene/Axis.js @@ -92,7 +92,6 @@ define([ */ Y_UP_TO_X_UP : Matrix4.fromRotationTranslation(Matrix3.fromRotationZ(-CesiumMath.PI_OVER_TWO)), - /** * Gets the axis by name *