Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

S3MCacheFileRenderEntity.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import S3MTilesVS from '../Shaders/S3MTilesVS.js'
  2. import S3MTilesFS from '../Shaders/S3MTilesFS.js'
  3. import RenderEntity from './RenderEntity.js'
  4. const { Cesium } = DC.Namespace
  5. function S3MCacheFileRenderEntity(options) {
  6. RenderEntity.call(this, options)
  7. this.vs = S3MTilesVS
  8. this.fs = S3MTilesFS
  9. this.useLineColor = false
  10. }
  11. S3MCacheFileRenderEntity.prototype = Object.create(RenderEntity.prototype)
  12. S3MCacheFileRenderEntity.prototype.constructor = RenderEntity
  13. function getOpaqueRenderState() {
  14. return Cesium.RenderState.fromCache({
  15. cull: {
  16. enabled: false
  17. },
  18. depthTest: {
  19. enabled: true,
  20. func: Cesium.DepthFunction.LESS_OR_EQUAL
  21. },
  22. blending: Cesium.BlendingState.ALPHA_BLEND
  23. })
  24. }
  25. function getTransparentRenderState() {
  26. return Cesium.RenderState.fromCache({
  27. cull: {
  28. enabled: true
  29. },
  30. depthTest: {
  31. enabled: true,
  32. func: Cesium.DepthFunction.LESS_OR_EQUAL
  33. },
  34. blending: Cesium.BlendingState.ALPHA_BLEND
  35. })
  36. }
  37. function getUniformMap(material, layer, ro) {
  38. return {
  39. uGeoMatrix: function() {
  40. return ro.geoMatrix
  41. },
  42. uTexMatrix: function() {
  43. return material.texMatrix
  44. },
  45. uFillForeColor: function() {
  46. if (ro.useLineColor) {
  47. return layer.style3D.lineColor
  48. }
  49. return layer.style3D.fillForeColor
  50. },
  51. uInverseGeoMatrix: function() {
  52. return ro.invGeoMatrix
  53. },
  54. uTexture: function() {
  55. return material.textures[0]
  56. },
  57. uTexture2: function() {
  58. return material.textures[1]
  59. },
  60. uTexture0Width: function() {
  61. return material.textures[0].width
  62. },
  63. uTexture1Width: function() {
  64. return material.textures[1].width
  65. },
  66. uDiffuseColor: function() {
  67. return material.diffuseColor
  68. },
  69. uSelectedColor: function() {
  70. return layer._selectedColor
  71. }
  72. }
  73. }
  74. S3MCacheFileRenderEntity.prototype.createCommand = function() {
  75. if (
  76. Cesium.defined(this.colorCommand) ||
  77. this.vertexBufferToCreate.length !== 0 ||
  78. this.indexBufferToCreate.length !== 0 ||
  79. this.shaderProgramToCreate.length !== 0
  80. ) {
  81. return
  82. }
  83. let layer = this.layer
  84. let context = layer.context
  85. let vertexPackage = this.vertexPackage
  86. let arrIndexPackage = this.arrIndexPackage
  87. let attributes = vertexPackage.vertexAttributes
  88. if (arrIndexPackage.length < 1) {
  89. return
  90. }
  91. let indexPackage = arrIndexPackage[0]
  92. let material = this.material
  93. this.vertexArray = new Cesium.VertexArray({
  94. context: context,
  95. attributes: attributes,
  96. indexBuffer: indexPackage.indexBuffer
  97. })
  98. let primitiveType = Cesium.PrimitiveType.TRIANGLES
  99. switch (indexPackage.primitiveType) {
  100. case 1:
  101. primitiveType = Cesium.PrimitiveType.POINTS
  102. break
  103. case 2:
  104. primitiveType = Cesium.PrimitiveType.LINES
  105. break
  106. case 4:
  107. primitiveType = Cesium.PrimitiveType.TRIANGLES
  108. break
  109. default:
  110. break
  111. }
  112. this.useLineColor = primitiveType === Cesium.PrimitiveType.LINES
  113. this.colorCommand = new Cesium.DrawCommand({
  114. primitiveType: primitiveType,
  115. modelMatrix: this.modelMatrix,
  116. boundingVolume: Cesium.BoundingSphere.clone(this.boundingVolume),
  117. pickId: this.pickColorIdentifier,
  118. vertexArray: this.vertexArray,
  119. shaderProgram: this.shaderProgram,
  120. pass: material.bTransparentSorting
  121. ? Cesium.Pass.TRANSLUCENT
  122. : Cesium.Pass.OPAQUE,
  123. renderState: material.bTransparentSorting
  124. ? getTransparentRenderState()
  125. : getOpaqueRenderState(),
  126. instanceCount: vertexPackage.instanceCount
  127. })
  128. let uniformMap = getUniformMap(material, layer, this)
  129. if (this.batchTable) {
  130. uniformMap = this.batchTable.getUniformMapCallback()(uniformMap)
  131. }
  132. this.colorCommand.uniformMap = uniformMap
  133. this.vertexPackage = undefined
  134. this.arrIndexPackage = undefined
  135. this.vs = undefined
  136. this.fs = undefined
  137. this.ready = true
  138. }
  139. S3MCacheFileRenderEntity.prototype.update = function(frameState, layer) {
  140. if (!this.ready) {
  141. this.createBatchTable(frameState)
  142. this.createPickIds()
  143. this.createBuffers(frameState)
  144. this.createShaderProgram(frameState)
  145. this.createCommand(frameState)
  146. this.initLayerSetting(layer)
  147. return
  148. }
  149. if (this.batchTableDirty) {
  150. this.updateBatchTableAttributes()
  151. this.batchTableDirty = false
  152. }
  153. if (this.batchTable) {
  154. this.batchTable.update(frameState)
  155. }
  156. frameState.commandList.push(this.colorCommand)
  157. }
  158. S3MCacheFileRenderEntity.prototype.isDestroyed = function() {
  159. return false
  160. }
  161. S3MCacheFileRenderEntity.prototype.destroy = function() {
  162. this.shaderProgram =
  163. this.shaderProgram &&
  164. !this.shaderProgram.isDestroyed() &&
  165. this.shaderProgram.destroy()
  166. this.vertexArray =
  167. this.vertexArray &&
  168. !this.vertexArray.isDestroyed() &&
  169. this.vertexArray.destroy()
  170. this.material =
  171. this.material && !this.material.isDestroyed() && this.material.destroy()
  172. this.batchTable =
  173. this.batchTable &&
  174. !this.batchTable.isDestroyed() &&
  175. this.batchTable.destroy()
  176. this.colorCommand = undefined
  177. this.vertexPackage = null
  178. this.arrIndexPackage = null
  179. this.modelMatrix = undefined
  180. this.pickInfo = undefined
  181. this.selectionInfoMap = undefined
  182. this.vs = undefined
  183. this.fs = undefined
  184. return Cesium.destroyObject(this)
  185. }
  186. export default S3MCacheFileRenderEntity