From 35e73a6baec3ac070ad58c3b4583f0b681407502 Mon Sep 17 00:00:00 2001 From: ggetz Date: Wed, 27 Jun 2018 15:30:39 -0400 Subject: [PATCH 1/2] Added RTC_CENTER property support to b3dm --- CHANGES.md | 1 + Source/Scene/Batched3DModel3DTileContent.js | 26 +++++++- .../batchedWithRtcCenter.b3dm | Bin 0 -> 9512 bytes .../Batched/BatchedWithRtcCenter/tileset.json | 59 ++++++++++++++++++ .../Scene/Batched3DModel3DTileContentSpec.js | 28 +++++++++ 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/batchedWithRtcCenter.b3dm create mode 100644 Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json diff --git a/CHANGES.md b/CHANGES.md index 04cd837bf343..2099307927be 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ Change Log * The `PostProcessStageLibrary.createBlackAndWhiteStage` and `PostProcessStageLibrary.createSilhouetteStage` have per-feature support. * Added CZML support for `zIndex` for `corridor`, `ellipse`, `polygon`, `polyline` and `rectangle`. [#6708](https://github.com/AnalyticalGraphicsInc/cesium/pull/6708) * Added CZML `clampToGround` option for `polyline`. [#6706](https://github.com/AnalyticalGraphicsInc/cesium/pull/6706) +* Added support for `RTC_CENTER` property in batched 3D model tilesets to conform to the updated [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/issues/263). [#6488](https://github.com/AnalyticalGraphicsInc/cesium/issues/6488) ##### Fixes :wrench: * Fixed a bug that caused Cesium to be unable to load local resources in Electron. [#6726](https://github.com/AnalyticalGraphicsInc/cesium/pull/6726) diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 81709266d6a7..247ce269b038 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -1,5 +1,7 @@ define([ + '../Core/Cartesian3', '../Core/Color', + '../Core/ComponentDatatype', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -9,6 +11,7 @@ define([ '../Core/FeatureDetection', '../Core/getBaseUri', '../Core/getStringFromTypedArray', + '../Core/Matrix4', '../Core/RequestType', '../Core/RuntimeError', '../Renderer/Pass', @@ -20,7 +23,9 @@ define([ './Model', './ModelUtility' ], function( + Cartesian3, Color, + ComponentDatatype, defaultValue, defined, defineProperties, @@ -30,6 +35,7 @@ define([ FeatureDetection, getBaseUri, getStringFromTypedArray, + Matrix4, RequestType, RuntimeError, Pass, @@ -73,6 +79,9 @@ define([ this._batchIdAttributeName = undefined; this._diffuseAttributeOrUniformName = {}; + this._rtcCenterTransform = undefined; + this._contentModelMatrix = undefined; + this.featurePropertiesDirty = false; initialize(this, arrayBuffer, byteOffset); @@ -346,6 +355,14 @@ define([ primitive : tileset }; + content._rtcCenterTransform = Matrix4.IDENTITY.clone(); + var rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', ComponentDatatype.FLOAT, 3); + if (defined(rtcCenter)) { + content._rtcCenterTransform = Matrix4.fromTranslation(Cartesian3.fromArray(rtcCenter), content._rtcCenterTransform); + } + + content._contentModelMatrix = Matrix4.multiply(tile.computedTransform, content._rtcCenterTransform, new Matrix4()); + if (!defined(tileset.classificationType)) { // PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes. // The pick shader still needs to be patched. @@ -356,7 +373,7 @@ define([ opaquePass : Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass basePath : resource, requestType : RequestType.TILES3D, - modelMatrix : tile.computedTransform, + modelMatrix: content._contentModelMatrix, upAxis : tileset._gltfUpAxis, forwardAxis : Axis.X, shadows: tileset.shadows, @@ -377,7 +394,7 @@ define([ cull : false, // The model is already culled by 3D Tiles basePath : resource, requestType : RequestType.TILES3D, - modelMatrix : tile.computedTransform, + modelMatrix: content._contentModelMatrix, upAxis : tileset._gltfUpAxis, forwardAxis : Axis.X, debugWireframe : tileset.debugWireframe, @@ -438,7 +455,10 @@ define([ // the content's resource loading. In the READY state, it will // actually generate commands. this._batchTable.update(tileset, frameState); - this._model.modelMatrix = this._tile.computedTransform; + + this._contentModelMatrix = Matrix4.multiply(this._tile.computedTransform, this._rtcCenterTransform, this._contentModelMatrix); + this._model.modelMatrix = this._contentModelMatrix; + this._model.shadows = this._tileset.shadows; this._model.debugWireframe = this._tileset.debugWireframe; diff --git a/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/batchedWithRtcCenter.b3dm b/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/batchedWithRtcCenter.b3dm new file mode 100644 index 0000000000000000000000000000000000000000..f9eaa6f7817e86636c34058fe404002a4a44f95d GIT binary patch literal 9512 zcmeHNdvIK375`BRXswbeg4EKM+k%zeuJ`?j)$S%uU#3Y(LPcw6H_0Yh%x2^6rnH1e zdE<*BQXjR{DvD4+6p*LTBvgcoSVd6^Xl+4JX&pyKXZ*`^ZgP@uw@aro#2LpVz32S) z+~4_~^PTUzcRQW7*ln5P0L(iJaLDsd&!l1Br&T4Is+X;;t*Kkuv`nis4P9$!s$N@N zQ`c0}pjEChVy14yEV}IG{@Kw_pO$XpJG!Y`x~)69t9!by2YT47Yqi<#j&z~7Ek%q4 zX3RE2FVF?pmS=ii=$e5qG2aYa$9H@?G+c=Vq3as1XFHxV8uKmJupPs-Lw8g!v_gso zj%~YRdVy*9cHmi-Cvu^0nZE6Np6iav1%Vd?z8RXvSbL#s`KD!=USK=Cl4L;^V#K_V z=nhSR0TFB~@N6%%csS8LpY(0dq7s3G0+RR4z@w%m(Q-V4vTWNCR$zp7=s33Fx;*4a z%MQ%IFhW1H-H}ib1h!#PayY8x)0zy+w%pM7l|&l1X*!`t3s{y)cXSqLAH0}l_>K_< zRM@0pxsD#j0^biq%lAUxplu0tKjzuA8KFU?0=nV5ObSeg#z~8?J&u@k6j;OaEsL8p zeGYk{W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+yk>WY53T;Zs_$sD8y)_=TW>rj5k)7LE7Va9fwJ@fJrzWC*lN5#!2KS<4t%orjVV2 zx8QAfE2iRP@>B74OhX0ULB0Z~;GH;??5Q{n@51SrPIfxpjhQ$DGcb$%49v!v(8y|- zgR^lK=Hfl%=i(f^7xOTm{5GF(pfa$JF{aTTt_HRP|vr|~IV zi_eh17N5oEa2?s}uo>6m^SFWR4fq1Sh%LAgUm|}azKpM6E7`61Dz@V$Y{S>cZ^Jk6 zb?m^+@C?~!@N4`A&tf0heRvMP#S3^Iza#%V_T%?BK=uF*;tzNUFXE5n YU&NpBC%lZmkbfDk;1CXzJ&eEN->Da-5&!@I literal 0 HcmV?d00001 diff --git a/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json b/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json new file mode 100644 index 000000000000..6c1800c9f636 --- /dev/null +++ b/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json @@ -0,0 +1,59 @@ +{ + "asset": { + "version": "0.0" + }, + "properties": { + "id": { + "minimum": 0, + "maximum": 9 + }, + "Longitude": { + "minimum": -1.3196972173766555, + "maximum": -1.3196718547473905 + }, + "Latitude": { + "minimum": 0.6988624606923348, + "maximum": 0.6988888301460953 + }, + "Height": { + "minimum": 6.2074098233133554, + "maximum": 12.83180232718587 + } + }, + "geometricError": 70, + "root": { + "transform": [ + 0.9686356343768792, + 0.24848542777253735, + 0, + 0, + -0.15986460744966327, + 0.623177611820219, + 0.765567091384559, + 0, + 0.19023226619126932, + -0.7415555652213445, + 0.6433560667227647, + 0, + 1215011.9317263428, + -4736309.3434217675, + 4081602.0044800863, + 1 + ], + "refine": "ADD", + "boundingVolume": { + "region": [ + -1.3197004795898053, + 0.6988582109, + -1.3196595204101946, + 0.6988897891, + 0, + 20 + ] + }, + "geometricError": 0, + "content": { + "url": "batchedWithRtcCenter.b3dm" + } + } +} diff --git a/Specs/Scene/Batched3DModel3DTileContentSpec.js b/Specs/Scene/Batched3DModel3DTileContentSpec.js index 67503975769e..18f2161b1c72 100644 --- a/Specs/Scene/Batched3DModel3DTileContentSpec.js +++ b/Specs/Scene/Batched3DModel3DTileContentSpec.js @@ -4,6 +4,7 @@ defineSuite([ 'Core/Color', 'Core/HeadingPitchRange', 'Core/HeadingPitchRoll', + 'Core/Matrix4', 'Core/Transforms', 'Scene/ClippingPlane', 'Scene/ClippingPlaneCollection', @@ -16,6 +17,7 @@ defineSuite([ Color, HeadingPitchRange, HeadingPitchRoll, + Matrix4, Transforms, ClippingPlane, ClippingPlaneCollection, @@ -42,6 +44,7 @@ defineSuite([ var deprecated1Url = './Data/Cesium3DTiles/Batched/BatchedDeprecated1/tileset.json'; var deprecated2Url = './Data/Cesium3DTiles/Batched/BatchedDeprecated2/tileset.json'; var gltfZUpUrl = './Data/Cesium3DTiles/Batched/BatchedGltfZUp/tileset.json'; + var withRtcCenterUrl = './Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json'; function setCamera(longitude, latitude) { // One feature is located at the center, point the camera there @@ -371,6 +374,31 @@ defineSuite([ }); }); + it('transforms model positions by RTC_CENTER property in the features table', function() { + return Cesium3DTilesTester.loadTileset(scene, withRtcCenterUrl).then(function(tileset) { + Cesium3DTilesTester.expectRenderTileset(scene, tileset); + + var rtcTransform = tileset._root._content._rtcCenterTransform; + expect(rtcTransform).toEqual(Matrix4.fromTranslation(new Cartesian3(0.1, 0.2, 0.3))); + + var expectedModelTransform = Matrix4.multiply(tileset._root.transform, rtcTransform, new Matrix4()); + expect(tileset._root._content._contentModelMatrix).toEqual(expectedModelTransform); + expect(tileset._root._content._model._modelMatrix).toEqual(expectedModelTransform ); + + // Update tile transform + var newLongitude = -1.31962; + var newLatitude = 0.698874; + var newCenter = Cartesian3.fromRadians(newLongitude, newLatitude, 0.0); + var newHPR = new HeadingPitchRoll(); + var newTransform = Transforms.headingPitchRollToFixedFrame(newCenter, newHPR); + tileset._root.transform = newTransform; + scene.renderForSpecs(); + + expectedModelTransform = Matrix4.multiply(tileset._root.computedTransform, rtcTransform, expectedModelTransform); + expect(tileset._root._content._model._modelMatrix).toEqual(expectedModelTransform); + }); + }); + it('destroys', function() { return Cesium3DTilesTester.tileDestroys(scene, withoutBatchTableUrl); }); From 5ce7a40c263430ef894eed08719c580004bebf11 Mon Sep 17 00:00:00 2001 From: ggetz Date: Fri, 29 Jun 2018 14:12:31 -0400 Subject: [PATCH 2/2] Cleanup b3dm RTC_CENTER --- Source/Scene/Batched3DModel3DTileContent.js | 2 +- .../Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json | 2 +- Specs/Scene/Batched3DModel3DTileContentSpec.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 247ce269b038..b89874f33998 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -355,7 +355,7 @@ define([ primitive : tileset }; - content._rtcCenterTransform = Matrix4.IDENTITY.clone(); + content._rtcCenterTransform = Matrix4.clone(Matrix4.IDENTITY); var rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', ComponentDatatype.FLOAT, 3); if (defined(rtcCenter)) { content._rtcCenterTransform = Matrix4.fromTranslation(Cartesian3.fromArray(rtcCenter), content._rtcCenterTransform); diff --git a/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json b/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json index 6c1800c9f636..fd8a0a97ba2a 100644 --- a/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json +++ b/Specs/Data/Cesium3DTiles/Batched/BatchedWithRtcCenter/tileset.json @@ -1,6 +1,6 @@ { "asset": { - "version": "0.0" + "version": "1.0" }, "properties": { "id": { diff --git a/Specs/Scene/Batched3DModel3DTileContentSpec.js b/Specs/Scene/Batched3DModel3DTileContentSpec.js index 18f2161b1c72..52a2ef22f301 100644 --- a/Specs/Scene/Batched3DModel3DTileContentSpec.js +++ b/Specs/Scene/Batched3DModel3DTileContentSpec.js @@ -383,7 +383,7 @@ defineSuite([ var expectedModelTransform = Matrix4.multiply(tileset._root.transform, rtcTransform, new Matrix4()); expect(tileset._root._content._contentModelMatrix).toEqual(expectedModelTransform); - expect(tileset._root._content._model._modelMatrix).toEqual(expectedModelTransform ); + expect(tileset._root._content._model._modelMatrix).toEqual(expectedModelTransform); // Update tile transform var newLongitude = -1.31962;