@loaders.gl/pointclouds 0.0.0-stage → 5.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (511) hide show
  1. package/LAS-README.md +12 -0
  2. package/LICENSE +24 -0
  3. package/PCD-README.md +12 -0
  4. package/PLY-README.md +38 -0
  5. package/README.md +11 -2
  6. package/THIRD-PARTY-NOTICES.md +27 -0
  7. package/dist/dist.dev.js +30165 -0
  8. package/dist/dist.min.js +54 -0
  9. package/dist/index.cjs +61 -0
  10. package/dist/index.cjs.map +7 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +13 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/las/bundled.cjs +72 -0
  16. package/dist/las/bundled.cjs.map +7 -0
  17. package/dist/las/bundled.d.ts +12 -0
  18. package/dist/las/bundled.d.ts.map +1 -0
  19. package/dist/las/bundled.js +12 -0
  20. package/dist/las/bundled.js.map +1 -0
  21. package/dist/las/index.cjs +78 -0
  22. package/dist/las/index.cjs.map +7 -0
  23. package/dist/las/index.d.ts +17 -0
  24. package/dist/las/index.d.ts.map +1 -0
  25. package/dist/las/index.js +15 -0
  26. package/dist/las/index.js.map +1 -0
  27. package/dist/las/las-copc-loader-types.cjs +49 -0
  28. package/dist/las/las-copc-loader-types.cjs.map +7 -0
  29. package/dist/las/las-copc-loader-types.d.ts +63 -0
  30. package/dist/las/las-copc-loader-types.d.ts.map +1 -0
  31. package/dist/las/las-copc-loader-types.js +14 -0
  32. package/dist/las/las-copc-loader-types.js.map +1 -0
  33. package/dist/las/las-copc-loader.cjs +57 -0
  34. package/dist/las/las-copc-loader.cjs.map +7 -0
  35. package/dist/las/las-copc-loader.d.ts +37 -0
  36. package/dist/las/las-copc-loader.d.ts.map +1 -0
  37. package/dist/las/las-copc-loader.js +40 -0
  38. package/dist/las/las-copc-loader.js.map +1 -0
  39. package/dist/las/las-format.cjs +44 -0
  40. package/dist/las/las-format.cjs.map +7 -0
  41. package/dist/las/las-format.d.ts +16 -0
  42. package/dist/las/las-format.d.ts.map +1 -0
  43. package/dist/las/las-format.js +19 -0
  44. package/dist/las/las-format.js.map +1 -0
  45. package/dist/las/las-loader-shared.cjs +82 -0
  46. package/dist/las/las-loader-shared.cjs.map +7 -0
  47. package/dist/las/las-loader-shared.d.ts +66 -0
  48. package/dist/las/las-loader-shared.d.ts.map +1 -0
  49. package/dist/las/las-loader-shared.js +58 -0
  50. package/dist/las/las-loader-shared.js.map +1 -0
  51. package/dist/las/las-loader-types.cjs +54 -0
  52. package/dist/las/las-loader-types.cjs.map +7 -0
  53. package/dist/las/las-loader-types.d.ts +104 -0
  54. package/dist/las/las-loader-types.d.ts.map +1 -0
  55. package/dist/las/las-loader-types.js +19 -0
  56. package/dist/las/las-loader-types.js.map +1 -0
  57. package/dist/las/las-loader.cjs +80 -0
  58. package/dist/las/las-loader.cjs.map +7 -0
  59. package/dist/las/las-loader.d.ts +45 -0
  60. package/dist/las/las-loader.d.ts.map +1 -0
  61. package/dist/las/las-loader.js +58 -0
  62. package/dist/las/las-loader.js.map +1 -0
  63. package/dist/las/las-writer.cjs +1054 -0
  64. package/dist/las/las-writer.cjs.map +7 -0
  65. package/dist/las/las-writer.d.ts +69 -0
  66. package/dist/las/las-writer.d.ts.map +1 -0
  67. package/dist/las/las-writer.js +994 -0
  68. package/dist/las/las-writer.js.map +1 -0
  69. package/dist/las/laz-rs-loader-types.cjs +49 -0
  70. package/dist/las/laz-rs-loader-types.cjs.map +7 -0
  71. package/dist/las/laz-rs-loader-types.d.ts +65 -0
  72. package/dist/las/laz-rs-loader-types.d.ts.map +1 -0
  73. package/dist/las/laz-rs-loader-types.js +16 -0
  74. package/dist/las/laz-rs-loader-types.js.map +1 -0
  75. package/dist/las/laz-rs-loader.cjs +272 -0
  76. package/dist/las/laz-rs-loader.cjs.map +7 -0
  77. package/dist/las/laz-rs-loader.d.ts +37 -0
  78. package/dist/las/laz-rs-loader.d.ts.map +1 -0
  79. package/dist/las/laz-rs-loader.js +38 -0
  80. package/dist/las/laz-rs-loader.js.map +1 -0
  81. package/dist/las/lazperf-loader-types.cjs +49 -0
  82. package/dist/las/lazperf-loader-types.cjs.map +7 -0
  83. package/dist/las/lazperf-loader-types.d.ts +67 -0
  84. package/dist/las/lazperf-loader-types.d.ts.map +1 -0
  85. package/dist/las/lazperf-loader-types.js +17 -0
  86. package/dist/las/lazperf-loader-types.js.map +1 -0
  87. package/dist/las/lazperf-loader.cjs +60 -0
  88. package/dist/las/lazperf-loader.cjs.map +7 -0
  89. package/dist/las/lazperf-loader.d.ts +39 -0
  90. package/dist/las/lazperf-loader.d.ts.map +1 -0
  91. package/dist/las/lazperf-loader.js +44 -0
  92. package/dist/las/lazperf-loader.js.map +1 -0
  93. package/dist/las/lib/copc/parse-las.cjs +177 -0
  94. package/dist/las/lib/copc/parse-las.cjs.map +7 -0
  95. package/dist/las/lib/copc/parse-las.d.ts +17 -0
  96. package/dist/las/lib/copc/parse-las.d.ts.map +1 -0
  97. package/dist/las/lib/copc/parse-las.js +215 -0
  98. package/dist/las/lib/copc/parse-las.js.map +1 -0
  99. package/dist/las/lib/get-las-schema.cjs +62 -0
  100. package/dist/las/lib/get-las-schema.cjs.map +7 -0
  101. package/dist/las/lib/get-las-schema.d.ts +16 -0
  102. package/dist/las/lib/get-las-schema.d.ts.map +1 -0
  103. package/dist/las/lib/get-las-schema.js +46 -0
  104. package/dist/las/lib/get-las-schema.js.map +1 -0
  105. package/dist/las/lib/las-compatibility.cjs +110 -0
  106. package/dist/las/lib/las-compatibility.cjs.map +7 -0
  107. package/dist/las/lib/las-compatibility.d.ts +40 -0
  108. package/dist/las/lib/las-compatibility.d.ts.map +1 -0
  109. package/dist/las/lib/las-compatibility.js +115 -0
  110. package/dist/las/lib/las-compatibility.js.map +1 -0
  111. package/dist/las/lib/las-extra-bytes.cjs +223 -0
  112. package/dist/las/lib/las-extra-bytes.cjs.map +7 -0
  113. package/dist/las/lib/las-extra-bytes.d.ts +35 -0
  114. package/dist/las/lib/las-extra-bytes.d.ts.map +1 -0
  115. package/dist/las/lib/las-extra-bytes.js +195 -0
  116. package/dist/las/lib/las-extra-bytes.js.map +1 -0
  117. package/dist/las/lib/las-types.cjs +19 -0
  118. package/dist/las/lib/las-types.cjs.map +7 -0
  119. package/dist/las/lib/las-types.d.ts +194 -0
  120. package/dist/las/lib/las-types.d.ts.map +1 -0
  121. package/dist/las/lib/las-types.js +5 -0
  122. package/dist/las/lib/las-types.js.map +1 -0
  123. package/dist/las/lib/las-waveform.cjs +196 -0
  124. package/dist/las/lib/las-waveform.cjs.map +7 -0
  125. package/dist/las/lib/las-waveform.d.ts +89 -0
  126. package/dist/las/lib/las-waveform.d.ts.map +1 -0
  127. package/dist/las/lib/las-waveform.js +193 -0
  128. package/dist/las/lib/las-waveform.js.map +1 -0
  129. package/dist/las/lib/laz-perf/laslaz-decoder.cjs +382 -0
  130. package/dist/las/lib/laz-perf/laslaz-decoder.cjs.map +7 -0
  131. package/dist/las/lib/laz-perf/laslaz-decoder.d.ts +129 -0
  132. package/dist/las/lib/laz-perf/laslaz-decoder.d.ts.map +1 -0
  133. package/dist/las/lib/laz-perf/laslaz-decoder.js +377 -0
  134. package/dist/las/lib/laz-perf/laslaz-decoder.js.map +1 -0
  135. package/dist/las/lib/laz-perf/parse-las.cjs +270 -0
  136. package/dist/las/lib/laz-perf/parse-las.cjs.map +7 -0
  137. package/dist/las/lib/laz-perf/parse-las.d.ts +24 -0
  138. package/dist/las/lib/laz-perf/parse-las.d.ts.map +1 -0
  139. package/dist/las/lib/laz-perf/parse-las.js +307 -0
  140. package/dist/las/lib/laz-perf/parse-las.js.map +1 -0
  141. package/dist/las/lib/laz-rs-wasm/laslaz-decoder.cjs +631 -0
  142. package/dist/las/lib/laz-rs-wasm/laslaz-decoder.cjs.map +7 -0
  143. package/dist/las/lib/laz-rs-wasm/laslaz-decoder.d.ts +129 -0
  144. package/dist/las/lib/laz-rs-wasm/laslaz-decoder.d.ts.map +1 -0
  145. package/dist/las/lib/laz-rs-wasm/laslaz-decoder.js +414 -0
  146. package/dist/las/lib/laz-rs-wasm/laslaz-decoder.js.map +1 -0
  147. package/dist/las/lib/laz-rs-wasm/parse-las.cjs +270 -0
  148. package/dist/las/lib/laz-rs-wasm/parse-las.cjs.map +7 -0
  149. package/dist/las/lib/laz-rs-wasm/parse-las.d.ts +24 -0
  150. package/dist/las/lib/laz-rs-wasm/parse-las.d.ts.map +1 -0
  151. package/dist/las/lib/laz-rs-wasm/parse-las.js +307 -0
  152. package/dist/las/lib/laz-rs-wasm/parse-las.js.map +1 -0
  153. package/dist/las/lib/typescript/parse-las.cjs +2767 -0
  154. package/dist/las/lib/typescript/parse-las.cjs.map +7 -0
  155. package/dist/las/lib/typescript/parse-las.d.ts +39 -0
  156. package/dist/las/lib/typescript/parse-las.d.ts.map +1 -0
  157. package/dist/las/lib/typescript/parse-las.js +2607 -0
  158. package/dist/las/lib/typescript/parse-las.js.map +1 -0
  159. package/dist/las/libs/laz-perf/laz-perf.cjs +18093 -0
  160. package/dist/las/libs/laz-perf/laz-perf.cjs.map +7 -0
  161. package/dist/las/libs/laz-perf/laz-perf.d.ts +2 -0
  162. package/dist/las/libs/laz-perf/laz-perf.d.ts.map +1 -0
  163. package/dist/las/libs/laz-perf/laz-perf.js +19003 -0
  164. package/dist/las/libs/laz-perf/laz-perf.js.map +1 -0
  165. package/dist/las/libs/laz-rs-wasm/laz_rs_wasm.d.ts +95 -0
  166. package/dist/las/libs/laz-rs-wasm/laz_rs_wasm.d.ts.map +1 -0
  167. package/dist/las/libs/laz-rs-wasm/laz_rs_wasm.js +442 -0
  168. package/dist/las/libs/laz-rs-wasm/laz_rs_wasm.js.map +1 -0
  169. package/dist/las/libs/laz-rs-wasm/laz_rs_wasm_bg.wasm +0 -0
  170. package/dist/las/libs/laz-rs-wasm/laz_rs_wasm_bg.wasm.d.ts +38 -0
  171. package/dist/las/unbundled.cjs +71 -0
  172. package/dist/las/unbundled.cjs.map +7 -0
  173. package/dist/las/unbundled.d.ts +11 -0
  174. package/dist/las/unbundled.d.ts.map +1 -0
  175. package/dist/las/unbundled.js +11 -0
  176. package/dist/las/unbundled.js.map +1 -0
  177. package/dist/las/workers/las-worker.cjs +23 -0
  178. package/dist/las/workers/las-worker.cjs.map +7 -0
  179. package/dist/las/workers/las-worker.d.ts +2 -0
  180. package/dist/las/workers/las-worker.d.ts.map +1 -0
  181. package/dist/las/workers/las-worker.js +23 -0
  182. package/dist/las/workers/las-worker.js.map +1 -0
  183. package/dist/las-copc-loader-types.cjs +51 -0
  184. package/dist/las-copc-loader-types.cjs.map +7 -0
  185. package/dist/las-copc-loader-types.d.ts +2 -0
  186. package/dist/las-copc-loader-types.d.ts.map +1 -0
  187. package/dist/las-copc-loader-types.js +2 -0
  188. package/dist/las-copc-loader-types.js.map +1 -0
  189. package/dist/las-copc-loader.cjs +59 -0
  190. package/dist/las-copc-loader.cjs.map +7 -0
  191. package/dist/las-copc-loader.d.ts +2 -0
  192. package/dist/las-copc-loader.d.ts.map +1 -0
  193. package/dist/las-copc-loader.js +2 -0
  194. package/dist/las-copc-loader.js.map +1 -0
  195. package/dist/las-loader-types.cjs +56 -0
  196. package/dist/las-loader-types.cjs.map +7 -0
  197. package/dist/las-loader-types.d.ts +2 -0
  198. package/dist/las-loader-types.d.ts.map +1 -0
  199. package/dist/las-loader-types.js +2 -0
  200. package/dist/las-loader-types.js.map +1 -0
  201. package/dist/las-loader.cjs +82 -0
  202. package/dist/las-loader.cjs.map +7 -0
  203. package/dist/las-loader.d.ts +2 -0
  204. package/dist/las-loader.d.ts.map +1 -0
  205. package/dist/las-loader.js +2 -0
  206. package/dist/las-loader.js.map +1 -0
  207. package/dist/las-worker.js +23169 -0
  208. package/dist/las-writer.cjs +1056 -0
  209. package/dist/las-writer.cjs.map +7 -0
  210. package/dist/las-writer.d.ts +2 -0
  211. package/dist/las-writer.d.ts.map +1 -0
  212. package/dist/las-writer.js +2 -0
  213. package/dist/las-writer.js.map +1 -0
  214. package/dist/laz-rs-loader-types.cjs +51 -0
  215. package/dist/laz-rs-loader-types.cjs.map +7 -0
  216. package/dist/laz-rs-loader-types.d.ts +2 -0
  217. package/dist/laz-rs-loader-types.d.ts.map +1 -0
  218. package/dist/laz-rs-loader-types.js +2 -0
  219. package/dist/laz-rs-loader-types.js.map +1 -0
  220. package/dist/laz-rs-loader.cjs +274 -0
  221. package/dist/laz-rs-loader.cjs.map +7 -0
  222. package/dist/laz-rs-loader.d.ts +2 -0
  223. package/dist/laz-rs-loader.d.ts.map +1 -0
  224. package/dist/laz-rs-loader.js +2 -0
  225. package/dist/laz-rs-loader.js.map +1 -0
  226. package/dist/lazperf-loader-types.cjs +51 -0
  227. package/dist/lazperf-loader-types.cjs.map +7 -0
  228. package/dist/lazperf-loader-types.d.ts +2 -0
  229. package/dist/lazperf-loader-types.d.ts.map +1 -0
  230. package/dist/lazperf-loader-types.js +2 -0
  231. package/dist/lazperf-loader-types.js.map +1 -0
  232. package/dist/lazperf-loader.cjs +62 -0
  233. package/dist/lazperf-loader.cjs.map +7 -0
  234. package/dist/lazperf-loader.d.ts +2 -0
  235. package/dist/lazperf-loader.d.ts.map +1 -0
  236. package/dist/lazperf-loader.js +2 -0
  237. package/dist/lazperf-loader.js.map +1 -0
  238. package/dist/pcd/bundled.cjs +33 -0
  239. package/dist/pcd/bundled.cjs.map +7 -0
  240. package/dist/pcd/bundled.d.ts +3 -0
  241. package/dist/pcd/bundled.d.ts.map +1 -0
  242. package/dist/pcd/bundled.js +5 -0
  243. package/dist/pcd/bundled.js.map +1 -0
  244. package/dist/pcd/index.cjs +40 -0
  245. package/dist/pcd/index.cjs.map +7 -0
  246. package/dist/pcd/index.d.ts +8 -0
  247. package/dist/pcd/index.d.ts.map +1 -0
  248. package/dist/pcd/index.js +10 -0
  249. package/dist/pcd/index.js.map +1 -0
  250. package/dist/pcd/lib/decompress-lzf.cjs +80 -0
  251. package/dist/pcd/lib/decompress-lzf.cjs.map +7 -0
  252. package/dist/pcd/lib/decompress-lzf.d.ts +7 -0
  253. package/dist/pcd/lib/decompress-lzf.d.ts.map +1 -0
  254. package/dist/pcd/lib/decompress-lzf.js +62 -0
  255. package/dist/pcd/lib/decompress-lzf.js.map +1 -0
  256. package/dist/pcd/lib/get-pcd-schema.cjs +70 -0
  257. package/dist/pcd/lib/get-pcd-schema.cjs.map +7 -0
  258. package/dist/pcd/lib/get-pcd-schema.d.ts +10 -0
  259. package/dist/pcd/lib/get-pcd-schema.d.ts.map +1 -0
  260. package/dist/pcd/lib/get-pcd-schema.js +53 -0
  261. package/dist/pcd/lib/get-pcd-schema.js.map +1 -0
  262. package/dist/pcd/lib/parse-pcd.cjs +354 -0
  263. package/dist/pcd/lib/parse-pcd.cjs.map +7 -0
  264. package/dist/pcd/lib/parse-pcd.d.ts +20 -0
  265. package/dist/pcd/lib/parse-pcd.d.ts.map +1 -0
  266. package/dist/pcd/lib/parse-pcd.js +341 -0
  267. package/dist/pcd/lib/parse-pcd.js.map +1 -0
  268. package/dist/pcd/lib/pcd-types.cjs +19 -0
  269. package/dist/pcd/lib/pcd-types.cjs.map +7 -0
  270. package/dist/pcd/lib/pcd-types.d.ts +31 -0
  271. package/dist/pcd/lib/pcd-types.d.ts.map +1 -0
  272. package/dist/pcd/lib/pcd-types.js +5 -0
  273. package/dist/pcd/lib/pcd-types.js.map +1 -0
  274. package/dist/pcd/pcd-format.cjs +42 -0
  275. package/dist/pcd/pcd-format.cjs.map +7 -0
  276. package/dist/pcd/pcd-format.d.ts +16 -0
  277. package/dist/pcd/pcd-format.d.ts.map +1 -0
  278. package/dist/pcd/pcd-format.js +19 -0
  279. package/dist/pcd/pcd-format.js.map +1 -0
  280. package/dist/pcd/pcd-loader-types.cjs +64 -0
  281. package/dist/pcd/pcd-loader-types.cjs.map +7 -0
  282. package/dist/pcd/pcd-loader-types.d.ts +105 -0
  283. package/dist/pcd/pcd-loader-types.d.ts.map +1 -0
  284. package/dist/pcd/pcd-loader-types.js +35 -0
  285. package/dist/pcd/pcd-loader-types.js.map +1 -0
  286. package/dist/pcd/pcd-loader.cjs +144 -0
  287. package/dist/pcd/pcd-loader.cjs.map +7 -0
  288. package/dist/pcd/pcd-loader.d.ts +44 -0
  289. package/dist/pcd/pcd-loader.d.ts.map +1 -0
  290. package/dist/pcd/pcd-loader.js +128 -0
  291. package/dist/pcd/pcd-loader.js.map +1 -0
  292. package/dist/pcd/pcd-writer.cjs +134 -0
  293. package/dist/pcd/pcd-writer.cjs.map +7 -0
  294. package/dist/pcd/pcd-writer.d.ts +37 -0
  295. package/dist/pcd/pcd-writer.d.ts.map +1 -0
  296. package/dist/pcd/pcd-writer.js +115 -0
  297. package/dist/pcd/pcd-writer.js.map +1 -0
  298. package/dist/pcd/unbundled.cjs +33 -0
  299. package/dist/pcd/unbundled.cjs.map +7 -0
  300. package/dist/pcd/unbundled.d.ts +3 -0
  301. package/dist/pcd/unbundled.d.ts.map +1 -0
  302. package/dist/pcd/unbundled.js +5 -0
  303. package/dist/pcd/unbundled.js.map +1 -0
  304. package/dist/pcd/workers/pcd-worker.cjs +23 -0
  305. package/dist/pcd/workers/pcd-worker.cjs.map +7 -0
  306. package/dist/pcd/workers/pcd-worker.d.ts +2 -0
  307. package/dist/pcd/workers/pcd-worker.d.ts.map +1 -0
  308. package/dist/pcd/workers/pcd-worker.js +23 -0
  309. package/dist/pcd/workers/pcd-worker.js.map +1 -0
  310. package/dist/pcd-loader-types.cjs +66 -0
  311. package/dist/pcd-loader-types.cjs.map +7 -0
  312. package/dist/pcd-loader-types.d.ts +2 -0
  313. package/dist/pcd-loader-types.d.ts.map +1 -0
  314. package/dist/pcd-loader-types.js +2 -0
  315. package/dist/pcd-loader-types.js.map +1 -0
  316. package/dist/pcd-loader.cjs +146 -0
  317. package/dist/pcd-loader.cjs.map +7 -0
  318. package/dist/pcd-loader.d.ts +2 -0
  319. package/dist/pcd-loader.d.ts.map +1 -0
  320. package/dist/pcd-loader.js +2 -0
  321. package/dist/pcd-loader.js.map +1 -0
  322. package/dist/pcd-worker.js +17655 -0
  323. package/dist/pcd-writer.cjs +136 -0
  324. package/dist/pcd-writer.cjs.map +7 -0
  325. package/dist/pcd-writer.d.ts +2 -0
  326. package/dist/pcd-writer.d.ts.map +1 -0
  327. package/dist/pcd-writer.js +2 -0
  328. package/dist/pcd-writer.js.map +1 -0
  329. package/dist/ply/bundled.cjs +33 -0
  330. package/dist/ply/bundled.cjs.map +7 -0
  331. package/dist/ply/bundled.d.ts +3 -0
  332. package/dist/ply/bundled.d.ts.map +1 -0
  333. package/dist/ply/bundled.js +5 -0
  334. package/dist/ply/bundled.js.map +1 -0
  335. package/dist/ply/index.cjs +40 -0
  336. package/dist/ply/index.cjs.map +7 -0
  337. package/dist/ply/index.d.ts +8 -0
  338. package/dist/ply/index.d.ts.map +1 -0
  339. package/dist/ply/index.js +11 -0
  340. package/dist/ply/index.js.map +1 -0
  341. package/dist/ply/lib/get-ply-schema.cjs +126 -0
  342. package/dist/ply/lib/get-ply-schema.cjs.map +7 -0
  343. package/dist/ply/lib/get-ply-schema.d.ts +10 -0
  344. package/dist/ply/lib/get-ply-schema.d.ts.map +1 -0
  345. package/dist/ply/lib/get-ply-schema.js +117 -0
  346. package/dist/ply/lib/get-ply-schema.js.map +1 -0
  347. package/dist/ply/lib/normalize-ply.cjs +96 -0
  348. package/dist/ply/lib/normalize-ply.cjs.map +7 -0
  349. package/dist/ply/lib/normalize-ply.d.ts +8 -0
  350. package/dist/ply/lib/normalize-ply.d.ts.map +1 -0
  351. package/dist/ply/lib/normalize-ply.js +89 -0
  352. package/dist/ply/lib/normalize-ply.js.map +1 -0
  353. package/dist/ply/lib/parse-ply-arrow.cjs +552 -0
  354. package/dist/ply/lib/parse-ply-arrow.cjs.map +7 -0
  355. package/dist/ply/lib/parse-ply-arrow.d.ts +25 -0
  356. package/dist/ply/lib/parse-ply-arrow.d.ts.map +1 -0
  357. package/dist/ply/lib/parse-ply-arrow.js +493 -0
  358. package/dist/ply/lib/parse-ply-arrow.js.map +1 -0
  359. package/dist/ply/lib/parse-ply-in-batches.cjs +607 -0
  360. package/dist/ply/lib/parse-ply-in-batches.cjs.map +7 -0
  361. package/dist/ply/lib/parse-ply-in-batches.d.ts +9 -0
  362. package/dist/ply/lib/parse-ply-in-batches.d.ts.map +1 -0
  363. package/dist/ply/lib/parse-ply-in-batches.js +625 -0
  364. package/dist/ply/lib/parse-ply-in-batches.js.map +1 -0
  365. package/dist/ply/lib/parse-ply.cjs +755 -0
  366. package/dist/ply/lib/parse-ply.cjs.map +7 -0
  367. package/dist/ply/lib/parse-ply.d.ts +69 -0
  368. package/dist/ply/lib/parse-ply.d.ts.map +1 -0
  369. package/dist/ply/lib/parse-ply.js +851 -0
  370. package/dist/ply/lib/parse-ply.js.map +1 -0
  371. package/dist/ply/lib/ply-types.cjs +19 -0
  372. package/dist/ply/lib/ply-types.cjs.map +7 -0
  373. package/dist/ply/lib/ply-types.d.ts +37 -0
  374. package/dist/ply/lib/ply-types.d.ts.map +1 -0
  375. package/dist/ply/lib/ply-types.js +2 -0
  376. package/dist/ply/lib/ply-types.js.map +1 -0
  377. package/dist/ply/ply-format.cjs +43 -0
  378. package/dist/ply/ply-format.cjs.map +7 -0
  379. package/dist/ply/ply-format.d.ts +18 -0
  380. package/dist/ply/ply-format.d.ts.map +1 -0
  381. package/dist/ply/ply-format.js +22 -0
  382. package/dist/ply/ply-format.js.map +1 -0
  383. package/dist/ply/ply-loader-types.cjs +65 -0
  384. package/dist/ply/ply-loader-types.cjs.map +7 -0
  385. package/dist/ply/ply-loader-types.d.ts +111 -0
  386. package/dist/ply/ply-loader-types.d.ts.map +1 -0
  387. package/dist/ply/ply-loader-types.js +38 -0
  388. package/dist/ply/ply-loader-types.js.map +1 -0
  389. package/dist/ply/ply-loader.cjs +134 -0
  390. package/dist/ply/ply-loader.cjs.map +7 -0
  391. package/dist/ply/ply-loader.d.ts +44 -0
  392. package/dist/ply/ply-loader.d.ts.map +1 -0
  393. package/dist/ply/ply-loader.js +121 -0
  394. package/dist/ply/ply-loader.js.map +1 -0
  395. package/dist/ply/ply-writer.cjs +175 -0
  396. package/dist/ply/ply-writer.cjs.map +7 -0
  397. package/dist/ply/ply-writer.d.ts +37 -0
  398. package/dist/ply/ply-writer.d.ts.map +1 -0
  399. package/dist/ply/ply-writer.js +140 -0
  400. package/dist/ply/ply-writer.js.map +1 -0
  401. package/dist/ply/unbundled.cjs +33 -0
  402. package/dist/ply/unbundled.cjs.map +7 -0
  403. package/dist/ply/unbundled.d.ts +3 -0
  404. package/dist/ply/unbundled.d.ts.map +1 -0
  405. package/dist/ply/unbundled.js +5 -0
  406. package/dist/ply/unbundled.js.map +1 -0
  407. package/dist/ply/workers/ply-worker.cjs +34 -0
  408. package/dist/ply/workers/ply-worker.cjs.map +7 -0
  409. package/dist/ply/workers/ply-worker.d.ts +2 -0
  410. package/dist/ply/workers/ply-worker.d.ts.map +1 -0
  411. package/dist/ply/workers/ply-worker.js +37 -0
  412. package/dist/ply/workers/ply-worker.js.map +1 -0
  413. package/dist/ply-loader-types.cjs +67 -0
  414. package/dist/ply-loader-types.cjs.map +7 -0
  415. package/dist/ply-loader-types.d.ts +2 -0
  416. package/dist/ply-loader-types.d.ts.map +1 -0
  417. package/dist/ply-loader-types.js +2 -0
  418. package/dist/ply-loader-types.js.map +1 -0
  419. package/dist/ply-loader.cjs +136 -0
  420. package/dist/ply-loader.cjs.map +7 -0
  421. package/dist/ply-loader.d.ts +2 -0
  422. package/dist/ply-loader.d.ts.map +1 -0
  423. package/dist/ply-loader.js +2 -0
  424. package/dist/ply-loader.js.map +1 -0
  425. package/dist/ply-worker.js +19308 -0
  426. package/dist/ply-writer.cjs +177 -0
  427. package/dist/ply-writer.cjs.map +7 -0
  428. package/dist/ply-writer.d.ts +2 -0
  429. package/dist/ply-writer.d.ts.map +1 -0
  430. package/dist/ply-writer.js +2 -0
  431. package/dist/ply-writer.js.map +1 -0
  432. package/package.json +237 -4
  433. package/src/index.ts +19 -0
  434. package/src/las/bundled.ts +39 -0
  435. package/src/las/index.ts +70 -0
  436. package/src/las/las-copc-loader-types.ts +18 -0
  437. package/src/las/las-copc-loader.ts +61 -0
  438. package/src/las/las-format.ts +21 -0
  439. package/src/las/las-loader-shared.ts +124 -0
  440. package/src/las/las-loader-types.ts +27 -0
  441. package/src/las/las-loader.ts +109 -0
  442. package/src/las/las-writer.ts +1473 -0
  443. package/src/las/laz-rs-loader-types.ts +21 -0
  444. package/src/las/laz-rs-loader.ts +53 -0
  445. package/src/las/lazperf-loader-types.ts +22 -0
  446. package/src/las/lazperf-loader.ts +65 -0
  447. package/src/las/lib/LASZIP-LICENSE +202 -0
  448. package/src/las/lib/LASZIP-NOTICE +4 -0
  449. package/src/las/lib/copc/parse-las.ts +265 -0
  450. package/src/las/lib/get-las-schema.ts +50 -0
  451. package/src/las/lib/las-compatibility.ts +178 -0
  452. package/src/las/lib/las-extra-bytes.ts +274 -0
  453. package/src/las/lib/las-types.ts +206 -0
  454. package/src/las/lib/las-waveform.ts +292 -0
  455. package/src/las/lib/laz-perf/laslaz-decoder.ts +443 -0
  456. package/src/las/lib/laz-perf/parse-las.ts +412 -0
  457. package/src/las/lib/laz-rs-wasm/laslaz-decoder.ts +488 -0
  458. package/src/las/lib/laz-rs-wasm/parse-las.ts +412 -0
  459. package/src/las/lib/typescript/parse-las.ts +3730 -0
  460. package/src/las/libs/laz-perf/laz-perf.ts +20615 -0
  461. package/src/las/libs/laz-rs-wasm/README.md +5 -0
  462. package/src/las/libs/laz-rs-wasm/laz_rs_wasm.d.ts +89 -0
  463. package/src/las/libs/laz-rs-wasm/laz_rs_wasm.js +497 -0
  464. package/src/las/libs/laz-rs-wasm/laz_rs_wasm_bg.wasm +0 -0
  465. package/src/las/libs/laz-rs-wasm/laz_rs_wasm_bg.wasm.d.ts +38 -0
  466. package/src/las/libs/laz-rs-wasm/package.json +25 -0
  467. package/src/las/unbundled.ts +38 -0
  468. package/src/las/workers/las-worker.ts +24 -0
  469. package/src/las-copc-loader-types.ts +1 -0
  470. package/src/las-copc-loader.ts +1 -0
  471. package/src/las-loader-types.ts +1 -0
  472. package/src/las-loader.ts +1 -0
  473. package/src/las-writer.ts +1 -0
  474. package/src/laz-rs-loader-types.ts +1 -0
  475. package/src/laz-rs-loader.ts +1 -0
  476. package/src/lazperf-loader-types.ts +1 -0
  477. package/src/lazperf-loader.ts +1 -0
  478. package/src/pcd/bundled.ts +9 -0
  479. package/src/pcd/index.ts +13 -0
  480. package/src/pcd/lib/decompress-lzf.ts +68 -0
  481. package/src/pcd/lib/get-pcd-schema.ts +66 -0
  482. package/src/pcd/lib/parse-pcd.ts +474 -0
  483. package/src/pcd/lib/pcd-types.ts +34 -0
  484. package/src/pcd/pcd-format.ts +21 -0
  485. package/src/pcd/pcd-loader-types.ts +53 -0
  486. package/src/pcd/pcd-loader.ts +179 -0
  487. package/src/pcd/pcd-writer.ts +152 -0
  488. package/src/pcd/unbundled.ts +6 -0
  489. package/src/pcd/workers/pcd-worker.ts +24 -0
  490. package/src/pcd-loader-types.ts +1 -0
  491. package/src/pcd-loader.ts +1 -0
  492. package/src/pcd-writer.ts +1 -0
  493. package/src/ply/bundled.ts +9 -0
  494. package/src/ply/index.ts +15 -0
  495. package/src/ply/lib/get-ply-schema.ts +133 -0
  496. package/src/ply/lib/normalize-ply.ts +110 -0
  497. package/src/ply/lib/parse-ply-arrow.ts +676 -0
  498. package/src/ply/lib/parse-ply-in-batches.ts +827 -0
  499. package/src/ply/lib/parse-ply.ts +1081 -0
  500. package/src/ply/lib/ply-types.ts +47 -0
  501. package/src/ply/ply-format.ts +24 -0
  502. package/src/ply/ply-loader-types.ts +61 -0
  503. package/src/ply/ply-loader.ts +185 -0
  504. package/src/ply/ply-writer.ts +215 -0
  505. package/src/ply/unbundled.ts +6 -0
  506. package/src/ply/workers/ply-worker.ts +40 -0
  507. package/src/ply-loader-types.ts +1 -0
  508. package/src/ply-loader.ts +1 -0
  509. package/src/ply-writer.ts +1 -0
  510. package/third-party-licenses/plasio-LICENSE +21 -0
  511. package/third-party-licenses/three-LICENSE +21 -0
