UNPKG

bp-cloner

Version:

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

112 lines (111 loc) 3.89 kB
import "./index-7uRiSnMV.js"; function m(t, e) { return e > 1023 ? t * Math.pow(2, 1023) * Math.pow(2, e - 1023) : e < -1074 ? t * Math.pow(2, -1074) * Math.pow(2, e + 1074) : t * Math.pow(2, e); } function p(t, e, a, i, l, r) { l > 0 ? (l = m(1, l - 136), t[r + 0] = e * l, t[r + 1] = a * l, t[r + 2] = i * l) : (t[r + 0] = 0, t[r + 1] = 0, t[r + 2] = 0); } function g(t, e) { let a = "", i = ""; for (let l = e; l < t.length - e && (i = String.fromCharCode(t[l]), i != ` `); l++) a += i; return a; } function D(t) { let e = 0, a = 0, i = g(t, 0); if (i[0] != "#" || i[1] != "?") throw "Bad HDR Format."; let l = !1, r = !1, o = 0; do o += i.length + 1, i = g(t, o), i == "FORMAT=32-bit_rle_rgbe" ? r = !0 : i.length == 0 && (l = !0); while (!l); if (!r) throw "HDR Bad header format, unsupported FORMAT"; o += i.length + 1, i = g(t, o); const n = /^-Y (.*) \+X (.*)$/g.exec(i); if (!n || n.length < 3) throw "HDR Bad header format, no size"; if (a = parseInt(n[2]), e = parseInt(n[1]), a < 8 || a > 32767) throw "HDR Bad header format, unsupported size"; return o += i.length + 1, { height: e, width: a, dataPosition: o }; } function b(t, e) { return _(t, e); } function _(t, e) { let a = e.height; const i = e.width; let l, r, o, c, n, s = e.dataPosition, f = 0, d = 0, h = 0; const B = new ArrayBuffer(i * 4), w = new Uint8Array(B), A = new ArrayBuffer(e.width * e.height * 4 * 3), u = new Float32Array(A); for (; a > 0; ) { if (l = t[s++], r = t[s++], o = t[s++], c = t[s++], l != 2 || r != 2 || o & 128 || e.width < 8 || e.width > 32767) return H(t, e); if ((o << 8 | c) != i) throw "HDR Bad header format, wrong scan line width"; for (f = 0, h = 0; h < 4; h++) for (d = (h + 1) * i; f < d; ) if (l = t[s++], r = t[s++], l > 128) { if (n = l - 128, n == 0 || n > d - f) throw "HDR Bad Format, bad scanline data (run)"; for (; n-- > 0; ) w[f++] = r; } else { if (n = l, n == 0 || n > d - f) throw "HDR Bad Format, bad scanline data (non-run)"; if (w[f++] = r, --n > 0) for (let R = 0; R < n; R++) w[f++] = t[s++]; } for (h = 0; h < i; h++) l = w[h], r = w[h + i], o = w[h + 2 * i], c = w[h + 3 * i], p(u, l, r, o, c, (e.height - a) * i * 3 + h * 3); a--; } return u; } function H(t, e) { let a = e.height; const i = e.width; let l, r, o, c, n, s = e.dataPosition; const f = new ArrayBuffer(e.width * e.height * 4 * 3), d = new Float32Array(f); for (; a > 0; ) { for (n = 0; n < e.width; n++) l = t[s++], r = t[s++], o = t[s++], c = t[s++], p(d, l, r, o, c, (e.height - a) * i * 3 + n * 3); a--; } return d; } class M { constructor() { this.supportCascades = !1; } /** * Uploads the cube texture data to the WebGL texture. It has already been bound. * Cube texture are not supported by .hdr files */ loadCubeData() { throw ".hdr 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(e, a, i) { const l = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), r = D(l), o = b(l, r), c = r.width * r.height, n = new Float32Array(c * 4); for (let s = 0; s < c; s += 1) n[s * 4] = o[s * 3], n[s * 4 + 1] = o[s * 3 + 1], n[s * 4 + 2] = o[s * 3 + 2], n[s * 4 + 3] = 1; i(r.width, r.height, a.generateMipMaps, !1, () => { const s = a.getEngine(); a.type = 1, a.format = 5, a._gammaSpace = !1, s._uploadDataToTextureDirectly(a, n); }); } } export { M as _HDRTextureLoader };