gltfexport-6ZX4IV4P.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. import {
  2. g,
  3. i,
  4. o as o3,
  5. s
  6. } from "./chunk-DO7VQYJK.js";
  7. import {
  8. c
  9. } from "./chunk-7NPG47AN.js";
  10. import {
  11. C,
  12. D
  13. } from "./chunk-MI7HWWFL.js";
  14. import {
  15. P
  16. } from "./chunk-2ADIR7NB.js";
  17. import "./chunk-4KFEVYXL.js";
  18. import {
  19. K,
  20. k
  21. } from "./chunk-5W6F4NR5.js";
  22. import {
  23. e as e2,
  24. o as o2,
  25. r as r3
  26. } from "./chunk-YZUP3MAF.js";
  27. import "./chunk-E3HOL2XO.js";
  28. import "./chunk-SCXOTZ6Q.js";
  29. import "./chunk-H4JLO5B2.js";
  30. import "./chunk-5JK4DCPE.js";
  31. import "./chunk-CRGVDJI6.js";
  32. import "./chunk-DH2OBAUC.js";
  33. import "./chunk-TNLRDNTC.js";
  34. import "./chunk-6P6NA7JB.js";
  35. import "./chunk-7XXXCK2A.js";
  36. import "./chunk-65BYCSII.js";
  37. import "./chunk-TERAW6FT.js";
  38. import "./chunk-N2663GRX.js";
  39. import "./chunk-O4FY3ITT.js";
  40. import "./chunk-JXW4QTJA.js";
  41. import {
  42. F as F2,
  43. _,
  44. e,
  45. o,
  46. z
  47. } from "./chunk-XNLG7T2T.js";
  48. import {
  49. f,
  50. l,
  51. n,
  52. t as t2
  53. } from "./chunk-IR4PV7VK.js";
  54. import "./chunk-OWVBLVP3.js";
  55. import "./chunk-MXB2XLKV.js";
  56. import "./chunk-HNOZUNJ4.js";
  57. import "./chunk-VNFRAYHO.js";
  58. import "./chunk-R5IG2D6H.js";
  59. import {
  60. it
  61. } from "./chunk-VBRY5KJM.js";
  62. import "./chunk-PDKDCAAD.js";
  63. import {
  64. j2 as j
  65. } from "./chunk-ECW2QABR.js";
  66. import "./chunk-GCDJLKH4.js";
  67. import "./chunk-MRJEICT6.js";
  68. import "./chunk-Y3WMVFTW.js";
  69. import "./chunk-SAS7RONY.js";
  70. import "./chunk-WSRBH7BF.js";
  71. import {
  72. r as r2
  73. } from "./chunk-IHXECKQQ.js";
  74. import {
  75. E
  76. } from "./chunk-ULGDPLM2.js";
  77. import "./chunk-EMJ4ZSM2.js";
  78. import "./chunk-IKP3YN53.js";
  79. import {
  80. F,
  81. r,
  82. t
  83. } from "./chunk-GZT4BVFP.js";
  84. import "./chunk-A5ICIBVI.js";
  85. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/glb.js
  86. var t3;
  87. !function(t4) {
  88. t4[t4.JSON = 1313821514] = "JSON", t4[t4.BIN = 5130562] = "BIN";
  89. }(t3 || (t3 = {}));
  90. var e3 = class {
  91. constructor(i3, r6) {
  92. if (!i3)
  93. throw new Error("GLB requires a JSON gltf chunk");
  94. this.length = e3.HEADER_SIZE, this.length += e3.CHUNK_HEADER_SIZE;
  95. const n2 = this._textToArrayBuffer(i3);
  96. if (this.length += this._alignTo(n2.byteLength, 4), r6 && (this.length += e3.CHUNK_HEADER_SIZE, this.length += r6.byteLength, r6.byteLength % 4))
  97. throw new Error("Expected BIN chunk length to be divisible by 4 at this point");
  98. this.buffer = new ArrayBuffer(this.length), this.outView = new DataView(this.buffer), this._writeHeader();
  99. const h2 = this._writeChunk(n2, 12, t3.JSON, 32);
  100. r6 && this._writeChunk(r6, h2, t3.BIN);
  101. }
  102. _writeHeader() {
  103. this.outView.setUint32(0, e3.MAGIC, true), this.outView.setUint32(4, e3.VERSION, true), this.outView.setUint32(8, this.length, true);
  104. }
  105. _writeChunk(t4, e4, i3, r6 = 0) {
  106. const n2 = this._alignTo(t4.byteLength, 4);
  107. for (this.outView.setUint32(e4, n2, true), this.outView.setUint32(e4 += 4, i3, true), this._writeArrayBuffer(this.outView.buffer, t4, e4 += 4, 0, t4.byteLength), e4 += t4.byteLength; e4 % 4; )
  108. r6 && this.outView.setUint8(e4, r6), e4++;
  109. return e4;
  110. }
  111. _writeArrayBuffer(t4, e4, i3, r6, n2) {
  112. new Uint8Array(t4, i3, n2).set(new Uint8Array(e4, r6, n2), 0);
  113. }
  114. _textToArrayBuffer(t4) {
  115. return new TextEncoder().encode(t4).buffer;
  116. }
  117. _alignTo(t4, e4) {
  118. return e4 * Math.ceil(t4 / e4);
  119. }
  120. };
  121. e3.HEADER_SIZE = 12, e3.CHUNK_HEADER_SIZE = 8, e3.MAGIC = 1179937895, e3.VERSION = 2;
  122. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/types.js
  123. var E2;
  124. var A;
  125. var R;
  126. var L;
  127. var o4;
  128. var I;
  129. var N;
  130. !function(E3) {
  131. E3[E3.External = 0] = "External", E3[E3.DataURI = 1] = "DataURI", E3[E3.GLB = 2] = "GLB";
  132. }(E2 || (E2 = {})), function(E3) {
  133. E3[E3.External = 0] = "External", E3[E3.DataURI = 1] = "DataURI", E3[E3.GLB = 2] = "GLB";
  134. }(A || (A = {})), function(E3) {
  135. E3[E3.ARRAY_BUFFER = 34962] = "ARRAY_BUFFER", E3[E3.ELEMENT_ARRAY_BUFFER = 34963] = "ELEMENT_ARRAY_BUFFER";
  136. }(R || (R = {})), function(E3) {
  137. E3.SCALAR = "SCALAR", E3.VEC2 = "VEC2", E3.VEC3 = "VEC3", E3.VEC4 = "VEC4", E3.MAT2 = "MAT2", E3.MAT3 = "MAT3", E3.MAT4 = "MAT4";
  138. }(L || (L = {})), function(E3) {
  139. E3[E3.POINTS = 0] = "POINTS", E3[E3.LINES = 1] = "LINES", E3[E3.LINE_LOOP = 2] = "LINE_LOOP", E3[E3.LINE_STRIP = 3] = "LINE_STRIP", E3[E3.TRIANGLES = 4] = "TRIANGLES", E3[E3.TRIANGLE_STRIP = 5] = "TRIANGLE_STRIP", E3[E3.TRIANGLE_FAN = 6] = "TRIANGLE_FAN";
  140. }(o4 || (o4 = {})), function(E3) {
  141. E3.OPAQUE = "OPAQUE", E3.MASK = "MASK", E3.BLEND = "BLEND";
  142. }(I || (I = {})), function(E3) {
  143. E3[E3.NoColor = 0] = "NoColor", E3[E3.FaceColor = 1] = "FaceColor", E3[E3.VertexColor = 2] = "VertexColor";
  144. }(N || (N = {}));
  145. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/bufferview.js
  146. var r4 = class {
  147. constructor(e4, s4, i3, r6, n2) {
  148. this.buffer = e4, this.componentType = i3, this.dataType = r6, this.data = [], this.isFinalized = false, this.accessorIndex = -1, this.accessorAttribute = null, this.accessorMin = null, this.accessorMax = null, s4.bufferViews || (s4.bufferViews = []), this.index = s4.bufferViews.length, this.bufferView = { buffer: e4.index, byteLength: -1, target: n2 };
  149. const a2 = this._getElementSize();
  150. a2 >= 4 && n2 !== R.ELEMENT_ARRAY_BUFFER && (this.bufferView.byteStride = a2), s4.bufferViews.push(this.bufferView), this.numComponentsForDataType = this._calculateNumComponentsForDataType();
  151. }
  152. push(e4) {
  153. const t4 = this.data.length;
  154. if (this.data.push(e4), this.accessorIndex >= 0) {
  155. const s4 = t4 % this.numComponentsForDataType, i3 = this.accessorMin[s4];
  156. this.accessorMin[s4] = typeof i3 != "number" ? e4 : Math.min(i3, e4);
  157. const r6 = this.accessorMax[s4];
  158. this.accessorMax[s4] = typeof r6 != "number" ? e4 : Math.max(r6, e4);
  159. }
  160. }
  161. get dataSize() {
  162. return this.data.length * this._sizeComponentType();
  163. }
  164. get byteSize() {
  165. function e4(e5, t4) {
  166. return t4 * Math.ceil(e5 / t4);
  167. }
  168. return e4(this.dataSize, 4);
  169. }
  170. getByteOffset() {
  171. if (!this.isFinalized)
  172. throw new Error("Cannot get BufferView offset until it is finalized");
  173. return this.buffer.getByteOffset(this);
  174. }
  175. get byteOffset() {
  176. if (!this.isFinalized)
  177. throw new Error("Cannot get BufferView offset until it is finalized");
  178. return this.buffer.getByteOffset(this);
  179. }
  180. _createTypedArray(e4, t4) {
  181. switch (this.componentType) {
  182. case C.BYTE:
  183. return new Int8Array(e4, t4);
  184. case C.FLOAT:
  185. return new Float32Array(e4, t4);
  186. case C.SHORT:
  187. return new Int16Array(e4, t4);
  188. case C.UNSIGNED_BYTE:
  189. return new Uint8Array(e4, t4);
  190. case C.UNSIGNED_INT:
  191. return new Uint32Array(e4, t4);
  192. case C.UNSIGNED_SHORT:
  193. return new Uint16Array(e4, t4);
  194. }
  195. }
  196. writeOutToBuffer(e4, t4) {
  197. this._createTypedArray(e4, t4).set(this.data);
  198. }
  199. writeAsync(e4) {
  200. if (this.asyncWritePromise)
  201. throw new Error("Can't write multiple bufferView values asynchronously");
  202. return this.asyncWritePromise = e4.then((e5) => {
  203. const t4 = new Uint8Array(e5);
  204. for (let s4 = 0; s4 < t4.length; ++s4)
  205. this.data.push(t4[s4]);
  206. delete this.asyncWritePromise;
  207. }), this.asyncWritePromise;
  208. }
  209. startAccessor(e4) {
  210. if (this.accessorIndex >= 0)
  211. throw new Error("Accessor was started without ending the previous one");
  212. this.accessorIndex = this.data.length, this.accessorAttribute = e4;
  213. const t4 = this.numComponentsForDataType;
  214. this.accessorMin = new Array(t4), this.accessorMax = new Array(t4);
  215. }
  216. endAccessor() {
  217. if (this.accessorIndex < 0)
  218. throw new Error("An accessor was not started, but was attempted to be ended");
  219. const e4 = this._getElementSize(), t4 = this.numComponentsForDataType, s4 = (this.data.length - this.accessorIndex) / t4;
  220. if (s4 % 1)
  221. throw new Error("An accessor was ended with missing component values");
  222. for (let i3 = 0; i3 < this.accessorMin.length; ++i3)
  223. typeof this.accessorMin[i3] != "number" && (this.accessorMin[i3] = 0), typeof this.accessorMax[i3] != "number" && (this.accessorMax[i3] = 0);
  224. const r6 = { byteOffset: e4 * (this.accessorIndex / t4), componentType: this.componentType, count: s4, type: this.dataType, min: this.accessorMin, max: this.accessorMax, name: this.accessorAttribute };
  225. switch (this.accessorAttribute) {
  226. case "TEXCOORD_0":
  227. case "TEXCOORD_1":
  228. case "COLOR_0":
  229. case "WEIGHTS_0":
  230. switch (this.componentType) {
  231. case C.UNSIGNED_BYTE:
  232. case C.UNSIGNED_SHORT:
  233. r6.normalized = true;
  234. }
  235. }
  236. return this.accessorIndex = -1, this.accessorAttribute = null, this.accessorMin = null, this.accessorMax = null, r6;
  237. }
  238. get finalized() {
  239. return this.finalizedPromise ? this.finalizedPromise : this.isFinalized ? this.finalizedPromise = Promise.resolve() : this.finalizedPromise = new Promise((e4) => this.finalizedPromiseResolve = e4);
  240. }
  241. finalize() {
  242. const t4 = this.bufferView;
  243. return new Promise((t5) => {
  244. const s4 = this.buffer.getViewFinalizePromises(this);
  245. this.asyncWritePromise && s4.push(this.asyncWritePromise), t5(E(s4));
  246. }).then(() => {
  247. this.isFinalized = true, t4.byteOffset = this.getByteOffset(), t4.byteLength = this.dataSize, this.finalizedPromiseResolve && this.finalizedPromiseResolve();
  248. });
  249. }
  250. _getElementSize() {
  251. return this._sizeComponentType() * this.numComponentsForDataType;
  252. }
  253. _sizeComponentType() {
  254. switch (this.componentType) {
  255. case C.BYTE:
  256. case C.UNSIGNED_BYTE:
  257. return 1;
  258. case C.SHORT:
  259. case C.UNSIGNED_SHORT:
  260. return 2;
  261. case C.UNSIGNED_INT:
  262. case C.FLOAT:
  263. return 4;
  264. }
  265. }
  266. _calculateNumComponentsForDataType() {
  267. switch (this.dataType) {
  268. case L.SCALAR:
  269. return 1;
  270. case L.VEC2:
  271. return 2;
  272. case L.VEC3:
  273. return 3;
  274. case L.VEC4:
  275. case L.MAT2:
  276. return 4;
  277. case L.MAT3:
  278. return 9;
  279. case L.MAT4:
  280. return 16;
  281. }
  282. }
  283. };
  284. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/buffer.js
  285. var r5 = class {
  286. constructor(e4) {
  287. this.gltf = e4, this.bufferViews = [], this.isFinalized = false, e4.buffers || (e4.buffers = []), this.index = e4.buffers.length;
  288. const i3 = { byteLength: -1 };
  289. e4.buffers.push(i3), this.buffer = i3;
  290. }
  291. addBufferView(e4, r6, t4) {
  292. if (this.finalizePromise)
  293. throw new Error("Cannot add buffer view after fiinalizing buffer");
  294. const f5 = new r4(this, this.gltf, e4, r6, t4);
  295. return this.bufferViews.push(f5), f5;
  296. }
  297. getByteOffset(e4) {
  298. let i3 = 0;
  299. for (const r6 of this.bufferViews) {
  300. if (r6 === e4)
  301. return i3;
  302. i3 += r6.byteSize;
  303. }
  304. throw new Error("Given bufferView was not present in this buffer");
  305. }
  306. getViewFinalizePromises(e4) {
  307. const i3 = [];
  308. for (const r6 of this.bufferViews) {
  309. if (e4 && r6 === e4)
  310. return i3;
  311. i3.push(r6.finalized);
  312. }
  313. return i3;
  314. }
  315. getArrayBuffer() {
  316. if (!this.isFinalized)
  317. throw new Error("Cannot get ArrayBuffer from Buffer before it is finalized");
  318. const e4 = this._getTotalSize(), i3 = new ArrayBuffer(e4);
  319. let r6 = 0;
  320. for (const t4 of this.bufferViews)
  321. t4.writeOutToBuffer(i3, r6), r6 += t4.byteSize;
  322. return i3;
  323. }
  324. finalize() {
  325. if (this.finalizePromise)
  326. throw new Error(`Buffer ${this.index} was already finalized`);
  327. return this.finalizePromise = new Promise((i3) => {
  328. i3(E(this.getViewFinalizePromises()));
  329. }).then(() => {
  330. this.isFinalized = true;
  331. const e4 = this.getArrayBuffer();
  332. this.buffer.byteLength = e4.byteLength, this.buffer.uri = e4;
  333. }), this.gltf.extras.promises.push(this.finalizePromise), this.finalizePromise;
  334. }
  335. _getTotalSize() {
  336. let e4 = 0;
  337. for (const i3 of this.bufferViews)
  338. e4 += i3.byteSize;
  339. return e4;
  340. }
  341. };
  342. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/geometry.js
  343. function f2(t4, n2) {
  344. if (t4.components)
  345. for (const e4 of t4.components)
  346. e4.faces && e4.shading === "smooth" && c2(e4, n2);
  347. }
  348. function c2(n2, a2) {
  349. t(a2.normal) && (a2.normal = new Float32Array(a2.position.length));
  350. const i3 = n2.faces, { position: f5, normal: c3 } = a2, m3 = i3.length / 3;
  351. for (let t4 = 0; t4 < m3; ++t4) {
  352. const n3 = 3 * i3[3 * t4 + 0], s4 = 3 * i3[3 * t4 + 1], a3 = 3 * i3[3 * t4 + 2], m4 = o(l2, f5[n3 + 0], f5[n3 + 1], f5[n3 + 2]), h2 = o(p, f5[s4 + 0], f5[s4 + 1], f5[s4 + 2]), g2 = o(x, f5[a3 + 0], f5[a3 + 1], f5[a3 + 2]), u = e(h2, h2, m4), j2 = e(g2, g2, m4), y = _(u, u, j2);
  353. c3[n3 + 0] += y[0], c3[n3 + 1] += y[1], c3[n3 + 2] += y[2], c3[s4 + 0] += y[0], c3[s4 + 1] += y[1], c3[s4 + 2] += y[2], c3[a3 + 0] += y[0], c3[a3 + 1] += y[1], c3[a3 + 2] += y[2];
  354. }
  355. for (let t4 = 0; t4 < c3.length; t4 += 3)
  356. o(h, c3[t4], c3[t4 + 1], c3[t4 + 2]), z(h, h), c3[t4 + 0] = h[0], c3[t4 + 1] = h[1], c3[t4 + 2] = h[2];
  357. }
  358. function m(t4) {
  359. if (r(t4.transform))
  360. return t4.transform.getOriginPoint(t4.spatialReference);
  361. const e4 = t4.extent.xmax - t4.extent.width / 2, o5 = t4.extent.ymax - t4.extent.height / 2, r6 = t4.extent.zmin;
  362. return new j({ x: e4, y: o5, z: r6, spatialReference: t4.extent.spatialReference });
  363. }
  364. var l2 = n();
  365. var p = n();
  366. var x = n();
  367. var h = n();
  368. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/gltf.js
  369. var M = class {
  370. constructor(e4, t4, s4) {
  371. this.params = {}, this.materialMap = new Array(), this.imageMap = new Map(), this.textureMap = new Map(), this.gltf = { asset: { version: "2.0", copyright: e4.copyright, generator: e4.generator }, extras: { options: t4, binChunkBuffer: null, promises: [] } }, s4 && (this.params = s4), this._addScenes(e4);
  372. }
  373. _addScenes(e4) {
  374. this.gltf.scene = e4.defaultScene;
  375. const t4 = this.gltf.extras.options.bufferOutputType === E2.GLB || this.gltf.extras.options.imageOutputType === A.GLB;
  376. t4 && (this.gltf.extras.binChunkBuffer = new r5(this.gltf)), e4.forEachScene((e5) => {
  377. this._addScene(e5);
  378. }), t4 && this.gltf.extras.binChunkBuffer.finalize();
  379. }
  380. _addScene(e4) {
  381. this.gltf.scenes || (this.gltf.scenes = []);
  382. const t4 = {};
  383. e4.name && (t4.name = e4.name), e4.forEachNode((e5) => {
  384. t4.nodes || (t4.nodes = []);
  385. const s4 = this._addNode(e5);
  386. t4.nodes.push(s4);
  387. }), this.gltf.scenes.push(t4);
  388. }
  389. _addNode(e4) {
  390. this.gltf.nodes || (this.gltf.nodes = []);
  391. const t4 = {};
  392. e4.name && (t4.name = e4.name);
  393. const s4 = e4.translation;
  394. F2(s4, f) || (t4.translation = t2(s4));
  395. const c3 = e4.rotation;
  396. K(c3, o2) || (t4.rotation = r3(c3));
  397. const u = e4.scale;
  398. F2(u, l) || (t4.scale = t2(u)), e4.mesh && e4.mesh.vertexAttributes.position ? t4.mesh = this._addMesh(e4.mesh) : e4.forEachNode((e5) => {
  399. t4.children || (t4.children = []);
  400. const s5 = this._addNode(e5);
  401. t4.children.push(s5);
  402. });
  403. const f5 = this.gltf.nodes.length;
  404. return this.gltf.nodes.push(t4), f5;
  405. }
  406. _addMesh(e4) {
  407. this.gltf.meshes || (this.gltf.meshes = []);
  408. const s4 = { primitives: [] }, i3 = this.gltf.extras.options.bufferOutputType === E2.GLB;
  409. let r6;
  410. r6 = i3 ? this.gltf.extras.binChunkBuffer : new r5(this.gltf), this.params.origin || (this.params.origin = m(e4));
  411. const a2 = P(e4.vertexAttributes, e4.transform, this.params.origin, { geographic: this.params.geographic, unit: "meters" });
  412. f2(e4, a2), this._flipYZAxis(a2);
  413. const o5 = r6.addBufferView(C.FLOAT, L.VEC3, R.ARRAY_BUFFER);
  414. let n2, l3, h2, c3;
  415. a2.normal && (n2 = r6.addBufferView(C.FLOAT, L.VEC3, R.ARRAY_BUFFER)), e4.vertexAttributes.uv && (l3 = r6.addBufferView(C.FLOAT, L.VEC2, R.ARRAY_BUFFER)), a2.tangent && (h2 = r6.addBufferView(C.FLOAT, L.VEC4, R.ARRAY_BUFFER)), e4.vertexAttributes.color && (c3 = r6.addBufferView(C.UNSIGNED_BYTE, L.VEC4, R.ARRAY_BUFFER)), o5.startAccessor("POSITION"), n2 && n2.startAccessor("NORMAL"), l3 && l3.startAccessor("TEXCOORD_0"), h2 && h2.startAccessor("TANGENT"), c3 && c3.startAccessor("COLOR_0");
  416. const g2 = a2.position.length / 3, { position: A2, normal: R2, tangent: T } = a2, { color: b, uv: M2 } = e4.vertexAttributes;
  417. for (let u = 0; u < g2; ++u)
  418. o5.push(A2[3 * u + 0]), o5.push(A2[3 * u + 1]), o5.push(A2[3 * u + 2]), n2 && r(R2) && (n2.push(R2[3 * u + 0]), n2.push(R2[3 * u + 1]), n2.push(R2[3 * u + 2])), l3 && r(M2) && (l3.push(M2[2 * u + 0]), l3.push(M2[2 * u + 1])), h2 && r(T) && (h2.push(T[4 * u + 0]), h2.push(T[4 * u + 1]), h2.push(T[4 * u + 2]), h2.push(T[4 * u + 3])), c3 && r(b) && (c3.push(b[4 * u + 0]), c3.push(b[4 * u + 1]), c3.push(b[4 * u + 2]), c3.push(b[4 * u + 3]));
  419. const O = o5.endAccessor(), N2 = this._addAccessor(o5.index, O);
  420. let C2, B, w, y, I2;
  421. if (n2) {
  422. const e5 = n2.endAccessor();
  423. C2 = this._addAccessor(n2.index, e5);
  424. }
  425. if (l3) {
  426. const e5 = l3.endAccessor();
  427. B = this._addAccessor(l3.index, e5);
  428. }
  429. if (h2) {
  430. const e5 = h2.endAccessor();
  431. w = this._addAccessor(h2.index, e5);
  432. }
  433. if (c3) {
  434. const e5 = c3.endAccessor();
  435. y = this._addAccessor(c3.index, e5);
  436. }
  437. e4.components && e4.components.length > 0 && e4.components[0].faces ? (I2 = r6.addBufferView(C.UNSIGNED_INT, L.SCALAR, R.ELEMENT_ARRAY_BUFFER), this._addMeshVertexIndexed(I2, e4.components, s4, N2, C2, B, w, y)) : this._addMeshVertexNonIndexed(e4.components, s4, N2, C2, B, w, y), o5.finalize(), n2 && n2.finalize(), l3 && l3.finalize(), h2 && h2.finalize(), I2 && I2.finalize(), c3 && c3.finalize(), i3 || r6.finalize();
  438. const S = this.gltf.meshes.length;
  439. return this.gltf.meshes.push(s4), S;
  440. }
  441. _flipYZAxis({ position: e4, normal: t4, tangent: s4 }) {
  442. this._flipYZBuffer(e4, 3), this._flipYZBuffer(t4, 3), this._flipYZBuffer(s4, 4);
  443. }
  444. _flipYZBuffer(e4, t4) {
  445. if (!t(e4))
  446. for (let s4 = 1, i3 = 2; s4 < e4.length; s4 += t4, i3 += t4) {
  447. const t5 = e4[s4], r6 = e4[i3];
  448. e4[s4] = r6, e4[i3] = -t5;
  449. }
  450. }
  451. _addMaterial(e4) {
  452. if (e4 === null)
  453. return;
  454. const s4 = this.materialMap.indexOf(e4);
  455. if (s4 !== -1)
  456. return s4;
  457. this.gltf.materials || (this.gltf.materials = []);
  458. const i3 = {};
  459. switch (e4.alphaMode) {
  460. case "mask":
  461. i3.alphaMode = I.MASK;
  462. break;
  463. case "auto":
  464. case "blend":
  465. i3.alphaMode = I.BLEND;
  466. }
  467. e4.alphaCutoff !== 0.5 && (i3.alphaCutoff = e4.alphaCutoff), e4.doubleSided && (i3.doubleSided = e4.doubleSided), i3.pbrMetallicRoughness = {};
  468. const r6 = (e5) => e5 ** 2.1, a2 = (e5) => {
  469. const t4 = e5.toRgba();
  470. return t4[0] = r6(t4[0] / 255), t4[1] = r6(t4[1] / 255), t4[2] = r6(t4[2] / 255), t4;
  471. };
  472. if (r(e4.color) && (i3.pbrMetallicRoughness.baseColorFactor = a2(e4.color)), r(e4.colorTexture) && (i3.pbrMetallicRoughness.baseColorTexture = { index: this._addTexture(e4.colorTexture) }), r(e4.normalTexture) && (i3.normalTexture = { index: this._addTexture(e4.normalTexture) }), e4 instanceof c) {
  473. if (r(e4.emissiveTexture) && (i3.emissiveTexture = { index: this._addTexture(e4.emissiveTexture) }), r(e4.emissiveColor)) {
  474. const t4 = a2(e4.emissiveColor);
  475. i3.emissiveFactor = [t4[0], t4[1], t4[2]];
  476. }
  477. r(e4.occlusionTexture) && (i3.occlusionTexture = { index: this._addTexture(e4.occlusionTexture) }), r(e4.metallicRoughnessTexture) && (i3.pbrMetallicRoughness.metallicRoughnessTexture = { index: this._addTexture(e4.metallicRoughnessTexture) }), i3.pbrMetallicRoughness.metallicFactor = e4.metallic, i3.pbrMetallicRoughness.roughnessFactor = e4.roughness;
  478. } else
  479. i3.pbrMetallicRoughness.metallicFactor = 1, i3.pbrMetallicRoughness.roughnessFactor = 1;
  480. const o5 = this.gltf.materials.length;
  481. return this.gltf.materials.push(i3), this.materialMap.push(e4), o5;
  482. }
  483. _addTexture(t4) {
  484. return this.gltf.textures || (this.gltf.textures = []), r2(this.textureMap, t4, () => {
  485. const e4 = { sampler: this._addSampler(t4), source: this._addImage(t4) }, s4 = this.gltf.textures.length;
  486. return this.gltf.textures.push(e4), s4;
  487. });
  488. }
  489. _addImage(e4) {
  490. const t4 = this.imageMap.get(e4);
  491. if (t4 != null)
  492. return t4;
  493. this.gltf.images || (this.gltf.images = []);
  494. const s4 = {};
  495. if (e4.url)
  496. s4.uri = e4.url;
  497. else {
  498. s4.extras = e4.data;
  499. for (let t5 = 0; t5 < this.gltf.images.length; ++t5)
  500. if (e4.data === this.gltf.images[t5].extras)
  501. return t5;
  502. switch (this.gltf.extras.options.imageOutputType) {
  503. case A.GLB: {
  504. const t5 = this.gltf.extras.binChunkBuffer.addBufferView(C.UNSIGNED_BYTE, L.SCALAR), i4 = o3(e4.data).then(({ data: e5, type: t6 }) => (s4.mimeType = t6, e5));
  505. t5.writeAsync(i4).then(() => {
  506. t5.finalize();
  507. }), s4.bufferView = t5.index;
  508. break;
  509. }
  510. case A.DataURI:
  511. s4.uri = i(e4.data);
  512. break;
  513. default:
  514. this.gltf.extras.promises.push(o3(e4.data).then(({ data: e5, type: t5 }) => {
  515. s4.uri = e5, s4.mimeType = t5;
  516. }));
  517. }
  518. }
  519. const i3 = this.gltf.images.length;
  520. return this.gltf.images.push(s4), this.imageMap.set(e4, i3), i3;
  521. }
  522. _addSampler(e4) {
  523. this.gltf.samplers || (this.gltf.samplers = []);
  524. let t4 = D.REPEAT, s4 = D.REPEAT;
  525. if (typeof e4.wrap == "string")
  526. switch (e4.wrap) {
  527. case "clamp":
  528. t4 = D.CLAMP_TO_EDGE, s4 = D.CLAMP_TO_EDGE;
  529. break;
  530. case "mirror":
  531. t4 = D.MIRRORED_REPEAT, s4 = D.MIRRORED_REPEAT;
  532. }
  533. else {
  534. switch (e4.wrap.vertical) {
  535. case "clamp":
  536. s4 = D.CLAMP_TO_EDGE;
  537. break;
  538. case "mirror":
  539. s4 = D.MIRRORED_REPEAT;
  540. }
  541. switch (e4.wrap.horizontal) {
  542. case "clamp":
  543. t4 = D.CLAMP_TO_EDGE;
  544. break;
  545. case "mirror":
  546. t4 = D.MIRRORED_REPEAT;
  547. }
  548. }
  549. const i3 = { wrapS: t4, wrapT: s4 };
  550. for (let a2 = 0; a2 < this.gltf.samplers.length; ++a2)
  551. if (JSON.stringify(i3) === JSON.stringify(this.gltf.samplers[a2]))
  552. return a2;
  553. const r6 = this.gltf.samplers.length;
  554. return this.gltf.samplers.push(i3), r6;
  555. }
  556. _addAccessor(e4, t4) {
  557. this.gltf.accessors || (this.gltf.accessors = []);
  558. const s4 = { bufferView: e4, byteOffset: t4.byteOffset, componentType: t4.componentType, count: t4.count, type: t4.type, min: t4.min, max: t4.max, name: t4.name };
  559. t4.normalized && (s4.normalized = true);
  560. const i3 = this.gltf.accessors.length;
  561. return this.gltf.accessors.push(s4), i3;
  562. }
  563. _addMeshVertexIndexed(e4, t4, s4, i3, r6, a2, o5, n2) {
  564. for (const l3 of t4) {
  565. e4.startAccessor("INDICES");
  566. for (let s5 = 0; s5 < l3.faces.length; ++s5)
  567. e4.push(l3.faces[s5]);
  568. const t5 = e4.endAccessor(), h2 = { attributes: { POSITION: i3 }, indices: this._addAccessor(e4.index, t5), material: this._addMaterial(l3.material) };
  569. r6 && l3.shading !== "flat" && (h2.attributes.NORMAL = r6), a2 && (h2.attributes.TEXCOORD_0 = a2), o5 && l3.shading !== "flat" && (h2.attributes.TANGENT = o5), n2 && (h2.attributes.COLOR_0 = n2), s4.primitives.push(h2);
  570. }
  571. }
  572. _addMeshVertexNonIndexed(e4, t4, s4, i3, r6, a2, o5) {
  573. const n2 = { attributes: { POSITION: s4 } };
  574. i3 && (n2.attributes.NORMAL = i3), r6 && (n2.attributes.TEXCOORD_0 = r6), a2 && (n2.attributes.TANGENT = a2), o5 && (n2.attributes.COLOR_0 = o5), e4 && (n2.material = this._addMaterial(e4[0].material)), t4.primitives.push(n2);
  575. }
  576. };
  577. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/asset.js
  578. var s2 = class {
  579. constructor() {
  580. this.copyright = "", this.defaultScene = 0, this.generator = "", this._scenes = [];
  581. }
  582. addScene(e4) {
  583. if (this._scenes.includes(e4))
  584. throw new Error("Scene already added");
  585. this._scenes.push(e4);
  586. }
  587. removeScene(s4) {
  588. F(this._scenes, s4);
  589. }
  590. forEachScene(e4) {
  591. this._scenes.forEach(e4);
  592. }
  593. };
  594. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/scene.js
  595. var d = class {
  596. constructor() {
  597. this.name = "", this._nodes = [];
  598. }
  599. addNode(d2) {
  600. if (this._nodes.includes(d2))
  601. throw new Error("Node already added");
  602. this._nodes.push(d2);
  603. }
  604. forEachNode(d2) {
  605. this._nodes.forEach(d2);
  606. }
  607. };
  608. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/node.js
  609. var i2 = class {
  610. constructor(s4) {
  611. this.mesh = s4, this.name = "", this.translation = n(), this.rotation = e2(), this.scale = t2(l), this._nodes = [];
  612. }
  613. addNode(s4) {
  614. if (this._nodes.includes(s4))
  615. throw new Error("Node already added");
  616. this._nodes.push(s4);
  617. }
  618. forEachNode(s4) {
  619. this._nodes.forEach(s4);
  620. }
  621. set rotationAngles(t4) {
  622. k(this.rotation, t4[0], t4[1], t4[2]);
  623. }
  624. };
  625. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/index.js
  626. var f3 = "model.gltf";
  627. var p2 = "model.glb";
  628. function a(a2, m3, c3) {
  629. const l3 = new M(a2, m3 = m3 || {}, c3);
  630. let g2 = l3.params;
  631. g2 ? g2.origin || (g2.origin = new j({ x: -1, y: -1, z: -1 })) : g2 = { origin: new j({ x: -1, y: -1, z: -1 }) };
  632. const y = g2.origin, d2 = l3.gltf, j2 = d2.extras.promises;
  633. let x2 = 1, b = 1, B = null;
  634. return E(j2).then(() => {
  635. const e4 = { origin: y };
  636. delete d2.extras;
  637. const t4 = typeof m3.jsonSpacing == "number" ? m3.jsonSpacing : 4, o5 = JSON.stringify(d2, (t5, r6) => {
  638. if (t5 !== "extras") {
  639. if (r6 instanceof ArrayBuffer) {
  640. if (g(r6))
  641. switch (m3.imageOutputType) {
  642. case A.DataURI:
  643. case A.GLB:
  644. break;
  645. case A.External:
  646. default: {
  647. const t6 = `img${b}.png`;
  648. return b++, e4[t6] = r6, t6;
  649. }
  650. }
  651. switch (m3.bufferOutputType) {
  652. case E2.DataURI:
  653. return s(r6);
  654. case E2.GLB:
  655. if (B)
  656. throw new Error("Already encountered an ArrayBuffer, there should only be one in the GLB format.");
  657. return void (B = r6);
  658. case E2.External:
  659. default: {
  660. const t6 = `data${x2}.bin`;
  661. return x2++, e4[t6] = r6, t6;
  662. }
  663. }
  664. }
  665. return r6;
  666. }
  667. }, t4);
  668. return m3.bufferOutputType === E2.GLB || m3.imageOutputType === A.GLB ? e4[p2] = new e3(o5, B).buffer : e4[f3] = o5, e4;
  669. });
  670. }
  671. function m2(e4, t4) {
  672. return a(e4, { bufferOutputType: E2.GLB, imageOutputType: A.GLB, jsonSpacing: 0 }, t4);
  673. }
  674. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/gltfexport.js
  675. var s3 = class {
  676. constructor(e4, o5) {
  677. this._file = { type: "model/gltf-binary", data: e4 }, this.origin = o5;
  678. }
  679. buffer() {
  680. return Promise.resolve(this._file);
  681. }
  682. download(o5) {
  683. it(new Blob([this._file.data], { type: this._file.type }), o5);
  684. }
  685. };
  686. function f4(e4, f5) {
  687. const d2 = new s2(), l3 = new d();
  688. return d2.addScene(l3), l3.addNode(new i2(e4)), m2(d2, f5).then((e5) => new s3(e5[p2], e5.origin));
  689. }
  690. export {
  691. f4 as toBinaryGLTF
  692. };
  693. //# sourceMappingURL=gltfexport-6ZX4IV4P.js.map