当前位置:   article > 正文

Cesium 源码分析 BatchTexture_cesium 通过多个颜色值构建texture

cesium 通过多个颜色值构建texture

        Cesium中针对3DTile瓦片的拾取、调试时设置瓦片颜色的两个过程需要BatchTexture.js这个类。

       瓦片拾取的过程:瓦片拾取的过程是,创建每一个gltf模型时给模型绑定一个数值id,并使用这个数值id创建一个颜色,拾取的时候模型使用该颜色值渲染到一张图片上,渲染后再鼠标所在的坐标位置采集图片上的颜色值,根据颜色转换为原来的数值id,最后根据这个数值id找到对应的模型,例如:数值的123,将123转换成颜色RGBA,  将123分成4个8位,不足的再前面补0,则生成的值为RGBA=(123,0,0,0); 并将这个颜色做成图片为模型提供采样的纹理。

        调试时的瓦片颜色【或者】Cesium3DTileStyle中根据属性设置颜色: cesium的这个调试方式还是很好的,如果是包围盒显示的杂乱,将每一个瓦片设置不同的颜色很好分辨,颜色的设置过程也比较简单,主要是根据瓦片中要素的数量创建相同的颜色个数,然后将每个瓦片的这些个颜色创建成一张图片,与瓦片的原有纹理在glsl中进行混合运算。

        缺点:这个过程要创建很多的纹理,占用显存

 具体的代码如下:

  1. /**
  2. * An object that manages color, show/hide and picking textures for a batch
  3. * table or feature table.
  4. * 一个对象,用于管理批次的颜色、显示/隐藏和拾取纹理表或特征表。
  5. *
  6. * @param {Object} options Object with the following properties:
  7. * @param {Number} featuresLength The number of features in the batch table or feature table
  8. * @param {Cesium3DTileContent|ModelFeatureTable} owner The owner of this batch texture. For 3D Tiles, this will be a {@link Cesium3DTileContent}. For glTF models, this will be a {@link ModelFeatureTable}.
  9. * @param {Object} [statistics] The statistics object to update with information about the batch texture.
  10. * @param {Function} [colorChangedCallback] A callback function that is called whenever the color of a feature changes.
  11. *
  12. * @alias BatchTexture
  13. * @constructor
  14. *
  15. * @private
  16. */
  17. export default function BatchTexture(options) {
  18. //>>includeStart('debug', pragmas.debug);
  19. Check.typeOf.number("options.featuresLength", options.featuresLength);
  20. Check.typeOf.object("options.owner", options.owner);
  21. //>>includeEnd('debug');
  22. // 要素个数
  23. var featuresLength = options.featuresLength;
  24. // PERFORMANCE_IDEA: These parallel arrays probably generate cache misses in get/set color/show
  25. // 这些并行数组可能会在get/set-color/show中生成缓存未命中,使用很多的内存,怎么时候很少的内存呢?
  26. // and use A LOT of memory. How can we use less memory?
  27. // 透明相关信息,两个字节,是否显示和透明度,是否显示使用0表示隐藏,255表示显示
  28. this._showAlphaProperties = undefined; // [Show (0 or 255), Alpha (0 to 255)] property for each feature
  29. // 批次表值
  30. this._batchValues = undefined; // Per-feature RGBA (A is based on the color's alpha and feature's show property)
  31. // 批次表值脏了
  32. this._batchValuesDirty = false;
  33. // 批次纹理
  34. this._batchTexture = undefined; // 漫反射 叠加 自定义颜色纹理(debug下的瓦片颜色)
  35. // 默认批次
  36. this._defaultTexture = undefined;
  37. // 拾取纹理
  38. this._pickTexture = undefined; // 拾取纹理
  39. // 拾取的id
  40. this._pickIds = [];
  41. // Dimensions for batch and pick textures
  42. // 批次表、拾取的纹理尺寸
  43. var textureDimensions;
  44. var textureStep;
  45. // 要素数量
  46. if (featuresLength > 0) {
  47. // PERFORMANCE_IDEA: this can waste memory in the last row in the uncommon case
  48. // when more than one row is needed (e.g., > 16K features in one tile) 在需要多行的情况下,这会浪费最后一行的内存
  49. // 纹理宽度
  50. var width = Math.min(featuresLength, ContextLimits.maximumTextureSize);
  51. // 纹理高度
  52. var height = Math.ceil(featuresLength / ContextLimits.maximumTextureSize);
  53. // x步长
  54. var stepX = 1.0 / width;
  55. var centerX = stepX * 0.5;
  56. // y步长
  57. var stepY = 1.0 / height;
  58. var centerY = stepY * 0.5;
  59. // 纹理大小
  60. textureDimensions = new Cartesian2(width, height);
  61. // 纹理步长
  62. textureStep = new Cartesian4(stepX, centerX, stepY, centerY);
  63. }
  64. // 透明要素长度
  65. this._translucentFeaturesLength = 0;
  66. // 要素数量
  67. this._featuresLength = featuresLength;
  68. // 纹理尺寸
  69. this._textureDimensions = textureDimensions;
  70. // 纹理步长
  71. this._textureStep = textureStep;
  72. // 主人
  73. this._owner = options.owner;
  74. // 统计
  75. this._statistics = options.statistics;
  76. // 颜色改变回调
  77. this._colorChangedCallback = options.colorChangedCallback;
  78. }
  79. Object.defineProperties(BatchTexture.prototype, {
  80. /**
  81. * Number of features that are translucent
  82. * 透明要素的数量
  83. *
  84. * @memberof BatchTexture.prototype
  85. * @type {Number}
  86. * @readonly
  87. * @private
  88. */
  89. translucentFeaturesLength: {
  90. get: function () {
  91. return this._translucentFeaturesLength;
  92. },
  93. },
  94. /**
  95. * Total size of all GPU resources used by this batch texture.
  96. * 批次表纹理显存
  97. *
  98. * @memberof BatchTexture.prototype
  99. * @type {Number}
  100. * @readonly
  101. * @private
  102. */
  103. memorySizeInBytes: {
  104. get: function () {
  105. var memory = 0;
  106. // 拾取纹理
  107. if (defined(this._pickTexture)) {
  108. memory += this._pickTexture.sizeInBytes;
  109. }
  110. // 批次表纹理
  111. if (defined(this._batchTexture)) {
  112. memory += this._batchTexture.sizeInBytes;
  113. }
  114. return memory;
  115. },
  116. },
  117. /**
  118. * Dimensions of the underlying batch texture.
  119. * 纹理尺寸
  120. *
  121. * @memberof BatchTexture.prototype
  122. * @type {Cartesian2}
  123. * @readonly
  124. * @private
  125. */
  126. textureDimensions: {
  127. get: function () {
  128. return this._textureDimensions;
  129. },
  130. },
  131. /**
  132. * Size of each texture and distance from side to center of a texel in
  133. * each direction. Stored as (stepX, centerX, stepY, centerY)
  134. * 步长
  135. *
  136. * @memberof BatchTexture.prototype
  137. * @type {Cartesian4}
  138. * @readonly
  139. * @private
  140. */
  141. textureStep: {
  142. get: function () {
  143. return this._textureStep;
  144. },
  145. },
  146. /**
  147. * The underlying texture used for styling. The texels are accessed
  148. * by batch ID, and the value is the color of this feature after accounting
  149. * for show/hide settings.
  150. * 批次纹理
  151. *
  152. * @memberof BatchTexture.prototype
  153. * @type {Texture}
  154. * @readonly
  155. * @private
  156. */
  157. batchTexture: {
  158. get: function () {
  159. return this._batchTexture;
  160. },
  161. },
  162. /**
  163. * The default texture to use when there are no batch values
  164. * 没有批次表时的默认纹理
  165. *
  166. * @memberof BatchTexture.prototype
  167. * @type {Texture}
  168. * @readonly
  169. * @private
  170. */
  171. defaultTexture: {
  172. get: function () {
  173. return this._defaultTexture;
  174. },
  175. },
  176. /**
  177. * The underlying texture used for picking. The texels are accessed by
  178. * batch ID, and the value is the pick color.
  179. * 拾取的纹理
  180. *
  181. * @memberof BatchTexture.prototype
  182. * @type {Texture}
  183. * @readonly
  184. * @private
  185. */
  186. pickTexture: {
  187. get: function () {
  188. return this._pickTexture;
  189. },
  190. },
  191. });
  192. BatchTexture.DEFAULT_COLOR_VALUE = Color.WHITE;
  193. BatchTexture.DEFAULT_SHOW_VALUE = true;
  194. // 批次表纹理数量
  195. function getByteLength(batchTexture) {
  196. var dimensions = batchTexture._textureDimensions;
  197. return dimensions.x * dimensions.y * 4;
  198. }
  199. // 获取批次表的值
  200. function getBatchValues(batchTexture) {
  201. if (!defined(batchTexture._batchValues)) {
  202. // Default batch texture to RGBA = 255: white highlight (RGB) and show/alpha = true/255 (A).
  203. var byteLength = getByteLength(batchTexture);
  204. // 创建内存
  205. var bytes = new Uint8Array(byteLength);
  206. // 填充255
  207. arrayFill(bytes, 255);
  208. // 批次表值
  209. batchTexture._batchValues = bytes;
  210. }
  211. return batchTexture._batchValues;
  212. }
  213. // 透明度值
  214. function getShowAlphaProperties(batchTexture) {
  215. if (!defined(batchTexture._showAlphaProperties)) {
  216. var byteLength = 2 * batchTexture._featuresLength;
  217. var bytes = new Uint8Array(byteLength);
  218. // [Show = true, Alpha = 255] 存储了两个值,一个是是否显示,一个是透明度
  219. arrayFill(bytes, 255);
  220. batchTexture._showAlphaProperties = bytes;
  221. }
  222. return batchTexture._showAlphaProperties;
  223. }
  224. // 检查批次表id
  225. function checkBatchId(batchId, featuresLength) {
  226. if (!defined(batchId) || batchId < 0 || batchId >= featuresLength) {
  227. throw new DeveloperError(
  228. "batchId is required and between zero and featuresLength - 1 (" +
  229. featuresLength -
  230. +")."
  231. );
  232. }
  233. }
  234. /**
  235. * Set whether a feature is visible.
  236. * 设置哪一个要素是可见的
  237. *
  238. * @param {Number} batchId the ID of the feature
  239. * @param {Boolean} show <code>true</code> if the feature should be shown, <code>false</code> otherwise
  240. * @private
  241. */
  242. BatchTexture.prototype.setShow = function (batchId, show) {
  243. //>>includeStart('debug', pragmas.debug);
  244. checkBatchId(batchId, this._featuresLength);
  245. Check.typeOf.bool("show", show);
  246. //>>includeEnd('debug');
  247. // 原来是显示的,别处修改了透明度,这里就需要处理,如果没有透明属性,就不在处理了
  248. if (show && !defined(this._showAlphaProperties)) {
  249. // Avoid allocating since the default is show = true
  250. return;
  251. }
  252. // 显示属性
  253. var showAlphaProperties = getShowAlphaProperties(this);
  254. // 存储了两个值,一个是是否显示,一个是透明度
  255. var propertyOffset = batchId * 2;
  256. // 显示
  257. var newShow = show ? 255 : 0;
  258. // 设置显示
  259. if (showAlphaProperties[propertyOffset] !== newShow) {
  260. showAlphaProperties[propertyOffset] = newShow;
  261. // 获取批次表值
  262. var batchValues = getBatchValues(this);
  263. // Compute alpha used in the shader based on show and color.alpha properties
  264. var offset = batchId * 4 + 3;
  265. // 设置批次表的显示透明度
  266. batchValues[offset] = show ? showAlphaProperties[propertyOffset + 1] : 0;
  267. // 批次表脏了
  268. this._batchValuesDirty = true;
  269. }
  270. };
  271. /**
  272. * Set the show for all features at once.
  273. * 显示所有的要素
  274. *
  275. * @param {Boolean} show <code>true</code> if the feature should be shown, <code>false</code> otherwise
  276. * @private
  277. */
  278. BatchTexture.prototype.setAllShow = function (show) {
  279. //>>includeStart('debug', pragmas.debug);
  280. Check.typeOf.bool("show", show);
  281. //>>includeEnd('debug');
  282. var featuresLength = this._featuresLength;
  283. for (var i = 0; i < featuresLength; ++i) {
  284. this.setShow(i, show);
  285. }
  286. };
  287. /**
  288. * Check the current show value for a feature
  289. * 获取当前的显示值
  290. *
  291. * @param {Number} batchId the ID of the feature
  292. * @return {Boolean} <code>true</code> if the feature is shown, or <code>false</code> otherwise
  293. * @private
  294. */
  295. BatchTexture.prototype.getShow = function (batchId) {
  296. //>>includeStart('debug', pragmas.debug);
  297. checkBatchId(batchId, this._featuresLength);
  298. //>>includeEnd('debug');
  299. if (!defined(this._showAlphaProperties)) {
  300. // Avoid allocating since the default is show = true
  301. return true;
  302. }
  303. var offset = batchId * 2;
  304. return this._showAlphaProperties[offset] === 255;
  305. };
  306. var scratchColorBytes = new Array(4);
  307. /**
  308. * Set the styling color of a feature
  309. * 设置要素的样式颜色
  310. *
  311. * @param {Number} batchId the ID of the feature
  312. * @param {Color} color the color to assign to this feature.
  313. *
  314. * @private
  315. */
  316. BatchTexture.prototype.setColor = function (batchId, color) {
  317. //>>includeStart('debug', pragmas.debug);
  318. checkBatchId(batchId, this._featuresLength);
  319. Check.typeOf.object("color", color);
  320. //>>includeEnd('debug');
  321. if (
  322. Color.equals(color, BatchTexture.DEFAULT_COLOR_VALUE) &&
  323. !defined(this._batchValues)
  324. ) {
  325. // Avoid allocating since the default is white
  326. return;
  327. }
  328. // 转换成颜色字节
  329. var newColor = color.toBytes(scratchColorBytes);
  330. // 新的颜色
  331. var newAlpha = newColor[3];
  332. var batchValues = getBatchValues(this);
  333. var offset = batchId * 4;
  334. var showAlphaProperties = getShowAlphaProperties(this);
  335. var propertyOffset = batchId * 2;
  336. if (
  337. batchValues[offset] !== newColor[0] ||
  338. batchValues[offset + 1] !== newColor[1] ||
  339. batchValues[offset + 2] !== newColor[2] ||
  340. showAlphaProperties[propertyOffset + 1] !== newAlpha
  341. ) {
  342. batchValues[offset] = newColor[0];
  343. batchValues[offset + 1] = newColor[1];
  344. batchValues[offset + 2] = newColor[2];
  345. var wasTranslucent = showAlphaProperties[propertyOffset + 1] !== 255;
  346. // Compute alpha used in the shader based on show and color.alpha properties
  347. var show = showAlphaProperties[propertyOffset] !== 0;
  348. batchValues[offset + 3] = show ? newAlpha : 0;
  349. showAlphaProperties[propertyOffset + 1] = newAlpha;
  350. // Track number of translucent features so we know if this tile needs
  351. // opaque commands, translucent commands, or both for rendering.
  352. var isTranslucent = newAlpha !== 255;
  353. if (isTranslucent && !wasTranslucent) {
  354. ++this._translucentFeaturesLength;
  355. } else if (!isTranslucent && wasTranslucent) {
  356. --this._translucentFeaturesLength;
  357. }
  358. this._batchValuesDirty = true;
  359. if (defined(this._colorChangedCallback)) {
  360. this._colorChangedCallback(batchId, color);
  361. }
  362. }
  363. };
  364. /**
  365. * Set the styling color for all features at once
  366. * 设置所有要素的颜色
  367. *
  368. * @param {Color} color the color to assign to all features.
  369. *
  370. * @private
  371. */
  372. BatchTexture.prototype.setAllColor = function (color) {
  373. //>>includeStart('debug', pragmas.debug);
  374. Check.typeOf.object("color", color);
  375. //>>includeEnd('debug');
  376. var featuresLength = this._featuresLength;
  377. for (var i = 0; i < featuresLength; ++i) {
  378. this.setColor(i, color);
  379. }
  380. };
  381. /**
  382. * Get the current color of a feature
  383. * 获取要素的当前颜色
  384. *
  385. * @param {Number} batchId The ID of the feature
  386. * @param {Color} result A color object where the result will be stored.
  387. * @return {Color} The color assigned to the selected feature
  388. *
  389. * @private
  390. */
  391. BatchTexture.prototype.getColor = function (batchId, result) {
  392. //>>includeStart('debug', pragmas.debug);
  393. checkBatchId(batchId, this._featuresLength);
  394. Check.typeOf.object("result", result);
  395. //>>includeEnd('debug');
  396. if (!defined(this._batchValues)) {
  397. return Color.clone(BatchTexture.DEFAULT_COLOR_VALUE, result);
  398. }
  399. var batchValues = this._batchValues;
  400. var offset = batchId * 4;
  401. var showAlphaProperties = this._showAlphaProperties;
  402. var propertyOffset = batchId * 2;
  403. return Color.fromBytes(
  404. batchValues[offset],
  405. batchValues[offset + 1],
  406. batchValues[offset + 2],
  407. showAlphaProperties[propertyOffset + 1],
  408. result
  409. );
  410. };
  411. /**
  412. * Get the pick color of a feature. This feature is an RGBA encoding of the
  413. * pick ID.
  414. * 获取拾取的颜色,
  415. *
  416. * @param {Number} batchId The ID of the feature
  417. * @return {PickId} The picking color assigned to this feature
  418. *
  419. * @private
  420. */
  421. BatchTexture.prototype.getPickColor = function (batchId) {
  422. //>>includeStart('debug', pragmas.debug);
  423. checkBatchId(batchId, this._featuresLength);
  424. //>>includeEnd('debug');
  425. return this._pickIds[batchId];
  426. };
  427. // 创建纹理
  428. function createTexture(batchTexture, context, bytes) {
  429. var dimensions = batchTexture._textureDimensions;
  430. // 创建纹理
  431. return new Texture({
  432. context: context, // webgl上下文
  433. pixelFormat: PixelFormat.RGBA, // 格式
  434. pixelDatatype: PixelDatatype.UNSIGNED_BYTE, // 像素数据的类型
  435. source: { // 数据源
  436. width: dimensions.x, // 纹理宽度
  437. height: dimensions.y, // 纹理高度
  438. arrayBufferView: bytes, // 纹理数据
  439. },
  440. flipY: false, // 是否反转Y
  441. sampler: Sampler.NEAREST, // 插值方式
  442. });
  443. }
  444. // 创建拾取纹理
  445. function createPickTexture(batchTexture, context) {
  446. // 要素数量
  447. var featuresLength = batchTexture._featuresLength;
  448. // 有要素、没有纹理
  449. if (!defined(batchTexture._pickTexture) && featuresLength > 0) {
  450. // 批次表id
  451. var pickIds = batchTexture._pickIds;
  452. // 批次表纹理占用的字节数量
  453. var byteLength = getByteLength(batchTexture);
  454. // 创建内存
  455. var bytes = new Uint8Array(byteLength);
  456. // 主人
  457. var owner = batchTexture._owner;
  458. // 统计信息
  459. var statistics = batchTexture._statistics;
  460. // PERFORMANCE_IDEA: we could skip the pick texture completely by allocating
  461. // a continuous range of pickIds and then converting the base pickId + batchId
  462. // to RGBA in the shader. The only consider is precision issues, which might
  463. // not be an issue in WebGL 2.
  464. // 我们可以通过分配连续范围的pickId,然后在着色器中将基础pickId+batchId转换为RGBA,从而完全跳过拾取纹理。
  465. // 唯一需要考虑的是精度问题,这在WebGL 2中可能不是一个问题。
  466. // 遍历要素
  467. for (var i = 0; i < featuresLength; ++i) {
  468. // 绑定拾取对象、颜色值
  469. var pickId = context.createPickId(owner.getFeature(i));
  470. // 将id添加到pickIds中
  471. pickIds.push(pickId);
  472. // 颜色
  473. var pickColor = pickId.color;
  474. // 偏移
  475. var offset = i * 4;
  476. // 设置pick颜色
  477. bytes[offset] = Color.floatToByte(pickColor.red);
  478. bytes[offset + 1] = Color.floatToByte(pickColor.green);
  479. bytes[offset + 2] = Color.floatToByte(pickColor.blue);
  480. bytes[offset + 3] = Color.floatToByte(pickColor.alpha);
  481. }
  482. // 创建拾取纹理
  483. batchTexture._pickTexture = createTexture(batchTexture, context, bytes);
  484. if (defined(statistics)) {
  485. // 批次表长度
  486. statistics.batchTableByteLength += batchTexture._pickTexture.sizeInBytes;
  487. }
  488. }
  489. }
  490. // 更新批次表pick纹理,将id拷贝到纹理上
  491. function updateBatchTexture(batchTexture) {
  492. // 纹理尺寸
  493. var dimensions = batchTexture._textureDimensions;
  494. // PERFORMANCE_IDEA: Instead of rewriting the entire texture, use fine-grained
  495. // texture updates when less than, for example, 10%, of the values changed. Or
  496. // even just optimize the common case when one feature show/color changed.
  497. // 将数据拷贝到纹理上
  498. batchTexture._batchTexture.copyFrom({
  499. source: {
  500. width: dimensions.x,
  501. height: dimensions.y,
  502. arrayBufferView: batchTexture._batchValues,
  503. },
  504. });
  505. }
  506. // 更新
  507. BatchTexture.prototype.update = function (tileset, frameState) {
  508. var context = frameState.context;
  509. // 默认纹理
  510. this._defaultTexture = context.defaultTexture;
  511. // 渲染那个过程
  512. var passes = frameState.passes;
  513. // 拾取的过程或者后处理的过程
  514. if (passes.pick || passes.postProcess) {
  515. // 创建拾取的纹理(没有就创建,有了就不在创建)
  516. createPickTexture(this, context);
  517. }
  518. // 批次表的pick颜色被修改了
  519. if (this._batchValuesDirty) {
  520. this._batchValuesDirty = false;
  521. // Create batch texture on-demand
  522. // 创建批次纹理(纹理大小改变了,重新创建纹理)-- 漫反射 叠加 自定义颜色(debug下的瓦片颜色)
  523. if (!defined(this._batchTexture)) {
  524. // 重新创建批次纹理
  525. this._batchTexture = createTexture(this, context, this._batchValues);
  526. if (defined(this._statistics)) {
  527. // 统计批次表所占的内存
  528. this._statistics.batchTableByteLength += this._batchTexture.sizeInBytes;
  529. }
  530. }
  531. // 用于每一个要素的显示和颜色更新
  532. updateBatchTexture(this); // Apply per-feature show/color updates
  533. }
  534. };
  535. /**
  536. * Returns true if this object was destroyed; otherwise, false.
  537. * <p>
  538. * If this object was destroyed, it should not be used; calling any function other than
  539. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
  540. * </p>
  541. *
  542. * @returns {Boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
  543. *
  544. * @see BatchTexture#destroy
  545. * @private
  546. */
  547. BatchTexture.prototype.isDestroyed = function () {
  548. return false;
  549. };
  550. /**
  551. * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
  552. * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
  553. * <p>
  554. * Once an object is destroyed, it should not be used; calling any function other than
  555. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
  556. * assign the return value (<code>undefined</code>) to the object as done in the example.
  557. * </p>
  558. *
  559. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  560. *
  561. * @example
  562. * e = e && e.destroy();
  563. *
  564. * @see BatchTexture#isDestroyed
  565. * @private
  566. */
  567. // 销毁
  568. BatchTexture.prototype.destroy = function () {
  569. // 批次纹理
  570. this._batchTexture = this._batchTexture && this._batchTexture.destroy();
  571. // 拾取纹理
  572. this._pickTexture = this._pickTexture && this._pickTexture.destroy();
  573. // 拾取id
  574. var pickIds = this._pickIds;
  575. // 拾取id
  576. var length = pickIds.length;
  577. for (var i = 0; i < length; ++i) {
  578. // 销毁
  579. pickIds[i].destroy();
  580. }
  581. return destroyObject(this);
  582. };