@@ -0,0 +1,1056 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/las-writer.ts
21
+ var las_writer_exports = {};
22
+ __export(las_writer_exports, {
23
+ LASWriter: () => LASWriter
24
+ });
25
+ module.exports = __toCommonJS(las_writer_exports);
26
+
27
+ // src/las/las-writer.ts
28
+ var import_loader_utils = require("@loaders.gl/core/loader-utils");
29
+ var import_schema_utils = require("@loaders.gl/core/schema-utils");
30
+ var import_las_format = require("./las-format.cjs");
31
+ var VERSION = true ? "5.0.0-beta.2" : "latest";
32
+ var LAS_HEADER_LENGTH = 227;
33
+ var LAS_1_4_HEADER_LENGTH = 375;
34
+ var LAS_1_5_HEADER_LENGTH = 393;
35
+ var VLR_HEADER_LENGTH = 54;
36
+ var EXTRA_BYTES_DESCRIPTOR_LENGTH = 192;
37
+ var DEFAULT_LAZ_CHUNK_SIZE = 5e4;
38
+ var VARIABLE_LAZ_CHUNK_SIZE = 4294967295;
39
+ var LAS_RETURN_BUCKET_COUNT = 15;
40
+ var POINT_RECORD_LENGTHS = {
41
+ 0: 20,
42
+ 1: 28,
43
+ 2: 26,
44
+ 3: 34,
45
+ 4: 57,
46
+ 5: 63,
47
+ 6: 30,
48
+ 7: 36,
49
+ 8: 38,
50
+ 9: 59,
51
+ 10: 67
52
+ };
53
+ var LASWriter = {
54
+ ...import_las_format.LASFormat,
55
+ dataType: null,
56
+ batchType: null,
57
+ version: VERSION,
58
+ extensions: ["las", "laz"],
59
+ options: {
60
+ las: {}
61
+ },
62
+ encode: async (data, options) => encodeLASSync(data, options),
63
+ encodeSync: encodeLASSync,
64
+ encodeInBatches: async function* (dataIterator, options) {
65
+ const batches = [];
66
+ for await (const batch of dataIterator) {
67
+ batches.push(batch);
68
+ }
69
+ yield encodeLASSync(mergeMeshBatches(batches), options);
70
+ }
71
+ };
72
+ function encodeLASSync(data, options = {}) {
73
+ const format = options.las?.format || "las";
74
+ const colorDepth = options.las?.colorDepth;
75
+ if (colorDepth !== void 0 && colorDepth !== "auto" && colorDepth !== 8 && colorDepth !== 16)
76
+ throw new Error("LASWriter: invalid source color depth");
77
+ const mesh = normalizeMesh(data);
78
+ const positionAttribute = getRequiredAttribute(mesh, "POSITION");
79
+ validatePositionAttribute(positionAttribute);
80
+ const vertexCount = positionAttribute.value.length / positionAttribute.size;
81
+ validateOptionalPointAttributes(mesh, vertexCount);
82
+ const colorAttribute = mesh.attributes.COLOR_0;
83
+ const intensityAttribute = mesh.attributes.intensity;
84
+ const classificationAttribute = mesh.attributes.classification;
85
+ const nirAttribute = mesh.attributes.nir;
86
+ const extraByteFields = getExtraByteFields(mesh, options, vertexCount);
87
+ const gpsTimeAttribute = mesh.attributes.gpsTime;
88
+ const scanAngleAttribute = mesh.attributes.scanAngle;
89
+ const userDataAttribute = mesh.attributes.userData;
90
+ const pointSourceIdAttribute = mesh.attributes.pointSourceId;
91
+ const returnNumberAttribute = mesh.attributes.returnNumber;
92
+ const numberOfReturnsAttribute = mesh.attributes.numberOfReturns;
93
+ const scannerChannelAttribute = mesh.attributes.scannerChannel;
94
+ const scanDirectionFlagAttribute = mesh.attributes.scanDirectionFlag;
95
+ const edgeOfFlightLineAttribute = mesh.attributes.edgeOfFlightLine;
96
+ const syntheticAttribute = mesh.attributes.synthetic;
97
+ const keyPointAttribute = mesh.attributes.keyPoint;
98
+ const withheldAttribute = mesh.attributes.withheld;
99
+ const overlapAttribute = mesh.attributes.overlap;
100
+ const waveformDescriptorAttribute = mesh.attributes.wavePacketDescriptorIndex;
101
+ const waveformOffsetAttribute = mesh.attributes.wavePacketOffset;
102
+ const waveformSizeAttribute = mesh.attributes.wavePacketSize;
103
+ const waveformReturnPointAttribute = mesh.attributes.wavePacketReturnPoint;
104
+ const waveformVectorAttribute = mesh.attributes.wavePacketVector;
105
+ const boundingBox = getBoundingBox(positionAttribute, vertexCount);
106
+ const returnCounts = getReturnCounts(returnNumberAttribute, vertexCount);
107
+ const scale = getScale(mesh, options);
108
+ const offset = getOffset(mesh, options, boundingBox);
109
+ validateCoordinateEncoding(positionAttribute, vertexCount, scale, offset);
110
+ const pointDataRecordFormat = options.las?.pointDataRecordFormat ?? getDefaultPointDataRecordFormat(options, colorAttribute);
111
+ validateReturnAttributes(mesh, vertexCount, pointDataRecordFormat);
112
+ const basePointDataRecordLength = POINT_RECORD_LENGTHS[pointDataRecordFormat];
113
+ if (!basePointDataRecordLength) {
114
+ throw new Error(`LASWriter: unsupported point data record format ${pointDataRecordFormat}`);
115
+ }
116
+ const pointDataRecordLength = basePointDataRecordLength + extraByteFields.reduce((byteLength, field) => byteLength + field.byteLength, 0);
117
+ if (pointDataRecordLength > 65535) {
118
+ throw new Error(
119
+ `LASWriter: point data record length ${pointDataRecordLength} exceeds the LAS limit`
120
+ );
121
+ }
122
+ validateExtraBytesVLR(extraByteFields);
123
+ const version = options.las?.version || (pointDataRecordFormat >= 6 ? "1.4" : "1.2");
124
+ const headerLength = version === "1.5" ? LAS_1_5_HEADER_LENGTH : version === "1.4" ? LAS_1_4_HEADER_LENGTH : LAS_HEADER_LENGTH;
125
+ validateLASVersionOptions(version, pointDataRecordFormat, options);
126
+ const gpsTimeRange = getGpsTimeRange(gpsTimeAttribute, vertexCount);
127
+ if (version === "1.5" && options.las?.timeOffset && !gpsTimeAttribute) {
128
+ throw new Error("LASWriter: LAS 1.5 timeOffset requires a GPS time attribute");
129
+ }
130
+ if (format === "laz") {
131
+ validateLAZOptions(version, pointDataRecordFormat, options.las?.chunkSize);
132
+ }
133
+ validatePointDataRecordVersion(version, pointDataRecordFormat);
134
+ const rawPointData = new Uint8Array(vertexCount * pointDataRecordLength);
135
+ const pointDataView = new DataView(rawPointData.buffer);
136
+ for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
137
+ const pointOffset = vertexIndex * pointDataRecordLength;
138
+ pointDataView.setInt32(
139
+ pointOffset,
140
+ Math.round((getComponent(positionAttribute, vertexIndex, 0) - offset[0]) / scale[0]),
141
+ true
142
+ );
143
+ pointDataView.setInt32(
144
+ pointOffset + 4,
145
+ Math.round((getComponent(positionAttribute, vertexIndex, 1) - offset[1]) / scale[1]),
146
+ true
147
+ );
148
+ pointDataView.setInt32(
149
+ pointOffset + 8,
150
+ Math.round((getComponent(positionAttribute, vertexIndex, 2) - offset[2]) / scale[2]),
151
+ true
152
+ );
153
+ writePointRecord(
154
+ pointDataView,
155
+ pointOffset,
156
+ vertexIndex,
157
+ pointDataRecordFormat,
158
+ basePointDataRecordLength,
159
+ {
160
+ intensityAttribute,
161
+ classificationAttribute,
162
+ nirAttribute,
163
+ colorAttribute,
164
+ colorDepth,
165
+ gpsTimeAttribute,
166
+ scanAngleAttribute,
167
+ userDataAttribute,
168
+ pointSourceIdAttribute,
169
+ returnNumberAttribute,
170
+ numberOfReturnsAttribute,
171
+ scannerChannelAttribute,
172
+ scanDirectionFlagAttribute,
173
+ edgeOfFlightLineAttribute,
174
+ syntheticAttribute,
175
+ keyPointAttribute,
176
+ withheldAttribute,
177
+ overlapAttribute,
178
+ waveformDescriptorAttribute,
179
+ waveformOffsetAttribute,
180
+ waveformSizeAttribute,
181
+ waveformReturnPointAttribute,
182
+ waveformVectorAttribute,
183
+ extraByteFields
184
+ }
185
+ );
186
+ }
187
+ const writeParameters = {
188
+ vertexCount,
189
+ boundingBox,
190
+ scale,
191
+ offset,
192
+ version,
193
+ headerLength,
194
+ pointDataRecordFormat,
195
+ pointDataRecordLength,
196
+ returnCounts,
197
+ maxGpsTime: gpsTimeRange.maximum,
198
+ minGpsTime: gpsTimeRange.minimum,
199
+ timeOffset: options.las?.timeOffset || 0,
200
+ hasGpsTime: Boolean(gpsTimeAttribute),
201
+ hasWkt: Boolean(options.las?.wkt)
202
+ };
203
+ if (format === "laz") {
204
+ return encodeLAZFile(
205
+ rawPointData,
206
+ writeParameters,
207
+ options.las?.chunkSize,
208
+ options.las?.variableChunkTable,
209
+ extraByteFields,
210
+ options
211
+ );
212
+ }
213
+ const metadataVLR = encodeMetadataVLRs(extraByteFields, options);
214
+ const pointDataOffset = headerLength + metadataVLR.byteLength;
215
+ const arrayBuffer = new ArrayBuffer(pointDataOffset + rawPointData.byteLength);
216
+ writeHeader(new DataView(arrayBuffer), {
217
+ ...writeParameters,
218
+ pointDataOffset,
219
+ vlrCount: countMetadataVLRs(extraByteFields, options)
220
+ });
221
+ const bytes = new Uint8Array(arrayBuffer);
222
+ bytes.set(metadataVLR, headerLength);
223
+ bytes.set(rawPointData, pointDataOffset);
224
+ return arrayBuffer;
225
+ }
226
+ function validatePointDataRecordVersion(version, pointDataRecordFormat) {
227
+ const minimumVersionByPointFormat = {
228
+ 0: "1.0",
229
+ 1: "1.1",
230
+ 2: "1.2",
231
+ 3: "1.2"
232
+ };
233
+ const minimumVersion = minimumVersionByPointFormat[pointDataRecordFormat];
234
+ if (minimumVersion && version < minimumVersion) {
235
+ throw new Error(
236
+ `LASWriter: point data record format ${pointDataRecordFormat} requires LAS ${minimumVersion} or newer; received ${version}`
237
+ );
238
+ }
239
+ if (pointDataRecordFormat >= 4 && pointDataRecordFormat <= 5 && !["1.3", "1.4", "1.5"].includes(version)) {
240
+ throw new Error(
241
+ `LASWriter: point data record format ${pointDataRecordFormat} requires LAS 1.3; received ${version}`
242
+ );
243
+ }
244
+ if (pointDataRecordFormat >= 6 && !["1.4", "1.5"].includes(version)) {
245
+ throw new Error(
246
+ `LASWriter: point data record format ${pointDataRecordFormat} requires LAS 1.4; received ${version}`
247
+ );
248
+ }
249
+ }
250
+ function validateLASVersionOptions(version, pointDataRecordFormat, options) {
251
+ if (version === "1.5") {
252
+ if (pointDataRecordFormat < 6 || pointDataRecordFormat > 10) {
253
+ throw new Error("LASWriter: LAS 1.5 output requires point data record format 6-10");
254
+ }
255
+ if (!options.las?.wkt?.trim()) {
256
+ throw new Error("LASWriter: LAS 1.5 output requires las.wkt");
257
+ }
258
+ const timeOffset = options.las?.timeOffset ?? 0;
259
+ if (!Number.isInteger(timeOffset) || timeOffset < 0 || timeOffset > 65535) {
260
+ throw new Error("LASWriter: LAS 1.5 timeOffset must be an unsigned 16-bit integer");
261
+ }
262
+ }
263
+ }
264
+ function encodeLAZFile(rawPointData, parameters, requestedChunkSize, variableChunkTable = false, extraByteFields = [], options = {}) {
265
+ const chunkSize = requestedChunkSize || DEFAULT_LAZ_CHUNK_SIZE;
266
+ const laszipVLR = (0, import_loader_utils.encodeLASzipVLR)({
267
+ pointDataRecordFormat: parameters.pointDataRecordFormat,
268
+ pointDataRecordLength: parameters.pointDataRecordLength,
269
+ chunkSize: variableChunkTable ? VARIABLE_LAZ_CHUNK_SIZE : chunkSize
270
+ });
271
+ const metadataVLR = encodeMetadataVLRs(extraByteFields, options);
272
+ const pointDataOffset = parameters.headerLength + metadataVLR.byteLength + laszipVLR.byteLength;
273
+ const compressedChunks = [];
274
+ const chunkTableEntries = [];
275
+ for (let pointOffset = 0; pointOffset < parameters.vertexCount; pointOffset += chunkSize) {
276
+ const pointCount = Math.min(chunkSize, parameters.vertexCount - pointOffset);
277
+ const byteOffset = pointOffset * parameters.pointDataRecordLength;
278
+ const compressed = (0, import_loader_utils.encodeLAZChunk)(
279
+ rawPointData.subarray(byteOffset, byteOffset + pointCount * parameters.pointDataRecordLength),
280
+ {
281
+ pointDataRecordFormat: parameters.pointDataRecordFormat,
282
+ pointDataRecordLength: parameters.pointDataRecordLength,
283
+ pointCount,
284
+ point14ItemVersion: 3,
285
+ rgb14ItemVersion: 3,
286
+ byte14ItemVersion: 3
287
+ }
288
+ );
289
+ compressedChunks.push(compressed);
290
+ chunkTableEntries.push({ pointCount, byteLength: compressed.byteLength });
291
+ }
292
+ const compressedPointDataByteLength = compressedChunks.reduce(
293
+ (byteLength, chunk) => byteLength + chunk.byteLength,
294
+ 0
295
+ );
296
+ const chunkTablePayload = (0, import_loader_utils.encodeLAZChunkTable)(chunkTableEntries, {
297
+ variable: variableChunkTable
298
+ });
299
+ const chunkTableOffset = pointDataOffset + 8 + compressedPointDataByteLength;
300
+ const arrayBuffer = new ArrayBuffer(chunkTableOffset + 8 + chunkTablePayload.byteLength);
301
+ const bytes = new Uint8Array(arrayBuffer);
302
+ const dataView = new DataView(arrayBuffer);
303
+ writeHeader(dataView, {
304
+ ...parameters,
305
+ pointDataOffset,
306
+ vlrCount: countMetadataVLRs(extraByteFields, options) + 1,
307
+ compressed: true
308
+ });
309
+ bytes.set(metadataVLR, parameters.headerLength);
310
+ bytes.set(laszipVLR, parameters.headerLength + metadataVLR.byteLength);
311
+ writeUint64Fallback(dataView, pointDataOffset, chunkTableOffset);
312
+ let compressedOffset = pointDataOffset + 8;
313
+ for (const chunk of compressedChunks) {
314
+ bytes.set(chunk, compressedOffset);
315
+ compressedOffset += chunk.byteLength;
316
+ }
317
+ dataView.setUint32(chunkTableOffset, 0, true);
318
+ dataView.setUint32(chunkTableOffset + 4, chunkTableEntries.length, true);
319
+ bytes.set(chunkTablePayload, chunkTableOffset + 8);
320
+ return arrayBuffer;
321
+ }
322
+ function getExtraByteFields(mesh, options, vertexCount) {
323
+ const extraBytes = options.las?.extraBytes || [];
324
+ const attributes = /* @__PURE__ */ new Set();
325
+ return extraBytes.map((field) => {
326
+ if (attributes.has(field.attribute)) {
327
+ throw new Error(`LASWriter: duplicate Extra Bytes attribute ${field.attribute}`);
328
+ }
329
+ attributes.add(field.attribute);
330
+ const meshAttribute = mesh.attributes[field.attribute];
331
+ if (!meshAttribute) {
332
+ throw new Error(`LASWriter: Extra Bytes attribute ${field.attribute} is missing`);
333
+ }
334
+ if (![1, 3].includes(meshAttribute.size)) {
335
+ throw new Error(`LASWriter: Extra Bytes attribute ${field.attribute} must have size 1 or 3`);
336
+ }
337
+ if (meshAttribute.value.length < vertexCount * meshAttribute.size) {
338
+ throw new Error(`LASWriter: Extra Bytes attribute ${field.attribute} is too short`);
339
+ }
340
+ validateFiniteAttributeValues(field.attribute, meshAttribute);
341
+ const dataType = getExtraBytesDataType(meshAttribute.value, meshAttribute.size);
342
+ return {
343
+ ...field,
344
+ meshAttribute,
345
+ dataType,
346
+ byteLength: getExtraBytesDataTypeByteLength(dataType, meshAttribute.size),
347
+ componentCount: meshAttribute.size
348
+ };
349
+ });
350
+ }
351
+ function getExtraBytesDataType(values, componentCount) {
352
+ let scalarDataType = 0;
353
+ if (values instanceof Uint8Array) scalarDataType = 1;
354
+ else if (values instanceof Int8Array) scalarDataType = 2;
355
+ else if (values instanceof Uint16Array) scalarDataType = 3;
356
+ else if (values instanceof Int16Array) scalarDataType = 4;
357
+ else if (values instanceof Uint32Array) scalarDataType = 5;
358
+ else if (values instanceof Int32Array) scalarDataType = 6;
359
+ else if (values instanceof BigUint64Array) scalarDataType = 7;
360
+ else if (values instanceof BigInt64Array) scalarDataType = 8;
361
+ else if (values instanceof Float32Array) scalarDataType = 9;
362
+ else if (values instanceof Float64Array) scalarDataType = 10;
363
+ if (scalarDataType) {
364
+ return scalarDataType + (componentCount === 3 ? 20 : 0);
365
+ }
366
+ throw new Error("LASWriter: Extra Bytes attributes require a supported typed array");
367
+ }
368
+ function getExtraBytesDataTypeByteLength(dataType, componentCount) {
369
+ const scalarDataType = dataType > 20 ? dataType - 20 : dataType > 10 ? dataType - 10 : dataType;
370
+ const scalarByteLength = scalarDataType <= 2 ? 1 : scalarDataType <= 4 ? 2 : scalarDataType <= 6 || scalarDataType === 9 ? 4 : 8;
371
+ return scalarByteLength * componentCount;
372
+ }
373
+ function encodeExtraBytesVLR(fields) {
374
+ if (fields.length === 0) {
375
+ return new Uint8Array(0);
376
+ }
377
+ const payload = new Uint8Array(fields.length * EXTRA_BYTES_DESCRIPTOR_LENGTH);
378
+ const dataView = new DataView(payload.buffer);
379
+ let byteOffset = 0;
380
+ for (const field of fields) {
381
+ dataView.setUint8(byteOffset + 2, field.dataType);
382
+ writeString(dataView, byteOffset + 4, field.name || field.attribute, 32);
383
+ writeString(dataView, byteOffset + 160, field.description || "", 32);
384
+ byteOffset += EXTRA_BYTES_DESCRIPTOR_LENGTH;
385
+ }
386
+ const bytes = new Uint8Array(VLR_HEADER_LENGTH + payload.byteLength);
387
+ const headerView = new DataView(bytes.buffer);
388
+ writeString(headerView, 2, "LASF_Spec", 16);
389
+ headerView.setUint16(18, 4, true);
390
+ headerView.setUint16(20, payload.byteLength, true);
391
+ writeString(headerView, 22, "Extra Bytes", 32);
392
+ bytes.set(payload, VLR_HEADER_LENGTH);
393
+ return bytes;
394
+ }
395
+ function encodeMetadataVLRs(fields, options) {
396
+ const records = [];
397
+ if (options.las?.wktMathTransform) {
398
+ records.push(encodeProjectionVLR(2111, "WKT Math Transform", options.las.wktMathTransform));
399
+ }
400
+ if (options.las?.wkt) {
401
+ records.push(encodeProjectionVLR(2112, "WKT Coordinate System", options.las.wkt));
402
+ }
403
+ const extraBytesVLR = encodeExtraBytesVLR(fields);
404
+ if (extraBytesVLR.byteLength) {
405
+ records.push(extraBytesVLR);
406
+ }
407
+ const byteLength = records.reduce((total, record) => total + record.byteLength, 0);
408
+ const bytes = new Uint8Array(byteLength);
409
+ let offset = 0;
410
+ for (const record of records) {
411
+ bytes.set(record, offset);
412
+ offset += record.byteLength;
413
+ }
414
+ return bytes;
415
+ }
416
+ function encodeProjectionVLR(recordId, description, wkt) {
417
+ const payload = new TextEncoder().encode(`${wkt}\0`);
418
+ if (payload.byteLength > 65535) {
419
+ throw new Error(`LASWriter: WKT VLR ${recordId} exceeds the LAS VLR size limit`);
420
+ }
421
+ const bytes = new Uint8Array(VLR_HEADER_LENGTH + payload.byteLength);
422
+ const dataView = new DataView(bytes.buffer);
423
+ writeString(dataView, 2, "LASF_Projection", 16);
424
+ dataView.setUint16(18, recordId, true);
425
+ dataView.setUint16(20, payload.byteLength, true);
426
+ writeString(dataView, 22, description, 32);
427
+ bytes.set(payload, VLR_HEADER_LENGTH);
428
+ return bytes;
429
+ }
430
+ function countMetadataVLRs(fields, options) {
431
+ return (options.las?.wktMathTransform ? 1 : 0) + (options.las?.wkt ? 1 : 0) + (fields.length ? 1 : 0);
432
+ }
433
+ function getGpsTimeRange(attribute, vertexCount) {
434
+ if (!attribute) {
435
+ return { minimum: 0, maximum: 0 };
436
+ }
437
+ let minimum = Number(attribute.value[0]);
438
+ let maximum = minimum;
439
+ for (let vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
440
+ const value = Number(attribute.value[vertexIndex * attribute.size]);
441
+ minimum = Math.min(minimum, value);
442
+ maximum = Math.max(maximum, value);
443
+ }
444
+ return { minimum, maximum };
445
+ }
446
+ function validateExtraBytesVLR(fields) {
447
+ const payloadByteLength = fields.length * EXTRA_BYTES_DESCRIPTOR_LENGTH;
448
+ if (payloadByteLength > 65535) {
449
+ throw new Error(
450
+ `LASWriter: Extra Bytes VLR payload ${payloadByteLength} exceeds the LAS limit`
451
+ );
452
+ }
453
+ }
454
+ function validateLAZOptions(version, pointDataRecordFormat, chunkSize) {
455
+ if (pointDataRecordFormat === 1 && !["1.1", "1.2", "1.3", "1.4", "1.5"].includes(version)) {
456
+ throw new Error(`LASWriter: LAZ PDRF 1 output requires LAS 1.1 or newer; received ${version}`);
457
+ }
458
+ if (pointDataRecordFormat >= 2 && pointDataRecordFormat <= 3 && !["1.2", "1.3", "1.4", "1.5"].includes(version)) {
459
+ throw new Error(
460
+ `LASWriter: LAZ PDRF ${pointDataRecordFormat} output requires LAS 1.2 or newer; received ${version}`
461
+ );
462
+ }
463
+ if (pointDataRecordFormat >= 4 && pointDataRecordFormat <= 5 && !["1.3", "1.4", "1.5"].includes(version)) {
464
+ throw new Error(
465
+ `LASWriter: LAZ PDRF ${pointDataRecordFormat} requires LAS 1.3 or newer; received ${version}`
466
+ );
467
+ }
468
+ if (pointDataRecordFormat >= 6 && !["1.4", "1.5"].includes(version)) {
469
+ throw new Error(`LASWriter: LAZ output requires LAS 1.4; received ${version}`);
470
+ }
471
+ if (![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].includes(pointDataRecordFormat)) {
472
+ throw new Error(
473
+ `LASWriter: LAZ output currently supports point data record formats 0-10; received ${pointDataRecordFormat}`
474
+ );
475
+ }
476
+ if (chunkSize !== void 0 && (!Number.isInteger(chunkSize) || chunkSize <= 0 || chunkSize > 4294967295)) {
477
+ throw new Error(`LASWriter: invalid LAZ chunk size ${chunkSize}`);
478
+ }
479
+ }
480
+ function normalizeMesh(data) {
481
+ if ("shape" in data && data.shape === "arrow-table") {
482
+ return (0, import_schema_utils.convertTableToMesh)(data);
483
+ }
484
+ return data;
485
+ }
486
+ function normalizeMeshArrowTable(data) {
487
+ return "shape" in data && data.shape === "arrow-table" ? data : (0, import_schema_utils.convertMeshToTable)(data, "arrow-table");
488
+ }
489
+ function mergeMeshBatches(batches) {
490
+ if (batches.length === 0) {
491
+ throw new Error("LASWriter: at least one input batch is required");
492
+ }
493
+ if (batches.length === 1) {
494
+ return batches[0];
495
+ }
496
+ const meshes = batches.map((batch) => (0, import_schema_utils.convertTableToMesh)(normalizeMeshArrowTable(batch)));
497
+ const firstMesh = meshes[0];
498
+ const mergedAttributes = {};
499
+ validateBatchAttributes(meshes);
500
+ for (const attributeName of Object.keys(firstMesh.attributes)) {
501
+ const firstAttribute = firstMesh.attributes[attributeName];
502
+ const values = meshes.map((mesh) => mesh.attributes[attributeName]?.value);
503
+ if (values.some((value) => !value)) {
504
+ continue;
505
+ }
506
+ const totalLength = values.reduce((length, value) => length + value.length, 0);
507
+ const Constructor = firstAttribute.value.constructor;
508
+ const mergedValue = new Constructor(totalLength);
509
+ let offset = 0;
510
+ for (const value of values) {
511
+ mergedValue.set(value, offset);
512
+ offset += value.length;
513
+ }
514
+ mergedAttributes[attributeName] = { ...firstAttribute, value: mergedValue };
515
+ }
516
+ return {
517
+ ...firstMesh,
518
+ attributes: mergedAttributes,
519
+ header: {
520
+ ...firstMesh.header,
521
+ vertexCount: getRequiredAttribute({ ...firstMesh, attributes: mergedAttributes }, "POSITION").value.length / 3
522
+ }
523
+ };
524
+ }
525
+ function validateBatchAttributes(meshes) {
526
+ const attributeNames = Object.keys(meshes[0].attributes);
527
+ for (const mesh of meshes.slice(1)) {
528
+ const meshAttributeNames = Object.keys(mesh.attributes);
529
+ if (meshAttributeNames.length !== attributeNames.length || attributeNames.some((attributeName) => !mesh.attributes[attributeName])) {
530
+ throw new Error("LASWriter: encodeInBatches requires consistent attribute names");
531
+ }
532
+ for (const attributeName of attributeNames) {
533
+ const firstAttribute = meshes[0].attributes[attributeName];
534
+ const attribute = mesh.attributes[attributeName];
535
+ if (attribute.size !== firstAttribute.size || attribute.value.constructor !== firstAttribute.value.constructor) {
536
+ throw new Error(`LASWriter: encodeInBatches requires a consistent ${attributeName} layout`);
537
+ }
538
+ }
539
+ }
540
+ }
541
+ function getRequiredAttribute(mesh, attributeName) {
542
+ const attribute = mesh.attributes[attributeName];
543
+ if (!attribute) {
544
+ throw new Error(`LASWriter: ${attributeName} attribute is required`);
545
+ }
546
+ return attribute;
547
+ }
548
+ function validatePositionAttribute(attribute) {
549
+ if (attribute.size !== 3) {
550
+ throw new Error(`LASWriter: POSITION attribute must have size 3`);
551
+ }
552
+ if (attribute.value.length % attribute.size !== 0) {
553
+ throw new Error(`LASWriter: POSITION attribute length must be divisible by its size`);
554
+ }
555
+ }
556
+ function validateCoordinateEncoding(attribute, vertexCount, scale, offset) {
557
+ for (let componentIndex = 0; componentIndex < 3; componentIndex++) {
558
+ if (!Number.isFinite(scale[componentIndex]) || scale[componentIndex] <= 0) {
559
+ throw new Error(`LASWriter: coordinate scale must be finite and positive`);
560
+ }
561
+ if (!Number.isFinite(offset[componentIndex])) {
562
+ throw new Error(`LASWriter: coordinate offset must be finite`);
563
+ }
564
+ }
565
+ for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
566
+ for (let componentIndex = 0; componentIndex < 3; componentIndex++) {
567
+ const positionValue = attribute.value[vertexIndex * attribute.size + componentIndex];
568
+ if (!Number.isFinite(positionValue)) {
569
+ throw new Error(`LASWriter: POSITION values must be finite`);
570
+ }
571
+ const encodedValue = Math.round(
572
+ (positionValue - offset[componentIndex]) / scale[componentIndex]
573
+ );
574
+ if (encodedValue < -2147483648 || encodedValue > 2147483647) {
575
+ throw new Error(`LASWriter: encoded coordinate exceeds the signed 32-bit LAS range`);
576
+ }
577
+ }
578
+ }
579
+ }
580
+ function validateOptionalPointAttributes(mesh, vertexCount) {
581
+ const scalarAttributeNames = [
582
+ "intensity",
583
+ "classification",
584
+ "gpsTime",
585
+ "scanAngle",
586
+ "userData",
587
+ "pointSourceId",
588
+ "returnNumber",
589
+ "numberOfReturns",
590
+ "scannerChannel",
591
+ "scanDirectionFlag",
592
+ "edgeOfFlightLine",
593
+ "synthetic",
594
+ "keyPoint",
595
+ "withheld",
596
+ "overlap",
597
+ "nir",
598
+ "wavePacketDescriptorIndex",
599
+ "wavePacketOffset",
600
+ "wavePacketSize",
601
+ "wavePacketReturnPoint"
602
+ ];
603
+ for (const attributeName of scalarAttributeNames) {
604
+ const attribute = mesh.attributes[attributeName];
605
+ if (attribute) {
606
+ validateOptionalAttribute(attributeName, attribute, vertexCount, 1);
607
+ }
608
+ }
609
+ const colorAttribute = mesh.attributes.COLOR_0;
610
+ if (colorAttribute) {
611
+ validateOptionalAttribute("COLOR_0", colorAttribute, vertexCount, 3, false);
612
+ }
613
+ const waveformVectorAttribute = mesh.attributes.wavePacketVector;
614
+ if (waveformVectorAttribute) {
615
+ validateOptionalAttribute("wavePacketVector", waveformVectorAttribute, vertexCount, 3);
616
+ }
617
+ }
618
+ function validateReturnAttributes(mesh, vertexCount, pointDataRecordFormat) {
619
+ const maximumReturnNumber = pointDataRecordFormat >= 6 ? 15 : 5;
620
+ const returnNumberAttribute = mesh.attributes.returnNumber;
621
+ const numberOfReturnsAttribute = mesh.attributes.numberOfReturns;
622
+ for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
623
+ const returnNumber = getUInt8Attribute(returnNumberAttribute, vertexIndex, 1);
624
+ const numberOfReturns = getUInt8Attribute(numberOfReturnsAttribute, vertexIndex, 1);
625
+ if (returnNumber < 1 || returnNumber > maximumReturnNumber) {
626
+ throw new Error(
627
+ `LASWriter: returnNumber must be between 1 and ${maximumReturnNumber} for point data record format ${pointDataRecordFormat}`
628
+ );
629
+ }
630
+ if (numberOfReturns < 1 || numberOfReturns > maximumReturnNumber) {
631
+ throw new Error(
632
+ `LASWriter: numberOfReturns must be between 1 and ${maximumReturnNumber} for point data record format ${pointDataRecordFormat}`
633
+ );
634
+ }
635
+ if (returnNumber > numberOfReturns) {
636
+ throw new Error(`LASWriter: returnNumber cannot exceed numberOfReturns`);
637
+ }
638
+ }
639
+ }
640
+ function validateOptionalAttribute(attributeName, attribute, vertexCount, minimumSize, requirePointCount = true) {
641
+ if (minimumSize === 1 ? attribute.size !== 1 : attribute.size < minimumSize) {
642
+ throw new Error(`LASWriter: ${attributeName} attribute must have size ${minimumSize}`);
643
+ }
644
+ validateFiniteAttributeValues(attributeName, attribute);
645
+ if (requirePointCount && attribute.value.length < vertexCount * attribute.size) {
646
+ throw new Error(`LASWriter: ${attributeName} attribute is too short`);
647
+ }
648
+ if (!requirePointCount && attribute.value.length < attribute.size) {
649
+ throw new Error(`LASWriter: ${attributeName} attribute is too short`);
650
+ }
651
+ }
652
+ function validateFiniteAttributeValues(attributeName, attribute) {
653
+ for (const value of attribute.value) {
654
+ if (!Number.isFinite(Number(value))) {
655
+ throw new Error(`LASWriter: ${attributeName} attribute must contain finite values`);
656
+ }
657
+ }
658
+ }
659
+ function writeHeader(dataView, parameters) {
660
+ const [versionMajor, versionMinor] = parameters.version.split(".").map(Number);
661
+ writeString(dataView, 0, "LASF", 4);
662
+ dataView.setUint8(24, versionMajor);
663
+ dataView.setUint8(25, versionMinor);
664
+ writeString(dataView, 26, "loaders.gl", 32);
665
+ writeString(dataView, 58, "loaders.gl", 32);
666
+ dataView.setUint16(94, parameters.headerLength, true);
667
+ dataView.setUint32(96, parameters.pointDataOffset, true);
668
+ dataView.setUint32(100, parameters.vlrCount || 0, true);
669
+ dataView.setUint8(104, parameters.pointDataRecordFormat | (parameters.compressed ? 128 : 0));
670
+ dataView.setUint16(105, parameters.pointDataRecordLength, true);
671
+ const isExtendedHeader = parameters.version === "1.4" || parameters.version === "1.5";
672
+ dataView.setUint32(107, isExtendedHeader ? 0 : parameters.vertexCount, true);
673
+ for (let returnIndex = 0; returnIndex < 5; returnIndex++) {
674
+ dataView.setUint32(
675
+ 111 + returnIndex * 4,
676
+ isExtendedHeader ? 0 : parameters.returnCounts[returnIndex],
677
+ true
678
+ );
679
+ }
680
+ if (parameters.version === "1.5") {
681
+ dataView.setUint16(
682
+ 6,
683
+ 16 | (parameters.hasGpsTime ? 1 : 0) | (parameters.timeOffset ? 64 : 0),
684
+ true
685
+ );
686
+ } else if (parameters.version === "1.4" && parameters.hasWkt) {
687
+ dataView.setUint16(6, 16, true);
688
+ }
689
+ dataView.setFloat64(131, parameters.scale[0], true);
690
+ dataView.setFloat64(139, parameters.scale[1], true);
691
+ dataView.setFloat64(147, parameters.scale[2], true);
692
+ dataView.setFloat64(155, parameters.offset[0], true);
693
+ dataView.setFloat64(163, parameters.offset[1], true);
694
+ dataView.setFloat64(171, parameters.offset[2], true);
695
+ dataView.setFloat64(179, parameters.boundingBox[1][0], true);
696
+ dataView.setFloat64(187, parameters.boundingBox[0][0], true);
697
+ dataView.setFloat64(195, parameters.boundingBox[1][1], true);
698
+ dataView.setFloat64(203, parameters.boundingBox[0][1], true);
699
+ dataView.setFloat64(211, parameters.boundingBox[1][2], true);
700
+ dataView.setFloat64(219, parameters.boundingBox[0][2], true);
701
+ if (isExtendedHeader) {
702
+ writeUint64Fallback(dataView, 247, parameters.vertexCount);
703
+ for (let returnIndex = 0; returnIndex < LAS_RETURN_BUCKET_COUNT; returnIndex++) {
704
+ writeUint64Fallback(dataView, 255 + returnIndex * 8, parameters.returnCounts[returnIndex]);
705
+ }
706
+ }
707
+ if (parameters.version === "1.5") {
708
+ dataView.setFloat64(375, parameters.maxGpsTime, true);
709
+ dataView.setFloat64(383, parameters.minGpsTime, true);
710
+ dataView.setUint16(391, parameters.timeOffset, true);
711
+ }
712
+ }
713
+ function writePointRecord(dataView, pointOffset, vertexIndex, pointDataRecordFormat, basePointDataRecordLength, attributes) {
714
+ dataView.setUint16(
715
+ pointOffset + 12,
716
+ getUInt16Attribute(attributes.intensityAttribute, vertexIndex),
717
+ true
718
+ );
719
+ if (pointDataRecordFormat <= 5) {
720
+ const returnNumber = getUInt8Attribute(attributes.returnNumberAttribute, vertexIndex, 1) & 7;
721
+ const numberOfReturns = getUInt8Attribute(attributes.numberOfReturnsAttribute, vertexIndex, 1) & 7;
722
+ dataView.setUint8(pointOffset + 14, returnNumber | numberOfReturns << 3);
723
+ dataView.setUint8(
724
+ pointOffset + 15,
725
+ getUInt8Attribute(attributes.classificationAttribute, vertexIndex) & 31
726
+ );
727
+ dataView.setInt8(
728
+ pointOffset + 16,
729
+ getInt16Attribute(attributes.scanAngleAttribute, vertexIndex)
730
+ );
731
+ dataView.setUint8(
732
+ pointOffset + 17,
733
+ getUInt8Attribute(attributes.userDataAttribute, vertexIndex)
734
+ );
735
+ dataView.setUint16(
736
+ pointOffset + 18,
737
+ getUInt16Attribute(attributes.pointSourceIdAttribute, vertexIndex),
738
+ true
739
+ );
740
+ if (pointDataRecordFormat === 1 || pointDataRecordFormat === 3 || pointDataRecordFormat >= 4) {
741
+ dataView.setFloat64(
742
+ pointOffset + 20,
743
+ getAttributeValue(attributes.gpsTimeAttribute, vertexIndex),
744
+ true
745
+ );
746
+ }
747
+ if (pointDataRecordFormat === 4 || pointDataRecordFormat === 5) {
748
+ const waveformOffset = pointDataRecordFormat === 4 ? 28 : 34;
749
+ writeWaveformPacket(dataView, pointOffset + waveformOffset, vertexIndex, attributes);
750
+ }
751
+ } else {
752
+ const returnNumber = getUInt8Attribute(attributes.returnNumberAttribute, vertexIndex, 1) & 15;
753
+ const numberOfReturns = getUInt8Attribute(attributes.numberOfReturnsAttribute, vertexIndex, 1) & 15;
754
+ const scannerChannel = getUInt8Attribute(attributes.scannerChannelAttribute, vertexIndex) & 3;
755
+ const returnFlags = returnNumber | numberOfReturns << 4;
756
+ const classificationFlags = (getBooleanAttribute(attributes.syntheticAttribute, vertexIndex) ? 1 << 0 : 0) | (getBooleanAttribute(attributes.keyPointAttribute, vertexIndex) ? 1 << 1 : 0) | (getBooleanAttribute(attributes.withheldAttribute, vertexIndex) ? 1 << 2 : 0) | (getBooleanAttribute(attributes.overlapAttribute, vertexIndex) ? 1 << 3 : 0) | scannerChannel << 4 | (getBooleanAttribute(attributes.scanDirectionFlagAttribute, vertexIndex) ? 1 << 6 : 0) | (getBooleanAttribute(attributes.edgeOfFlightLineAttribute, vertexIndex) ? 1 << 7 : 0);
757
+ dataView.setUint8(pointOffset + 14, returnFlags);
758
+ dataView.setUint8(pointOffset + 15, classificationFlags);
759
+ dataView.setUint8(
760
+ pointOffset + 16,
761
+ getUInt8Attribute(attributes.classificationAttribute, vertexIndex)
762
+ );
763
+ dataView.setUint8(
764
+ pointOffset + 17,
765
+ getUInt8Attribute(attributes.userDataAttribute, vertexIndex)
766
+ );
767
+ dataView.setInt16(
768
+ pointOffset + 18,
769
+ getInt16Attribute(attributes.scanAngleAttribute, vertexIndex),
770
+ true
771
+ );
772
+ dataView.setUint16(
773
+ pointOffset + 20,
774
+ getUInt16Attribute(attributes.pointSourceIdAttribute, vertexIndex),
775
+ true
776
+ );
777
+ dataView.setFloat64(
778
+ pointOffset + 22,
779
+ getAttributeValue(attributes.gpsTimeAttribute, vertexIndex),
780
+ true
781
+ );
782
+ if (pointDataRecordFormat === 9 || pointDataRecordFormat === 10) {
783
+ const waveformOffset = pointDataRecordFormat === 9 ? 30 : 38;
784
+ writeWaveformPacket(dataView, pointOffset + waveformOffset, vertexIndex, attributes);
785
+ }
786
+ }
787
+ writePointColor(
788
+ dataView,
789
+ pointOffset,
790
+ vertexIndex,
791
+ pointDataRecordFormat,
792
+ attributes.colorAttribute,
793
+ attributes.colorDepth
794
+ );
795
+ if (pointDataRecordFormat === 8 || pointDataRecordFormat === 10) {
796
+ dataView.setUint16(
797
+ pointOffset + 36,
798
+ getUInt16Attribute(attributes.nirAttribute, vertexIndex),
799
+ true
800
+ );
801
+ }
802
+ writeExtraBytes(
803
+ dataView,
804
+ pointOffset,
805
+ vertexIndex,
806
+ basePointDataRecordLength,
807
+ attributes.extraByteFields
808
+ );
809
+ }
810
+ function writeWaveformPacket(dataView, byteOffset, vertexIndex, attributes) {
811
+ dataView.setUint8(
812
+ byteOffset,
813
+ getUInt8Attribute(attributes.waveformDescriptorAttribute, vertexIndex)
814
+ );
815
+ dataView.setBigUint64(
816
+ byteOffset + 1,
817
+ getBigUint64Attribute(attributes.waveformOffsetAttribute, vertexIndex),
818
+ true
819
+ );
820
+ dataView.setUint32(
821
+ byteOffset + 9,
822
+ getUInt32Attribute(attributes.waveformSizeAttribute, vertexIndex),
823
+ true
824
+ );
825
+ dataView.setFloat32(
826
+ byteOffset + 13,
827
+ getAttributeValue(attributes.waveformReturnPointAttribute, vertexIndex),
828
+ true
829
+ );
830
+ for (let componentIndex = 0; componentIndex < 3; componentIndex++) {
831
+ dataView.setFloat32(
832
+ byteOffset + 17 + componentIndex * 4,
833
+ getComponent(attributes.waveformVectorAttribute, vertexIndex, componentIndex),
834
+ true
835
+ );
836
+ }
837
+ }
838
+ function writeExtraBytes(dataView, pointOffset, vertexIndex, basePointDataRecordLength, fields) {
839
+ let byteOffset = pointOffset + basePointDataRecordLength;
840
+ for (const field of fields) {
841
+ for (let componentIndex = 0; componentIndex < field.componentCount; componentIndex++) {
842
+ writeExtraBytesValue(dataView, byteOffset, vertexIndex, componentIndex, field);
843
+ byteOffset += field.byteLength / field.componentCount;
844
+ }
845
+ }
846
+ }
847
+ function writeExtraBytesValue(dataView, byteOffset, vertexIndex, componentIndex, field) {
848
+ const value = field.meshAttribute.value[vertexIndex * field.componentCount + componentIndex];
849
+ const scalarDataType = field.dataType > 20 ? field.dataType - 20 : field.dataType > 10 ? field.dataType - 10 : field.dataType;
850
+ switch (scalarDataType) {
851
+ case 1:
852
+ dataView.setUint8(byteOffset, Number(value));
853
+ break;
854
+ case 2:
855
+ dataView.setInt8(byteOffset, Number(value));
856
+ break;
857
+ case 3:
858
+ dataView.setUint16(byteOffset, Number(value), true);
859
+ break;
860
+ case 4:
861
+ dataView.setInt16(byteOffset, Number(value), true);
862
+ break;
863
+ case 5:
864
+ dataView.setUint32(byteOffset, Number(value), true);
865
+ break;
866
+ case 6:
867
+ dataView.setInt32(byteOffset, Number(value), true);
868
+ break;
869
+ case 7:
870
+ dataView.setBigUint64(byteOffset, BigInt(value), true);
871
+ break;
872
+ case 8:
873
+ dataView.setBigInt64(byteOffset, BigInt(value), true);
874
+ break;
875
+ case 9:
876
+ dataView.setFloat32(byteOffset, Number(value), true);
877
+ break;
878
+ case 10:
879
+ dataView.setFloat64(byteOffset, Number(value), true);
880
+ break;
881
+ default:
882
+ throw new Error(`LASWriter: unsupported Extra Bytes data type ${field.dataType}`);
883
+ }
884
+ }
885
+ function writePointColor(dataView, pointOffset, vertexIndex, pointDataRecordFormat, colorAttribute, colorDepth) {
886
+ const colorOffset = getColorOffset(pointDataRecordFormat);
887
+ if (colorOffset < 0 || !colorAttribute) {
888
+ return;
889
+ }
890
+ dataView.setUint16(
891
+ pointOffset + colorOffset,
892
+ getLASColor(colorAttribute, vertexIndex, 0, colorDepth),
893
+ true
894
+ );
895
+ dataView.setUint16(
896
+ pointOffset + colorOffset + 2,
897
+ getLASColor(colorAttribute, vertexIndex, 1, colorDepth),
898
+ true
899
+ );
900
+ dataView.setUint16(
901
+ pointOffset + colorOffset + 4,
902
+ getLASColor(colorAttribute, vertexIndex, 2, colorDepth),
903
+ true
904
+ );
905
+ }
906
+ function getColorOffset(pointDataRecordFormat) {
907
+ switch (pointDataRecordFormat) {
908
+ case 2:
909
+ return 20;
910
+ case 3:
911
+ return 28;
912
+ case 5:
913
+ return 57;
914
+ case 7:
915
+ case 8:
916
+ case 10:
917
+ return 30;
918
+ default:
919
+ return -1;
920
+ }
921
+ }
922
+ function getDefaultPointDataRecordFormat(options, colorAttribute) {
923
+ if (options.las?.format === "laz" || options.las?.version === "1.4") {
924
+ return colorAttribute ? 7 : 6;
925
+ }
926
+ return colorAttribute ? 2 : 0;
927
+ }
928
+ function writeUint64Fallback(dataView, byteOffset, value) {
929
+ dataView.setUint32(byteOffset, value >>> 0, true);
930
+ dataView.setUint32(byteOffset + 4, Math.floor(value / 2 ** 32), true);
931
+ }
932
+ function writeString(dataView, byteOffset, text, byteLength) {
933
+ if (/[^\x00-\x7f]/.test(text)) {
934
+ throw new Error("LASWriter fixed-width text must be ASCII");
935
+ }
936
+ for (let characterIndex = 0; characterIndex < byteLength; characterIndex++) {
937
+ dataView.setUint8(byteOffset + characterIndex, text.charCodeAt(characterIndex) || 0);
938
+ }
939
+ }
940
+ function getComponent(attribute, vertexIndex, componentIndex) {
941
+ return attribute ? attribute.value[vertexIndex * attribute.size + componentIndex] || 0 : 0;
942
+ }
943
+ function getUInt16Attribute(attribute, vertexIndex) {
944
+ return attribute ? Math.max(0, Math.min(65535, Math.round(getComponent(attribute, vertexIndex, 0)))) : 0;
945
+ }
946
+ function getUInt32Attribute(attribute, vertexIndex) {
947
+ return attribute ? Math.max(0, Math.min(4294967295, Math.round(getComponent(attribute, vertexIndex, 0)))) : 0;
948
+ }
949
+ function getBigUint64Attribute(attribute, vertexIndex) {
950
+ if (!attribute) {
951
+ return 0n;
952
+ }
953
+ const value = attribute.value[vertexIndex * attribute.size];
954
+ return typeof value === "bigint" ? value : BigInt(Math.max(0, Math.round(Number(value))));
955
+ }
956
+ function getUInt8Attribute(attribute, vertexIndex, defaultValue = 0) {
957
+ return attribute ? Math.max(0, Math.min(255, Math.round(getComponent(attribute, vertexIndex, 0)))) : defaultValue;
958
+ }
959
+ function getInt16Attribute(attribute, vertexIndex) {
960
+ return attribute ? Math.max(-32768, Math.min(32767, Math.round(getComponent(attribute, vertexIndex, 0)))) : 0;
961
+ }
962
+ function getAttributeValue(attribute, vertexIndex) {
963
+ return attribute ? getComponent(attribute, vertexIndex, 0) : 0;
964
+ }
965
+ function getBooleanAttribute(attribute, vertexIndex) {
966
+ return Boolean(getAttributeValue(attribute, vertexIndex));
967
+ }
968
+ function getReturnCounts(returnNumberAttribute, vertexCount) {
969
+ const returnCounts = new Array(LAS_RETURN_BUCKET_COUNT).fill(0);
970
+ for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
971
+ const returnNumber = getUInt8Attribute(returnNumberAttribute, vertexIndex, 1) & 15;
972
+ if (returnNumber >= 1 && returnNumber <= LAS_RETURN_BUCKET_COUNT) {
973
+ returnCounts[returnNumber - 1]++;
974
+ }
975
+ }
976
+ return returnCounts;
977
+ }
978
+ function getLASColor(attribute, vertexIndex, componentIndex, colorDepth) {
979
+ const value = getComponent(attribute, vertexIndex, componentIndex);
980
+ if (attribute.normalized) {
981
+ return scaleNormalizedColor(attribute, value);
982
+ }
983
+ if (colorDepth === 8) return clampUInt16(value * 257);
984
+ if (colorDepth === 16) return clampUInt16(value);
985
+ if (value <= 1) {
986
+ return clampUInt16(value * 65535);
987
+ }
988
+ if (value <= 255) {
989
+ return clampUInt16(value * 257);
990
+ }
991
+ return clampUInt16(value);
992
+ }
993
+ function scaleNormalizedColor(attribute, value) {
994
+ const componentMaximum = getComponentMaximum(attribute.value);
995
+ return clampUInt16(value / componentMaximum * 65535);
996
+ }
997
+ function getComponentMaximum(values) {
998
+ if (values instanceof Uint8Array || values instanceof Uint8ClampedArray) {
999
+ return 255;
1000
+ }
1001
+ if (values instanceof Uint16Array) {
1002
+ return 65535;
1003
+ }
1004
+ return 1;
1005
+ }
1006
+ function clampUInt16(value) {
1007
+ return Math.max(0, Math.min(65535, Math.round(value)));
1008
+ }
1009
+ function getBoundingBox(positionAttribute, vertexCount) {
1010
+ if (vertexCount === 0) {
1011
+ return [
1012
+ [0, 0, 0],
1013
+ [0, 0, 0]
1014
+ ];
1015
+ }
1016
+ const minimum = [
1017
+ Number.POSITIVE_INFINITY,
1018
+ Number.POSITIVE_INFINITY,
1019
+ Number.POSITIVE_INFINITY
1020
+ ];
1021
+ const maximum = [
1022
+ Number.NEGATIVE_INFINITY,
1023
+ Number.NEGATIVE_INFINITY,
1024
+ Number.NEGATIVE_INFINITY
1025
+ ];
1026
+ for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
1027
+ for (let componentIndex = 0; componentIndex < 3; componentIndex++) {
1028
+ const value = getComponent(positionAttribute, vertexIndex, componentIndex);
1029
+ minimum[componentIndex] = Math.min(minimum[componentIndex], value);
1030
+ maximum[componentIndex] = Math.max(maximum[componentIndex], value);
1031
+ }
1032
+ }
1033
+ return [minimum, maximum];
1034
+ }
1035
+ function getScale(mesh, options) {
1036
+ return options.las?.scale || getNumericTuple(mesh.schema.metadata?.las_scale) || [1e-3, 1e-3, 1e-3];
1037
+ }
1038
+ function getOffset(mesh, options, boundingBox) {
1039
+ return options.las?.offset || getNumericTuple(mesh.schema.metadata?.las_offset) || boundingBox[0];
1040
+ }
1041
+ function getNumericTuple(value) {
1042
+ if (typeof value !== "string") {
1043
+ return void 0;
1044
+ }
1045
+ try {
1046
+ const parsedValue = JSON.parse(value);
1047
+ return Array.isArray(parsedValue) && parsedValue.length === 3 && parsedValue.every((component) => typeof component === "number") ? [parsedValue[0], parsedValue[1], parsedValue[2]] : void 0;
1048
+ } catch {
1049
+ return void 0;
1050
+ }
1051
+ }
1052
+ // Annotate the CommonJS export names for ESM import in node:
1053
+ 0 && (module.exports = {
1054
+ LASWriter
1055
+ });
1056
+ //# sourceMappingURL=las-writer.cjs.map