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.

S3MObliqueRenderEntity.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import S3MTilesNoLightVS from '../Shaders/S3MTilesNoLightVS.js'
  2. import S3MTilesNoLightFS from '../Shaders/S3MTilesNoLightFS.js'
  3. import RenderEntity from './RenderEntity.js'
  4. const { Cesium } = DC.Namespace
  5. function S3MObliqueRenderEntity(options) {
  6. RenderEntity.call(this, options)
  7. this.vs = S3MTilesNoLightVS
  8. this.fs = S3MTilesNoLightFS
  9. }
  10. S3MObliqueRenderEntity.prototype = Object.create(RenderEntity.prototype)
  11. S3MObliqueRenderEntity.prototype.constructor = RenderEntity
  12. function getOpaqueRenderState() {
  13. return Cesium.RenderState.fromCache({
  14. cull: {
  15. enabled: true
  16. },
  17. depthTest: {
  18. enabled: true,
  19. func: Cesium.DepthFunction.LESS_OR_EQUAL
  20. },
  21. blending: Cesium.BlendingState.ALPHA_BLEND
  22. })
  23. }
  24. function getUniformMap(material, layer, ro) {
  25. return {
  26. uGeoMatrix: function() {
  27. return ro.geoMatrix
  28. },
  29. uInverseGeoMatrix: function() {
  30. return ro.invGeoMatrix
  31. },
  32. uTexture: function() {
  33. return material.textures[0]
  34. },
  35. uTexture0Width: function() {
  36. return material.textures[0].width
  37. }
  38. }
  39. }
  40. S3MObliqueRenderEntity.prototype.createCommand = function() {
  41. if (
  42. Cesium.defined(this.colorCommand) ||
  43. this.vertexBufferToCreate.length !== 0 ||
  44. this.indexBufferToCreate.length !== 0 ||
  45. this.shaderProgramToCreate.length !== 0
  46. ) {
  47. return
  48. }
  49. let layer = this.layer
  50. let context = layer.context
  51. let vertexPackage = this.vertexPackage
  52. let arrIndexPackage = this.arrIndexPackage
  53. let attributes = vertexPackage.vertexAttributes
  54. if (arrIndexPackage.length < 1) {
  55. return
  56. }
  57. let indexPackage = arrIndexPackage[0]
  58. let material = this.material
  59. this.vertexArray = new Cesium.VertexArray({
  60. context: context,
  61. attributes: attributes,
  62. indexBuffer: indexPackage.indexBuffer
  63. })
  64. this.colorCommand = new Cesium.DrawCommand({
  65. primitiveType: indexPackage.primitiveType,
  66. modelMatrix: this.modelMatrix,
  67. boundingVolume: Cesium.BoundingSphere.clone(this.boundingVolume),
  68. vertexArray: this.vertexArray,
  69. shaderProgram: this.shaderProgram,
  70. pass: material.bTransparentSorting
  71. ? Cesium.Pass.TRANSLUCENT
  72. : Cesium.Pass.OPAQUE,
  73. renderState: getOpaqueRenderState(),
  74. instanceCount: vertexPackage.instanceCount
  75. })
  76. this.colorCommand.uniformMap = getUniformMap(material, layer, this)
  77. this.vertexPackage = undefined
  78. this.arrIndexPackage = undefined
  79. this.vs = undefined
  80. this.fs = undefined
  81. this.ready = true
  82. }
  83. S3MObliqueRenderEntity.prototype.update = function(frameState, layer) {
  84. if (!this.ready) {
  85. this.createBuffers(frameState)
  86. this.createShaderProgram(frameState)
  87. this.createCommand(frameState)
  88. this.initLayerSetting(layer)
  89. return
  90. }
  91. frameState.commandList.push(this.colorCommand)
  92. }
  93. S3MObliqueRenderEntity.prototype.isDestroyed = function() {
  94. return false
  95. }
  96. S3MObliqueRenderEntity.prototype.destroy = function() {
  97. this.shaderProgram =
  98. this.shaderProgram &&
  99. !this.shaderProgram.isDestroyed() &&
  100. this.shaderProgram.destroy()
  101. this.vertexArray =
  102. this.vertexArray &&
  103. !this.vertexArray.isDestroyed() &&
  104. this.vertexArray.destroy()
  105. this.material =
  106. this.material && !this.material.isDestroyed() && this.material.destroy()
  107. this.colorCommand = undefined
  108. this.vertexPackage = null
  109. this.arrIndexPackage = null
  110. this.modelMatrix = undefined
  111. this.pickInfo = undefined
  112. this.selectionInfoMap = undefined
  113. this.vs = undefined
  114. this.fs = undefined
  115. return Cesium.destroyObject(this)
  116. }
  117. export default S3MObliqueRenderEntity