r3f-managed-glb
Version:
Wrapper around the gbl/gltf loader that allows handling and customizing only selected nodes in JSX instead of generating the full JSX file.
698 lines (695 loc) • 23.4 kB
JavaScript
import Ie, { forwardRef as oe, useRef as pr, useEffect as mr, useMemo as De } from "react";
import { useGLTF as $e, useAnimations as hr } from "@react-three/drei";
import * as Ye from "three";
var ue = { exports: {} }, N = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Fe;
function yr() {
if (Fe) return N;
Fe = 1;
var i = Ie, c = Symbol.for("react.element"), T = Symbol.for("react.fragment"), g = Object.prototype.hasOwnProperty, O = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, S = { key: !0, ref: !0, __self: !0, __source: !0 };
function C(R, p, x) {
var f, b = {}, _ = null, A = null;
x !== void 0 && (_ = "" + x), p.key !== void 0 && (_ = "" + p.key), p.ref !== void 0 && (A = p.ref);
for (f in p) g.call(p, f) && !S.hasOwnProperty(f) && (b[f] = p[f]);
if (R && R.defaultProps) for (f in p = R.defaultProps, p) b[f] === void 0 && (b[f] = p[f]);
return { $$typeof: c, type: R, key: _, ref: A, props: b, _owner: O.current };
}
return N.Fragment = T, N.jsx = C, N.jsxs = C, N;
}
var V = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var We;
function gr() {
return We || (We = 1, process.env.NODE_ENV !== "production" && function() {
var i = Ie, c = Symbol.for("react.element"), T = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), S = Symbol.for("react.profiler"), C = Symbol.for("react.provider"), R = Symbol.for("react.context"), p = Symbol.for("react.forward_ref"), x = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), b = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), A = Symbol.for("react.offscreen"), I = Symbol.iterator, m = "@@iterator";
function D(e) {
if (e === null || typeof e != "object")
return null;
var r = I && e[I] || e[m];
return typeof r == "function" ? r : null;
}
var P = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function d(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
B("error", e, t);
}
}
function B(e, r, t) {
{
var n = P.ReactDebugCurrentFrame, u = n.getStackAddendum();
u !== "" && (r += "%s", t = t.concat([u]));
var s = t.map(function(o) {
return String(o);
});
s.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, s);
}
}
var G = !1, J = !1, $ = !1, Y = !1, U = !1, se;
se = Symbol.for("react.module.reference");
function Ue(e) {
return !!(typeof e == "string" || typeof e == "function" || e === g || e === S || U || e === O || e === x || e === f || Y || e === A || G || J || $ || typeof e == "object" && e !== null && (e.$$typeof === _ || e.$$typeof === b || e.$$typeof === C || e.$$typeof === R || e.$$typeof === p || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === se || e.getModuleId !== void 0));
}
function Me(e, r, t) {
var n = e.displayName;
if (n)
return n;
var u = r.displayName || r.name || "";
return u !== "" ? t + "(" + u + ")" : t;
}
function le(e) {
return e.displayName || "Context";
}
function w(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case g:
return "Fragment";
case T:
return "Portal";
case S:
return "Profiler";
case O:
return "StrictMode";
case x:
return "Suspense";
case f:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case R:
var r = e;
return le(r) + ".Consumer";
case C:
var t = e;
return le(t._context) + ".Provider";
case p:
return Me(e, e.render, "ForwardRef");
case b:
var n = e.displayName || null;
return n !== null ? n : w(e.type) || "Memo";
case _: {
var u = e, s = u._payload, o = u._init;
try {
return w(o(s));
} catch {
return null;
}
}
}
return null;
}
var j = Object.assign, M = 0, ce, fe, de, ve, pe, me, he;
function ye() {
}
ye.__reactDisabledLog = !0;
function Le() {
{
if (M === 0) {
ce = console.log, fe = console.info, de = console.warn, ve = console.error, pe = console.group, me = console.groupCollapsed, he = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: ye,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
M++;
}
}
function Ne() {
{
if (M--, M === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: j({}, e, {
value: ce
}),
info: j({}, e, {
value: fe
}),
warn: j({}, e, {
value: de
}),
error: j({}, e, {
value: ve
}),
group: j({}, e, {
value: pe
}),
groupCollapsed: j({}, e, {
value: me
}),
groupEnd: j({}, e, {
value: he
})
});
}
M < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var Z = P.ReactCurrentDispatcher, Q;
function q(e, r, t) {
{
if (Q === void 0)
try {
throw Error();
} catch (u) {
var n = u.stack.trim().match(/\n( *(at )?)/);
Q = n && n[1] || "";
}
return `
` + Q + e;
}
}
var ee = !1, K;
{
var Ve = typeof WeakMap == "function" ? WeakMap : Map;
K = new Ve();
}
function ge(e, r) {
if (!e || ee)
return "";
{
var t = K.get(e);
if (t !== void 0)
return t;
}
var n;
ee = !0;
var u = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var s;
s = Z.current, Z.current = null, Le();
try {
if (r) {
var o = function() {
throw Error();
};
if (Object.defineProperty(o.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(o, []);
} catch (y) {
n = y;
}
Reflect.construct(e, [], o);
} else {
try {
o.call();
} catch (y) {
n = y;
}
e.call(o.prototype);
}
} else {
try {
throw Error();
} catch (y) {
n = y;
}
e();
}
} catch (y) {
if (y && n && typeof y.stack == "string") {
for (var a = y.stack.split(`
`), h = n.stack.split(`
`), l = a.length - 1, v = h.length - 1; l >= 1 && v >= 0 && a[l] !== h[v]; )
v--;
for (; l >= 1 && v >= 0; l--, v--)
if (a[l] !== h[v]) {
if (l !== 1 || v !== 1)
do
if (l--, v--, v < 0 || a[l] !== h[v]) {
var E = `
` + a[l].replace(" at new ", " at ");
return e.displayName && E.includes("<anonymous>") && (E = E.replace("<anonymous>", e.displayName)), typeof e == "function" && K.set(e, E), E;
}
while (l >= 1 && v >= 0);
break;
}
}
} finally {
ee = !1, Z.current = s, Ne(), Error.prepareStackTrace = u;
}
var W = e ? e.displayName || e.name : "", k = W ? q(W) : "";
return typeof e == "function" && K.set(e, k), k;
}
function Be(e, r, t) {
return ge(e, !1);
}
function Ge(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function z(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return ge(e, Ge(e));
if (typeof e == "string")
return q(e);
switch (e) {
case x:
return q("Suspense");
case f:
return q("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case p:
return Be(e.render);
case b:
return z(e.type, r, t);
case _: {
var n = e, u = n._payload, s = n._init;
try {
return z(s(u), r, t);
} catch {
}
}
}
return "";
}
var L = Object.prototype.hasOwnProperty, be = {}, Ee = P.ReactDebugCurrentFrame;
function X(e) {
if (e) {
var r = e._owner, t = z(e.type, e._source, r ? r.type : null);
Ee.setExtraStackFrame(t);
} else
Ee.setExtraStackFrame(null);
}
function Je(e, r, t, n, u) {
{
var s = Function.call.bind(L);
for (var o in e)
if (s(e, o)) {
var a = void 0;
try {
if (typeof e[o] != "function") {
var h = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw h.name = "Invariant Violation", h;
}
a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (l) {
a = l;
}
a && !(a instanceof Error) && (X(u), d("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, o, typeof a), X(null)), a instanceof Error && !(a.message in be) && (be[a.message] = !0, X(u), d("Failed %s type: %s", t, a.message), X(null));
}
}
}
var qe = Array.isArray;
function re(e) {
return qe(e);
}
function Ke(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function ze(e) {
try {
return Re(e), !1;
} catch {
return !0;
}
}
function Re(e) {
return "" + e;
}
function _e(e) {
if (ze(e))
return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ke(e)), Re(e);
}
var Te = P.ReactCurrentOwner, Xe = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Oe, Se;
function He(e) {
if (L.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function Ze(e) {
if (L.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function Qe(e, r) {
typeof e.ref == "string" && Te.current;
}
function er(e, r) {
{
var t = function() {
Oe || (Oe = !0, d("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function rr(e, r) {
{
var t = function() {
Se || (Se = !0, d("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var tr = function(e, r, t, n, u, s, o) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: c,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: o,
// Record the component responsible for creating this element.
_owner: s
};
return a._store = {}, Object.defineProperty(a._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(a, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: n
}), Object.defineProperty(a, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: u
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
};
function nr(e, r, t, n, u) {
{
var s, o = {}, a = null, h = null;
t !== void 0 && (_e(t), a = "" + t), Ze(r) && (_e(r.key), a = "" + r.key), He(r) && (h = r.ref, Qe(r, u));
for (s in r)
L.call(r, s) && !Xe.hasOwnProperty(s) && (o[s] = r[s]);
if (e && e.defaultProps) {
var l = e.defaultProps;
for (s in l)
o[s] === void 0 && (o[s] = l[s]);
}
if (a || h) {
var v = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && er(o, v), h && rr(o, v);
}
return tr(e, a, h, u, n, Te.current, o);
}
}
var te = P.ReactCurrentOwner, xe = P.ReactDebugCurrentFrame;
function F(e) {
if (e) {
var r = e._owner, t = z(e.type, e._source, r ? r.type : null);
xe.setExtraStackFrame(t);
} else
xe.setExtraStackFrame(null);
}
var ne;
ne = !1;
function ae(e) {
return typeof e == "object" && e !== null && e.$$typeof === c;
}
function Pe() {
{
if (te.current) {
var e = w(te.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function ar(e) {
return "";
}
var we = {};
function ir(e) {
{
var r = Pe();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function Ce(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = ir(r);
if (we[t])
return;
we[t] = !0;
var n = "";
e && e._owner && e._owner !== te.current && (n = " It was passed a child from " + w(e._owner.type) + "."), F(e), d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), F(null);
}
}
function je(e, r) {
{
if (typeof e != "object")
return;
if (re(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
ae(n) && Ce(n, r);
}
else if (ae(e))
e._store && (e._store.validated = !0);
else if (e) {
var u = D(e);
if (typeof u == "function" && u !== e.entries)
for (var s = u.call(e), o; !(o = s.next()).done; )
ae(o.value) && Ce(o.value, r);
}
}
}
function or(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === p || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === b))
t = r.propTypes;
else
return;
if (t) {
var n = w(r);
Je(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !ne) {
ne = !0;
var u = w(r);
d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function ur(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
F(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), F(null);
break;
}
}
e.ref !== null && (F(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), F(null));
}
}
var ke = {};
function Ae(e, r, t, n, u, s) {
{
var o = Ue(e);
if (!o) {
var a = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var h = ar();
h ? a += h : a += Pe();
var l;
e === null ? l = "null" : re(e) ? l = "array" : e !== void 0 && e.$$typeof === c ? (l = "<" + (w(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : l = typeof e, d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", l, a);
}
var v = nr(e, r, t, u, s);
if (v == null)
return v;
if (o) {
var E = r.children;
if (E !== void 0)
if (n)
if (re(E)) {
for (var W = 0; W < E.length; W++)
je(E[W], e);
Object.freeze && Object.freeze(E);
} else
d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
je(E, e);
}
if (L.call(r, "key")) {
var k = w(e), y = Object.keys(r).filter(function(vr) {
return vr !== "key";
}), ie = y.length > 0 ? "{key: someKey, " + y.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!ke[k + ie]) {
var dr = y.length > 0 ? "{" + y.join(": ..., ") + ": ...}" : "{}";
d(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, ie, k, dr, k), ke[k + ie] = !0;
}
}
return e === g ? ur(v) : or(v), v;
}
}
function sr(e, r, t) {
return Ae(e, r, t, !0);
}
function lr(e, r, t) {
return Ae(e, r, t, !1);
}
var cr = lr, fr = sr;
V.Fragment = g, V.jsx = cr, V.jsxs = fr;
}()), V;
}
process.env.NODE_ENV === "production" ? ue.exports = yr() : ue.exports = gr();
var H = ue.exports;
const Or = (i) => $e.preload(i), br = (i) => {
const c = {
name: i.name,
animations: i.animations,
position: i.position,
rotation: i.rotation,
scale: i.scale,
userData: i.userData,
matrix: i.matrix,
matrixAutoUpdate: i.matrixAutoUpdate,
matrixWorld: i.matrixWorld,
matrixWorldAutoUpdate: i.matrixWorldAutoUpdate,
matrixWorldNeedsUpdate: i.matrixWorldNeedsUpdate,
castShadow: i.castShadow,
receiveShadow: i.receiveShadow,
renderOrder: i.renderOrder,
// quaternion: node.quaternion, // breaks setting rotation via props.rotation
up: i.up,
visible: i.visible,
uuid: i.uuid
};
return i instanceof Ye.Mesh ? {
...c,
material: i.material,
geometry: i.geometry
} : c;
}, Er = (i, c) => c.split("|").includes(i), Rr = (i, c) => {
const g = Object.keys(c).find((O) => Er(i, O));
return g ? c[g] : null;
}, Sr = (i, c = 10) => Array.apply(null, Array(c)).map((T, g) => i + "_" + (g + 1)).join("|"), xr = oe((i, c) => {
const { custom: T = {}, path: g, debug: O, onInit: S, castShadow: C = !0, recieveShadow: R = !0 } = i, p = pr(null), x = $e(g), { scene: f, animations: b } = x, { actions: _ } = hr(b, p);
mr(() => {
f && (S == null || S({ scene: f, animations: b, actions: _ }));
}, [f]), O && console.log(f);
const A = (m) => {
c && (typeof c == "function" ? c(m) : c.current = m), p.current = m;
}, I = (m) => {
const D = Rr(m.name, T), P = m.name === f.name ? { ...i, ref: A, dispose: null } : {}, d = {
...br(m),
...C,
...R,
...P
}, B = De(
() => oe(
({ children: $, ...Y }, U) => /* @__PURE__ */ H.jsxs("group", { ref: U, ...d, ...Y, children: [
J(),
$
] }, m.name)
),
[m.name, d]
), G = De(
() => oe(
({ children: $, ...Y }, U) => /* @__PURE__ */ H.jsxs("mesh", { ref: U, ...d, ...Y, children: [
J(),
$
] }, m.name)
),
[m.name, d]
), J = () => m.children.map(I);
return m instanceof Ye.Mesh ? D ? D(G, m) : /* @__PURE__ */ H.jsx(G, {}) : D ? D(B, m) : /* @__PURE__ */ H.jsx(B, {});
};
return I(f);
});
export {
xr as ManagedGLB,
Sr as meshesInNodeByCount,
Or as preloadGLB
};