lunchboxjs 0.2.1001-beta.302 → 0.2.1013
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lunchboxjs.js +30 -8
- package/dist/lunchboxjs.min.js +1 -1
- package/dist/lunchboxjs.module.js +30 -8
- package/package.json +4 -5
- package/src/index.ts +32 -14
package/dist/lunchboxjs.js
CHANGED
|
@@ -1660,13 +1660,19 @@
|
|
|
1660
1660
|
/** Run a function using the current camera when it's present. */
|
|
1661
1661
|
|
|
1662
1662
|
const onCameraReady = cb => {
|
|
1663
|
-
const
|
|
1663
|
+
const existing = useCamera();
|
|
1664
|
+
|
|
1665
|
+
if (existing.value) {
|
|
1666
|
+
cb(existing.value);
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
let stopWatch = null;
|
|
1671
|
+
stopWatch = vue.watch(useCamera(), newVal => {
|
|
1664
1672
|
if (newVal) {
|
|
1665
1673
|
cb(newVal);
|
|
1666
|
-
stopWatch();
|
|
1674
|
+
stopWatch?.();
|
|
1667
1675
|
}
|
|
1668
|
-
}, {
|
|
1669
|
-
immediate: true
|
|
1670
1676
|
});
|
|
1671
1677
|
};
|
|
1672
1678
|
/** The current renderer as a computed value. */
|
|
@@ -1675,10 +1681,18 @@
|
|
|
1675
1681
|
/** Run a function using the current renderer when it's present. */
|
|
1676
1682
|
|
|
1677
1683
|
const onRendererReady = cb => {
|
|
1678
|
-
const
|
|
1684
|
+
const existing = useRenderer();
|
|
1685
|
+
|
|
1686
|
+
if (existing.value) {
|
|
1687
|
+
cb(existing.value);
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
let stopWatch = null;
|
|
1692
|
+
stopWatch = vue.watch(useRenderer(), newVal => {
|
|
1679
1693
|
if (newVal) {
|
|
1680
1694
|
cb(newVal);
|
|
1681
|
-
stopWatch();
|
|
1695
|
+
stopWatch?.();
|
|
1682
1696
|
}
|
|
1683
1697
|
}, {
|
|
1684
1698
|
immediate: true
|
|
@@ -1690,10 +1704,18 @@
|
|
|
1690
1704
|
/** Run a function using the current scene when it's present. */
|
|
1691
1705
|
|
|
1692
1706
|
const onSceneReady = cb => {
|
|
1693
|
-
const
|
|
1707
|
+
const existing = useScene();
|
|
1708
|
+
|
|
1709
|
+
if (existing.value) {
|
|
1710
|
+
cb(existing.value);
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
let stopWatch = null;
|
|
1715
|
+
stopWatch = vue.watch(useScene(), newVal => {
|
|
1694
1716
|
if (newVal) {
|
|
1695
1717
|
cb(newVal);
|
|
1696
|
-
stopWatch();
|
|
1718
|
+
stopWatch?.();
|
|
1697
1719
|
}
|
|
1698
1720
|
}, {
|
|
1699
1721
|
immediate: true
|
package/dist/lunchboxjs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("three"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","vue","three","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Lunchbox={},e.vue,e.three,e.lodash)}(this,(function(e,t,r,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=o(r);const i=e=>e?.$el&&e?.$el?.hasOwnProperty?.("instance"),s=e=>"domMeta"===e?.metaType||e?.props?.["data-lunchbox"],c=e=>"standardMeta"===e?.metaType,d=e=>e.isLunchboxRootNode;function l(t={}){const r={text:t.text??""};return new e.MiniDom.RendererCommentNode({...r,...t,metaType:"commentMeta"})}function u(t={}){const r={domElement:document.createElement(t.type??"")};return new e.MiniDom.RendererDomNode({...r,...t,metaType:"domMeta"})}function p(t={}){const r={text:t.text??""};return new e.MiniDom.RendererTextNode({...t,...r,metaType:"textMeta"})}function m(t={},r={}){const n={attached:t.attached??[],attachedArray:t.attachedArray??{},instance:t.instance??null},o=new e.MiniDom.RendererStandardNode({...t,...n,metaType:"standardMeta"});return!o.type||d(o)||o.instance||(o.instance=E({...o,props:{...o.props,...r}})),o}function h({node:e,key:t,interactables:r,value:n}){return e.eventListeners[t]||(e.eventListeners[t]=[]),e.eventListenerRemoveFunctions[t]||(e.eventListenerRemoveFunctions[t]=[]),e.eventListeners[t].push(n),f.includes(t)&&e.instance&&!r.value.includes(e)&&(r.value.push(e),e.eventListenerRemoveFunctions[t].push((()=>{const t=r.value.indexOf(e);-1!==t&&r.value.splice(t,1)}))),e}const f=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"],y=(e,r,n,o,a)=>{if(!r?.domElement||!n||!e)return;const i=(o=o??window.innerWidth)/(a=a??window.innerHeight);if("perspectivecamera"===e.type?.toLowerCase()){const t=e;t.aspect=i,t.updateProjectionMatrix()}else if("orthographiccamera"===e.type?.toLowerCase()){const t=e,r=a/o;t.top=10*r,t.bottom=10*-r,t.right=10,t.left=-10,t.updateProjectionMatrix()}r.setSize(o,a),n&&e&&r.render(t.toRaw(n),t.toRaw(e))},b=(e,t,r,n,o)=>{const a=e.value?.domElement;if(!a)throw new Error("missing container");const i=()=>{if("container"===o){const e=(e=>{const t=getComputedStyle(e);return{width:e.clientWidth-parseFloat(t.paddingLeft)-parseFloat(t.paddingRight),height:e.clientHeight-parseFloat(t.paddingTop)-parseFloat(t.paddingBottom)}})(a);y(t,r,n,e.width,e.height)}else y(t,r,n)};i();let s=new ResizeObserver((()=>{i()}));return a&&s.observe(a),{dispose(){a&&s.unobserve(a)}}},g=t.defineComponent({name:"LunchboxScene",setup:(e,{slots:r})=>()=>t.createVNode(t.resolveComponent("scene"),null,{default:()=>[r.default?.()]})}),v=t.defineComponent({name:"LunchboxEventHandlers",setup(){const e=Le(),r=Pe(),n=t.ref({x:1/0,y:1/0}),o=t.ref(!1);let i=[];const s=new a.Raycaster(new a.Vector3,new a.Vector3(0,0,-1)),c=({element:e,eventKeys:t,intersection:r})=>{e&&t.forEach((t=>{e.eventListeners[t]&&e.eventListeners[t].forEach((e=>{e({intersection:r})}))}))};xe((e=>{if(!e?.domElement)return;const{domElement:t}=e;t.addEventListener("pointermove",(e=>{const o=(t.width??1)/r.dpr,a=(t.height??1)/r.dpr;n.value.x=e.offsetX/o*2-1,n.value.y=-e.offsetY/a*2+1})),t.addEventListener("pointerdown",(()=>o.value=!0)),t.addEventListener("pointerup",(()=>o.value=!1))}));const d=ge(),l=()=>{const t=d.value;if(!t)return;s.setFromCamera(n.value,t);const r=s.intersectObjects(e?.value.map((e=>e.instance))??[]);let o=[],a=[],l=[];o=i.map((e=>e.intersection)),r?.forEach((t=>{if(-1===i.findIndex((e=>e.intersection.object===t.object))){const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&a.push({element:r,intersection:t})}else{const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&l.push({element:r,intersection:t})}const r=o.findIndex((e=>e.object.uuid===t.object.uuid));-1!==r&&o.splice(r,1)}));const u=o.map((t=>({element:e?.value.find((e=>e.instance?.uuid===t.object.uuid)),intersection:t})));a.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerEnter"],intersection:t})})),l.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerOver","onPointerMove"],intersection:t})})),u.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerLeave","onPointerOut"],intersection:t})})),i=[].concat(a,l)};ne(l);t.onBeforeUnmount((()=>oe(l)));const u=["onClick","onPointerDown","onPointerUp"];return t.watch(o,(e=>{l();const t=[];i.forEach((r=>{u.forEach((n=>{const o=r.element.uuid+n;!e||"onClick"!==n&&"onPointerDown"!==n?e||"onPointerUp"!==n||t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.intersection}))),t.push(o)):t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.intersection}))),t.push(o))}))}))})),()=>t.createVNode(t.resolveComponent("object3D"),null,null)}}),x=e=>({position:e,top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",display:"block"}),R=t.defineComponent({name:"Lunchbox",props:{background:String,cameraArgs:Array,cameraLook:Array,cameraLookAt:Array,cameraPosition:Array,dpr:Number,ortho:Boolean,orthographic:Boolean,r3f:Boolean,rendererArguments:Object,rendererProperties:Object,sizePolicy:String,shadow:[Boolean,Object],transparent:Boolean,zoom:Number,updateSource:Object},setup(e,r){const n=t.ref();let o=e.dpr??-1;const i=t.ref(),s=t.ref(),c=t.ref(),d=t.ref(),l=Pe(),u=Ce(),p=Ae(),m=t.reactive({}),h=Ee();e.r3f&&a?.ColorManagement&&(a.ColorManagement.legacyMode=!1);const f=Le();t.onMounted((async()=>{if(!n.value&&!r.slots?.renderer?.()?.length)throw new Error("missing canvas");for(r.slots?.camera?.()?.length||(e.cameraPosition&&(m.position=e.cameraPosition),(e.cameraLook||e.cameraLookAt)&&(m.lookAt=e.cameraLook||e.cameraLookAt),void 0!==e.zoom&&(m.zoom=e.zoom)),d.value?.$el?.instance&&e.background&&(d.value.$el.instance.background=new a.Color(e.background)),-1===o&&(o=window.devicePixelRatio),u?.({dpr:o});!s.value?.$el?.instance&&!s.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));for(;!d.value?.$el?.instance&&!d.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));const t=s.value?.$el?.instance??s.value?.component?.ctx.$el?.instance;t.setPixelRatio(l.dpr);const f=d.value?.$el?.instance??d.value?.component?.ctx.$el?.instance,y=c.value?.$el?.instance??c.value?.component?.ctx.$el?.instance;if(!r.slots?.renderer?.()?.length){b(i,y,t,f,e.sizePolicy),e.r3f&&(t.outputEncoding=a.sRGBEncoding,t.toneMapping=a.ACESFilmicToneMapping);const r={shadow:e.shadow};r?.shadow&&(t.shadowMap.enabled=!0,"object"==typeof r.shadow&&(t.shadowMap.type=r.shadow.type))}if(!p)throw new Error("error creating app");p.config.globalProperties.lunchbox.camera=y,p.config.globalProperties.lunchbox.renderer=t,p.config.globalProperties.lunchbox.scene=f;for(let e of h??[])e({app:p,camera:y,renderer:t,scene:f});te({app:p,camera:y,renderer:t,scene:f,updateSource:e.updateSource})})),t.onBeforeUnmount((()=>{ie(),ce()}));const y="container"===e.sizePolicy?"static":"absolute",R="container"===e.sizePolicy?"static":"fixed",w=t.computed((()=>{const e=r.slots?.camera?.().find((e=>e.type?.name));return e||e}));return t.watch(w,(async(e,t)=>{e&&e?.props?.key!==t?.props?.key&&(c.value=e)}),{immediate:!0}),()=>t.createVNode(t.Fragment,null,[r.slots?.renderer?.()?.length?s.value=r.slots?.renderer?.()[0]:t.createVNode(t.Fragment,null,[t.createVNode("div",{class:"lunchbox-container",style:x(y),ref:i,"data-lunchbox":"true"},[t.createVNode("canvas",{ref:n,class:"lunchbox-canvas",style:x(R),"data-lunchbox":"true"},null)]),n.value?.domElement&&t.createVNode(t.resolveComponent("webGLRenderer"),t.mergeProps(e.rendererProperties??{},{ref:s,args:[{alpha:e.transparent,antialias:!0,canvas:n.value?.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}}]}),null)]),r.slots?.scene?.()?.length?d.value=r.slots?.scene?.()[0]:t.createVNode(g,{ref:d},{default:()=>[r.slots?.default?.()]}),r.slots?.camera?.()?.length?c.value:e.ortho||e.orthographic?t.createVNode(t.resolveComponent("orthographicCamera"),t.mergeProps({ref:c,args:e.cameraArgs??[]},m),null):t.createVNode(t.resolveComponent("perspectiveCamera"),t.mergeProps({ref:c,args:e.cameraArgs??[e.r3f?75:45,.5625,1,1e3]},m),null),f?.value.length&&t.createVNode(v,null,null)])}}),w={},P={...["mesh","instancedMesh","scene","sprite","object3D","instancedBufferGeometry","bufferGeometry","boxBufferGeometry","circleBufferGeometry","coneBufferGeometry","cylinderBufferGeometry","dodecahedronBufferGeometry","extrudeBufferGeometry","icosahedronBufferGeometry","latheBufferGeometry","octahedronBufferGeometry","parametricBufferGeometry","planeBufferGeometry","polyhedronBufferGeometry","ringBufferGeometry","shapeBufferGeometry","sphereBufferGeometry","tetrahedronBufferGeometry","textBufferGeometry","torusBufferGeometry","torusKnotBufferGeometry","tubeBufferGeometry","wireframeGeometry","parametricGeometry","tetrahedronGeometry","octahedronGeometry","icosahedronGeometry","dodecahedronGeometry","polyhedronGeometry","tubeGeometry","torusKnotGeometry","torusGeometry","sphereGeometry","ringGeometry","planeGeometry","latheGeometry","shapeGeometry","extrudeGeometry","edgesGeometry","coneGeometry","cylinderGeometry","circleGeometry","boxGeometry","material","shadowMaterial","spriteMaterial","rawShaderMaterial","shaderMaterial","pointsMaterial","meshPhysicalMaterial","meshStandardMaterial","meshPhongMaterial","meshToonMaterial","meshNormalMaterial","meshLambertMaterial","meshDepthMaterial","meshDistanceMaterial","meshBasicMaterial","meshMatcapMaterial","lineDashedMaterial","lineBasicMaterial","light","spotLightShadow","spotLight","pointLight","rectAreaLight","hemisphereLight","directionalLightShadow","directionalLight","ambientLight","lightShadow","ambientLightProbe","hemisphereLightProbe","lightProbe","texture","videoTexture","dataTexture","dataTexture3D","compressedTexture","cubeTexture","canvasTexture","depthTexture","textureLoader","group","catmullRomCurve3","points","raycaster","cameraHelper","camera","perspectiveCamera","orthographicCamera","cubeCamera","arrayCamera","webGLRenderer"].map((e=>t.defineComponent({inheritAttrs:!1,name:e,setup:(r,n)=>()=>t.h(e,n.attrs,n.slots?.default?.()||[])}))).reduce(((e,t)=>(e[t.name]=t,e)),{}),Lunchbox:R},C=e=>t.defineComponent({inheritAttrs:!1,name:e,render(){return t.h(e,this.$attrs,this.$slots?.default?.()||[])}}),A=({app:e,...t})=>{Object.keys(t).forEach((r=>{e.component(r,C(r)),w[r]=t[r]}))};function E(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),r=t.replace(/Lunchbox$/,""),n=w[e.type]||a[t]||w[r]||a[r];if(!n)throw`${t} is not part of the THREE namespace! Did you forget to extend? import {extend} from 'lunchbox'; extend({app, YourComponent, ...})`;const o=(e.props.args??[]).map((t=>function({node:e,prop:t}){const r="string"==typeof t&&t.startsWith("$attachedArray"),n=function({node:e,prop:t}){return"string"==typeof t&&t.startsWith("$attachedArray")?e.attachedArray[t.replace("$attachedArray.","")]:"string"==typeof t&&t.startsWith("$attached")?e.attached[t.replace("$attached.","")]:t}({node:e,prop:t});return Array.isArray(n)&&r?n:[n]}({node:e,prop:t})));let i=[];o.forEach((e=>{i=i.concat(e)}));return new n(...i)}var L,N=new Uint8Array(16);function M(){if(!L&&!(L="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return L(N)}var S=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function B(e){return"string"==typeof e&&S.test(e)}for(var j=[],G=0;G<256;++G)j.push((G+256).toString(16).substr(1));function T(e,t,r){var n=(e=e||{}).random||(e.rng||M)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(j[e[t+0]]+j[e[t+1]]+j[e[t+2]]+j[e[t+3]]+"-"+j[e[t+4]]+j[e[t+5]]+"-"+j[e[t+6]]+j[e[t+7]]+"-"+j[e[t+8]]+j[e[t+9]]+"-"+j[e[t+10]]+j[e[t+11]]+j[e[t+12]]+j[e[t+13]]+j[e[t+14]]+j[e[t+15]]).toLowerCase();if(!B(r))throw TypeError("Stringified UUID is invalid");return r}(n)}e.MiniDom=void 0,function(e){e.BaseNode=class{constructor(e={},t){this.parentNode=e?.parentNode??t??null,this.minidomType="MinidomBaseNode",this.uuid=e?.uuid??T()}uuid;parentNode;get nextSibling(){if(!this.parentNode)return null;const e=this.parentNode.children.findIndex((e=>e.uuid===this.uuid));return-1!==e&&e<this.parentNode.children.length-1?this.parentNode.children[e+1]:null}insertBefore(e,t){e.removeAsChildFromAnyParents(),e.parentNode=this;const r=this.children.findIndex((e=>e.uuid===t?.uuid));-1!==r?this.children.splice(r,0,e):this.children.push(e)}removeChild(e){const t=this.children.findIndex((t=>t?.uuid===e?.uuid));-1!==t&&this.children.splice(t,1)}children=[];addChild(e){return e&&(e.removeAsChildFromAnyParents(),e.parentNode=this,this.insertBefore(e,null)),this}getPath(){const e=[];let t=this;for(;t;)e.unshift(t),t=t.parentNode;return e}drop(){this.removeAsChildFromAnyParents(),this.parentNode=null}walk(e){const t=[this,...this.children],r=[];let n=!0;for(;t.length&&n;){const o=t.shift();if(o){if(r.includes(o))continue;r.push(o),t.push(...o.children.filter((e=>!r.includes(e)))),n=e(o)}else n=!1}}minidomType;removeAsChildFromAnyParents(){this.parentNode?.removeChild(this)}};class t extends e.BaseNode{constructor(e={},t){super(e,t),this.minidomType="RendererNode",this.eventListeners={},this.eventListenerRemoveFunctions={},this.name=e.name??"",this.metaType=e.metaType??"standardMeta",this.props=e.props??[],this.type=e.type??""}eventListeners;eventListenerRemoveFunctions;name;metaType;props;type;drop(){super.drop(),Object.keys(this.eventListenerRemoveFunctions).forEach((e=>{this.eventListenerRemoveFunctions[e].forEach((e=>e()))}))}}e.RendererBaseNode=t;class r extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement;isLunchboxRootNode=!0}e.RendererRootNode=r;class n extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererCommentNode=n;class o extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement}e.RendererDomNode=o;class a extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererTextNode=a;class i extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.attached=e.attached??[],this.attachedArray=e.attachedArray??{},this.instance=e.instance??null}attached;attachedArray;instance}e.RendererStandardNode=i}(e.MiniDom||(e.MiniDom={}));const k=Symbol(),O=Symbol(),$=Symbol(),D=Symbol(),F=Symbol(),K=Symbol(),V=Symbol(),I=Symbol(),U=Symbol(),z=Symbol(),H=Symbol(),W=Symbol(),q=Symbol(),_=Symbol(),X=Symbol(),Y=Symbol(),J=Symbol(),Q=Symbol(),Z=Symbol(),ee=e=>{"number"==typeof e.app.config.globalProperties.lunchbox.frameId&&cancelAnimationFrame(e.app.config.globalProperties.lunchbox.frameId),e.app.config.globalProperties.lunchbox.frameId=requestAnimationFrame((()=>te({app:e.app,renderer:e.renderer,scene:e.scene,camera:e.camera,updateSource:e.updateSource})))},te=e=>{e.updateSource?e.app.config.globalProperties.lunchbox.watchStopHandle||(e.app.config.globalProperties.lunchbox.watchStopHandle=t.watch(e.updateSource,(()=>{ee(e)}),{deep:!0})):ee(e);const{app:r,renderer:n,scene:o}=e;r.config.globalProperties.lunchbox.beforeRender.forEach((t=>{t?.(e)})),n&&o&&e.app.config.globalProperties.lunchbox.camera&&(r.customRender?r.customRender(e):n.render(t.toRaw(o),e.app.config.globalProperties.lunchbox.camera)),r.config.globalProperties.lunchbox.afterRender.forEach((t=>{t?.(e)}))},re=()=>({onBeforeRender:t.inject(K),offBeforeRender:t.inject(V)}),ne=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},oe=e=>{re().offBeforeRender?.(e)},ae=()=>{const e=t.inject(H);return()=>{void 0!==e&&cancelAnimationFrame(e)}},ie=()=>{ae()?.()},se=()=>{const e=t.inject(W);return()=>e?.()},ce=()=>{se()?.()};function de({node:e,key:t,interactables:r,value:o}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return h({node:e,key:t,interactables:r,value:o});const a=t.replace(/-/g,"."),i=le[a]||a;if(pe.includes(t)||pe.includes(i))return e;if(!c(e))return e;if("string"==typeof o&&o.startsWith("$attached")){const t=o.replace("$attached.","");o=n.get(e.attached,t,null)}const s=e.instance;if(!s)return e;let d;for(let e=0;e<ue.length&&!d;e++){const t=[ue[e],i].filter(Boolean).join(".");d=d=n.get(s,t)}if(d&&n.isNumber(o)&&d.setScalar)d.setScalar(o);else if(d&&d.set){const e=Array.isArray(o)?o:[o];s[i].set(...e)}else if("function"==typeof d)if("onbeforerender"===i.toLowerCase()||"onafterrender"===i.toLowerCase())s[i]=o;else{if(!Array.isArray(o))throw new Error('Arguments on a declarative method must be wrapped in an array.\nWorks:\n<example :methodCall="[256]" />\nDoesn\'t work:\n<example :methodCall="256" />');d.bind(e.instance)(...o)}else void 0!==n.get(s,i,void 0)?n.set(s,i,""===o||o):console.log(`No property ${i} found on ${s}`);const l=s?.texture?.type||s?.type;if("string"==typeof l){const e=l.toLowerCase();switch(!0){case e.includes("material"):s.needsUpdate=!0;break;case e.includes("camera")&&s.updateProjectionMatrix:s.updateProjectionMatrix()}}return e}const le={x:"position.x",y:"position.y",z:"position.z"},ue=["","parameters"],pe=["args","attach","attachArray","is.default","isDefault","key","onAdded","ref","src"],me=["geometry","material"],he=(e,t,r,n)=>{const o={type:e,props:n};if(s(o)){return u(o)}const a=m(o);return me.forEach((t=>{e.toLowerCase().endsWith(t)&&(a.props.attach=t)})),a},fe=(e,t,r)=>{if(!t)throw new Error("missing parent");if(t.insertBefore(e,r),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(s(e)&&(s(t)||d(t))&&t.domElement.appendChild(e.domElement),c(e))){let r=t.metaType;if("textMeta"===r||"commentMeta"===r){const e=t.getPath();for(let r=e.length-1;r>=0;r--)if("textMeta"!==e[r].metaType&&"commentMeta"!==e[r].metaType){t=e[r];break}}if(c(e)&&e.instance?.isObject3D&&c(t)&&t.instance?.isObject3D&&t.instance?.add?.(e.instance),e?.props?.attach&&c(t)&&t?.instance){e.type?.toLowerCase().endsWith("loader")&&e.props.src&&(e.props.attach||e.props.attachArray)?function(e,t){const r=e.instance;if(t.attached=t.attached||{},t.attachedArray=t.attachedArray||{},!e.props.attach)return;if("textureloader"===e.type?.toLowerCase()){const n=r.load(e.props.src);ye(e,t,e.props.attach,n)}else r.load(e.props.src,(r=>{ye(e,t,e.props.attach,r)}),null,(e=>{throw new Error(e)}))}(e,t):ye(e,t,e.props.attach)}e.props?.onAdded&&e.props.onAdded({instance:e.instance})}};function ye(e,t,r,n){const o=n??e.instance,a=t.instance;e.props.attach===r&&(t.attached={[r]:o,...t.attached||{}},a[r]=n??e.instance),e.props.attachArray===r&&(t.attachedArray[e.props.attachArray]||(t.attachedArray[e.props.attachArray]=[]),t.attachedArray[e.props.attachArray].push(o),a[r]=[a[r]])}const be=e=>{if(!e)return;const t=[];e.walk((e=>(t.push(e),!0))),t.forEach((e=>{if(c(e)){e.instance?.removeFromParent?.();const t="scene"!==e.type&&e.instance?.dispose;t&&t.bind(e.instance)(),e.instance=null}e.drop()}))},ge=()=>t.inject(J),ve=()=>t.inject(X),xe=e=>{const r=t.watch(ve(),(t=>{t&&(e(t),r())}),{immediate:!0})},Re=()=>t.inject(Y),we=()=>({setCustomRender:t.inject($),clearCustomRender:t.inject(D)}),Pe=()=>t.inject(k),Ce=()=>t.inject(O),Ae=()=>t.inject(_),Ee=()=>t.inject(Z),Le=()=>t.inject(Q);e.addEventListener=h,e.afterRenderKey=I,e.appCameraKey=J,e.appKey=_,e.appRenderersKey=X,e.appRootNodeKey=q,e.appSceneKey=Y,e.beforeRenderKey=F,e.cancelUpdate=ie,e.cancelUpdateSource=ce,e.clearCustomRender=()=>{we()?.clearCustomRender?.()},e.clearCustomRenderKey=D,e.createApp=r=>{const{nodeOps:n,interactables:o}=(()=>{const e=t.ref([]);return{nodeOps:{createElement:he,createText:e=>p({text:e}),createComment:e=>l({text:e}),insert:fe,nextSibling:e=>e.nextSibling||null,parentNode:e=>e.parentNode||null,patchProp(t,r,n,o){s(t)?"style"===r?Object.keys(o).forEach((e=>{t.domElement.style[e]=o[e]})):t.domElement.setAttribute(r,o):d(t)||r.startsWith("$")||de({node:t,key:r,interactables:e,value:o})},remove:be,setElementText(){},setText(){}},interactables:e}})(),a=t.createRenderer(n).createApp(r);a.provide(Q,o),Object.keys(P).forEach((e=>{a?.component(e,P[e])})),a.provide($,(e=>{a.setCustomRender(e)})),a.provide(D,(()=>{a.clearCustomRender()}));const i=[];a.provide(F,i),a.provide(K,((e,t=1/0)=>{t===1/0?i.push(e):i.splice(t,0,e)})),a.provide(V,(e=>{if(isFinite(e))i.splice(e,1);else{const t=i.findIndex((t=>t==e));-1!==t&&i.splice(t,1)}}));const c=[];a.provide(I,c),a.provide(U,((e,t=1/0)=>{t===1/0?c.push(e):c.splice(t,0,e)})),a.provide(z,(e=>{if(isFinite(e))c.splice(e,1);else{const t=c.findIndex((t=>t==e));-1!==t&&c.splice(t,1)}})),a.config.globalProperties.lunchbox=t.reactive({afterRender:c,beforeRender:i,camera:null,dpr:1,frameId:-1,renderer:null,scene:null,watchStopHandle:null}),a.provide(k,a.config.globalProperties.lunchbox),a.provide(O,(e=>{Object.keys(e).forEach((t=>{const r=t;a.config.globalProperties.lunchbox[r]=e[r]}))})),a.provide(H,a.config.globalProperties.lunchbox.frameId),a.provide(W,a.config.globalProperties.lunchbox.watchStopHandle);const{mount:u}=a;a.mount=(t,...r)=>{const n="string"==typeof t?document.querySelector(t):t,o=new e.MiniDom.RendererRootNode({domElement:n,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});a.rootNode=o,a.provide(q,o);return u(o,...r)},a.extend=e=>(A({app:a,...e}),a);return a.provide(Z,[]),a.setCustomRender=e=>{a&&(a.customRender=e)},a.clearCustomRender=()=>{a&&(a.customRender=null)},a.provide(_,a),a.provide(X,t.computed((()=>a.config.globalProperties.lunchbox.renderer))),a.provide(Y,t.computed((()=>a.config.globalProperties.lunchbox.scene))),a.provide(J,t.computed((()=>a.config.globalProperties.lunchbox.camera))),a},e.createCommentNode=l,e.createDomNode=u,e.createNode=m,e.createTextNode=p,e.extend=A,e.find=function(e){return e=t.isRef(e)?e.value:e,c(e)?e?.instance:i(e)?e?.$el?.instance:t.isVNode(e)?e.el?.instance:null},e.frameIdKey=H,e.globalsInjectionKey=k,e.instantiateThreeObject=E,e.isMinidomNode=function(e){return"RendererNode"===e?.minidomType},e.lunchboxInteractables=Q,e.nestedPropertiesToCheck=ue,e.offAfterRender=e=>{re().offBeforeRender?.(e)},e.offAfterRenderKey=z,e.offBeforeRender=oe,e.offBeforeRenderKey=V,e.onAfterRender=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},e.onAfterRenderKey=U,e.onBeforeRender=ne,e.onBeforeRenderKey=K,e.onCameraReady=e=>{const r=t.watch(ge(),(t=>{t&&(e(t),r())}),{immediate:!0})},e.onRendererReady=xe,e.onSceneReady=e=>{const r=t.watch(Re(),(t=>{t&&(e(t),r())}),{immediate:!0})},e.onStart=(e,t=1/0)=>{const r=Ee();t===1/0?r?.push(e):r?.splice(t,0,e)},e.setCustomRender=e=>{we()?.setCustomRender?.(e)},e.setCustomRenderKey=$,e.startCallbackKey=Z,e.update=te,e.updateGlobals=e=>{Ce()?.(e)},e.updateGlobalsInjectionKey=O,e.updateObjectProp=de,e.useAfterRender=()=>({onAfterRender:t.inject(K),offAfterRender:t.inject(V)}),e.useApp=Ae,e.useBeforeRender=re,e.useCamera=ge,e.useCancelUpdate=ae,e.useCancelUpdateSource=se,e.useCustomRender=we,e.useGlobals=Pe,e.useLunchboxInteractables=Le,e.useRenderer=ve,e.useScene=Re,e.useStartCallbacks=Ee,e.useUpdateGlobals=Ce,e.watchStopHandleKey=W,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("three"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","vue","three","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Lunchbox={},e.vue,e.three,e.lodash)}(this,(function(e,t,r,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=o(r);const i=e=>e?.$el&&e?.$el?.hasOwnProperty?.("instance"),s=e=>"domMeta"===e?.metaType||e?.props?.["data-lunchbox"],c=e=>"standardMeta"===e?.metaType,d=e=>e.isLunchboxRootNode;function l(t={}){const r={text:t.text??""};return new e.MiniDom.RendererCommentNode({...r,...t,metaType:"commentMeta"})}function u(t={}){const r={domElement:document.createElement(t.type??"")};return new e.MiniDom.RendererDomNode({...r,...t,metaType:"domMeta"})}function p(t={}){const r={text:t.text??""};return new e.MiniDom.RendererTextNode({...t,...r,metaType:"textMeta"})}function m(t={},r={}){const n={attached:t.attached??[],attachedArray:t.attachedArray??{},instance:t.instance??null},o=new e.MiniDom.RendererStandardNode({...t,...n,metaType:"standardMeta"});return!o.type||d(o)||o.instance||(o.instance=E({...o,props:{...o.props,...r}})),o}function h({node:e,key:t,interactables:r,value:n}){return e.eventListeners[t]||(e.eventListeners[t]=[]),e.eventListenerRemoveFunctions[t]||(e.eventListenerRemoveFunctions[t]=[]),e.eventListeners[t].push(n),f.includes(t)&&e.instance&&!r.value.includes(e)&&(r.value.push(e),e.eventListenerRemoveFunctions[t].push((()=>{const t=r.value.indexOf(e);-1!==t&&r.value.splice(t,1)}))),e}const f=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"],y=(e,r,n,o,a)=>{if(!r?.domElement||!n||!e)return;const i=(o=o??window.innerWidth)/(a=a??window.innerHeight);if("perspectivecamera"===e.type?.toLowerCase()){const t=e;t.aspect=i,t.updateProjectionMatrix()}else if("orthographiccamera"===e.type?.toLowerCase()){const t=e,r=a/o;t.top=10*r,t.bottom=10*-r,t.right=10,t.left=-10,t.updateProjectionMatrix()}r.setSize(o,a),n&&e&&r.render(t.toRaw(n),t.toRaw(e))},b=(e,t,r,n,o)=>{const a=e.value?.domElement;if(!a)throw new Error("missing container");const i=()=>{if("container"===o){const e=(e=>{const t=getComputedStyle(e);return{width:e.clientWidth-parseFloat(t.paddingLeft)-parseFloat(t.paddingRight),height:e.clientHeight-parseFloat(t.paddingTop)-parseFloat(t.paddingBottom)}})(a);y(t,r,n,e.width,e.height)}else y(t,r,n)};i();let s=new ResizeObserver((()=>{i()}));return a&&s.observe(a),{dispose(){a&&s.unobserve(a)}}},v=t.defineComponent({name:"LunchboxScene",setup:(e,{slots:r})=>()=>t.createVNode(t.resolveComponent("scene"),null,{default:()=>[r.default?.()]})}),g=t.defineComponent({name:"LunchboxEventHandlers",setup(){const e=Le(),r=Pe(),n=t.ref({x:1/0,y:1/0}),o=t.ref(!1);let i=[];const s=new a.Raycaster(new a.Vector3,new a.Vector3(0,0,-1)),c=({element:e,eventKeys:t,intersection:r})=>{e&&t.forEach((t=>{e.eventListeners[t]&&e.eventListeners[t].forEach((e=>{e({intersection:r})}))}))};xe((e=>{if(!e?.domElement)return;const{domElement:t}=e;t.addEventListener("pointermove",(e=>{const o=(t.width??1)/r.dpr,a=(t.height??1)/r.dpr;n.value.x=e.offsetX/o*2-1,n.value.y=-e.offsetY/a*2+1})),t.addEventListener("pointerdown",(()=>o.value=!0)),t.addEventListener("pointerup",(()=>o.value=!1))}));const d=ve(),l=()=>{const t=d.value;if(!t)return;s.setFromCamera(n.value,t);const r=s.intersectObjects(e?.value.map((e=>e.instance))??[]);let o=[],a=[],l=[];o=i.map((e=>e.intersection)),r?.forEach((t=>{if(-1===i.findIndex((e=>e.intersection.object===t.object))){const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&a.push({element:r,intersection:t})}else{const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&l.push({element:r,intersection:t})}const r=o.findIndex((e=>e.object.uuid===t.object.uuid));-1!==r&&o.splice(r,1)}));const u=o.map((t=>({element:e?.value.find((e=>e.instance?.uuid===t.object.uuid)),intersection:t})));a.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerEnter"],intersection:t})})),l.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerOver","onPointerMove"],intersection:t})})),u.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerLeave","onPointerOut"],intersection:t})})),i=[].concat(a,l)};ne(l);t.onBeforeUnmount((()=>oe(l)));const u=["onClick","onPointerDown","onPointerUp"];return t.watch(o,(e=>{l();const t=[];i.forEach((r=>{u.forEach((n=>{const o=r.element.uuid+n;!e||"onClick"!==n&&"onPointerDown"!==n?e||"onPointerUp"!==n||t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.intersection}))),t.push(o)):t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.intersection}))),t.push(o))}))}))})),()=>t.createVNode(t.resolveComponent("object3D"),null,null)}}),x=e=>({position:e,top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",display:"block"}),R=t.defineComponent({name:"Lunchbox",props:{background:String,cameraArgs:Array,cameraLook:Array,cameraLookAt:Array,cameraPosition:Array,dpr:Number,ortho:Boolean,orthographic:Boolean,r3f:Boolean,rendererArguments:Object,rendererProperties:Object,sizePolicy:String,shadow:[Boolean,Object],transparent:Boolean,zoom:Number,updateSource:Object},setup(e,r){const n=t.ref();let o=e.dpr??-1;const i=t.ref(),s=t.ref(),c=t.ref(),d=t.ref(),l=Pe(),u=Ce(),p=Ae(),m=t.reactive({}),h=Ee();e.r3f&&a?.ColorManagement&&(a.ColorManagement.legacyMode=!1);const f=Le();t.onMounted((async()=>{if(!n.value&&!r.slots?.renderer?.()?.length)throw new Error("missing canvas");for(r.slots?.camera?.()?.length||(e.cameraPosition&&(m.position=e.cameraPosition),(e.cameraLook||e.cameraLookAt)&&(m.lookAt=e.cameraLook||e.cameraLookAt),void 0!==e.zoom&&(m.zoom=e.zoom)),d.value?.$el?.instance&&e.background&&(d.value.$el.instance.background=new a.Color(e.background)),-1===o&&(o=window.devicePixelRatio),u?.({dpr:o});!s.value?.$el?.instance&&!s.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));for(;!d.value?.$el?.instance&&!d.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));const t=s.value?.$el?.instance??s.value?.component?.ctx.$el?.instance;t.setPixelRatio(l.dpr);const f=d.value?.$el?.instance??d.value?.component?.ctx.$el?.instance,y=c.value?.$el?.instance??c.value?.component?.ctx.$el?.instance;if(!r.slots?.renderer?.()?.length){b(i,y,t,f,e.sizePolicy),e.r3f&&(t.outputEncoding=a.sRGBEncoding,t.toneMapping=a.ACESFilmicToneMapping);const r={shadow:e.shadow};r?.shadow&&(t.shadowMap.enabled=!0,"object"==typeof r.shadow&&(t.shadowMap.type=r.shadow.type))}if(!p)throw new Error("error creating app");p.config.globalProperties.lunchbox.camera=y,p.config.globalProperties.lunchbox.renderer=t,p.config.globalProperties.lunchbox.scene=f;for(let e of h??[])e({app:p,camera:y,renderer:t,scene:f});te({app:p,camera:y,renderer:t,scene:f,updateSource:e.updateSource})})),t.onBeforeUnmount((()=>{ie(),ce()}));const y="container"===e.sizePolicy?"static":"absolute",R="container"===e.sizePolicy?"static":"fixed",w=t.computed((()=>{const e=r.slots?.camera?.().find((e=>e.type?.name));return e||e}));return t.watch(w,(async(e,t)=>{e&&e?.props?.key!==t?.props?.key&&(c.value=e)}),{immediate:!0}),()=>t.createVNode(t.Fragment,null,[r.slots?.renderer?.()?.length?s.value=r.slots?.renderer?.()[0]:t.createVNode(t.Fragment,null,[t.createVNode("div",{class:"lunchbox-container",style:x(y),ref:i,"data-lunchbox":"true"},[t.createVNode("canvas",{ref:n,class:"lunchbox-canvas",style:x(R),"data-lunchbox":"true"},null)]),n.value?.domElement&&t.createVNode(t.resolveComponent("webGLRenderer"),t.mergeProps(e.rendererProperties??{},{ref:s,args:[{alpha:e.transparent,antialias:!0,canvas:n.value?.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}}]}),null)]),r.slots?.scene?.()?.length?d.value=r.slots?.scene?.()[0]:t.createVNode(v,{ref:d},{default:()=>[r.slots?.default?.()]}),r.slots?.camera?.()?.length?c.value:e.ortho||e.orthographic?t.createVNode(t.resolveComponent("orthographicCamera"),t.mergeProps({ref:c,args:e.cameraArgs??[]},m),null):t.createVNode(t.resolveComponent("perspectiveCamera"),t.mergeProps({ref:c,args:e.cameraArgs??[e.r3f?75:45,.5625,1,1e3]},m),null),f?.value.length&&t.createVNode(g,null,null)])}}),w={},P={...["mesh","instancedMesh","scene","sprite","object3D","instancedBufferGeometry","bufferGeometry","boxBufferGeometry","circleBufferGeometry","coneBufferGeometry","cylinderBufferGeometry","dodecahedronBufferGeometry","extrudeBufferGeometry","icosahedronBufferGeometry","latheBufferGeometry","octahedronBufferGeometry","parametricBufferGeometry","planeBufferGeometry","polyhedronBufferGeometry","ringBufferGeometry","shapeBufferGeometry","sphereBufferGeometry","tetrahedronBufferGeometry","textBufferGeometry","torusBufferGeometry","torusKnotBufferGeometry","tubeBufferGeometry","wireframeGeometry","parametricGeometry","tetrahedronGeometry","octahedronGeometry","icosahedronGeometry","dodecahedronGeometry","polyhedronGeometry","tubeGeometry","torusKnotGeometry","torusGeometry","sphereGeometry","ringGeometry","planeGeometry","latheGeometry","shapeGeometry","extrudeGeometry","edgesGeometry","coneGeometry","cylinderGeometry","circleGeometry","boxGeometry","material","shadowMaterial","spriteMaterial","rawShaderMaterial","shaderMaterial","pointsMaterial","meshPhysicalMaterial","meshStandardMaterial","meshPhongMaterial","meshToonMaterial","meshNormalMaterial","meshLambertMaterial","meshDepthMaterial","meshDistanceMaterial","meshBasicMaterial","meshMatcapMaterial","lineDashedMaterial","lineBasicMaterial","light","spotLightShadow","spotLight","pointLight","rectAreaLight","hemisphereLight","directionalLightShadow","directionalLight","ambientLight","lightShadow","ambientLightProbe","hemisphereLightProbe","lightProbe","texture","videoTexture","dataTexture","dataTexture3D","compressedTexture","cubeTexture","canvasTexture","depthTexture","textureLoader","group","catmullRomCurve3","points","raycaster","cameraHelper","camera","perspectiveCamera","orthographicCamera","cubeCamera","arrayCamera","webGLRenderer"].map((e=>t.defineComponent({inheritAttrs:!1,name:e,setup:(r,n)=>()=>t.h(e,n.attrs,n.slots?.default?.()||[])}))).reduce(((e,t)=>(e[t.name]=t,e)),{}),Lunchbox:R},C=e=>t.defineComponent({inheritAttrs:!1,name:e,render(){return t.h(e,this.$attrs,this.$slots?.default?.()||[])}}),A=({app:e,...t})=>{Object.keys(t).forEach((r=>{e.component(r,C(r)),w[r]=t[r]}))};function E(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),r=t.replace(/Lunchbox$/,""),n=w[e.type]||a[t]||w[r]||a[r];if(!n)throw`${t} is not part of the THREE namespace! Did you forget to extend? import {extend} from 'lunchbox'; extend({app, YourComponent, ...})`;const o=(e.props.args??[]).map((t=>function({node:e,prop:t}){const r="string"==typeof t&&t.startsWith("$attachedArray"),n=function({node:e,prop:t}){return"string"==typeof t&&t.startsWith("$attachedArray")?e.attachedArray[t.replace("$attachedArray.","")]:"string"==typeof t&&t.startsWith("$attached")?e.attached[t.replace("$attached.","")]:t}({node:e,prop:t});return Array.isArray(n)&&r?n:[n]}({node:e,prop:t})));let i=[];o.forEach((e=>{i=i.concat(e)}));return new n(...i)}var L,N=new Uint8Array(16);function M(){if(!L&&!(L="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return L(N)}var S=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function B(e){return"string"==typeof e&&S.test(e)}for(var j=[],G=0;G<256;++G)j.push((G+256).toString(16).substr(1));function T(e,t,r){var n=(e=e||{}).random||(e.rng||M)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(j[e[t+0]]+j[e[t+1]]+j[e[t+2]]+j[e[t+3]]+"-"+j[e[t+4]]+j[e[t+5]]+"-"+j[e[t+6]]+j[e[t+7]]+"-"+j[e[t+8]]+j[e[t+9]]+"-"+j[e[t+10]]+j[e[t+11]]+j[e[t+12]]+j[e[t+13]]+j[e[t+14]]+j[e[t+15]]).toLowerCase();if(!B(r))throw TypeError("Stringified UUID is invalid");return r}(n)}e.MiniDom=void 0,function(e){e.BaseNode=class{constructor(e={},t){this.parentNode=e?.parentNode??t??null,this.minidomType="MinidomBaseNode",this.uuid=e?.uuid??T()}uuid;parentNode;get nextSibling(){if(!this.parentNode)return null;const e=this.parentNode.children.findIndex((e=>e.uuid===this.uuid));return-1!==e&&e<this.parentNode.children.length-1?this.parentNode.children[e+1]:null}insertBefore(e,t){e.removeAsChildFromAnyParents(),e.parentNode=this;const r=this.children.findIndex((e=>e.uuid===t?.uuid));-1!==r?this.children.splice(r,0,e):this.children.push(e)}removeChild(e){const t=this.children.findIndex((t=>t?.uuid===e?.uuid));-1!==t&&this.children.splice(t,1)}children=[];addChild(e){return e&&(e.removeAsChildFromAnyParents(),e.parentNode=this,this.insertBefore(e,null)),this}getPath(){const e=[];let t=this;for(;t;)e.unshift(t),t=t.parentNode;return e}drop(){this.removeAsChildFromAnyParents(),this.parentNode=null}walk(e){const t=[this,...this.children],r=[];let n=!0;for(;t.length&&n;){const o=t.shift();if(o){if(r.includes(o))continue;r.push(o),t.push(...o.children.filter((e=>!r.includes(e)))),n=e(o)}else n=!1}}minidomType;removeAsChildFromAnyParents(){this.parentNode?.removeChild(this)}};class t extends e.BaseNode{constructor(e={},t){super(e,t),this.minidomType="RendererNode",this.eventListeners={},this.eventListenerRemoveFunctions={},this.name=e.name??"",this.metaType=e.metaType??"standardMeta",this.props=e.props??[],this.type=e.type??""}eventListeners;eventListenerRemoveFunctions;name;metaType;props;type;drop(){super.drop(),Object.keys(this.eventListenerRemoveFunctions).forEach((e=>{this.eventListenerRemoveFunctions[e].forEach((e=>e()))}))}}e.RendererBaseNode=t;class r extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement;isLunchboxRootNode=!0}e.RendererRootNode=r;class n extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererCommentNode=n;class o extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement}e.RendererDomNode=o;class a extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererTextNode=a;class i extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.attached=e.attached??[],this.attachedArray=e.attachedArray??{},this.instance=e.instance??null}attached;attachedArray;instance}e.RendererStandardNode=i}(e.MiniDom||(e.MiniDom={}));const k=Symbol(),O=Symbol(),$=Symbol(),D=Symbol(),F=Symbol(),K=Symbol(),V=Symbol(),I=Symbol(),U=Symbol(),z=Symbol(),H=Symbol(),W=Symbol(),q=Symbol(),_=Symbol(),X=Symbol(),Y=Symbol(),J=Symbol(),Q=Symbol(),Z=Symbol(),ee=e=>{"number"==typeof e.app.config.globalProperties.lunchbox.frameId&&cancelAnimationFrame(e.app.config.globalProperties.lunchbox.frameId),e.app.config.globalProperties.lunchbox.frameId=requestAnimationFrame((()=>te({app:e.app,renderer:e.renderer,scene:e.scene,camera:e.camera,updateSource:e.updateSource})))},te=e=>{e.updateSource?e.app.config.globalProperties.lunchbox.watchStopHandle||(e.app.config.globalProperties.lunchbox.watchStopHandle=t.watch(e.updateSource,(()=>{ee(e)}),{deep:!0})):ee(e);const{app:r,renderer:n,scene:o}=e;r.config.globalProperties.lunchbox.beforeRender.forEach((t=>{t?.(e)})),n&&o&&e.app.config.globalProperties.lunchbox.camera&&(r.customRender?r.customRender(e):n.render(t.toRaw(o),e.app.config.globalProperties.lunchbox.camera)),r.config.globalProperties.lunchbox.afterRender.forEach((t=>{t?.(e)}))},re=()=>({onBeforeRender:t.inject(K),offBeforeRender:t.inject(V)}),ne=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},oe=e=>{re().offBeforeRender?.(e)},ae=()=>{const e=t.inject(H);return()=>{void 0!==e&&cancelAnimationFrame(e)}},ie=()=>{ae()?.()},se=()=>{const e=t.inject(W);return()=>e?.()},ce=()=>{se()?.()};function de({node:e,key:t,interactables:r,value:o}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return h({node:e,key:t,interactables:r,value:o});const a=t.replace(/-/g,"."),i=le[a]||a;if(pe.includes(t)||pe.includes(i))return e;if(!c(e))return e;if("string"==typeof o&&o.startsWith("$attached")){const t=o.replace("$attached.","");o=n.get(e.attached,t,null)}const s=e.instance;if(!s)return e;let d;for(let e=0;e<ue.length&&!d;e++){const t=[ue[e],i].filter(Boolean).join(".");d=d=n.get(s,t)}if(d&&n.isNumber(o)&&d.setScalar)d.setScalar(o);else if(d&&d.set){const e=Array.isArray(o)?o:[o];s[i].set(...e)}else if("function"==typeof d)if("onbeforerender"===i.toLowerCase()||"onafterrender"===i.toLowerCase())s[i]=o;else{if(!Array.isArray(o))throw new Error('Arguments on a declarative method must be wrapped in an array.\nWorks:\n<example :methodCall="[256]" />\nDoesn\'t work:\n<example :methodCall="256" />');d.bind(e.instance)(...o)}else void 0!==n.get(s,i,void 0)?n.set(s,i,""===o||o):console.log(`No property ${i} found on ${s}`);const l=s?.texture?.type||s?.type;if("string"==typeof l){const e=l.toLowerCase();switch(!0){case e.includes("material"):s.needsUpdate=!0;break;case e.includes("camera")&&s.updateProjectionMatrix:s.updateProjectionMatrix()}}return e}const le={x:"position.x",y:"position.y",z:"position.z"},ue=["","parameters"],pe=["args","attach","attachArray","is.default","isDefault","key","onAdded","ref","src"],me=["geometry","material"],he=(e,t,r,n)=>{const o={type:e,props:n};if(s(o)){return u(o)}const a=m(o);return me.forEach((t=>{e.toLowerCase().endsWith(t)&&(a.props.attach=t)})),a},fe=(e,t,r)=>{if(!t)throw new Error("missing parent");if(t.insertBefore(e,r),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(s(e)&&(s(t)||d(t))&&t.domElement.appendChild(e.domElement),c(e))){let r=t.metaType;if("textMeta"===r||"commentMeta"===r){const e=t.getPath();for(let r=e.length-1;r>=0;r--)if("textMeta"!==e[r].metaType&&"commentMeta"!==e[r].metaType){t=e[r];break}}if(c(e)&&e.instance?.isObject3D&&c(t)&&t.instance?.isObject3D&&t.instance?.add?.(e.instance),e?.props?.attach&&c(t)&&t?.instance){e.type?.toLowerCase().endsWith("loader")&&e.props.src&&(e.props.attach||e.props.attachArray)?function(e,t){const r=e.instance;if(t.attached=t.attached||{},t.attachedArray=t.attachedArray||{},!e.props.attach)return;if("textureloader"===e.type?.toLowerCase()){const n=r.load(e.props.src);ye(e,t,e.props.attach,n)}else r.load(e.props.src,(r=>{ye(e,t,e.props.attach,r)}),null,(e=>{throw new Error(e)}))}(e,t):ye(e,t,e.props.attach)}e.props?.onAdded&&e.props.onAdded({instance:e.instance})}};function ye(e,t,r,n){const o=n??e.instance,a=t.instance;e.props.attach===r&&(t.attached={[r]:o,...t.attached||{}},a[r]=n??e.instance),e.props.attachArray===r&&(t.attachedArray[e.props.attachArray]||(t.attachedArray[e.props.attachArray]=[]),t.attachedArray[e.props.attachArray].push(o),a[r]=[a[r]])}const be=e=>{if(!e)return;const t=[];e.walk((e=>(t.push(e),!0))),t.forEach((e=>{if(c(e)){e.instance?.removeFromParent?.();const t="scene"!==e.type&&e.instance?.dispose;t&&t.bind(e.instance)(),e.instance=null}e.drop()}))},ve=()=>t.inject(J),ge=()=>t.inject(X),xe=e=>{const r=ge();if(r.value)return void e(r.value);let n=null;n=t.watch(ge(),(t=>{t&&(e(t),n?.())}),{immediate:!0})},Re=()=>t.inject(Y),we=()=>({setCustomRender:t.inject($),clearCustomRender:t.inject(D)}),Pe=()=>t.inject(k),Ce=()=>t.inject(O),Ae=()=>t.inject(_),Ee=()=>t.inject(Z),Le=()=>t.inject(Q);e.addEventListener=h,e.afterRenderKey=I,e.appCameraKey=J,e.appKey=_,e.appRenderersKey=X,e.appRootNodeKey=q,e.appSceneKey=Y,e.beforeRenderKey=F,e.cancelUpdate=ie,e.cancelUpdateSource=ce,e.clearCustomRender=()=>{we()?.clearCustomRender?.()},e.clearCustomRenderKey=D,e.createApp=r=>{const{nodeOps:n,interactables:o}=(()=>{const e=t.ref([]);return{nodeOps:{createElement:he,createText:e=>p({text:e}),createComment:e=>l({text:e}),insert:fe,nextSibling:e=>e.nextSibling||null,parentNode:e=>e.parentNode||null,patchProp(t,r,n,o){s(t)?"style"===r?Object.keys(o).forEach((e=>{t.domElement.style[e]=o[e]})):t.domElement.setAttribute(r,o):d(t)||r.startsWith("$")||de({node:t,key:r,interactables:e,value:o})},remove:be,setElementText(){},setText(){}},interactables:e}})(),a=t.createRenderer(n).createApp(r);a.provide(Q,o),Object.keys(P).forEach((e=>{a?.component(e,P[e])})),a.provide($,(e=>{a.setCustomRender(e)})),a.provide(D,(()=>{a.clearCustomRender()}));const i=[];a.provide(F,i),a.provide(K,((e,t=1/0)=>{t===1/0?i.push(e):i.splice(t,0,e)})),a.provide(V,(e=>{if(isFinite(e))i.splice(e,1);else{const t=i.findIndex((t=>t==e));-1!==t&&i.splice(t,1)}}));const c=[];a.provide(I,c),a.provide(U,((e,t=1/0)=>{t===1/0?c.push(e):c.splice(t,0,e)})),a.provide(z,(e=>{if(isFinite(e))c.splice(e,1);else{const t=c.findIndex((t=>t==e));-1!==t&&c.splice(t,1)}})),a.config.globalProperties.lunchbox=t.reactive({afterRender:c,beforeRender:i,camera:null,dpr:1,frameId:-1,renderer:null,scene:null,watchStopHandle:null}),a.provide(k,a.config.globalProperties.lunchbox),a.provide(O,(e=>{Object.keys(e).forEach((t=>{const r=t;a.config.globalProperties.lunchbox[r]=e[r]}))})),a.provide(H,a.config.globalProperties.lunchbox.frameId),a.provide(W,a.config.globalProperties.lunchbox.watchStopHandle);const{mount:u}=a;a.mount=(t,...r)=>{const n="string"==typeof t?document.querySelector(t):t,o=new e.MiniDom.RendererRootNode({domElement:n,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});a.rootNode=o,a.provide(q,o);return u(o,...r)},a.extend=e=>(A({app:a,...e}),a);return a.provide(Z,[]),a.setCustomRender=e=>{a&&(a.customRender=e)},a.clearCustomRender=()=>{a&&(a.customRender=null)},a.provide(_,a),a.provide(X,t.computed((()=>a.config.globalProperties.lunchbox.renderer))),a.provide(Y,t.computed((()=>a.config.globalProperties.lunchbox.scene))),a.provide(J,t.computed((()=>a.config.globalProperties.lunchbox.camera))),a},e.createCommentNode=l,e.createDomNode=u,e.createNode=m,e.createTextNode=p,e.extend=A,e.find=function(e){return e=t.isRef(e)?e.value:e,c(e)?e?.instance:i(e)?e?.$el?.instance:t.isVNode(e)?e.el?.instance:null},e.frameIdKey=H,e.globalsInjectionKey=k,e.instantiateThreeObject=E,e.isMinidomNode=function(e){return"RendererNode"===e?.minidomType},e.lunchboxInteractables=Q,e.nestedPropertiesToCheck=ue,e.offAfterRender=e=>{re().offBeforeRender?.(e)},e.offAfterRenderKey=z,e.offBeforeRender=oe,e.offBeforeRenderKey=V,e.onAfterRender=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},e.onAfterRenderKey=U,e.onBeforeRender=ne,e.onBeforeRenderKey=K,e.onCameraReady=e=>{const r=ve();if(r.value)return void e(r.value);let n=null;n=t.watch(ve(),(t=>{t&&(e(t),n?.())}))},e.onRendererReady=xe,e.onSceneReady=e=>{const r=Re();if(r.value)return void e(r.value);let n=null;n=t.watch(Re(),(t=>{t&&(e(t),n?.())}),{immediate:!0})},e.onStart=(e,t=1/0)=>{const r=Ee();t===1/0?r?.push(e):r?.splice(t,0,e)},e.setCustomRender=e=>{we()?.setCustomRender?.(e)},e.setCustomRenderKey=$,e.startCallbackKey=Z,e.update=te,e.updateGlobals=e=>{Ce()?.(e)},e.updateGlobalsInjectionKey=O,e.updateObjectProp=de,e.useAfterRender=()=>({onAfterRender:t.inject(K),offAfterRender:t.inject(V)}),e.useApp=Ae,e.useBeforeRender=re,e.useCamera=ve,e.useCancelUpdate=ae,e.useCancelUpdateSource=se,e.useCustomRender=we,e.useGlobals=Pe,e.useLunchboxInteractables=Le,e.useRenderer=ge,e.useScene=Re,e.useStartCallbacks=Ee,e.useUpdateGlobals=Ce,e.watchStopHandleKey=W,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
@@ -1638,13 +1638,19 @@ const useCamera = () => inject(appCameraKey);
|
|
|
1638
1638
|
/** Run a function using the current camera when it's present. */
|
|
1639
1639
|
|
|
1640
1640
|
const onCameraReady = cb => {
|
|
1641
|
-
const
|
|
1641
|
+
const existing = useCamera();
|
|
1642
|
+
|
|
1643
|
+
if (existing.value) {
|
|
1644
|
+
cb(existing.value);
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
let stopWatch = null;
|
|
1649
|
+
stopWatch = watch(useCamera(), newVal => {
|
|
1642
1650
|
if (newVal) {
|
|
1643
1651
|
cb(newVal);
|
|
1644
|
-
stopWatch();
|
|
1652
|
+
stopWatch?.();
|
|
1645
1653
|
}
|
|
1646
|
-
}, {
|
|
1647
|
-
immediate: true
|
|
1648
1654
|
});
|
|
1649
1655
|
};
|
|
1650
1656
|
/** The current renderer as a computed value. */
|
|
@@ -1653,10 +1659,18 @@ const useRenderer = () => inject(appRenderersKey);
|
|
|
1653
1659
|
/** Run a function using the current renderer when it's present. */
|
|
1654
1660
|
|
|
1655
1661
|
const onRendererReady = cb => {
|
|
1656
|
-
const
|
|
1662
|
+
const existing = useRenderer();
|
|
1663
|
+
|
|
1664
|
+
if (existing.value) {
|
|
1665
|
+
cb(existing.value);
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
let stopWatch = null;
|
|
1670
|
+
stopWatch = watch(useRenderer(), newVal => {
|
|
1657
1671
|
if (newVal) {
|
|
1658
1672
|
cb(newVal);
|
|
1659
|
-
stopWatch();
|
|
1673
|
+
stopWatch?.();
|
|
1660
1674
|
}
|
|
1661
1675
|
}, {
|
|
1662
1676
|
immediate: true
|
|
@@ -1668,10 +1682,18 @@ const useScene = () => inject(appSceneKey);
|
|
|
1668
1682
|
/** Run a function using the current scene when it's present. */
|
|
1669
1683
|
|
|
1670
1684
|
const onSceneReady = cb => {
|
|
1671
|
-
const
|
|
1685
|
+
const existing = useScene();
|
|
1686
|
+
|
|
1687
|
+
if (existing.value) {
|
|
1688
|
+
cb(existing.value);
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
let stopWatch = null;
|
|
1693
|
+
stopWatch = watch(useScene(), newVal => {
|
|
1672
1694
|
if (newVal) {
|
|
1673
1695
|
cb(newVal);
|
|
1674
|
-
stopWatch();
|
|
1696
|
+
stopWatch?.();
|
|
1675
1697
|
}
|
|
1676
1698
|
}, {
|
|
1677
1699
|
immediate: true
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lunchboxjs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1013",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite -c utils/vite.config.ts",
|
|
6
6
|
"build": "vue-tsc --noEmit && vite build -c utils/vite.config.ts",
|
|
7
7
|
"build:tsc": "tsc --project ./utils/tsconfig.lib.json",
|
|
8
8
|
"build:rollup": "rollup -c ./utils/lib-rollup.ts",
|
|
9
|
-
"build:dts": "cp utils/lib-dts.d.ts dist/lunchboxjs.es.d.ts && cp utils/lib-dts.d.ts dist/lunchboxjs.umd.d.ts",
|
|
10
|
-
"build:lib": "
|
|
9
|
+
"build:dts": "node utils/cp utils/lib-dts.d.ts dist/lunchboxjs.es.d.ts && node utils/cp utils/lib-dts.d.ts dist/lunchboxjs.umd.d.ts",
|
|
10
|
+
"build:lib": "node utils/rm js && npm run build:tsc && npm run build:rollup && npm run build:dts",
|
|
11
11
|
"prepare": "npm run build:lib",
|
|
12
12
|
"docs:dev": "vitepress dev docs",
|
|
13
13
|
"docs:build": "vitepress build docs",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"nice-color-palettes": "3.0.0",
|
|
39
39
|
"prompt": "1.3.0",
|
|
40
40
|
"prompts": "2.4.2",
|
|
41
|
-
"rimraf": "3.0.2",
|
|
42
41
|
"rollup-plugin-delete": "2.0.0",
|
|
43
42
|
"rollup-plugin-jsx": "1.0.3",
|
|
44
43
|
"rollup-plugin-terser": "7.0.2",
|
|
@@ -52,7 +51,7 @@
|
|
|
52
51
|
},
|
|
53
52
|
"peerDependencies": {
|
|
54
53
|
"lodash": "^4.17.21",
|
|
55
|
-
"three": "0.
|
|
54
|
+
"three": "^0.133.0"
|
|
56
55
|
},
|
|
57
56
|
"files": [
|
|
58
57
|
"dist",
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
watch,
|
|
8
8
|
reactive,
|
|
9
9
|
Ref,
|
|
10
|
+
WatchStopHandle,
|
|
10
11
|
} from 'vue'
|
|
11
12
|
import { createNodeOps } from './nodeOps'
|
|
12
13
|
import { extend, MiniDom } from './core'
|
|
@@ -29,16 +30,19 @@ export const useCamera = <T extends THREE.Camera = THREE.Camera>() =>
|
|
|
29
30
|
export const onCameraReady = <T extends THREE.Camera = THREE.Camera>(
|
|
30
31
|
cb: (camera?: T) => void
|
|
31
32
|
) => {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
const existing = useCamera<T>()
|
|
34
|
+
if (existing.value) {
|
|
35
|
+
cb(existing.value)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let stopWatch: WatchStopHandle | null = null
|
|
40
|
+
stopWatch = watch(useCamera<T>(), (newVal) => {
|
|
41
|
+
if (newVal) {
|
|
42
|
+
cb(newVal)
|
|
43
|
+
stopWatch?.()
|
|
44
|
+
}
|
|
45
|
+
})
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/** The current renderer as a computed value. */
|
|
@@ -48,12 +52,19 @@ export const useRenderer = <T extends THREE.Renderer = THREE.WebGLRenderer>() =>
|
|
|
48
52
|
export const onRendererReady = <T extends THREE.Renderer = THREE.Renderer>(
|
|
49
53
|
cb: (renderer?: T) => void
|
|
50
54
|
) => {
|
|
51
|
-
const
|
|
55
|
+
const existing = useRenderer<T>()
|
|
56
|
+
if (existing.value) {
|
|
57
|
+
cb(existing.value)
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let stopWatch: WatchStopHandle | null = null
|
|
62
|
+
stopWatch = watch(
|
|
52
63
|
useRenderer<T>(),
|
|
53
64
|
(newVal) => {
|
|
54
65
|
if (newVal) {
|
|
55
66
|
cb(newVal)
|
|
56
|
-
stopWatch()
|
|
67
|
+
stopWatch?.()
|
|
57
68
|
}
|
|
58
69
|
},
|
|
59
70
|
{ immediate: true }
|
|
@@ -67,12 +78,19 @@ export const useScene = <T extends THREE.Scene = THREE.Scene>() =>
|
|
|
67
78
|
export const onSceneReady = <T extends THREE.Scene = THREE.Scene>(
|
|
68
79
|
cb: (scene?: T) => void
|
|
69
80
|
) => {
|
|
70
|
-
const
|
|
81
|
+
const existing = useScene<T>()
|
|
82
|
+
if (existing.value) {
|
|
83
|
+
cb(existing.value)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let stopWatch: WatchStopHandle | null = null
|
|
88
|
+
stopWatch = watch(
|
|
71
89
|
useScene<T>(),
|
|
72
90
|
(newVal) => {
|
|
73
91
|
if (newVal) {
|
|
74
92
|
cb(newVal)
|
|
75
|
-
stopWatch()
|
|
93
|
+
stopWatch?.()
|
|
76
94
|
}
|
|
77
95
|
},
|
|
78
96
|
{ immediate: true }
|