UNPKG

bp-cloner

Version:

More info and explanations here - https://doc.babylonjs.com/communityExtensions/clonerSystem

199 lines (198 loc) 6.1 kB
import { c as A } from "./index-7uRiSnMV.js"; const U = 1, d = 2, N = 3, L = 9, O = 10, Y = 11, k = 48, z = 4, P = 0, B = 1, C = 2, M = 3; function G(o) { let n = 0; return { id_length: o[n++], colormap_type: o[n++], image_type: o[n++], colormap_index: o[n++] | o[n++] << 8, colormap_length: o[n++] | o[n++] << 8, colormap_size: o[n++], origin: [o[n++] | o[n++] << 8, o[n++] | o[n++] << 8], width: o[n++] | o[n++] << 8, height: o[n++] | o[n++] << 8, pixel_size: o[n++], flags: o[n++] }; } function R(o, n) { if (n.length < 19) { A.Error("Unable to load TGA file - Not enough data to contain header"); return; } let a = 18; const r = G(n); if (r.id_length + a > n.length) { A.Error("Unable to load TGA file - Not enough data"); return; } a += r.id_length; let _ = !1, f = !1, w = !1; switch (r.image_type) { case L: _ = !0; // eslint-disable-next-line no-fallthrough case U: f = !0; break; case O: _ = !0; // eslint-disable-next-line no-fallthrough case d: break; case Y: _ = !0; // eslint-disable-next-line no-fallthrough case N: w = !0; break; } let p; const u = r.pixel_size >> 3, l = r.width * r.height * u; let s; if (f && (s = n.subarray(a, a += r.colormap_length * (r.colormap_size >> 3))), _) { p = new Uint8Array(l); let I, y, x, b = 0; const T = new Uint8Array(u); for (; a < l && b < l; ) if (I = n[a++], y = (I & 127) + 1, I & 128) { for (x = 0; x < u; ++x) T[x] = n[a++]; for (x = 0; x < y; ++x) p.set(T, b + x * u); b += u * y; } else { for (y *= u, x = 0; x < y; ++x) p[b + x] = n[a++]; b += y; } } else p = n.subarray(a, a += f ? r.width * r.height : l); let g, c, i, e, t, h; switch ((r.flags & k) >> z) { default: case C: g = 0, i = 1, h = r.width, c = 0, e = 1, t = r.height; break; case P: g = 0, i = 1, h = r.width, c = r.height - 1, e = -1, t = -1; break; case M: g = r.width - 1, i = -1, h = -1, c = 0, e = 1, t = r.height; break; case B: g = r.width - 1, i = -1, h = -1, c = r.height - 1, e = -1, t = -1; break; } const m = "_getImageData" + (w ? "Grey" : "") + r.pixel_size + "bits", D = j[m](r, s, p, c, e, t, g, i, h); o.getEngine()._uploadDataToTextureDirectly(o, D); } function H(o, n, a, r, _, f, w, p, u) { const l = a, s = n, g = o.width, c = o.height; let i, e = 0, t, h; const m = new Uint8Array(g * c * 4); for (h = r; h !== f; h += _) for (t = w; t !== u; t += p, e++) i = l[e], m[(t + g * h) * 4 + 3] = 255, m[(t + g * h) * 4 + 2] = s[i * 3 + 0], m[(t + g * h) * 4 + 1] = s[i * 3 + 1], m[(t + g * h) * 4 + 0] = s[i * 3 + 2]; return m; } function S(o, n, a, r, _, f, w, p, u) { const l = a, s = o.width, g = o.height; let c, i = 0, e, t; const h = new Uint8Array(s * g * 4); for (t = r; t !== f; t += _) for (e = w; e !== u; e += p, i += 2) { c = l[i + 0] + (l[i + 1] << 8); const m = ((c & 31744) >> 10) * 255 / 31 | 0, D = ((c & 992) >> 5) * 255 / 31 | 0, E = (c & 31) * 255 / 31 | 0; h[(e + s * t) * 4 + 0] = m, h[(e + s * t) * 4 + 1] = D, h[(e + s * t) * 4 + 2] = E, h[(e + s * t) * 4 + 3] = c & 32768 ? 0 : 255; } return h; } function X(o, n, a, r, _, f, w, p, u) { const l = a, s = o.width, g = o.height; let c = 0, i, e; const t = new Uint8Array(s * g * 4); for (e = r; e !== f; e += _) for (i = w; i !== u; i += p, c += 3) t[(i + s * e) * 4 + 3] = 255, t[(i + s * e) * 4 + 2] = l[c + 0], t[(i + s * e) * 4 + 1] = l[c + 1], t[(i + s * e) * 4 + 0] = l[c + 2]; return t; } function v(o, n, a, r, _, f, w, p, u) { const l = a, s = o.width, g = o.height; let c = 0, i, e; const t = new Uint8Array(s * g * 4); for (e = r; e !== f; e += _) for (i = w; i !== u; i += p, c += 4) t[(i + s * e) * 4 + 2] = l[c + 0], t[(i + s * e) * 4 + 1] = l[c + 1], t[(i + s * e) * 4 + 0] = l[c + 2], t[(i + s * e) * 4 + 3] = l[c + 3]; return t; } function F(o, n, a, r, _, f, w, p, u) { const l = a, s = o.width, g = o.height; let c, i = 0, e, t; const h = new Uint8Array(s * g * 4); for (t = r; t !== f; t += _) for (e = w; e !== u; e += p, i++) c = l[i], h[(e + s * t) * 4 + 0] = c, h[(e + s * t) * 4 + 1] = c, h[(e + s * t) * 4 + 2] = c, h[(e + s * t) * 4 + 3] = 255; return h; } function K(o, n, a, r, _, f, w, p, u) { const l = a, s = o.width, g = o.height; let c = 0, i, e; const t = new Uint8Array(s * g * 4); for (e = r; e !== f; e += _) for (i = w; i !== u; i += p, c += 2) t[(i + s * e) * 4 + 0] = l[c + 0], t[(i + s * e) * 4 + 1] = l[c + 0], t[(i + s * e) * 4 + 2] = l[c + 0], t[(i + s * e) * 4 + 3] = l[c + 1]; return t; } const j = { /** * Gets the header of a TGA file * @param data defines the TGA data * @returns the header */ GetTGAHeader: G, /** * Uploads TGA content to a Babylon Texture * @internal */ UploadContent: R, /** @internal */ _getImageData8bits: H, /** @internal */ _getImageData16bits: S, /** @internal */ _getImageData24bits: X, /** @internal */ _getImageData32bits: v, /** @internal */ _getImageDataGrey8bits: F, /** @internal */ _getImageDataGrey16bits: K }; class J { constructor() { this.supportCascades = !1; } /** * Uploads the cube texture data to the WebGL texture. It has already been bound. */ loadCubeData() { throw ".env not supported in Cube."; } /** * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback. * @param data contains the texture data * @param texture defines the BabylonJS internal texture * @param callback defines the method to call once ready to upload */ loadData(n, a, r) { const _ = new Uint8Array(n.buffer, n.byteOffset, n.byteLength), f = G(_); r(f.width, f.height, a.generateMipMaps, !1, () => { R(a, _); }); } } export { J as _TGATextureLoader };