@realsee/five
Version:
Realsee Renderer SDK
609 lines (608 loc) • 29.4 kB
JavaScript
/**
* @license
* @realsee/five
* Generated: 10/8/2026
* Version: 6.9.2
* Terms:
* Realsee SDK License Agreement
* Update: July 28, 2021
* THIS LICENSE AGREEMENT BETWEEN YOU AND 【BEIKE REALSEE TECHNOLOGY (HK)
* LIMITED】(“Realsee”) FORMS A LEGALLY BINDING CONTRACT BETWEEN YOU AND REALSEE IN
* RELATION TO YOUR USE OF THE SDK. This License Agreement accompanies the Realsee
* Software Development Kit(s) for the software and related explanatory materials
* (the "SDK") and includes any upgrades, modified versions, updates, additions,
* and copies of the SDK licensed to You by Realsee.
* BY DOWNLOADING, INSTALLING, OR OTHERWISE ACCESSING OR USING THE SDK, YOU AGREE
* THAT YOU HAVE READ, UNDERSTOOD, AND AGREE TO BE BOUND BY THIS AGREEMENT. YOU ARE
* AGREEING ON YOUR OWN BEHALF AND/OR ON BEHALF OF YOUR COMPANY OR ORGANIZATION TO
* THE TERMS AND CONDITIONS STATED BELOW.
* This Agreement applies to Your use of the SDK in the country in which You
* legally install it (“Territory”) and is subject to the laws of such Territory
* and further subject to Section 12 below. Different terms, conditions, and
* limitations may apply to the use of the SDK in any additional countries.
* 1. DEFINITIONS.
* “Agreement” means this Realsee SDK License Agreement.
* “Developer”, “You” and “Your” means the person(s) or entity acquiring or using
* the SDK or otherwise exercising rights under the terms of this Agreement.
* “Documentation” means the technical or other specifications or documentation
* that Realsee may provide to You for use in connection with the SDK.
* “Integrated Product” means any software, website, or on-line service developed
* by You based on or using the SDK (collectively, the “Integrated Product”).
* “Intellectual Property” means any patents, patent rights, trademarks, service
* marks, registered and unregistered designs, applications for any of the
* foregoing, copyright, and any other similar protected rights in any country and
* to the extent recognised by any relevant jurisdiction as intellectual property,
* trade secrets, know-how and confidential information. Realsee reserves all
* rights not expressly granted to You.
* “Realsee” means [Beike Realsee Technology (HK) Limited, a company incorporated
* and validly existing under the laws of Hong Kong].
* “SDK” means the Realsee-proprietary Software Development Kits (SDK) provided
* hereunder, includes all development tools (including any compiler and debugger),
* application programming interfaces (“APIs”), libraries, binary utilities, header
* files, Documentation, content, data, code samples, and other materials provided
* to You in connection with this Agreement, whether delivered through a download,
* or any other media or form, and is licensed, not sold, to You by Realsee for use
* only under the terms of this Agreement. The terms of this Agreement will govern
* any updates provided by Realsee that replace and/or supplement the original SDK
* delivered to You, unless such update is accompanied by a separate license, in
* which case the terms of such license will govern.
* 2. LICENSED USES AND RESTRICTIONS.
* 2.1 Subject to the restrictions contained in this Section 2, Realsee grants to
* You during the term, a limited, non-exclusive, revocable, non-sublicensable,
* non-transferable license to install and use the SDK within the Territory only
* for the purpose of internal development.
* 2.2 Restrictions. You acknowledge and agree that, You shall not, and shall
* ensure that Your affiliates, employees, agents, representatives, officers,
* representatives, and subcontractors do not (directly or indirectly):
* 2.2.1 decompile, reverse engineer, disassemble or attempt to derive the source
* code of, those components of the SDK provided in object code form, or any part
* thereof;
* 2.2.2 remove, alter, or obscure any copyright notice or other proprietary rights
* notice on any part of the SDK;
* 2.2.3 sell, assign, pledge, rent, lease, lend, upload to or host on any website
* or server for use by any third party except You, redistribute, or sublicense the
* SDK (or any part thereof), or operate the SDK (or any part thereof) in the
* capacity of a service bureau or other hosted services provider, in whole or in
* part, nor may You enable others to do so;
* 2.2.4 or alter, modify, customize or improve the SDK, or any part thereof;
* 2.2.5 use the SDK (or any part thereof) for any illegal purpose, in any manner
* that is inconsistent with the terms of this Agreement, or to engage in any
* illegal activity;
* 2.2.6 use the SDK (or any part thereof) in any manner that may damage the
* operation of Realsee’s products or services; or
* 2.2.7 use the SDK or any information contained therein or otherwise provided by
* Realsee for the purpose of developing, or having developed, any product
* competitive with any Realsee product or service, as determined by Realsee in its
* sole discretion;
* 2.2.8 include any portion of the SDK in Your Developer products.
* 2.3 Realsee has the right to impose reasonable conditions such as a reasonable
* fee for use of the SDK in Integrated Product in the future.
* 2.4 You may make a limited number of copies of the SDK to be used by Your
* employees or consultants as provided herein, and not for general business
* purposes, and such employees or consultants shall be subject to the obligations
* and restrictions in this Agreement.
* 2.5 All licenses not expressly granted in this Agreement are reserved and no
* other licenses, immunity, or rights, express or implied, are granted by Realsee,
* by implication, estoppel, or otherwise.
* 3. CONFIDENTIALITY.
* The SDK and all source code, Documentation, specifications, engineering details,
* and related information pertaining to the SDK, whether in oral, written,
* graphic, or electronic form, are and shall remain the confidential and
* proprietary information of Realsee or its licensors (collectively, the
* “Confidential Information”). You shall (i) disclose Confidential Information to
* only those directors and employees (collectively, “Affiliates”) whose duties
* justify their need to know such information and who have been clearly informed
* of their obligation to maintain the confidential, proprietary, and/or trade
* secret status of such Confidential Information; and (ii) use Confidential
* Information solely in accordance with the license granted hereunder. In any
* event, You and Your Affiliates shall treat Confidential Information as strictly
* confidential and shall use the same care to prevent disclosure of such
* information as You use with respect to Your own similar confidential and/or
* proprietary information, which shall not be less than the care a reasonable
* person would use under similar circumstances. All Confidential Information, and
* any copies thereof, shall be returned promptly to Realsee upon request. You
* shall ensure that Your Affiliates comply with the provisions of this Section 3,
* and You shall be liable for any breach of this Section 3 resulting from the act
* or omission of any of Your Affiliates. You shall not disclose Confidential
* Information to any third party, including, without limitation, any of Your
* subcontractors.
* 4. PROPRIETARY RIGHTS.
* 4.1 As between You and Realsee, Realsee and/or its licensors retain ownership of
* all right, title, and interest in, to, and under the SDK, including, without
* limitation, all patents, copyrights, trade secrets, trademarks and other
* intellectual property and other proprietary rights therein, and reserve all
* rights not expressly granted to You.
* 4.2 The items contained in the SDK are the intellectual property of Realsee and
* its licensors and are protected by PRC copyright and patent law, international
* treaty provisions and applicable laws of the country in which it is being used.
* You agree to protect all copyright and other ownership interests of Realsee
* and/or its licensors in all items in the SDK supplied under this License
* Agreement. You agree that all copies of the items in the SDK, reproduced for any
* reason by You, contain the same copyright notices, and other proprietary notices
* as appropriate, as appear on or in the original items delivered by Realsee in
* the SDK. Realsee and/or its licensors retain title and ownership of the items in
* the SDK, the media on which it is loaded, and all subsequent copies, regardless
* of the form or media in or on which the original and other copies may exist.
* Except as stated above, this Agreement does not grant You any rights to patents,
* copyrights, trade secrets, trademarks or any other rights in respect to the
* items in the SDK.
* 5. TERM AND TERMINATION.
* 5.1 This Agreement is effective until terminated. Realsee has the right to
* terminate this Agreement immediately, without judicial intervention, if You fail
* to comply with any term herein. Upon any such termination You must remove all
* full and partial copies of the items in the SDK from Your computer and
* discontinue the use of the items in the SDK.
* 5.2 Realsee may at any time, terminate the Agreement with You if: (A) You have
* breached any provision of the Agreement; or (B) Realsee is required to do so by
* law; or (C) Realsee decides to no longer provide the SDK or certain parts of the
* SDK to users in the country in which You are resident or from which You use the
* service, or the provision of the SDK or certain SDK services to You by Realsee
* is, in Realsee's sole discretion, no longer legally or commercially viable.
* 5.3 When the Agreement comes to an end, all of the legal rights, obligations and
* liabilities that You and Realsee have benefited from, been subject to (or which
* have accrued over time whilst the Agreement has been in force) or which are
* expressed to continue indefinitely, shall be unaffected by this cessation, and
* the provisions of Section 3, 4, 6, 7 and 8 shall continue to apply to such
* rights, obligations and liabilities indefinitely.
* 6. DISCLAIMER OF WARRANTY.
* YOU EXPRESSLY ACKNOWLEDGE AND AGREE THAT, TO THE EXTENT PERMITTED BY APPLICABLE
* LAW, USE OF THE SDK (OR ANY PART THEREOF) IS AT YOUR SOLE RISK AND THAT THE
* ENTIRE RISK AS TO SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS
* WITH YOU. REALSEE LICENSES THE SDK TO YOU ONLY ON AN "AS-IS" BASIS. REALSEE
* MAKES NO REPRESENTATION WITH RESPECT TO THE ADEQUACY OF ANY ITEMS IN THE SDK,
* WHETHER OR NOT USED BY YOU IN THE DEVELOPMENT OF INTEGRATED PRODUCT, FOR ANY
* PARTICULAR PURPOSE OR WITH RESPECT TO THEIR ADEQUACY TO PRODUCE ANY PARTICULAR
* RESULT. REALSEE AND ITS LICENSORS SHALL NOT BE LIABLE FOR LOSS OR DAMAGE ARISING
* OUT OF THIS AGREEMENT OR FROM THE DISTRIBUTION OR USE OF INTEGRATED PRODUCT
* CONTAINING PORTIONS OF THE SDK. REALSEE AND ITS LICENSORS DISCLAIM ALL
* WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED
* CONDITIONS OR WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* OR NONINFRINGEMENT OF ANY THIRD PARTY RIGHT IN RESPECT OF THE ITEMS IN THE SDK
* OR ANY SERVICES RELATED TO THE SDK.
* REALSEE IS UNDER NO OBLIGATION TO PROVIDE ANY SUPPORT UNDER THIS LICENSE
* AGREEMENT, INCLUDING UPGRADES OR FUTURE VERSIONS OF THE SDK OR ANY PORTIONS
* THEREOF, TO YOU, END USER OR TO ANY OTHER PARTY.
* 7. LIMITATION OF LIABILITY.
* TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, IN NO EVENT WILL REALSEE OR ITS
* LICENSORS BE LIABLE FOR ANY DIRECT, INCIDENTAL, SPECIAL, INDIRECT, OR
* CONSEQUENTIAL DAMAGES, INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE,
* LOSS OF BUSINESS, REVENUE, OR PROFITS, LOSS OF OPPORTUNITY (WHETHER DIRECT OR
* INDIRECT), CORRUPTION OR LOSS OF DATA, LOSS OF REPUTATION OR SAVINGS, DOWNTIME,
* OR DAMAGE TO, LOSS OF OR REPLACEMENT OF DATA OR TRANSACTIONS, COST OF
* PROCUREMENT OF SUBSTITUTE SERVICES, BUSINESS INTERRUPTION, OR ANY OTHER
* COMMERCIAL DAMAGES OR LOSSES, ARISING OUT OF OR RELATED TO YOUR USE OR INABILITY
* TO USE THE SDK (OR ANY PART THEREOF), ANY INTEGRATED PRODUCT, OR ANY THIRD PARTY
* SOFTWARE, APPLICATIONS, OR SERVICES IN CONJUNCTION WITH THE SDK (OR ANY PART
* THEREOF), HOWEVER CAUSED, REGARDLESS OF THE THEORY OF LIABILITY (CONTRACT, TORT,
* OR OTHERWISE) AND EVEN IF REALSEE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES. IN NO EVENT WILL REALSEE’S TOTAL LIABILITY TO YOU FOR ALL DAMAGES
* EXCEED ONE HUNDRED DOLLARS ($100.00). THE FOREGOING LIMITATIONS WILL APPLY EVEN
* IF THE ABOVE STATED REMEDY FAILS OF ITS ESSENTIAL PURPOSE. THE LIMITATIONS
* CONTAINED IN SECTIONS 6 AND THIS SECTION 7 ARE A FUNDAMENTAL PART OF THE BASIS
* OF REALSEE’S BARGAIN HEREUNDER, AND REALSEE WOULD NOT ENTER INTO THIS AGREEMENT
* OR PROVIDE YOU WITH ACCESS TO THE SDK ABSENT SUCH LIMITATIONS.
* 8. INDEMNIFICATION.
* To the extent permitted by applicable law, You agree to indemnify, defend and
* hold harmless Realsee, its affiliates and each of their directors, officers,
* employees, independent contractors, and agents (each a “Realsee Indemnified
* Party”) from any and all claims, losses, liabilities, damages, expenses, and
* costs (including without limitation attorneys’ fees and court costs) incurred by
* a Realsee Indemnified Party as a result of: (i) Your non-compliance with any
* terms of this Agreement; (ii) Your use of the SDK (or any part thereof); or
* (iii) Your use of any Integrated Product, including any claim that Integrated
* Product infringes the copyright, trademark, trade secret or other intellectual
* property right of a third party.
* 9. ACKNOWLEDGEMENTS.
* Portions of the SDK may utilize or include third party software and other
* copyrighted material. Acknowledgments, licensing terms, and disclaimers for such
* material are contained in Documentation for the SDK or may otherwise accompany
* such material, and Your use of such materials governed by their respective
* terms. In the event of conflict between the terms of this Agreement and an
* applicable open source or third party agreement, the open source or third party
* agreement will control solely with respect to the open source software or third
* party software. Moreover, You shall not subject any items (including not limited
* to source code, object code, and any software) included in the SDK to any open
* source license.
* 10. NON-BLOCKING OF REALSEE DEVELOPMENT.
* You acknowledge that Realsee is currently developing or may develop technologies
* and products in the future that have or may have design and/or functionality
* similar to Integrated Product that You may develop based on Your license herein.
* Nothing in this Agreement shall impair, limit or curtail Realsee's right to
* continue with its development, maintenance and/or distribution of Realsee's
* technology or products.
* 11. GENERAL.
* 11.1 Export Control. You may not use or otherwise export or re-export the SDK
* (or any part thereof) except as authorized by United States law and the laws of
* the jurisdiction(s) in which the SDK (or any part thereof) was obtained. In
* particular, but without limitation, the SDK may not be exported or re-exported
* (i) into any U.S. embargoed countries or (ii) to anyone on the U.S. Treasury
* Department's list of Specially Designated Nationals or the U.S. Department of
* Commerce Denied Person's List or Entity List. By using the SDK (or any part
* thereof), You represent and warrant that You are not located in any such country
* or on any such list.
* 11.2 Governing Law. This Agreement and the rights of the parties hereunder shall
* be governed by and construed in accordance with the laws of People’s Republic of
* China (for purpose of this Agreement, excluding Hong Kong, Taiwan, and Macau),
* without reference to its conflict of laws principles. Any dispute, controversy
* or claim arising from or in connection with this Agreement, or the breach,
* termination or invalidity thereof, shall be submitted to China International
* Economic and Trade Arbitration Commission (“CIETAC”) for arbitration in Beijing
* which shall be conducted in accordance with the CIETAC's arbitration rules in
* effect at the time of applying for arbitration. The arbitral award is final and
* binding upon both parties.
* 11.3 Severability. If any provision of this Agreement is held by a court of
* competent jurisdiction to be unenforceable for any reason, the remaining
* provisions hereof will be unaffected and remain in full force and effect.
* 11.4. Modifications. Realsee reserves the right, from time to time, with or
* without notice to You, to make revisions to this Agreement in our sole and
* absolute discretion. The most current version of this Agreement will supersede
* all previous versions and shall be made available on the website where the SDK
* is made available, or by such other means as Realsee may determine in its
* discretion. Any modified versions of this Agreement hereto shall take effect
* from the time that it is made available. You shall be responsible for regularly
* checking for notice of any such modifications. You agree that Your continued use
* of the SDK constitutes Your agreement to the modified Agreement.
* 11.5 Relationship of the Parties. This Agreement will not be construed as
* creating an agency, partnership, joint venture, fiduciary duty, or any other
* form of legal association between You and Realsee, and You will not represent to
* the contrary, whether expressly, by implication, appearance, or otherwise.
* 11.6 Entire Agreement; Governing Language. This Agreement constitutes the entire
* agreement between You and Realsee with respect to the use of the SDK licensed
* hereunder and supersedes all prior understandings regarding such subject matter.
* No amendment to or modification of this Agreement will be binding unless in
* writing and signed by Realsee. You and Realsee hereto confirm that this
* Agreement and all related documents shall be drafted in English.
*/import { createWriteStream as e, existsSync as t } from "node:fs";
import { mkdir as n, readFile as r, writeFile as i } from "node:fs/promises";
import { dirname as a, extname as o, join as s, resolve as c } from "node:path";
import { Readable as l } from "node:stream";
import u from "sharp";
//#region node_modules/tslib/tslib.es6.mjs
function d(e, t, n, r) {
function i(e) {
return e instanceof n ? e : new n(function(t) {
t(e);
});
}
return new (n || (n = Promise))(function(n, a) {
function o(e) {
try {
c(r.next(e));
} catch (e) {
a(e);
}
}
function s(e) {
try {
c(r.throw(e));
} catch (e) {
a(e);
}
}
function c(e) {
e.done ? n(e.value) : i(e.value).then(o, s);
}
c((r = r.apply(e, t || [])).next());
});
}
//#endregion
//#region build/work-downloader/utils/relative-url.js
function f(e, t) {
if (t && t[t.length - 1] !== "/" && (t += "/"), e.length > t.length && e.startsWith(t)) return e.slice(t.length);
throw Error(`${e} is not starting with ${t}`);
}
//#endregion
//#region build/work-downloader/utils/join-url.js
function p(...e) {
let t = [];
e = e.map((e) => (e == null ? "" : e).trim()).filter((e) => e.length > 0 && !/^\/+$/.test(e));
for (let n = 0; n < e.length; n++) {
let r = n === 0, i = n === e.length - 1, a = e[n];
r || (a = a.replace(/^\.\//, "").replace(/^\/+/, "")), i || (a = a.replace(/\/+$/, "")), t.push(a);
}
return t.join("/");
}
//#endregion
//#region build/work-downloader/utils/download-to-file.js
var m = 1024 * 1024 * 5;
function h(r, o, s) {
return d(this, void 0, void 0, function* () {
var c;
if (t(o)) return o;
let u = yield s(r);
if (u.ok && u.body) {
if (yield n(a(o), { recursive: !0 }), Number((c = u.headers.get("content-length")) == null ? "Infinity" : c) > m) return new Promise((t, n) => {
let r = l.fromWeb(u.body), i = e(o);
r.pipe(i), r.on("error", n), i.on("finish", () => t(o));
});
{
let e = yield u.arrayBuffer();
return yield i(o, Buffer.from(e)), o;
}
}
throw Error(`url: ${r}(${u.statusText})`);
});
}
//#endregion
//#region build/work-downloader/utils/image-processing.js
var g = ["jpg", "png"], _ = 95;
function v(e, t) {
let n = o(e).slice(1) || "jpg", { cut: r, size: i, format: a = n } = t, s = "";
if (t.toFilename) s = t.toFilename(e, {
cut: t.cut,
size: t.size,
format: t.format
});
else {
let t = "", o = "", c = a;
r && (t = r.join("x")), i && (o = `${i}x`), c === n && !o && !t && (c = ""), s = [
e,
t,
o,
c
].filter((e) => e.length > 0).join(".");
}
return s;
}
function y(e, n) {
return d(this, void 0, void 0, function* () {
let r = o(e).slice(1) || "jpg", { cut: i, size: a, format: s = r } = n, c = e;
if ((i || a) && s !== r && g.includes(s)) {
let r = v(e, {
format: s,
toFilename: n.toFilename
});
r !== c && t(r) && (c = r);
}
let l = u(c);
i && (l = l.extract({
left: i[0],
top: i[1],
width: i[2],
height: i[3]
})), a && (l = l.resize(a)), l = l.toFormat(s, { quality: _ });
let d = v(e, n);
return d !== e && !t(d) ? l.toFile(d).then(() => d) : d;
});
}
//#endregion
//#region build/work-downloader/components/model-3d-tile.js
function b(e) {
let t = [];
if (e.content && (e.content.uri ? t.push(e.content.uri) : e.content.url && t.push(e.content.url)), e.children) for (let n of e.children) {
let e = b(n);
if (e.length > 0) for (let n = 0; n < e.length; n++) t.push(e[n]);
}
return t;
}
function x(e, t, n) {
return d(this, void 0, void 0, function* () {
let r = new URL(e, t).href, i = h(r, s(n.distPath, f(r, n.baseURL)), n.fetch);
n.log((e) => `download: ${r} -> ${e}`, i), yield i, /\.json$/.test(e) && (yield S(r, n));
});
}
function S(e, t) {
return d(this, void 0, void 0, function* () {
let n = new URL("tileset_checksum.json", e).href, i = s(t.distPath, f(n, t.baseURL)), a = null;
try {
let e = h(n, i, t.fetch);
t.log((e) => `download: ${n} -> ${e}`, e), yield e;
let { file_md5: o } = JSON.parse(yield r(i, "utf8"));
if (typeof o == "object") {
let e = Object.keys(o);
e.length > 0 && (a = e);
}
} catch (e) {}
if (a && a.length > 0) {
let e = [];
for (let r of a) {
let i = new URL(r, n).href, a = h(i, s(t.distPath, f(i, t.baseURL)), t.fetch);
if (t.log((e) => `download: ${i} -> ${e}`, a), e.push(a), e.length >= 10) {
let t = e;
e = [], yield Promise.all(t);
}
}
yield Promise.all(e);
return;
}
let o = s(t.distPath, f(e, t.baseURL)), c = h(e, o, t.fetch);
t.log((t) => `download: ${e} -> ${t}`, c), yield c;
let l = JSON.parse(yield r(o, "utf8"));
if (l.asset.overview) {
let n = new URL(l.asset.overview.imageFile, e).href, r = h(n, s(t.distPath, f(n, t.baseURL)), t.fetch);
t.log((e) => `download: ${n} -> ${e}`, r), yield r;
}
if (l.asset.trajectories) for (let n of l.asset.trajectories.list) {
let r = new URL(n.file, e).href, i = h(r, s(t.distPath, f(r, t.baseURL)), t.fetch);
t.log((e) => `download: ${r} -> ${e}`, i), yield i;
}
let u = b(l.root);
for (let n = 0; n < u.length; n += 6) {
let r = [];
for (let i = 0; i < 6; i++) {
let a = u[n + i];
if (a) {
let n = x(a, e, t);
r.push(n);
}
}
yield Promise.all(r);
}
});
}
//#endregion
//#region build/work-downloader/components/model.js
function C(e, t) {
return d(this, void 0, void 0, function* () {
if (t.log("process model"), e.model) {
let { textures: n, layers: r, file: i, textureBase: a } = e.model;
if (i) {
t.log("process model file");
let r = e.getURL(i), o = h(r, s(t.distPath, f(r, t.baseURL)), t.fetch);
if (t.log((e) => `download: ${i} -> ${e}`, o), yield o, n) for (let r of n) {
let n = p(e.getURL(a == null ? "" : a), r), i = s(t.distPath, f(n, t.baseURL)), o = h(n, i, t.fetch);
t.log((e) => `download: ${n} -> ${e}`, o), yield o;
let c = t.imageOptions.format;
c.length === 0 && c.push(void 0);
let l = t.imageOptions.size;
l.length === 0 && l.push(void 0);
let u = [];
for (let e of c) for (let n of l) {
let r = y(i, {
format: e,
size: n,
toFilename: t.imageProcessingFilename
});
t.log((e) => `imageProcessing: ${i} -> ${e}`, r), u.push(r);
}
yield Promise.all(u);
}
}
if (r) for (let n of r) {
let { tileset: r } = n;
t.log("process model layer"), yield S(e.getURL(r), t);
}
}
});
}
//#endregion
//#region build/work-downloader/components/observer.js
function w(e, t, n) {
return d(this, void 0, void 0, function* () {
let r = s(n.distPath, f(e, n.baseURL)), i = h(e, r, n.fetch);
n.log((t) => `download: ${e} -> ${t}`, i), yield i;
let a = Math.pow(2, t.level), o = n.imageOptions.format;
o.length === 0 && o.push(void 0);
let c = [];
if (a > 1) for (let e = 0; e < a; e++) for (let i = 0; i < a; i++) for (let s of o) {
let o = [
t.size / a * i,
t.size / a * e,
t.size / a,
t.size / a
], l = y(r, {
format: s,
size: t.scale >= 1 ? void 0 : t.scale * t.size / a,
cut: o,
toFilename: n.imageProcessingFilename
});
if (n.log((e) => `imageProcessing: ${r} -> ${e}`, l), c.push(l), t.level === 1 && t.scale >= .5 && (s === "jpg" || /\.jpg$/.test(r))) {
let e = y(r, {
format: s,
size: void 0,
cut: o,
toFilename: n.imageProcessingFilename
});
n.log((e) => `imageProcessing: ${r} -> ${e}`, e), c.push(e);
}
}
yield Promise.all(c);
});
}
function T(e, t) {
return d(this, void 0, void 0, function* () {
yield Promise.all([
w(e.work.getURL(e.front), e, t),
w(e.work.getURL(e.back), e, t),
w(e.work.getURL(e.left), e, t),
w(e.work.getURL(e.right), e, t),
w(e.work.getURL(e.up), e, t),
w(e.work.getURL(e.down), e, t)
]);
});
}
function E(e, t, n) {
return d(this, void 0, void 0, function* () {
let r = s(n.distPath, f(e, n.baseURL)), i = h(e, r, n.fetch);
n.log((t) => `download: ${e} -> ${t}`, i), yield i;
let a = n.imageOptions.format;
a.length === 0 && a.push(void 0);
let o = n.imageOptions.size;
o.length === 0 && o.push(void 0);
for (let r of t) {
let t = e.replace(/cube\_\d+/, `cube_${r}`), i = s(n.distPath, f(t, n.baseURL)), o = h(t, i, n.fetch);
n.log((e) => `download ${t} -> ${i}`, o), yield o;
for (let e of a) {
let t = y(i, {
format: e,
toFilename: n.imageProcessingFilename
});
n.log((e) => `imageProcessing: ${i} -> ${e}`, t), yield t;
}
}
let c = [];
for (let e of a) for (let t of o) {
let i = y(r, {
format: e,
size: t,
toFilename: n.imageProcessingFilename
});
n.log((e) => `imageProcessing: ${r} -> ${e}`, i), c.push(i);
}
yield Promise.all(c);
});
}
function D(e, t) {
return d(this, void 0, void 0, function* () {
let { images: n } = e;
yield Promise.all([
E(n.work.getURL(n.front), n.sizeList, t),
E(n.work.getURL(n.back), n.sizeList, t),
E(n.work.getURL(n.left), n.sizeList, t),
E(n.work.getURL(n.right), n.sizeList, t),
E(n.work.getURL(n.up), n.sizeList, t),
E(n.work.getURL(n.down), n.sizeList, t)
]), n.tiles && (yield Promise.all(n.tiles.map((e) => T(e, t))));
});
}
function O(e, t) {
return d(this, void 0, void 0, function* () {
let { observers: n } = e;
for (let e of n) {
let n = D(e, t);
t.log(`process observer #${e.index} derived: ${e.derivedIdStr}`, n), yield n;
}
});
}
//#endregion
//#region build/work-downloader/utils/log.js
function k(e, t) {
if (t) {
let n = Date.now();
t.then((t) => {
let r = Date.now() - n, i = typeof e == "function" ? e(t) : e;
console.log(i + `(${r}ms)`);
}).catch(() => {});
} else {
let t = typeof e == "function" ? e(null) : e;
console.log(t);
}
}
//#endregion
//#region build/work-downloader/download.js
function A(e) {
return d(this, arguments, void 0, function* (e, r = {}) {
var a, o, s, l, u, d, f, p, m, h;
let g = e.baseURL, _ = "";
if (r.distPath) _ = c(process.cwd(), r.distPath);
else for (_ = c(process.cwd(), (a = e.workCode) == null ? `work-${Date.now()}` : a); t(_);) /.-(\d+)$/.test(_) ? _ = _.replace(/.-(\d+)$/, (e, t) => "-" + (Number(t) + 1)) : _ += "-1";
let v = {
baseURL: g,
distPath: _,
fetch: (o = r.fetch) == null ? fetch : o,
imageOptions: {
size: (l = (s = r.imageOptions) == null ? void 0 : s.size) == null ? [] : l,
format: (d = (u = r.imageOptions) == null ? void 0 : u.format) == null ? [] : d
},
textureOptions: {
size: (p = (f = r.textureOptions) == null ? void 0 : f.size) == null ? [] : p,
format: (h = (m = r.textureOptions) == null ? void 0 : m.format) == null ? [] : h
},
log: r.log ? k : (() => Promise.resolve()),
imageProcessingFilename: r.imageProcessingFilename
};
v.log(JSON.stringify(v, null, " ")), yield n(_, { recursive: !0 }), yield i(c(_, "work.json"), JSON.stringify(e.toJSON(), null, " ")), yield O(e, v), yield C(e, v);
});
}
//#endregion
export { A as download };