S3MTilesParser.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /**
  2. * Cesium - https://github.com/CesiumGS/cesium
  3. *
  4. * Copyright 2011-2020 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/CesiumGS/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['./when-8d13db60', './Check-70bec281', './Math-61ede240', './Cartographic-fe4be337', './Cartesian4-5af5bb24', './createTaskProcessorWorker', './Cartesian2-85064f09', './BoundingSphere-8f8a682c', './RuntimeError-ba10bc3e', './WebGLConstants-4c11ee5f', './ComponentDatatype-5862616f', './PrimitiveType-97893bc7', './FeatureDetection-7bd32c34', './IndexDatatype-9435b55f', './BoundingRectangle-dc808c42', './Color-69f1845f', './pako_inflate-8ea163f9', './S3MCompressType-8d63b515'], function (when, Check, _Math, Cartographic, Cartesian4, createTaskProcessorWorker, Cartesian2, BoundingSphere, RuntimeError, WebGLConstants, ComponentDatatype, PrimitiveType, FeatureDetection, IndexDatatype, BoundingRectangle, Color, pako_inflate, S3MCompressType) { 'use strict';
  24. function Bound3D(left, bottom, right, top, minHeight, maxHeight) {
  25. this.left = left;
  26. this.bottom = bottom;
  27. this.right = right;
  28. this.top = top;
  29. this.minHeight = minHeight;
  30. this.maxHeight = maxHeight;
  31. this.width = right - left;
  32. this.length = top - bottom;
  33. this.height = maxHeight - minHeight;
  34. }
  35. function parseGeoPackage(geoPackage, typedArray, view, bytesOffset, transferableObjects) {
  36. var geoName = view.getUint32(bytesOffset, true);
  37. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  38. var byteLength = 0;
  39. var vertexPackage = {};
  40. var attributes = vertexPackage.vertexAttributes = [];
  41. var attrLocation = vertexPackage.attrLocation = {};
  42. vertexPackage.instanceCount = 0;
  43. vertexPackage.instanceMode = 0;
  44. var index = 0;
  45. var nVertexOptions = view.getUint32(bytesOffset, true);
  46. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  47. var vertexDimension = view.getUint16(bytesOffset, true);
  48. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  49. var normalDimension = vertexDimension;
  50. if (vertexDimension > 4) {
  51. normalDimension = vertexDimension >> 8;
  52. vertexDimension = vertexDimension & 0x0f;
  53. }
  54. var verticesCount = view.getUint32(bytesOffset, true);
  55. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  56. if (verticesCount > 0) {
  57. var vertexStride = view.getUint16(bytesOffset, true);
  58. vertexStride = vertexDimension * Float32Array.BYTES_PER_ELEMENT;
  59. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  60. byteLength = verticesCount * vertexStride;
  61. attrLocation['aPosition'] = index;
  62. attributes.push({
  63. index: attrLocation['aPosition'],
  64. typedArray: typedArray.subarray(bytesOffset, bytesOffset + byteLength),
  65. componentsPerAttribute: vertexDimension,
  66. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  67. offsetInBytes: 0,
  68. strideInBytes: vertexStride,
  69. normalize: false
  70. });
  71. index++;
  72. bytesOffset += byteLength;
  73. }
  74. var normalCount = view.getUint32(bytesOffset, true);
  75. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  76. if (normalCount > 0) {
  77. var normalStride = view.getUint16(bytesOffset, true);
  78. normalStride = normalDimension * Float32Array.BYTES_PER_ELEMENT;
  79. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  80. byteLength = normalCount * normalStride;
  81. if(!geoPackage.ignoreNormal){
  82. attrLocation['aNormal'] = index;
  83. attributes.push({
  84. index: attrLocation['aNormal'],
  85. typedArray: typedArray.subarray(bytesOffset, bytesOffset + byteLength),
  86. componentsPerAttribute: normalDimension,
  87. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  88. offsetInBytes: 0,
  89. strideInBytes: normalStride,
  90. normalize: false
  91. });
  92. index++;
  93. }
  94. bytesOffset += byteLength;
  95. }
  96. var vertexColorCount = view.getUint32(bytesOffset, true);
  97. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  98. if (vertexColorCount > 0) {
  99. var vertexColor = new Uint8Array(4 * vertexColorCount);
  100. transferableObjects.push(vertexColor.buffer);
  101. var vertexColorStride = view.getUint32(bytesOffset, true);
  102. vertexColorStride = 4 * Float32Array.BYTES_PER_ELEMENT;
  103. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  104. byteLength = vertexColorCount * vertexColorStride;
  105. var oriVertexColor = new Float32Array(typedArray.buffer, bytesOffset, verticesCount * 4);
  106. for (var m = 0; m < verticesCount; m++) {
  107. vertexColor[4 * m] = oriVertexColor[4 * m] * 255;
  108. vertexColor[4 * m + 1] = oriVertexColor[4 * m + 1] * 255;
  109. vertexColor[4 * m + 2] = oriVertexColor[4 * m + 2] * 255;
  110. vertexColor[4 * m + 3] = oriVertexColor[4 * m + 3] * 255;
  111. }
  112. bytesOffset += byteLength;
  113. attrLocation['aColor'] = index;
  114. attributes.push({
  115. index: attrLocation['aColor'],
  116. typedArray: vertexColor,
  117. componentsPerAttribute: 4,
  118. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  119. offsetInBytes: 0,
  120. strideInBytes: 4,
  121. normalize: true
  122. });
  123. index++;
  124. }
  125. var secondVertexColorCount = view.getUint32(bytesOffset, true);
  126. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  127. if (secondVertexColorCount > 0) {
  128. byteLength = secondVertexColorCount * 16;
  129. bytesOffset += byteLength;
  130. }
  131. var textureCount = view.getUint32(bytesOffset, true);
  132. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  133. var instanceIndex = -1;
  134. var texCoordCount, texCoordStride, texCoordDim;
  135. for (var j = 0; j < textureCount; j++) {
  136. texCoordCount = view.getUint32(bytesOffset, true);
  137. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  138. texCoordDim = view.getUint16(bytesOffset, true);
  139. bytesOffset += Uint16Array.BYTES_PER_ELEMENT;
  140. texCoordStride = view.getUint16(bytesOffset, true);
  141. bytesOffset += Uint16Array.BYTES_PER_ELEMENT;
  142. byteLength = texCoordCount * texCoordDim * Float32Array.BYTES_PER_ELEMENT;
  143. var texBuffer = typedArray.subarray(bytesOffset, bytesOffset + byteLength);
  144. if (instanceIndex == -1 && (texCoordDim == 20 || texCoordDim == 35)) {
  145. instanceIndex = j;
  146. vertexPackage.instanceCount = texCoordCount;
  147. vertexPackage.instanceMode = texCoordDim;
  148. vertexPackage.instanceBuffer = texBuffer;
  149. var byteStride;
  150. if (texCoordDim === 20) {
  151. byteStride = Float32Array.BYTES_PER_ELEMENT * 20;
  152. attrLocation['uv2'] = index++;
  153. attributes.push({
  154. index: attrLocation['uv2'],
  155. componentsPerAttribute: 4,
  156. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  157. normalize: false,
  158. offsetInBytes: 0,
  159. strideInBytes: byteStride,
  160. instanceDivisor: 1
  161. });
  162. attrLocation['uv3'] = index++;
  163. attributes.push({
  164. index: attrLocation['uv3'],
  165. componentsPerAttribute: 4,
  166. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  167. normalize: false,
  168. offsetInBytes: 4 * Float32Array.BYTES_PER_ELEMENT,
  169. strideInBytes: byteStride,
  170. instanceDivisor: 1
  171. });
  172. attrLocation['uv4'] = index++;
  173. attributes.push({
  174. index: attrLocation['uv4'],
  175. componentsPerAttribute: 4,
  176. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  177. normalize: false,
  178. offsetInBytes: 8 * Float32Array.BYTES_PER_ELEMENT,
  179. strideInBytes: byteStride,
  180. instanceDivisor: 1
  181. });
  182. attrLocation['secondary_colour'] = index++;
  183. attributes.push({
  184. index: attrLocation['secondary_colour'],
  185. componentsPerAttribute: 4,
  186. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  187. normalize: false,
  188. offsetInBytes: 12 * Float32Array.BYTES_PER_ELEMENT,
  189. strideInBytes: byteStride,
  190. instanceDivisor: 1
  191. });
  192. attrLocation['uv6'] = index++;
  193. attributes.push({
  194. index: attrLocation['uv6'],
  195. componentsPerAttribute: 4,
  196. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  197. normalize: false,
  198. offsetInBytes: 16 * Float32Array.BYTES_PER_ELEMENT,
  199. strideInBytes: byteStride,
  200. instanceDivisor: 1
  201. });
  202. }
  203. else if (texCoordDim === 35) {
  204. byteStride = Float32Array.BYTES_PER_ELEMENT * 35;
  205. attrLocation['uv1'] = index++;
  206. attributes.push({
  207. index: attrLocation['uv1'],
  208. componentsPerAttribute: 4,
  209. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  210. normalize: false,
  211. offsetInBytes: 0,
  212. strideInBytes: byteStride,
  213. instanceDivisor: 1,
  214. byteLength: byteLength
  215. });
  216. attrLocation['uv2'] = index++;
  217. attributes.push({
  218. index: attrLocation['uv2'],
  219. componentsPerAttribute: 4,
  220. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  221. normalize: false,
  222. offsetInBytes: 4 * Float32Array.BYTES_PER_ELEMENT,
  223. strideInBytes: byteStride,
  224. instanceDivisor: 1
  225. });
  226. attrLocation['uv3'] = index++;
  227. attributes.push({
  228. index: attrLocation['uv3'],
  229. componentsPerAttribute: 4,
  230. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  231. normalize: false,
  232. offsetInBytes: 8 * Float32Array.BYTES_PER_ELEMENT,
  233. strideInBytes: byteStride,
  234. instanceDivisor: 1
  235. });
  236. attrLocation['uv4'] = index++;
  237. attributes.push({
  238. index: attrLocation['uv4'],
  239. componentsPerAttribute: 4,
  240. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  241. normalize: false,
  242. offsetInBytes: 12 * Float32Array.BYTES_PER_ELEMENT,
  243. strideInBytes: byteStride,
  244. instanceDivisor: 1
  245. });
  246. attrLocation['uv5'] = index++;
  247. attributes.push({
  248. index: attrLocation['uv5'],
  249. componentsPerAttribute: 4,
  250. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  251. normalize: false,
  252. offsetInBytes: 16 * Float32Array.BYTES_PER_ELEMENT,
  253. strideInBytes: byteStride,
  254. instanceDivisor: 1
  255. });
  256. attrLocation['uv6'] = index++;
  257. attributes.push({
  258. index: attrLocation['uv6'],
  259. componentsPerAttribute: 4,
  260. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  261. normalize: false,
  262. offsetInBytes: 20 * Float32Array.BYTES_PER_ELEMENT,
  263. strideInBytes: byteStride,
  264. instanceDivisor: 1
  265. });
  266. attrLocation['uv7'] = index++;
  267. attributes.push({
  268. index: attrLocation['uv7'],
  269. componentsPerAttribute: 3,
  270. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  271. normalize: false,
  272. offsetInBytes: 24 * Float32Array.BYTES_PER_ELEMENT,
  273. strideInBytes: byteStride,
  274. instanceDivisor: 1
  275. });
  276. attrLocation['secondary_colour'] = index++;
  277. attributes.push({
  278. index: attrLocation['secondary_colour'],
  279. componentsPerAttribute: 4,
  280. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  281. normalize: false,
  282. offsetInBytes: 27 * Float32Array.BYTES_PER_ELEMENT,
  283. strideInBytes: byteStride,
  284. instanceDivisor: 1
  285. });
  286. attrLocation['uv9'] = index++;
  287. attributes.push({
  288. index: attrLocation['uv9'],
  289. componentsPerAttribute: 4,
  290. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  291. normalize: false,
  292. offsetInBytes: 31 * Float32Array.BYTES_PER_ELEMENT,
  293. strideInBytes: byteStride,
  294. instanceDivisor: 1
  295. });
  296. }
  297. }
  298. else {
  299. if (instanceIndex !== -1) {
  300. vertexPackage.instanceBounds = new Float32Array(typedArray.buffer, bytesOffset, texCoordCount * texCoordDim);
  301. }
  302. else {
  303. var str = 'aTexCoord' + j;
  304. attrLocation[str] = index++;
  305. attributes.push({
  306. index: attrLocation[str],
  307. typedArray: texBuffer,
  308. componentsPerAttribute: texCoordDim,
  309. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  310. offsetInBytes: 0,
  311. strideInBytes: texCoordDim * Float32Array.BYTES_PER_ELEMENT,
  312. normalize: false
  313. });
  314. }
  315. }
  316. bytesOffset += byteLength;
  317. }
  318. vertexPackage.verticesCount = verticesCount;
  319. vertexPackage.instanceIndex = instanceIndex;
  320. var indexPackageSize = view.getUint32(bytesOffset, true);
  321. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  322. var arrIndexPackage = [];
  323. for (var j = 0; j < indexPackageSize; j++) {
  324. var indexPackage = {};
  325. var indicesCount = view.getUint32(bytesOffset, true);
  326. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  327. var indexType = view.getUint8(bytesOffset, true);
  328. bytesOffset += Uint8Array.BYTES_PER_ELEMENT;
  329. var useIndex = view.getUint8(bytesOffset, true);
  330. bytesOffset += Uint8Array.BYTES_PER_ELEMENT;
  331. var primitiveType = view.getUint8(bytesOffset, true);
  332. bytesOffset += Uint8Array.BYTES_PER_ELEMENT;
  333. bytesOffset += 1;
  334. indexPackage.indicesCount = indicesCount;
  335. indexPackage.indexType = indexType;
  336. indexPackage.primitiveType = primitiveType;
  337. var indexOffset = bytesOffset;
  338. if (indicesCount > 0) {
  339. if (indexType == 0) {
  340. byteLength = indicesCount * Uint16Array.BYTES_PER_ELEMENT;
  341. bytesOffset += byteLength;
  342. if (indicesCount % 2 == 1) {
  343. bytesOffset += 2;
  344. }
  345. }
  346. else {
  347. byteLength = indicesCount * 4;
  348. bytesOffset += byteLength;
  349. }
  350. }
  351. indexPackage.indicesTypedArray = typedArray.subarray(indexOffset, indexOffset + byteLength);
  352. var passNameCount = view.getUint32(bytesOffset, true);
  353. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  354. var materialCode = view.getUint32(bytesOffset, true);
  355. bytesOffset += Uint32Array.BYTES_PER_ELEMENT * passNameCount;
  356. indexPackage.materialCode = materialCode;
  357. arrIndexPackage.push(indexPackage);
  358. }
  359. geoPackage[geoName] = {
  360. vertexPackage: vertexPackage,
  361. arrIndexPackage: arrIndexPackage
  362. };
  363. return bytesOffset;
  364. }
  365. function createBatchIdAttribute(vertexPackage, typedArray, instanceDivisor) {
  366. var vertexAttributes = vertexPackage.vertexAttributes;
  367. var attrLocation = vertexPackage.attrLocation;
  368. var len = vertexAttributes.length;
  369. var attrName = instanceDivisor === 1 ? 'instanceId' : 'batchId';
  370. attrLocation[attrName] = len;
  371. vertexAttributes.push({
  372. index: len,
  373. typedArray: typedArray,
  374. componentsPerAttribute: 1,
  375. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  376. offsetInBytes: 0,
  377. strideInBytes: 0,
  378. instanceDivisor : instanceDivisor
  379. });
  380. }
  381. function S3MTilesParser(parameters, transferableObjects) {
  382. var buffer = parameters.buffer;
  383. //transferableObjects.push(buffer);
  384. var supportCompressType = parameters.supportCompressType;
  385. var bVolume = parameters.bVolume;//是否是体渲染数据
  386. var bound3D = null;
  387. var volBounds = null;
  388. var volImageBuffer = null;
  389. if (bVolume) {
  390. if (parameters.volbuffer.byteLength < 8) {
  391. bVolume = false;
  392. }
  393. }
  394. if (bVolume) {
  395. var volData = parameters.volbuffer;
  396. var dataZip = new Uint8Array(volData, 8);
  397. var volumeBuffer = pako_inflate.pako.inflate(dataZip).buffer;
  398. var volVersion = new Float64Array(volumeBuffer, 0, 1);
  399. var volFormat = new Uint32Array(volumeBuffer , 48, 1);
  400. if(volVersion[0] === 0.0 || volFormat[0] === 3200 || volFormat[0] === 3201)
  401. {
  402. var nHeaderOffset = 0;
  403. if(volVersion[0] === 0.0)
  404. {
  405. nHeaderOffset = 8;
  406. }
  407. transferableObjects.push(volumeBuffer);
  408. var boundsArray = new Float64Array(volumeBuffer, nHeaderOffset, 6);
  409. var left = boundsArray[0];
  410. var top = boundsArray[1];
  411. var right = boundsArray[2];
  412. var bottom = boundsArray[3];
  413. var minHeight = boundsArray[4] < boundsArray[5] ? boundsArray[4] : boundsArray[5];
  414. var maxHeight = boundsArray[4] > boundsArray[5] ? boundsArray[4] : boundsArray[5];
  415. bound3D = new Bound3D(left, bottom, right, top, minHeight, maxHeight);
  416. volBounds = {
  417. left: left,
  418. top: top,
  419. right: right,
  420. bottom: bottom,
  421. minHeight: minHeight,
  422. maxHeight: maxHeight,
  423. width: bound3D.width,
  424. length: bound3D.length,
  425. height: bound3D.height
  426. };
  427. // 中间空出来
  428. var infoVolume = new Uint32Array(volumeBuffer, 48 + nHeaderOffset, 7);
  429. var nFormat = infoVolume[0];
  430. var nSideBlockCount = infoVolume[1];
  431. var nBlockLength = infoVolume[2];
  432. var nLength = infoVolume[3];
  433. var nWidth = infoVolume[4];
  434. var nHeight = infoVolume[5];
  435. var nDepth = infoVolume[6];
  436. var nCount = nLength * nLength * 4;
  437. var image = new Uint8Array(volumeBuffer, 76 + nHeaderOffset, nCount);
  438. volImageBuffer = {
  439. nFormat: nFormat,
  440. nSideBlockCount: nSideBlockCount,
  441. nBlockLength: nBlockLength,
  442. nLength: nLength,
  443. nWidth: nWidth,
  444. nHeight: nHeight,
  445. nDepth: nDepth,
  446. imageArray: image
  447. };
  448. }
  449. }
  450. var bytesOffset = 0;
  451. var header = new Uint8Array(buffer, 0, 4);
  452. if (header[0] !== 115 || header[1] !== 51 || header[2] !== 109) {
  453. return {
  454. result: false
  455. };
  456. }
  457. var version = header[3];
  458. var dataZip = new Uint8Array(buffer, 4);
  459. var unzipBuffer = pako_inflate.pako.inflate(dataZip).buffer;
  460. var typedArray = new Uint8Array(unzipBuffer);
  461. transferableObjects.push(typedArray.buffer);
  462. var view = new DataView(unzipBuffer);
  463. var xmlSize = view.getUint32(bytesOffset, true);
  464. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  465. var xmlBuffer = new Uint8Array(unzipBuffer, bytesOffset, xmlSize);
  466. var nAlign = xmlSize % 4;
  467. if(nAlign){
  468. nAlign = 4 - nAlign;
  469. }
  470. bytesOffset += xmlSize + nAlign;
  471. var xmlDoc = S3MCompressType.getStringFromTypedArray(xmlBuffer, undefined, undefined, 'gbk');
  472. xmlDoc = xmlDoc.replace(new RegExp("\r\n",'gm'),'');
  473. xmlDoc = xmlDoc.replace(new RegExp(":",'gm'),'');
  474. var packageSize = view.getUint32(bytesOffset, true);
  475. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  476. var geoCount = view.getUint32(bytesOffset, true);
  477. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  478. var geoPackage = {};
  479. geoPackage.ignoreNormal = parameters.ignoreNormal;
  480. for (var i = 0; i < geoCount; i++) {
  481. bytesOffset = parseGeoPackage(geoPackage, typedArray, view, bytesOffset, transferableObjects);
  482. }
  483. var pickInfoPackageCount = view.getUint32(bytesOffset, true);
  484. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  485. var pickColorCount = view.getUint32(bytesOffset, true);
  486. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  487. for (var i = 0; i < pickColorCount; i++) {
  488. var geoName = view.getUint32(bytesOffset, true);
  489. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  490. var pickIdsCount = view.getUint32(bytesOffset, true);
  491. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  492. var pickInfo = {};
  493. var bInstanced = geoPackage[geoName].vertexPackage.instanceIndex;
  494. if (bInstanced == -1) {
  495. var batchIds = new Float32Array(geoPackage[geoName].vertexPackage.verticesCount);
  496. for (var j = 0; j < pickIdsCount; j++) {
  497. var pickId = view.getUint32(bytesOffset, true);
  498. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  499. var size = view.getUint32(bytesOffset, true);
  500. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  501. var vertexCount = 0, vertexColorOffset = 0;
  502. pickInfo[pickId] = {
  503. batchId : j
  504. };
  505. for (var k = 0; k < size; k++) {
  506. vertexColorOffset = view.getUint32(bytesOffset, true);
  507. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  508. vertexCount = view.getUint32(bytesOffset, true);
  509. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  510. if (batchIds.fill) {
  511. batchIds.fill(j, vertexColorOffset, vertexColorOffset + vertexCount);
  512. } else {
  513. var total = vertexColorOffset + vertexColorOffset;
  514. for(var m = vertexColorOffset; m < total; m++) {
  515. batchIds[m] = j;
  516. }
  517. }
  518. }
  519. pickInfo[pickId].vertexColorOffset = vertexColorOffset;
  520. pickInfo[pickId].vertexColorCount = vertexCount;
  521. }
  522. createBatchIdAttribute(geoPackage[geoName].vertexPackage, batchIds, undefined);
  523. }
  524. else {
  525. var instanceCount = geoPackage[geoName].vertexPackage.instanceCount;
  526. var instanceArray = geoPackage[geoName].vertexPackage.instanceBuffer;
  527. var instanceMode = geoPackage[geoName].vertexPackage.instanceMode;
  528. var instanceIds = new Float32Array(instanceCount);
  529. var instanceIdIndex = 0;
  530. for (var j = 0; j < pickIdsCount; j++) {
  531. var pickId = view.getUint32(bytesOffset, true);
  532. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  533. var size = view.getUint32(bytesOffset, true);
  534. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  535. for (var k = 0; k < size; k++) {
  536. var instanceId = view.getUint32(bytesOffset, true);
  537. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  538. instanceIds[instanceIdIndex] = instanceIdIndex;
  539. if(pickInfo[pickId] === undefined){
  540. pickInfo[pickId] = {
  541. vertexColorCount : 1,
  542. instanceIds : [],
  543. vertexColorOffset : instanceIdIndex
  544. };
  545. }
  546. pickInfo[pickId].instanceIds.push(instanceId);
  547. instanceIdIndex ++;
  548. }
  549. }
  550. createBatchIdAttribute(geoPackage[geoName].vertexPackage, instanceIds, 1);
  551. }
  552. geoPackage[geoName].pickInfo = pickInfo;
  553. }
  554. var texturePackageCount = view.getUint32(bytesOffset, true);
  555. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  556. var imageCount = view.getUint32(bytesOffset, true);
  557. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  558. var texturePackage = {};
  559. for (var i = 0; i < imageCount; i++) {
  560. var id = view.getUint32(bytesOffset, true);
  561. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  562. var width = view.getUint32(bytesOffset, true);
  563. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  564. var height = view.getUint32(bytesOffset, true);
  565. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  566. var compressType = view.getUint32(bytesOffset, true);
  567. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  568. var size = view.getUint32(bytesOffset, true);
  569. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  570. var pixelFormat = view.getUint32(bytesOffset, true);
  571. bytesOffset += Uint32Array.BYTES_PER_ELEMENT;
  572. var imageTypedArray = null;
  573. if (compressType === S3MCompressType.S3MCompressType.enrS3TCDXTN && supportCompressType !== 1) {
  574. var pEncode = null;
  575. if (pixelFormat > S3MCompressType.S3MPixelFormat.BGR || pixelFormat === S3MCompressType.S3MPixelFormat.LUMINANCE_ALPHA) {
  576. pEncode = new Uint8Array(unzipBuffer, bytesOffset, width * height);
  577. imageTypedArray = new Uint8Array(width * height * 4);
  578. }
  579. else {
  580. pEncode = new Uint16Array(unzipBuffer, bytesOffset, size / 2);
  581. imageTypedArray = new Uint16Array(width * height);
  582. }
  583. S3MCompressType.DXTTextureDecode.decode(imageTypedArray, width, height, pEncode, pixelFormat);
  584. transferableObjects.push(imageTypedArray.buffer);
  585. compressType = 0;
  586. }
  587. else {
  588. imageTypedArray = new Uint8Array(unzipBuffer, bytesOffset, size);
  589. }
  590. texturePackage[id] = {
  591. id: id,
  592. width: width,
  593. height: height,
  594. compressType: compressType,
  595. nFormat: pixelFormat,
  596. imageBuffer: imageTypedArray
  597. };
  598. bytesOffset += size;
  599. }
  600. return {
  601. result: true,
  602. version: version,
  603. xmlDoc: xmlDoc,
  604. geoPackage: geoPackage,
  605. texturePackage: texturePackage,
  606. volImageBuffer: volImageBuffer,
  607. volBounds: volBounds
  608. };
  609. }
  610. var S3MTilesParser$1 = createTaskProcessorWorker(S3MTilesParser);
  611. return S3MTilesParser$1;
  612. });