1、在构造函数BatchTexture中的的属性中:

        a、featuresLength:代表要素的数量,这个要参考3dtile的数据规范,要素代表着一个瓦片中单体的数量;

        b、_showAlphaProperties:这个属性的数量与要素数量相同,代表着每一个单体是否显示、以及透明度(透明度是瓦片原有纹理颜色和设置颜色的混合比例);

        c、_batchValues:这个属性代表着混合的颜色值,以及与_showAlphaProperties中的alpha值相同的透明度;

        d、_pickIds:这个参数是用于拾取的,是一个数组,其中包含了每个要素的对象信息,例如瓦片中模型的id,以及一个key,就是开头提到的颜色值,还有使用这个值创建的一个rgba颜色;

  1. // pick保存在一个对象中
  2. function PickId(pickObjects, key, color) {
  3. this._pickObjects = pickObjects; // 拾取的对象
  4. this.key = key; // 颜色number
  5. this.color = color; // 颜色rgba
  6. }

        e、textureDimensions、textureStep:这两个属性存储的是根据要素数量创建的纹理的尺寸、纹素之间的距离,创建一张纹理要有宽度、高度,宽度的设定是依据要素数量和webgl本身支持的纹理大小决定的,要素数量大于webgl纹理尺寸就增加一行进行存储(浪费了部分空间),通常一个瓦片中的要素数量不会很多,所以只有一行;

  1. // 要素数量
  2. if (featuresLength > 0) {
  3. // PERFORMANCE_IDEA: this can waste memory in the last row in the uncommon case
  4. // when more than one row is needed (e.g., > 16K features in one tile) 在需要多行的情况下,这会浪费最后一行的内存
  5. // 纹理宽度
  6. var width = Math.min(featuresLength, ContextLimits.maximumTextureSize);
  7. // 纹理高度
  8. var height = Math.ceil(featuresLength / ContextLimits.maximumTextureSize);
  9. // x步长
  10. var stepX = 1.0 / width;
  11. var centerX = stepX * 0.5;
  12. // y步长
  13. var stepY = 1.0 / height;
  14. var centerY = stepY * 0.5;
  15. // 纹理大小
  16. textureDimensions = new Cartesian2(width, height);
  17. // 纹理步长
  18. textureStep = new Cartesian4(stepX, centerX, stepY, centerY);
  19. }

        f、_statistics:用于统计当前场景的显存占用,统计的是顶点数量、三角形数量、顶点缓存、纹理缓存等相关信息;

        以上就是本章的解析

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/99769
推荐阅读
相关标签
  

闽ICP备14008679号