UNPKG

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.

31 lines (28 loc) 15.7 kB
(function(T,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@react-three/drei"),require("three")):typeof define=="function"&&define.amd?define(["exports","react","@react-three/drei","three"],b):(T=typeof globalThis<"u"?globalThis:T||self,b(T.ManagedGLB={},T.React,T.ReactThreeDrei,T.THREE))})(this,function(T,b,ee,Le){"use strict";function Ye(a){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const R in a)if(R!=="default"){const h=Object.getOwnPropertyDescriptor(a,R);Object.defineProperty(c,R,h.get?h:{enumerable:!0,get:()=>a[R]})}}return c.default=a,Object.freeze(c)}const le=Ye(Le);var re={exports:{}},L={};/** * @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 Ue(){if(fe)return L;fe=1;var a=b,c=Symbol.for("react.element"),R=Symbol.for("react.fragment"),h=Object.prototype.hasOwnProperty,P=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,w={key:!0,ref:!0,__self:!0,__source:!0};function k(O,p,j){var f,E={},S=null,F=null;j!==void 0&&(S=""+j),p.key!==void 0&&(S=""+p.key),p.ref!==void 0&&(F=p.ref);for(f in p)h.call(p,f)&&!w.hasOwnProperty(f)&&(E[f]=p[f]);if(O&&O.defaultProps)for(f in p=O.defaultProps,p)E[f]===void 0&&(E[f]=p[f]);return{$$typeof:c,type:O,key:S,ref:F,props:E,_owner:P.current}}return L.Fragment=R,L.jsx=k,L.jsxs=k,L}var Y={};/** * @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 de;function Ne(){return de||(de=1,process.env.NODE_ENV!=="production"&&function(){var a=b,c=Symbol.for("react.element"),R=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),k=Symbol.for("react.provider"),O=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),E=Symbol.for("react.memo"),S=Symbol.for("react.lazy"),F=Symbol.for("react.offscreen"),U=Symbol.iterator,m="@@iterator";function I(e){if(e===null||typeof e!="object")return null;var r=U&&e[U]||e[m];return typeof r=="function"?r:null}var x=a.__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];$("error",e,t)}}function $(e,r,t){{var n=x.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var s=t.map(function(i){return String(i)});s.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,s)}}var z=!1,H=!1,N=!1,V=!1,B=!1,ve;ve=Symbol.for("react.module.reference");function ze(e){return!!(typeof e=="string"||typeof e=="function"||e===h||e===w||B||e===P||e===j||e===f||V||e===F||z||H||N||typeof e=="object"&&e!==null&&(e.$$typeof===S||e.$$typeof===E||e.$$typeof===k||e.$$typeof===O||e.$$typeof===p||e.$$typeof===ve||e.getModuleId!==void 0))}function He(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function pe(e){return e.displayName||"Context"}function C(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 h:return"Fragment";case R:return"Portal";case w:return"Profiler";case P:return"StrictMode";case j:return"Suspense";case f:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case O:var r=e;return pe(r)+".Consumer";case k:var t=e;return pe(t._context)+".Provider";case p:return He(e,e.render,"ForwardRef");case E:var n=e.displayName||null;return n!==null?n:C(e.type)||"Memo";case S:{var u=e,s=u._payload,i=u._init;try{return C(i(s))}catch{return null}}}return null}var D=Object.assign,G=0,me,he,ye,ge,be,Re,Ee;function _e(){}_e.__reactDisabledLog=!0;function Xe(){{if(G===0){me=console.log,he=console.info,ye=console.warn,ge=console.error,be=console.group,Re=console.groupCollapsed,Ee=console.groupEnd;var e={configurable:!0,enumerable:!0,value:_e,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}G++}}function qe(){{if(G--,G===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:me}),info:D({},e,{value:he}),warn:D({},e,{value:ye}),error:D({},e,{value:ge}),group:D({},e,{value:be}),groupCollapsed:D({},e,{value:Re}),groupEnd:D({},e,{value:Ee})})}G<0&&d("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var te=x.ReactCurrentDispatcher,ne;function X(e,r,t){{if(ne===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);ne=n&&n[1]||""}return` `+ne+e}}var ae=!1,q;{var Ze=typeof WeakMap=="function"?WeakMap:Map;q=new Ze}function Te(e,r){if(!e||ae)return"";{var t=q.get(e);if(t!==void 0)return t}var n;ae=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=te.current,te.current=null,Xe();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(g){n=g}Reflect.construct(e,[],i)}else{try{i.call()}catch(g){n=g}e.call(i.prototype)}}else{try{throw Error()}catch(g){n=g}e()}}catch(g){if(g&&n&&typeof g.stack=="string"){for(var o=g.stack.split(` `),y=n.stack.split(` `),l=o.length-1,v=y.length-1;l>=1&&v>=0&&o[l]!==y[v];)v--;for(;l>=1&&v>=0;l--,v--)if(o[l]!==y[v]){if(l!==1||v!==1)do if(l--,v--,v<0||o[l]!==y[v]){var _=` `+o[l].replace(" at new "," at ");return e.displayName&&_.includes("<anonymous>")&&(_=_.replace("<anonymous>",e.displayName)),typeof e=="function"&&q.set(e,_),_}while(l>=1&&v>=0);break}}}finally{ae=!1,te.current=s,qe(),Error.prepareStackTrace=u}var M=e?e.displayName||e.name:"",A=M?X(M):"";return typeof e=="function"&&q.set(e,A),A}function Qe(e,r,t){return Te(e,!1)}function er(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function Z(e,r,t){if(e==null)return"";if(typeof e=="function")return Te(e,er(e));if(typeof e=="string")return X(e);switch(e){case j:return X("Suspense");case f:return X("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case p:return Qe(e.render);case E:return Z(e.type,r,t);case S:{var n=e,u=n._payload,s=n._init;try{return Z(s(u),r,t)}catch{}}}return""}var J=Object.prototype.hasOwnProperty,Oe={},Se=x.ReactDebugCurrentFrame;function Q(e){if(e){var r=e._owner,t=Z(e.type,e._source,r?r.type:null);Se.setExtraStackFrame(t)}else Se.setExtraStackFrame(null)}function rr(e,r,t,n,u){{var s=Function.call.bind(J);for(var i in e)if(s(e,i)){var o=void 0;try{if(typeof e[i]!="function"){var y=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw y.name="Invariant Violation",y}o=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){o=l}o&&!(o instanceof Error)&&(Q(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,i,typeof o),Q(null)),o instanceof Error&&!(o.message in Oe)&&(Oe[o.message]=!0,Q(u),d("Failed %s type: %s",t,o.message),Q(null))}}}var tr=Array.isArray;function oe(e){return tr(e)}function nr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function ar(e){try{return Pe(e),!1}catch{return!0}}function Pe(e){return""+e}function we(e){if(ar(e))return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",nr(e)),Pe(e)}var je=x.ReactCurrentOwner,or={key:!0,ref:!0,__self:!0,__source:!0},xe,Ce;function ir(e){if(J.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function ur(e){if(J.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function sr(e,r){typeof e.ref=="string"&&je.current}function cr(e,r){{var t=function(){xe||(xe=!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 lr(e,r){{var t=function(){Ce||(Ce=!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 fr=function(e,r,t,n,u,s,i){var o={$$typeof:c,type:e,key:r,ref:t,props:i,_owner:s};return o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o};function dr(e,r,t,n,u){{var s,i={},o=null,y=null;t!==void 0&&(we(t),o=""+t),ur(r)&&(we(r.key),o=""+r.key),ir(r)&&(y=r.ref,sr(r,u));for(s in r)J.call(r,s)&&!or.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var l=e.defaultProps;for(s in l)i[s]===void 0&&(i[s]=l[s])}if(o||y){var v=typeof e=="function"?e.displayName||e.name||"Unknown":e;o&&cr(i,v),y&&lr(i,v)}return fr(e,o,y,u,n,je.current,i)}}var ie=x.ReactCurrentOwner,ke=x.ReactDebugCurrentFrame;function W(e){if(e){var r=e._owner,t=Z(e.type,e._source,r?r.type:null);ke.setExtraStackFrame(t)}else ke.setExtraStackFrame(null)}var ue;ue=!1;function se(e){return typeof e=="object"&&e!==null&&e.$$typeof===c}function De(){{if(ie.current){var e=C(ie.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function vr(e){return""}var Ae={};function pr(e){{var r=De();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 Fe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=pr(r);if(Ae[t])return;Ae[t]=!0;var n="";e&&e._owner&&e._owner!==ie.current&&(n=" It was passed a child from "+C(e._owner.type)+"."),W(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),W(null)}}function Ie(e,r){{if(typeof e!="object")return;if(oe(e))for(var t=0;t<e.length;t++){var n=e[t];se(n)&&Fe(n,r)}else if(se(e))e._store&&(e._store.validated=!0);else if(e){var u=I(e);if(typeof u=="function"&&u!==e.entries)for(var s=u.call(e),i;!(i=s.next()).done;)se(i.value)&&Fe(i.value,r)}}}function mr(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||r.$$typeof===E))t=r.propTypes;else return;if(t){var n=C(r);rr(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ue){ue=!0;var u=C(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 hr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){W(e),d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),W(null);break}}e.ref!==null&&(W(e),d("Invalid attribute `ref` supplied to `React.Fragment`."),W(null))}}var We={};function Me(e,r,t,n,u,s){{var i=ze(e);if(!i){var o="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(o+=" 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 y=vr();y?o+=y:o+=De();var l;e===null?l="null":oe(e)?l="array":e!==void 0&&e.$$typeof===c?(l="<"+(C(e.type)||"Unknown")+" />",o=" 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,o)}var v=dr(e,r,t,u,s);if(v==null)return v;if(i){var _=r.children;if(_!==void 0)if(n)if(oe(_)){for(var M=0;M<_.length;M++)Ie(_[M],e);Object.freeze&&Object.freeze(_)}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 Ie(_,e)}if(J.call(r,"key")){var A=C(e),g=Object.keys(r).filter(function(_r){return _r!=="key"}),ce=g.length>0?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}";if(!We[A+ce]){var Er=g.length>0?"{"+g.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} />`,ce,A,Er,A),We[A+ce]=!0}}return e===h?hr(v):mr(v),v}}function yr(e,r,t){return Me(e,r,t,!0)}function gr(e,r,t){return Me(e,r,t,!1)}var br=gr,Rr=yr;Y.Fragment=h,Y.jsx=br,Y.jsxs=Rr}()),Y}process.env.NODE_ENV==="production"?re.exports=Ue():re.exports=Ne();var K=re.exports;const Ve=a=>ee.useGLTF.preload(a),Be=a=>{const c={name:a.name,animations:a.animations,position:a.position,rotation:a.rotation,scale:a.scale,userData:a.userData,matrix:a.matrix,matrixAutoUpdate:a.matrixAutoUpdate,matrixWorld:a.matrixWorld,matrixWorldAutoUpdate:a.matrixWorldAutoUpdate,matrixWorldNeedsUpdate:a.matrixWorldNeedsUpdate,castShadow:a.castShadow,receiveShadow:a.receiveShadow,renderOrder:a.renderOrder,up:a.up,visible:a.visible,uuid:a.uuid};return a instanceof le.Mesh?{...c,material:a.material,geometry:a.geometry}:c},Ge=(a,c)=>c.split("|").includes(a),Je=(a,c)=>{const h=Object.keys(c).find(P=>Ge(a,P));return h?c[h]:null},Ke=(a,c=10)=>Array.apply(null,Array(c)).map((R,h)=>a+"_"+(h+1)).join("|"),$e=b.forwardRef((a,c)=>{const{custom:R={},path:h,debug:P,onInit:w,castShadow:k=!0,recieveShadow:O=!0}=a,p=b.useRef(null),j=ee.useGLTF(h),{scene:f,animations:E}=j,{actions:S}=ee.useAnimations(E,p);b.useEffect(()=>{f&&(w==null||w({scene:f,animations:E,actions:S}))},[f]),P&&console.log(f);const F=m=>{c&&(typeof c=="function"?c(m):c.current=m),p.current=m},U=m=>{const I=Je(m.name,R),x=m.name===f.name?{...a,ref:F,dispose:null}:{},d={...Be(m),...k,...O,...x},$=b.useMemo(()=>b.forwardRef(({children:N,...V},B)=>K.jsxs("group",{ref:B,...d,...V,children:[H(),N]},m.name)),[m.name,d]),z=b.useMemo(()=>b.forwardRef(({children:N,...V},B)=>K.jsxs("mesh",{ref:B,...d,...V,children:[H(),N]},m.name)),[m.name,d]),H=()=>m.children.map(U);return m instanceof le.Mesh?I?I(z,m):K.jsx(z,{}):I?I($,m):K.jsx($,{})};return U(f)});T.ManagedGLB=$e,T.meshesInNodeByCount=Ke,T.preloadGLB=Ve,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});