园林绿化
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.9 KiB

  1. // 兼容不同版本cesium,补充官方删除更改的方法或类名 by mars3d.cn
  2. // import * as mars3d from "mars3d"
  3. // const Cesium = mars3d.Cesium
  4. // 兼容1.96(2022-08-01)删除的方法
  5. if (!Cesium.Cesium3DTileFeature.prototype.getPropertyNames) {
  6. Cesium.Cesium3DTileFeature.prototype.getPropertyNames = Cesium.Cesium3DTileFeature.prototype.getPropertyIds
  7. Cesium.Cesium3DTilePointFeature.prototype.getPropertyNames = Cesium.Cesium3DTilePointFeature.prototype.getPropertyIds
  8. Cesium.ModelFeature.prototype.getPropertyNames = Cesium.Cesium3DTilePointFeature.prototype.getPropertyIds
  9. }
  10. // 兼容1.94(2022-06-01)删除的方法
  11. if (!Cesium.ImagerySplitDirection) {
  12. Cesium.ImagerySplitDirection = Cesium.SplitDirection
  13. }
  14. // 兼容1.92(2022-4-2)删除的方法
  15. // 请引入cesium-when.js
  16. // 兼容1.87(2021-11-1)删除的方法
  17. Cesium.sprintf =
  18. Cesium.sprintf ||
  19. function (format) {
  20. return format
  21. }
  22. // 兼容1.73(2020-9-1)删除的方法
  23. Cesium.BingMapsApi = Cesium.BingMapsApi || { defaultKey: "" }
  24. Cesium.MapboxApi = Cesium.BingMapsApi || { defaultAccessToken: "" }
  25. // 兼容1.67(2020-3-3)删除的方法
  26. if (!Cesium.defineProperties) {
  27. Cesium.defineProperties = Object.defineProperties
  28. }
  29. if (!Cesium.isArray) {
  30. Cesium.isArray = Array.isArray
  31. }
  32. // 兼容1.62(2019-10-01)改名的方法
  33. if (!Cesium.Matrix4.getMatrix3) {
  34. Cesium.Matrix4.getMatrix3 = Cesium.Matrix4.getRotation
  35. }
  36. if (!Cesium.TileMapServiceImageryProvider) {
  37. Cesium.TileMapServiceImageryProvider = Cesium.createTileMapServiceImageryProvider
  38. }
  39. if (!Cesium.createTileMapServiceImageryProvider) {
  40. Cesium.createTileMapServiceImageryProvider = function (options) {
  41. return new Cesium.TileMapServiceImageryProvider(options)
  42. }
  43. }
  44. // 兼容1.50 (2018-10-01)版本更改了名称,造成部分3dtiles可能会出现加载不上导致渲染停止的错误。
  45. // 错误说明为:RuntimeError: Unsupported glTF Extension: KHR_technique_webgl
  46. // 原因:KHR_technique_webgl扩展新版Cesium已经不支持的缘故,需要升级一下gltf数据,使用KHR_techniques_webgl扩展即可(注意多了一个s)。
  47. try {
  48. // var fixGltf = function (gltf) {
  49. // if (!gltf.extensionsUsed || !gltf.extensionsUsed.indexOf || !gltf.extensionsRequired) {
  50. // return;
  51. // }
  52. // var v = gltf.extensionsUsed.indexOf('KHR_technique_webgl');
  53. // if (v == -1) return;
  54. // // 中招了。。
  55. // var t = gltf.extensionsRequired.indexOf('KHR_technique_webgl');
  56. // gltf.extensionsRequired.splice(t, 1, 'KHR_techniques_webgl');
  57. // gltf.extensionsUsed.splice(v, 1, 'KHR_techniques_webgl');
  58. // gltf.extensions = gltf.extensions || {};
  59. // gltf.extensions['KHR_techniques_webgl'] = {};
  60. // gltf.extensions['KHR_techniques_webgl'].programs = gltf.programs;
  61. // gltf.extensions['KHR_techniques_webgl'].shaders = gltf.shaders;
  62. // gltf.extensions['KHR_techniques_webgl'].techniques = gltf.techniques;
  63. // var techniques = gltf.extensions['KHR_techniques_webgl'].techniques;
  64. // gltf.materials.forEach(function (mat, index) {
  65. // gltf.materials[index].extensions || (gltf.materials[index].extensions = { KHR_technique_webgl: {} });
  66. // gltf.materials[index].extensions['KHR_technique_webgl'].values = gltf.materials[index].values;
  67. // gltf.materials[index].extensions['KHR_techniques_webgl'] = gltf.materials[index].extensions['KHR_technique_webgl'];
  68. // var myMaterialExtension = gltf.materials[index].extensions['KHR_techniques_webgl'];
  69. // myMaterialExtension.technique || (myMaterialExtension.technique = gltf.materials[index].technique);
  70. // for (var value in myMaterialExtension.values) {
  71. // var us = techniques[myMaterialExtension.technique].uniforms;
  72. // for (var key in us) {
  73. // if (us[key] === value) {
  74. // myMaterialExtension.values[key] = myMaterialExtension.values[value];
  75. // delete myMaterialExtension.values[value];
  76. // break;
  77. // }
  78. // }
  79. // };
  80. // });
  81. // techniques.forEach(function (t) {
  82. // for (var attribute in t.attributes) {
  83. // var name = t.attributes[attribute];
  84. // t.attributes[attribute] = t.parameters[name];
  85. // };
  86. // for (var uniform in t.uniforms) {
  87. // var name = t.uniforms[uniform];
  88. // t.uniforms[uniform] = t.parameters[name];
  89. // };
  90. // });
  91. // }
  92. // Object.defineProperties(Cesium.Model.prototype, {
  93. // _cachedGltf: {
  94. // set: function (value) {
  95. // this._my_cachedGltf = value;
  96. // if (this._my_cachedGltf && this._my_cachedGltf._gltf) {
  97. // fixGltf(this._my_cachedGltf._gltf);
  98. // }
  99. // },
  100. // get: function () {
  101. // return this._my_cachedGltf;
  102. // }
  103. // }
  104. // });
  105. } catch (e) {
  106. console.log(e)
  107. }