@realsee/five
Version:
Realsee Renderer SDK
968 lines (967 loc) • 41.5 kB
JavaScript
/**
* @license
* @realsee/five
* Generated: 10/28/2026
* Version: 6.9.3
* 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 * as e from "react";
import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
import * as a from "three";
import { Five as o, getViewportScale as s } from "@realsee/five";
//#region build/react/rendererPool.js
var c = [], l = [], u = null, d = 3e3;
function f({ preserveDrawingBuffer: e, premultipliedAlpha: t, stencil: n, antialias: r, webgl2: i, logarithmicDepthBuffer: o, precision: s, powerPreference: c }) {
let l = {
antialias: r,
alpha: !0,
depth: !0,
preserveDrawingBuffer: e,
stencil: n,
premultipliedAlpha: t,
powerPreference: c
}, u = {
logarithmicDepthBuffer: o,
precision: s
}, d;
if (i) {
let e = document.createElement("canvas"), t = e.getContext("webgl2", l);
t ? d = new a.WebGLRenderer(Object.assign(Object.assign(Object.assign({}, l), u), {
canvas: e,
context: t
})) : (console.error("error occurred when getting webgl2 canvas context, maybe webgl2 not supported, fallback to webgl."), d = new a.WebGLRenderer(Object.assign(Object.assign({}, l), u)));
} else d = new a.WebGLRenderer(Object.assign(Object.assign({}, l), u));
return d.outputEncoding = a.sRGBEncoding, d.autoClear = !0, d;
}
function p({ preserveDrawingBuffer: e = !0, premultipliedAlpha: t = !0, stencil: n = !0, antialias: r = !1, webgl2: i = !1, logarithmicDepthBuffer: a, precision: o, powerPreference: s, backgroundColor: d = 1579548, backgroundAlpha: p = 1, pixelRatio: m } = {}) {
if (typeof window > "u") return;
u && (clearTimeout(u), u = null);
let h;
return h = i ? l.shift() : c.shift(), h || (h = f({
preserveDrawingBuffer: e,
premultipliedAlpha: t,
stencil: n,
antialias: r,
webgl2: i,
logarithmicDepthBuffer: a,
precision: o,
powerPreference: s
})), m !== void 0 && h.setPixelRatio(m), h.setClearColor(d, p), h.autoClear = !0, h;
}
function m(e) {
e && (e.capabilities.isWebGL2 ? l.indexOf(e) === -1 && l.push(e) : c.indexOf(e) === -1 && c.push(e), h());
}
function h(e = d) {
u && clearTimeout(u), u = setTimeout(() => {
u = null, g();
}, e);
}
function g() {
for (let e of c) e.dispose();
for (let e of l) e.dispose();
c.length = 0, l.length = 0;
}
//#endregion
//#region build/react/context.js
var _ = e.createContext(null);
function v() {
let t = e.useContext(_);
if (!t) throw Error("FiveProvider never found.");
return t.five;
}
function y() {
let t = e.useContext(_);
if (!t) throw Error("FiveProvider never found.");
return t.loadWork;
}
//#endregion
//#region build/react/createProvider.js
function b(e, t) {
let n = Array.isArray(e) ? e : [e], r = Array.isArray(t) ? t : [t];
if (n.length !== r.length) return !1;
for (let e = 0; e < n.length; e++) if (n[e].workCode !== r[e].workCode) return !1;
return !0;
}
function x(e = {}) {
let t = s() === 1 ? window.devicePixelRatio : 1, n = e.backgroundColor;
return {
webgl2: e.webgl2,
preserveDrawingBuffer: e.preserveDrawingBuffer,
antialias: e.antialias,
logarithmicDepthBuffer: e.logarithmicDepthBuffer,
precision: e.precision,
powerPreference: e.powerPreference,
backgroundColor: (n instanceof a.Color, n),
backgroundAlpha: e.backgroundAlpha,
pixelRatio: t
};
}
function S(t = {}) {
return class extends e.Component {
constructor(e) {
super(e), this.__fiveEventDisposers = [], this.__fiveDisposeTimer = null, this.five = new o(Object.assign(Object.assign({}, t), { renderer: void 0 })), this.loadWork = this.loadWork.bind(this), this.state = {};
}
loadWork(e, t, n, r = !0) {
if (this.props.work) throw Error("props 'works' is set in fiveProvider, if you need modify work internal, use 'initialWork' instead.");
return this.five.load(e, t, n, r);
}
shouldComponentUpdate(e) {
return this.five.renderer && this.five && e.work && !b(e.work, this.five.works) && this.five.load(e.work, e.initialState, e.initialOptions), !0;
}
componentDidMount() {
var e;
clearTimeout(this.__fiveDisposeTimer), this.__fiveDisposeTimer = null;
let n;
typeof window < "u" && (n = p(x(t))), this.five.renderer = n, this.setState({ renderer: n }), this.__fiveEventDisposers.push(this.five.on("load", () => {
this.props.onWorksChange && this.props.onWorksChange(this.five.works);
})), this.__fiveEventDisposers.push(this.five.on("stateChange", (e, t) => {
this.props.onStateChange && this.props.onStateChange(e, t);
})), this.__fiveEventDisposers.push(this.five.on("currentStateChange", (e, t) => {
this.props.onCurrentStateChange && this.props.onCurrentStateChange(e, t);
})), this.__fiveEventDisposers.push(this.five.on("error", (e) => {
this.props.onError ? this.props.onError(e) : console.warn(e.message);
}));
let r = this.props.work || this.props.initialWork;
r && this.five.load(r, this.props.initialState, this.props.initialOptions, (e = this.props.initialUserAction) == null ? !0 : e);
}
componentWillUnmount() {
var e;
(e = this.five.controller) == null || e.destroy();
let t = this.five.renderer;
this.five.renderer = void 0, m(t), this.setState({ renderer: void 0 }), this.__fiveDisposeTimer = setTimeout(() => {
this.__fiveDisposeTimer = null, this.five.dispose();
}, 1e3);
}
render() {
let t = this.five, n = this.loadWork, r = this.state.renderer;
return e.createElement(_.Provider, { value: {
renderer: r,
five: t,
loadWork: n
} }, this.props.children);
}
};
}
//#endregion
//#region build/react/canvas.js
var C = typeof window < "u" ? e.useLayoutEffect : e.useEffect, w = {
display: "inline-block",
overflow: "hidden"
}, T = ({ width: t, height: n }) => {
let r = v(), i = e.createRef(), a = Object.assign({
width: t,
height: n
}, w);
return C(() => {
let e = i.current;
if (!e || !r.renderer) return;
let a = r.renderer.domElement;
if (a.parentNode !== null && a.parentNode !== e) throw Error("There are more than 2 fiveCanvas in this context.");
return a.parentNode !== e && e.appendChild(a), r.camera.aspect = t / n, r.camera.updateProjectionMatrix(), r.renderer.setSize(t, n), r.refresh({
width: t,
height: n
}), r.needsRender = !0, () => {
a.parentNode === e && e.removeChild(a);
};
}, [
r,
r.renderer,
t,
n,
i.current
]), e.createElement("div", {
ref: i,
style: a
});
}, E = ({ children: t }) => {
let n = v(), r = e.useRef(null);
return e.useEffect(() => {
let e = r.current;
if (!e || !n.renderer) return;
let t = n.renderer.domElement;
e.appendChild(t);
let i = () => {
var t;
let { width: r, height: i } = e.getBoundingClientRect();
r === 0 || i === 0 || (n.camera.aspect = r / i, n.camera.updateProjectionMatrix(), (t = n.renderer) == null || t.setSize(r, i), n.refresh({
width: r,
height: i
}), n.needsRender = !0);
}, a = new ResizeObserver(i);
return a.observe(e), i(), () => {
t.parentNode === e && e.removeChild(t), a.unobserve(e), a.disconnect();
};
}, []), e.createElement("div", {
ref: r,
style: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0
}
}, t);
}, D = ({ renderChildren: t, load: n, children: r, fallback: i }) => {
let a = e.useContext(_), o = a == null ? void 0 : a.five, [s, c] = e.useState(!!t), [l, u] = e.useState(!1);
return e.useEffect(() => {
o && o.getElement() && (c(!0), n && n(o).then((e) => {
o.load(...e);
}));
}, [o]), e.useEffect(() => {
if (!o) return;
let e = () => u(!0);
return o.on("works.load", e), o.works && o.works.length > 0 && u(!0), () => {
o.off("works.load", e);
};
}, [o]), !o || !l && !t || !s ? i == null ? null : e.createElement(e.Fragment, null, i) : e.createElement(e.Fragment, null, r);
}, O = {
position: "relative",
width: "100vw",
height: "100vh",
overflow: "hidden"
}, k = {
backgroundAlpha: 1,
backgroundColor: 0,
imageOptions: { size: 512 },
textureOptions: { autoResize: !1 },
preserveDrawingBuffer: !0,
webgl2: !0
}, A = ({ fiveInitArgs: t = k, renderChildren: n, plugins: r, load: i, children: a, fullscreen: o, autoCanvas: s = !0, fallback: c }) => {
let [l] = e.useState(() => S(Object.assign(Object.assign({}, t), { plugins: r }))), u = [];
s && u.push(e.createElement(E, { key: "auto-canvas" })), a && u.push(a);
let d = e.createElement(l, null, e.createElement(D, {
load: i,
renderChildren: n,
fallback: c
}, ...u));
return o ? e.createElement("div", { style: O }, d) : d;
};
//#endregion
//#region build/react/hooks/unsafe__useFiveInstance.js
function j() {
return v();
}
//#endregion
//#region build/react/hooks/useFiveSceneEffect.js
function M(t, n) {
let r = v(), i = [r];
n !== void 0 && (i = i.concat(n)), e.useLayoutEffect(() => t(r.scene), i);
}
var ee = M;
//#endregion
//#region build/react/hooks/useFiveWork.js
function te() {
let t = v(), n = y(), [r, i] = e.useState(() => t.works);
return e.useLayoutEffect(() => t.on("load", () => i(t.works)), [t]), [r, n];
}
//#endregion
//#region build/react/hooks/useFiveState.js
function N(e) {
return Object.assign({}, e.state);
}
function P() {
let t = v(), [n, r] = e.useState(() => N(t)), i = e.useCallback((e, n = !1, r = !0) => {
let i = typeof e == "function" ? e(t.getCurrentState()) : e;
t.setState(i, n, r);
}, [t]);
return e.useLayoutEffect(() => t.on("stateChange", () => r(N(t))), [t]), [n, i];
}
//#endregion
//#region build/react/hooks/useFiveCurrentState.js
function F() {
let t = v(), [n, r] = e.useState(() => t.getCurrentState()), i = e.useCallback((e, n = !1, r = !0) => {
let i = typeof e == "function" ? e(t.getCurrentState()) : e;
t.setState(i, n, r);
}, [t]);
return e.useLayoutEffect(() => t.on("currentStateChange", () => r(t.getCurrentState())), [t]), [n, i];
}
//#endregion
//#region build/react/hooks/useFiveCurrentObserver.js
function I() {
let t = v(), [n, r] = e.useState(() => t.getCurrentState());
return e.useLayoutEffect(() => t.on("currentStateChange", () => r(t.getCurrentState())), [t]), t.works.getObserver(n);
}
//#endregion
//#region build/react/hooks/useFiveEventCallback.js
function L(t, n, r) {
let i = v(), a = [i, t];
r !== void 0 && (a = a.concat(r)), e.useLayoutEffect(() => i.on(t, n), a);
}
//#endregion
//#region build/react/hooks/useFiveAction.js
function R() {
let t = v();
return {
updateCamera: e.useCallback((e, n) => t.updateCamera(e, n), [t]),
getPixels: e.useCallback(t.getPixels.bind(t), [t]),
render: e.useCallback((e) => t.render(e), [t]),
needsRender: e.useCallback(() => t.needsRender = !0, [t]),
preloadPano: e.useCallback((e, n) => t.preloadPano(e, n), [t])
};
}
//#endregion
//#region build/react/hooks/useFiveProject2d.js
function ne() {
let t = v(), [n, r] = e.useState(() => Symbol());
return e.useLayoutEffect(() => t.on("cameraUpdate", () => r(Symbol())), [t]), e.useCallback((e, n) => t.project2d(e, n), [t]);
}
//#endregion
//#region build/react/hooks/useFiveCameraRaycaster.js
function z(e) {
let t = e.camera.getWorldDirection(new a.Vector3());
return new a.Raycaster(e.camera.position, t);
}
function re() {
let t = v(), [n, r] = e.useState(() => z(t));
return e.useLayoutEffect(() => t.on("cameraUpdate", () => r(z(t))), [t]), n;
}
//#endregion
//#region build/react/hooks/useFiveCameraDirection.js
function B(e) {
return e.camera.getWorldDirection(new a.Vector3());
}
function ie() {
let t = v(), [n, r] = e.useState(() => B(t));
return e.useLayoutEffect(() => t.on("cameraUpdate", () => r(B(t))), [t]), n;
}
//#endregion
//#region build/react/hooks/useFiveModelIntersectRaycaster.js
function ae() {
let t = v();
return e.useCallback((e) => t.model.intersectRaycaster(e), [t]);
}
//#endregion
//#region build/react/hooks/useFiveModelReadyState.js
function V(e) {
return e.model.empty ? "Empty" : "Loaded";
}
function H() {
let t = v(), [n, r] = e.useState(() => V(t));
return e.useLayoutEffect(() => t.on("modelLoaded", () => r(V(t))), [t]), n;
}
//#endregion
//#region build/react/hooks/useFivePlugin.js
var U = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new Map();
function G(e) {
let t = W.get(e);
t && t.forEach((e) => e());
}
function K(e, t) {
return W.has(e) || W.set(e, /* @__PURE__ */ new Set()), W.get(e).add(t), () => {
let n = W.get(e);
n && (n.delete(t), n.size === 0 && W.delete(e));
};
}
function q(e, t) {
return `${e}:${t}`;
}
function J(e, t) {
var n;
return (n = U.get(q(e, t))) == null ? void 0 : n.plugin;
}
function oe(e, t, n) {
U.set(q(e, t), { plugin: n }), G(e);
}
function se(e, a) {
var o, s;
let c = v(), l = (s = (o = c.work) == null ? void 0 : o.workCode) == null ? "" : s, u = q(l, e), d = r(c), [, f] = i(0);
return n(() => {
if (l) return K(l, () => f((e) => e + 1));
}, [l]), n(() => {
if (d.current === c) return;
d.current = c;
let t = U.get(u);
if (!t) return;
let n = t.plugin;
if (a != null && a.reCreateOnFiveChange && a.createPlugin) {
typeof n.dispose == "function" && n.dispose();
let t = a.createPlugin(c);
U.set(u, { plugin: t }), c.plugins[e] = t, G(l);
} else n && (typeof n.updateFive == "function" ? n.updateFive(c) : "five" in n && (n.five = c));
}, [c]), t(() => {
let t = U.get(u);
if (t) return c.plugins[e] = t.plugin, t.plugin;
let n = c.plugins[e];
if (n) return U.set(u, { plugin: n }), n;
if (a != null && a.createPlugin) {
let t = a.createPlugin(c);
return U.set(u, { plugin: t }), c.plugins[e] = t, G(l), t;
}
}, [
u,
c,
a == null ? void 0 : a.createPlugin
])();
}
//#endregion
//#region build/react/hooks/useFiveFloor.js
function ce() {
let t = v(), [n, r] = e.useState(t.model.shownFloor), [i, a] = e.useState(t.model.floorLength), o = e.useCallback((e) => {
typeof e == "number" ? t.model.show(e) : t.model.show();
}, [t]);
return e.useLayoutEffect(() => {
let e = [];
return e.push(t.on("modelShownFloorChange", () => r(t.model.shownFloor))), e.push(t.on("modelLoaded", () => a(t.model.floorLength))), () => {
let t;
for (; t = e.shift();) t();
};
}, [t]), [
n,
i,
o
];
}
//#endregion
//#region build/react/hooks/useFiveHelper.js
function le() {
let t = v(), [n, r] = e.useState(t.helperVisible), i = e.useCallback((e) => {
t.helperVisible = e;
}, [t]);
return e.useLayoutEffect(() => t.on("helpersVisibleChange", (e) => r(e)), [t]), [n, i];
}
//#endregion
//#region build/react/withFive.js
var ue = "$five";
function Y(e, t) {
return t.indexOf(e) >= 0;
}
function X(e, t) {
for (let n of Object.keys(t)) t[n] !== void 0 && (e[n] = t[n]);
}
function de(t, n) {
let r = Y("state", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return Object.assign({}, t.state);
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("stateChange", () => a(Symbol()));
}, [t]), [o, i];
}
function fe(t, n) {
let r = Y("currentState", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return t.getCurrentState();
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("currentStateChange", () => a(Symbol()));
}, [t]), [o, i];
}
function pe(t, n) {
let r = Y("currentObserver", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return t.getCurrentState();
}, [t, i]);
e.useLayoutEffect(() => {
if (r) return t.on("currentStateChange", () => a(Symbol()));
}, [t]);
let s;
return o && (s = t.works.getObserver(o)), [s, i];
}
function me(e, t) {
return [Y("unsafe__fiveInstance", t) ? e : void 0];
}
function he(t, n) {
let r = Y("works", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return t.works;
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("load", () => a(Symbol()));
}, [t]), [o, i];
}
function ge(t, n) {
let r = Y("model", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return t.model;
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("modelLoaded", () => a(Symbol()));
}, [t]), [o, i];
}
function Z(e, t) {
return [Y("scene", t) ? e.scene : void 0];
}
function _e(t, n) {
let r = Y("cameraDirection", n), [i, o] = e.useState(Symbol()), s = e.useMemo(() => {
if (r) return t.camera.getWorldDirection(new a.Vector3());
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("cameraUpdate", () => o(Symbol()));
}, [t]), [s, i];
}
function ve(t, n) {
let r = Y("cameraRaycaster", n), [i, o] = e.useState(Symbol()), s = e.useMemo(() => {
if (r) {
let e = t.camera.getWorldDirection(new a.Vector3());
return new a.Raycaster(t.camera.position, e);
}
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("cameraUpdate", () => o(Symbol()));
}, [t]), [s, i];
}
function ye(t, n) {
let r = Y("modelReadyState", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return t.model.empty ? "Empty" : "Loaded";
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("modelLoaded", () => a(Symbol()));
}, [t]), [o, i];
}
function be(t, n) {
let r = Y("shownFloor", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return t.model.shownFloor;
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("modelShownFloorChange", () => a(Symbol()));
}, [t]), [o, i];
}
function xe(t, n) {
let r = Y("helperVisible", n), [i, a] = e.useState(Symbol()), o = e.useMemo(() => {
if (r) return t.helperVisible;
}, [t, i]);
return e.useLayoutEffect(() => {
if (r) return t.on("helpersVisibleChange", () => a(Symbol()));
}, [t]), [o, i];
}
function Se(e, t) {
if (Y("loadWork", t)) return e;
}
function Ce(e, t) {
if (Y("setState", t)) return (...t) => e.setState(...t);
}
function we(e, t) {
if (Y("on", t)) return (...t) => e.on(...t);
}
function Te(e, t) {
if (Y("on", t)) return (...t) => e.once(...t);
}
function Ee(e, t) {
if (Y("off", t)) return (...t) => e.off(...t);
}
function De(e, t) {
if (Y("intersectRaycaster", t)) return (...t) => e.model.intersectRaycaster(...t);
}
function Oe(e, t) {
if (Y("project2d", t)) return (...t) => e.project2d(...t);
}
function ke(e, t) {
if (Y("updateCamera", t)) return (...t) => e.updateCamera(...t);
}
function Ae(e, t) {
if (Y("getPixels", t)) return e.getPixels.bind(e);
}
function je(e, t) {
if (Y("render", t)) return (...t) => e.render(...t);
}
function Me(e, t) {
if (Y("needsRender", t)) return () => {
e.needsRender = !0;
};
}
function Ne(e, t) {
if (Y("preloadPano", t)) return (...t) => e.preloadPano(...t);
}
function Pe(e, t) {
if (Y("showFloor", t)) return (t) => {
typeof t == "number" ? e.model.show(t) : e.model.show();
};
}
function Fe(e, t) {
if (Y("toggleHelperVisible", t)) return (t) => {
e.helperVisible = t;
};
}
function Ie(t) {
return function(n) {
return e.forwardRef((r, i) => {
let a = v(), o = y(), [s] = me(a, t), [c, l] = de(a, t), [u, d] = fe(a, t), [f, p] = pe(a, t), [m, h] = he(a, t), [g, _] = ge(a, t), [b] = Z(a, t), [x, S] = _e(a, t), [C, w] = ve(a, t), [T, E] = ye(a, t), [D, O] = be(a, t), [k, A] = xe(a, t), j = e.useMemo(() => {
let e = {};
return X(e, {
setState: Ce(a, t),
loadWork: Se(o, t),
on: we(a, t),
once: Te(a, t),
off: Ee(a, t),
intersectRaycaster: De(a, t),
project2d: Oe(a, t),
updateCamera: ke(a, t),
getPixels: Ae(a, t),
render: je(a, t),
needsRender: Me(a, t),
preloadPano: Ne(a, t),
showFloor: Pe(a, t),
toggleHelperVisible: Fe(a, t)
}), e;
}, [a, o]), M = e.useMemo(() => {
let e = Object.assign({}, j);
return X(e, {
unsafe__fiveInstance: s,
state: c,
currentState: u,
currentObserver: f,
work: m,
model: g,
scene: b,
cameraDirection: x,
cameraRaycaster: C,
modelReadyState: T,
shownFloor: D,
helperVisible: k
}), e;
}, [
a,
j,
l,
d,
p,
h,
_,
S,
w,
E,
O,
A
]);
return e.createElement(n, Object.assign({
ref: i,
$five: M
}, r));
});
};
}
function Le(...e) {
return e;
}
//#endregion
//#region build/react/createStore.js
function Q(e, t) {
let n = {}, r = t.length, i = -1;
for (; ++i < r;) {
let r = t[i];
r in e && (n[r] = e[r]);
}
return n;
}
function Re(e, t) {
return typeof e == "number" && typeof t == "number" && isNaN(e) && isNaN(t) ? !0 : e === t;
}
function ze(e, t) {
for (let n = 0; n < e.length; n++) for (let r = 0; r < t.length; r++) if (e[n] === t[r]) return !0;
return !1;
}
var $ = class {
constructor(e, t) {
this.values = e, this.listeners = [], this.onValuesChange = t;
}
on(e, t) {
let n = [e, t];
return this.listeners.push(n), () => {
let e = this.listeners.indexOf(n);
e >= 0 && this.listeners.splice(e, 1);
};
}
getValues(e) {
return Q(this.values, e);
}
setValues(e, t) {
let n = [];
for (let r in t) e.indexOf(r) >= 0 && !Re(t[r], this.values[r]) && n.push(r);
if (n.length === 0) return;
let r = Object.assign({}, this.values);
for (let e of n) this.values[e] = t[e];
this.onValuesChange && this.onValuesChange(this.values, r);
for (let [e, t] of this.listeners) {
if (!ze(e, n)) continue;
let i = Q(r, e);
t(Q(this.values, e), i);
}
}
};
function Be(t) {
let n = e.createContext(null);
return {
useStore(t) {
let r = e.useContext(n);
if (r === null) throw Error("StoreProvider never found.");
let i = e.useRef(!0), [a, o] = e.useState(r.getValues(t)), s = [r, ...t];
return e.useLayoutEffect(() => (i.current ? i.current = !1 : o(r.getValues(t)), r.on(t, (e) => o(e))), s), [a, e.useCallback((e) => r.setValues(t, e), s)];
},
useStoreSetter(t) {
let r = e.useContext(n);
if (r === null) throw Error("StoreProvider never found.");
return e.useCallback((e) => r.setValues(t, e), [r, ...t]);
},
watchStore(t, r, i) {
let a = e.useContext(n);
if (a === null) throw Error("StoreProvider never found.");
let o = [a, ...t];
i !== void 0 && (o = o.concat(i)), e.useLayoutEffect(() => a.on(t, r), o);
},
useStoreAction(r) {
let i = e.useContext(n);
if (i === null) throw Error("StoreProvider never found.");
return e.useCallback((...e) => {
let [n, ...a] = t[r];
return n(() => i.getValues(a), (e) => i.setValues(a, e), ...e);
}, []);
},
StoreProvider: class extends e.Component {
constructor(e) {
super(e), this.store = new $(e.initialValue, (...e) => {
this.props.onValuesChange && this.props.onValuesChange(...e);
});
}
shouldComponentUpdate(e) {
return e.children !== this.props.children;
}
render() {
return e.createElement(n.Provider, { value: this.store }, this.props.children);
}
}
};
}
//#endregion
export { A as FiveApp, E as FiveAutoCanvas, T as FiveCanvas, ue as INJECTION_PROPNAME, $ as Store, Le as createFiveFeature, S as createFiveProvider, Be as createStore, J as getPlugin, oe as setPlugin, j as unsafe__useFiveInstance, R as useFiveAction, ie as useFiveCameraDirection, re as useFiveCameraRaycaster, I as useFiveCurrentObserver, F as useFiveCurrentState, L as useFiveEventCallback, ce as useFiveFloor, le as useFiveHelper, ae as useFiveModelIntersectRaycaster, H as useFiveModelReadyState, se as useFivePlugin, ne as useFiveProject2d, ee as useFiveScene, M as useFiveSceneEffect, P as useFiveState, te as useFiveWork, Ie as withFive };