gltfexport-YWNKMN7W.js 27 KB

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