@tresjs/core 2.4.0-next.1 → 2.4.0-next.10

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/tres.umd.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.4.0-next.0
3
+ * version: v2.4.0-next.10
4
4
  * (c) 2023
5
5
  * description: Declarative ThreeJS using Vue Components
6
6
  * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
7
  */
8
- (function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,u,g,f){"use strict";function le(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const t=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,t.get?t:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const fe=le(g);function Y(e){const n=u.shallowRef([]),a=u.computed(()=>n.value.find(c=>c.userData.IS_ACTIVE_CAMERA));function t(c,o=!0){n.value.push(c),o&&r(c.uuid)}function r(c){const o=n.value.find(s=>s.uuid===c);o&&(n.value.forEach(s=>s.userData.IS_ACTIVE_CAMERA=!1),o.userData.IS_ACTIVE_CAMERA=!0)}function i(){n.value=[]}return u.watchEffect(()=>{var c;(c=e.aspectRatio)!=null&&c.value&&(console.log("camera watcher aspectRatio",e.aspectRatio.value),n.value.forEach(o=>{o instanceof g.PerspectiveCamera&&(o.aspect=e.aspectRatio.value),o.updateProjectionMatrix()}))}),{cameras:n,camera:a,addCamera:t,setCameraToActive:r,clearCameras:i}}const K=f.createEventHook(),X=f.createEventHook(),I=f.createEventHook(),E=new g.Clock;let R=0,x=0;const{pause:de,resume:me,isActive:pe}=f.useRafFn(()=>{K.trigger({delta:R,elapsed:x,clock:E}),X.trigger({delta:R,elapsed:x,clock:E}),I.trigger({delta:R,elapsed:x,clock:E})},{immediate:!1});I.on(()=>{R=E.getDelta(),x=E.getElapsedTime()});function z(){return{onBeforeLoop:K.on,onLoop:X.on,onAfterLoop:I.on,pause:de,resume:me,isActive:pe}}function ve(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function J(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const G={realistic:{outputColorSpace:g.SRGBColorSpace,toneMapping:g.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:g.PCFSoftShadowMap}}},Q=(e,n)=>{for(const a of Object.keys(n))n[a]instanceof Object&&Object.assign(n[a],Q(e[a],n[a]));return Object.assign(e||{},n),e},ge=we("html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot");function k(e){return e.replace(/-([a-z])/g,(n,a)=>a.toUpperCase())}function we(e,n){const a=Object.create(null),t=e.split(",");for(let r=0;r<t.length;r++)a[t[r]]=!0;return n?r=>!!a[r.toLowerCase()]:r=>!!a[r]}const be=(e,n)=>{const a=new Set,t=[];for(const r of e){const i=n(r);a.has(i)||(a.add(i),t.push(r))}return t},ye=!0,Z="[TresJS ▲ ■ ●] ";function A(){function e(t,r){console.error(`${Z} ${t}`,r||"")}function n(t){console.warn(`${Z} ${t}`)}function a(t,r){}return{logError:e,logWarning:n,logMessage:a}}function H(e,n,a){const t=u.shallowRef(),r=u.ref(!1),{alpha:i=!0,antialias:c=!0,depth:o,logarithmicDepthBuffer:s,failIfMajorPerformanceCaveat:l,precision:p,premultipliedAlpha:w,stencil:v,shadows:_=!1,shadowMapType:P=g.PCFShadowMap,useLegacyLights:h=!1,outputColorSpace:C=g.LinearSRGBColorSpace,toneMapping:M=g.NoToneMapping,toneMappingExposure:O=1,context:V=void 0,powerPreference:j="default",preserveDrawingBuffer:B=!1,clearColor:S,windowSize:m=!1,preset:b=void 0}=u.toRefs(a),{cameras:Ue,setRenderer:je,sizes:q}=n,{logError:Be,logWarning:$e}=A(),{pixelRatio:D}=f.useDevicePixelRatio(),{pause:De,resume:Ie}=z(),ce=()=>{t.value&&(t.value.setSize(q.width.value,q.height.value),t.value.setPixelRatio(Math.min(D.value,2)))},ue=()=>{if(!t.value)return;const T=f.toValue(b);if(T){T in G||Be("Renderer Preset must be one of these: "+Object.keys(G).join(", ")),Q(t.value,G[T]);return}t.value.shadowMap.enabled=f.toValue(_),t.value.shadowMap.type=f.toValue(P),t.value.toneMapping=f.toValue(M)||g.NoToneMapping,t.value.toneMappingExposure=f.toValue(O),t.value.outputColorSpace=f.toValue(C)||g.LinearSRGBColorSpace,S!=null&&S.value&&t.value.setClearColor(J(f.toValue(S))),t.value.useLegacyLights=f.toValue(h)},ze=()=>{const T=f.unrefElement(e);console.count("init renderer"),T&&(t.value=new g.WebGLRenderer({canvas:T,alpha:f.toValue(i),antialias:f.toValue(c),context:f.toValue(V),depth:f.toValue(o),failIfMajorPerformanceCaveat:f.toValue(l),logarithmicDepthBuffer:f.toValue(s),powerPreference:f.toValue(j),precision:f.toValue(p),stencil:f.toValue(v),preserveDrawingBuffer:f.toValue(B),premultipliedAlpha:f.toValue(w)}),je(t.value),ue(),ce(),Ie(),r.value=!0)},Ge=()=>{t.value&&(t.value.dispose(),t.value=void 0,r.value=!1,De())};return u.watchEffect(()=>{var T;((T=q.aspectRatio)!=null&&T.value||D!=null&&D.value)&&ce()}),u.watch([_,P,C,h,M,O,S],ue),u.watch(e,()=>{f.unrefElement(e)&&ze()},{immediate:!0,deep:!0}),{renderer:t,isReady:r,dispose:Ge}}const ee=e=>typeof e=="function",te=e=>!!e&&e.constructor===Array;function ne(e){const n={nodes:{},materials:{}};return e&&e.traverse(a=>{a.name&&(n.nodes[a.name]=a),a.material&&!n.materials[a.material.name]&&(n.materials[a.material.name]=a.material)}),n}async function Ce(e,n,a,t,r){const{logError:i}=A(),c=new e;r&&r(c),a&&a(c);const s=(Array.isArray(n)?n:[n]).map(l=>new Promise((p,w)=>{c.load(l,v=>{v.scene&&Object.assign(v,ne(v.scene)),p(v)},t,v=>w(i("[useLoader] - Failed to load resource",v)))}));return te(n)?await Promise.all(s):await s[0]}async function he(e){const n=new g.LoadingManager,a=new g.TextureLoader(n),t=r=>new Promise((i,c)=>{a.load(r,o=>i(o),()=>null,()=>{c(new Error("[useTextures] - Failed to load texture"))})});if(te(e)){const r=await Promise.all(e.map(i=>t(i)));return e.length>1?r:r[0]}else{const{map:r,displacementMap:i,normalMap:c,roughnessMap:o,metalnessMap:s,aoMap:l,alphaMap:p,matcap:w}=e;return{map:r?await t(r):null,displacementMap:i?await t(i):null,normalMap:c?await t(c):null,roughnessMap:o?await t(o):null,metalnessMap:s?await t(s):null,aoMap:l?await t(l):null,alphaMap:p?await t(p):null,matcap:w?await t(w):null}}}const y=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function Pe(){const e=Math.random()*4294967295|0,n=Math.random()*4294967295|0,a=Math.random()*4294967295|0,t=Math.random()*4294967295|0;return(y[e&255]+y[e>>8&255]+y[e>>16&255]+y[e>>24&255]+"-"+y[n&255]+y[n>>8&255]+"-"+y[n>>16&15|64]+y[n>>24&255]+"-"+y[a&63|128]+y[a>>8&255]+"-"+y[a>>16&255]+y[a>>24&255]+y[t&255]+y[t>>8&255]+y[t>>16&255]+y[t>>24&255]).toLowerCase()}const N=Symbol();function Me(){const e=u.shallowReactive({uuid:Pe(),camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,aspectRatio:void 0,pointerEventHandler:void 0});function n(r){return e[r]}function a(r,i){e[r]=i}const t={state:e,...u.toRefs(e),getState:n,setState:a};return u.provide(N,t),t}const ae=()=>u.inject(N,{state:u.shallowReactive({camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,pointerEventHandler:void 0})}),oe=e=>{const{state:n}=ae(),a=u.computed(()=>{var m;return(m=n.canvas)==null?void 0:m.value}),{x:t,y:r}=f.usePointer({target:a}),{width:i,height:c,top:o,left:s}=f.useElementBounding(a),l=new g.Raycaster,p=({x:m,y:b})=>{if(a.value)return{x:(m-s.value)/i.value*2-1,y:-((b-o.value)/c.value)*2+1}},w=({x:m,y:b})=>{if(n.camera)return l.setFromCamera(new g.Vector2(m,b),n.camera),l.intersectObjects(e.value,!1)},v=m=>{const b=p({x:(m==null?void 0:m.clientX)??t.value,y:(m==null?void 0:m.clientY)??r.value});return b?w(b)||[]:[]},_=u.computed(()=>v()),P=f.createEventHook(),h=f.createEventHook(),C=(m,b)=>{m.trigger({event:b,intersects:v(b)})},M=m=>{C(h,m)};let O;const V=m=>{var b;O=(b=v(m)[0])==null?void 0:b.object},j=m=>{var b;m instanceof PointerEvent&&O===((b=v(m)[0])==null?void 0:b.object)&&C(P,m)},B=m=>h.trigger({event:m,intersects:[]}),S=u.watchEffect(()=>{a!=null&&a.value&&(a.value.addEventListener("pointerup",j),a.value.addEventListener("pointerdown",V),a.value.addEventListener("pointermove",M),a.value.addEventListener("pointerleave",B),S())});return u.onUnmounted(()=>{a!=null&&a.value&&(a.value.removeEventListener("pointerup",j),a.value.removeEventListener("pointerdown",V),a.value.removeEventListener("pointermove",M),a.value.removeEventListener("pointerleave",B))}),{intersects:_,onClick:m=>P.on(m).off,onPointerMove:m=>h.on(m).off}};function _e(){const{logWarning:e}=A();function n(t,r,i){let c=null;return t.traverse(o=>{o[r]===i&&(c=o)}),c||e(`Child with ${r} '${i}' not found.`),c}function a(t,r){return n(t,"name",r)}return{seek:n,seekByName:a}}const Te=()=>{const e=u.reactive({click:new Map,pointerMove:new Map,pointerEnter:new Map,pointerLeave:new Map}),n=o=>{Object.values(e).forEach(s=>s.delete(o))},a=o=>{const{onClick:s,onPointerMove:l,onPointerEnter:p,onPointerLeave:w}=o;s&&e.click.set(o,s),l&&e.pointerMove.set(o,l),p&&e.pointerEnter.set(o,p),w&&e.pointerLeave.set(o,w),o.addEventListener("removed",()=>{o.traverse(v=>{n(v)}),n(o)})},t=u.computed(()=>be(Object.values(e).map(o=>Array.from(o.keys())).flat(),({uuid:o})=>o)),{onClick:r,onPointerMove:i}=oe(t);r(({intersects:o,event:s})=>{var l;o.length&&((l=e.click.get(o[0].object))==null||l(o[0],s))});let c;return i(({intersects:o,event:s})=>{var _,P,h,C;const l=(_=o==null?void 0:o[0])==null?void 0:_.object,{pointerLeave:p,pointerEnter:w,pointerMove:v}=e;c&&c!==l&&((P=p.get(c))==null||P(c,s)),l&&(c!==l&&((h=w.get(l))==null||h(o[0],s)),(C=v.get(l))==null||C(o[0],s)),c=l||null}),{registerObject:a,deregisterObject:n}},{logError:Ae}=A();function re(e,n,a){var h;e||Ae("A scene most be provided to the TresProvider");const{width:t,height:r}=f.toValue(a.windowSize)==!0||f.toValue(a.windowSize)===""||f.toValue(a.windowSize)==="true"||n.value===void 0?f.useWindowSize():f.useElementSize((h=n.value)==null?void 0:h.parentElement),i=u.computed(()=>t.value/r.value),c={height:r,width:t,aspectRatio:i},o=u.shallowRef(e),{camera:s,cameras:l,addCamera:p,setCameraToActive:w}=Y(c),v=u.shallowRef(null);function _(C){v.value||(v.value=C)}const P={scene:u.readonly(o),cameras:u.readonly(l),camera:s,addCamera:p,setCameraToActive:w,renderer:u.readonly(v),setRenderer:_,sizes:c};return u.provide("useTres",P),P}function Se(){const e=u.inject("useTres");if(!e)throw new Error("useTresContext must be used within a TresProvider");return e}const F=u.ref({}),W=e=>void Object.assign(F.value,e),U={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp",REGISTER_AT_POINTER_EVENT_HANDLER:"tres__registerAtPointerEventHandler"};function Fe(e){}let $=null,L=null;const{logError:ie}=A(),Ee={createElement(e,n,a,t){var s,l;if(t||(t={}),t.args||(t.args=[]),e==="template"||ge(e))return null;let r=e.replace("Tres",""),i;if(e==="primitive"){(t==null?void 0:t.object)===void 0&&ie("Tres primitives need a prop 'object'");const p=t.object;r=p.type,i=Object.assign(p,{type:r,attach:t.attach,primitive:!0})}else{const p=F.value[r];p||ie(`${r} is not defined on the THREE namespace. Use extend to add it to the catalog.`),i=new p(...t.args)}i.isCamera&&(t!=null&&t.position||i.position.set(3,3,3),t!=null&&t.lookAt||i.lookAt(0,0,0)),(t==null?void 0:t.attach)===void 0&&(i.isMaterial?i.attach="material":i.isBufferGeometry&&(i.attach="geometry"));const{GEOMETRY_VIA_PROP:c,MATERIAL_VIA_PROP:o}=U;return i.isObject3D&&((s=t==null?void 0:t.material)!=null&&s.isMaterial&&(i.userData[o]=!0),(l=t==null?void 0:t.geometry)!=null&&l.isBufferGeometry&&(i.userData[c]=!0)),i},insert(e,n){var a,t,r,i,c,o,s;if(n&&n.isScene&&(L=n),(((a=e==null?void 0:e.__vnode)==null?void 0:a.type)==="TresGroup"||((t=e==null?void 0:e.__vnode)==null?void 0:t.type)==="TresObject3D")&&n===null&&!((i=(r=e==null?void 0:e.__vnode)==null?void 0:r.ctx)!=null&&i.asyncResolved)){$=e;return}else(c=e==null?void 0:e.__vnode)!=null&&c.type.includes("Controls")&&n===null&&($=L);n||(n=$),e!=null&&e.isObject3D&&(n!=null&&n.isObject3D)?(n.add(e),e.dispatchEvent({type:"added"}),(s=(o=L==null?void 0:L.userData)==null?void 0:o[U.REGISTER_AT_POINTER_EVENT_HANDLER])==null||s.call(o,e)):e!=null&&e.isFog?n.fog=e:typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[n==null?void 0:n.attach],n&&(n[e.attach]=e))},remove(e){var n,a;if(e){if(e.isObject3D){const t=e,r=i=>{var s,l;const{GEOMETRY_VIA_PROP:c,MATERIAL_VIA_PROP:o}=U;i.userData[o]||(s=i.material)==null||s.dispose(),i.userData[c]||(l=i.geometry)==null||l.dispose()};t.traverse(i=>{r(i)}),r(t)}(n=e.removeFromParent)==null||n.call(e),(a=e.dispose)==null||a.call(e)}},patchProp(e,n,a,t){if(e){let r=e,i=n,c=k(i),o=r==null?void 0:r[c];if(r.type==="BufferGeometry"){if(i==="args")return;r.setAttribute(k(i),new g.BufferAttribute(...t));return}if(i.includes("-")&&o===void 0){const l=i.split("-");o=l.reduce((p,w)=>p[k(w)],r),i=l.pop(),c=i.toLowerCase(),o!=null&&o.set||(r=l.reduce((p,w)=>p[k(w)],r))}let s=t;if(s===""&&(s=!0),ee(o)){Array.isArray(s)?e[c](...s):e[c](s);return}!(o!=null&&o.set)&&!ee(o)?r[c]=s:o.constructor===s.constructor&&(o!=null&&o.copy)?o==null||o.copy(s):Array.isArray(s)?o.set(...s):!o.isColor&&o.setScalar?o.setScalar(s):o.set(s)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:Le}=u.createRenderer(Ee),Oe=e=>{const n=Le(a);function a(){return e&&e.default?e.default():[]}return n};W(fe);const Re=["data-scene"],se=u.defineComponent({__name:"TresCanvas",props:{shadows:{type:Boolean},shadowMapType:{},useLegacyLights:{type:Boolean},outputColorSpace:{},toneMapping:{},toneMappingExposure:{},context:{},powerPreference:{},preserveDrawingBuffer:{type:Boolean},clearColor:{},windowSize:{type:Boolean},preset:{},disableRender:{type:Boolean},camera:{}},setup(e){const n=e,{logWarning:a}=A(),t=u.ref(),r=u.shallowRef(new g.Scene),{onLoop:i}=z(),c=u.useSlots();function o(){const s=re(r.value,t,n),{addCamera:l,camera:p,clearCameras:w}=s;let v;function _(){v=Oe(c),v.provide("useTres",s),v.provide("extend",W),v.mount(r.value),h()}_();const{renderer:P}=H(t,s,n);n.camera&&l(n.camera),i(()=>{var C;p.value&&n.disableRender!==!0&&((C=P.value)==null||C.render(r.value,p.value))});function h(){const C=r.value.getObjectByProperty("isCamera",!0);if(C)l(C);else{a("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene.");const M=new g.PerspectiveCamera(45,window.innerWidth/window.innerHeight,.1,1e3);M.position.set(3,3,3),M.lookAt(0,0,0),l(M)}u.watch(()=>n.camera,M=>{M&&(w(),l(M))})}}return u.onMounted(()=>{o()}),u.onUnmounted(()=>{}),(s,l)=>(u.openBlock(),u.createElementBlock("canvas",{ref_key:"canvas",ref:t,"data-scene":r.value.uuid,style:u.normalizeStyle({display:"block",width:"100%",height:"100%",position:s.windowSize?"fixed":"relative",top:0,left:0,pointerEvents:"auto",touchAction:"none",zIndex:1})},null,12,Re))}}),xe=["TresCanvas","TresLeches","TresScene"],ke={template:{compilerOptions:{isCustomElement:e=>e.startsWith("Tres")&&!xe.includes(e)||e==="primitive"}}},Ve={install(e){e.component("TresCanvas",se)}};d.TRES_CONTEXT_KEY=N,d.TresCanvas=se,d.catalogue=F,d.default=Ve,d.extend=W,d.isProd=ye,d.normalizeColor=J,d.normalizeVectorFlexibleParam=ve,d.templateCompilerOptions=ke,d.trasverseObjects=ne,d.useCamera=Y,d.useLoader=Ce,d.useLogger=A,d.usePointerEventHandler=Te,d.useRaycaster=oe,d.useRenderLoop=z,d.useRenderer=H,d.useSeek=_e,d.useTexture=he,d.useTres=ae,d.useTresContext=Se,d.useTresContextProvider=re,d.useTresProvider=Me,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ (function(v,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],c):(v=typeof globalThis<"u"?globalThis:v||self,c(v.tres={},v.Vue,v.Three,v.VueUseCore))})(this,function(v,c,g,p){"use strict";function re(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const ae=re(g),z=c.ref({}),j=e=>void Object.assign(z.value,e),W=e=>typeof e=="function",$=e=>!!e&&e.constructor===Array,q=({sizes:e,scene:r})=>{const t=c.ref([]),n=c.computed(()=>t.value[0]),o=(a,s=!1)=>{t.value.some(({uuid:u})=>u===a.uuid)||(s?l(a):t.value.push(a))},i=a=>{t.value=t.value.filter(({uuid:s})=>s!==a.uuid)},l=a=>{const s=a instanceof g.Camera?a:t.value.find(f=>f.uuid===a);if(!s)return;const u=t.value.filter(({uuid:f})=>f!==s.uuid);t.value=[s,...u]};return c.watchEffect(()=>{e.aspectRatio.value&&t.value.forEach(a=>{a instanceof g.PerspectiveCamera&&(a.aspect=e.aspectRatio.value),(a instanceof g.PerspectiveCamera||a instanceof g.OrthographicCamera)&&a.updateProjectionMatrix()})}),r.userData.tres__registerCamera=o,r.userData.tres__deregisterCamera=i,c.onUnmounted(()=>{t.value=[]}),{camera:n,cameras:t,addCamera:o,removeCamera:i,setCameraActive:l}},I=p.createEventHook(),N=p.createEventHook(),F=p.createEventHook(),A=new g.Clock;let x=0,B=0;const{pause:oe,resume:se,isActive:ie}=p.useRafFn(()=>{I.trigger({delta:x,elapsed:B,clock:A}),N.trigger({delta:x,elapsed:B,clock:A}),F.trigger({delta:x,elapsed:B,clock:A})},{immediate:!1});F.on(()=>{x=A.getDelta(),B=A.getElapsedTime()});const G=()=>({onBeforeLoop:I.on,onLoop:N.on,onAfterLoop:F.on,pause:oe,resume:se,isActive:ie}),V={realistic:{outputColorSpace:g.SRGBColorSpace,toneMapping:g.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:g.PCFSoftShadowMap}}},U=(e,r)=>{for(const t of Object.keys(r))r[t]instanceof Object&&Object.assign(r[t],U(e[t],r[t]));return Object.assign(e||{},r),e},ue=le("html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot");function T(e){return e.replace(/-([a-z])/g,(r,t)=>t.toUpperCase())}function le(e,r){const t=Object.create(null),n=e.split(",");for(let o=0;o<n.length;o++)t[n[o]]=!0;return r?o=>!!t[o.toLowerCase()]:o=>!!t[o]}const ce=(e,r)=>{const t=new Set,n=[];for(const o of e){const i=r(o);t.has(i)||(t.add(i),n.push(o))}return n},J=(e,r)=>{if(!r)return;const t=Array.isArray(r)?r:r.match(/([^[.\]])+/g);return t==null?void 0:t.reduce((n,o)=>n&&n[o],e)},fe=(e,r,t)=>{const n=Array.isArray(r)?r:r.match(/([^[.\]])+/g);n&&n.reduce((o,i,l)=>(o[i]===void 0&&(o[i]={}),l===n.length-1&&(o[i]=t),o[i]),e)},me=!0,K="[TresJS ▲ ■ ●] ";function S(){function e(n,o){console.error(`${K} ${n}`,o||"")}function r(n){console.warn(`${K} ${n}`)}function t(n,o){}return{logError:e,logWarning:r,logMessage:t}}function pe(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function X(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}function Y({scene:e,canvas:r,options:t,disableRender:n,contextParts:{sizes:o,camera:i}}){const l=c.computed(()=>({alpha:p.toValue(t.alpha),depth:p.toValue(t.depth),canvas:p.unrefElement(r),context:p.toValue(t.context),stencil:p.toValue(t.stencil),antialias:p.toValue(t.antialias)===void 0?!0:p.toValue(t.antialias),precision:p.toValue(t.precision),powerPreference:p.toValue(t.powerPreference),premultipliedAlpha:p.toValue(t.premultipliedAlpha),preserveDrawingBuffer:p.toValue(t.preserveDrawingBuffer),logarithmicDepthBuffer:p.toValue(t.logarithmicDepthBuffer),failIfMajorPerformanceCaveat:p.toValue(t.failIfMajorPerformanceCaveat)})),a=c.shallowRef(new g.WebGLRenderer(l.value));c.watch(l,()=>{a.value.dispose(),a.value=new g.WebGLRenderer(l.value)}),c.watchEffect(()=>{a.value.setSize(o.width.value,o.height.value)});const{pixelRatio:s}=p.useDevicePixelRatio();c.watchEffect(()=>{a.value.setPixelRatio(s.value)});const{logError:u}=S(),m=(()=>{const w=new g.WebGLRenderer,C={shadowMap:{enabled:w.shadowMap.enabled,type:w.shadowMap.type},toneMapping:w.toneMapping,toneMappingExposure:w.toneMappingExposure,outputColorSpace:w.outputColorSpace,useLegacyLights:w.useLegacyLights};return w.dispose(),C})();c.watchEffect(()=>{const w=p.toValue(t.preset);w&&(w in V||u("Renderer Preset must be one of these: "+Object.keys(V).join(", ")),U(a.value,V[w]));const C=(D,k)=>{const O=p.toValue(D),E=()=>{if(w)return J(V[w],k)};if(O!==void 0)return O;const d=E();return d!==void 0?d:J(m,k)},y=(D,k)=>fe(a.value,k,C(D,k));y(t.shadows,"shadowMap.enabled"),y(t.toneMapping,"toneMapping"),y(t.shadowMapType,"shadowMap.type"),y(t.useLegacyLights,"useLegacyLights"),y(t.outputColorSpace,"outputColorSpace"),y(t.toneMappingExposure,"toneMappingExposure");const h=C(t.clearColor,"clearColor");h&&a.value.setClearColor(h?X(h):new g.Color(0))});const{pause:M,resume:_,onLoop:b}=G();return b(()=>{i.value&&!p.toValue(n)&&a.value.render(e,i.value)}),_(),c.onUnmounted(()=>{M(),a.value.dispose(),a.value.forceContextLoss()}),{renderer:a}}function Q(e){const r={nodes:{},materials:{}};return e&&e.traverse(t=>{t.name&&(r.nodes[t.name]=t),t.material&&!r.materials[t.material.name]&&(r.materials[t.material.name]=t.material)}),r}async function de(e,r,t,n,o){const{logError:i}=S(),l=new e;o&&o(l),t&&t(l);const s=(Array.isArray(r)?r:[r]).map(u=>new Promise((f,m)=>{l.load(u,M=>{M.scene&&Object.assign(M,Q(M.scene)),f(M)},n,M=>m(i("[useLoader] - Failed to load resource",M)))}));return $(r)?await Promise.all(s):await s[0]}async function ve(e){const r=new g.LoadingManager,t=new g.TextureLoader(r),n=o=>new Promise((i,l)=>{t.load(o,a=>i(a),()=>null,()=>{l(new Error("[useTextures] - Failed to load texture"))})});if($(e)){const o=await Promise.all(e.map(i=>n(i)));return e.length>1?o:o[0]}else{const{map:o,displacementMap:i,normalMap:l,roughnessMap:a,metalnessMap:s,aoMap:u,alphaMap:f,matcap:m}=e;return{map:o?await n(o):null,displacementMap:i?await n(i):null,normalMap:l?await n(l):null,roughnessMap:a?await n(a):null,metalnessMap:s?await n(s):null,aoMap:u?await n(u):null,alphaMap:f?await n(f):null,matcap:m?await n(m):null}}}const Z=(e,{renderer:r,camera:t})=>{const n=c.computed(()=>r.value.domElement),{x:o,y:i}=p.usePointer({target:n}),{width:l,height:a,top:s,left:u}=p.useElementBounding(n),f=new g.Raycaster,m=({x:d,y:L})=>{if(n.value)return{x:(d-u.value)/l.value*2-1,y:-((L-s.value)/a.value)*2+1}},M=({x:d,y:L})=>{if(t.value)return f.setFromCamera(new g.Vector2(d,L),t.value),f.intersectObjects(e.value,!1)},_=d=>{const L=m({x:(d==null?void 0:d.clientX)??o.value,y:(d==null?void 0:d.clientY)??i.value});return L?M(L)||[]:[]},b=c.computed(()=>_()),w=p.createEventHook(),C=p.createEventHook(),y=(d,L)=>{d.trigger({event:L,intersects:_(L)})},h=d=>{y(C,d)};let D;const k=d=>{var L;D=(L=_(d)[0])==null?void 0:L.object},O=d=>{var L;d instanceof PointerEvent&&D===((L=_(d)[0])==null?void 0:L.object)&&y(w,d)},E=d=>C.trigger({event:d,intersects:[]});return n.value.addEventListener("pointerup",O),n.value.addEventListener("pointerdown",k),n.value.addEventListener("pointermove",h),n.value.addEventListener("pointerleave",E),c.onUnmounted(()=>{n!=null&&n.value&&(n.value.removeEventListener("pointerup",O),n.value.removeEventListener("pointerdown",k),n.value.removeEventListener("pointermove",h),n.value.removeEventListener("pointerleave",E))}),{intersects:b,onClick:d=>w.on(d).off,onPointerMove:d=>C.on(d).off}};function ge(){const{logWarning:e}=S();function r(n,o,i){let l=null;return n.traverse(a=>{a[o]===i&&(l=a)}),l||e(`Child with ${o} '${i}' not found.`),l}function t(n,o){return r(n,"name",o)}return{seek:r,seekByName:t}}const H=({scene:e,contextParts:r})=>{const t=c.reactive({click:new Map,pointerMove:new Map,pointerEnter:new Map,pointerLeave:new Map}),n=u=>{Object.values(t).forEach(f=>f.delete(u))},o=u=>{const{onClick:f,onPointerMove:m,onPointerEnter:M,onPointerLeave:_}=u;f&&t.click.set(u,f),m&&t.pointerMove.set(u,m),M&&t.pointerEnter.set(u,M),_&&t.pointerLeave.set(u,_)};e.userData.tres__registerAtPointerEventHandler=o,e.userData.tres__deregisterAtPointerEventHandler=n;const i=c.computed(()=>ce(Object.values(t).map(u=>Array.from(u.keys())).flat(),({uuid:u})=>u)),{onClick:l,onPointerMove:a}=Z(i,r);l(({intersects:u,event:f})=>{var m;u.length&&((m=t.click.get(u[0].object))==null||m(u[0],f))});let s;return a(({intersects:u,event:f})=>{var w,C,y,h;const m=(w=u==null?void 0:u[0])==null?void 0:w.object,{pointerLeave:M,pointerEnter:_,pointerMove:b}=t;s&&s!==m&&((C=M.get(s))==null||C(s,f)),m&&(s!==m&&((y=_.get(m))==null||y(u[0],f)),(h=b.get(m))==null||h(u[0],f)),s=m||null}),{registerObject:o,deregisterObject:n}};function ee({scene:e,canvas:r,windowSize:t,disableRender:n,rendererOptions:o}){const i=c.computed(()=>p.toValue(t)?p.useWindowSize():p.useElementSize(p.toValue(r).parentElement)),l=c.computed(()=>i.value.width.value),a=c.computed(()=>i.value.height.value),s=c.computed(()=>l.value/a.value),u={height:a,width:l,aspectRatio:s},f=c.shallowRef(e),{camera:m,cameras:M,addCamera:_,removeCamera:b,setCameraActive:w}=q({sizes:u,scene:e}),{renderer:C}=Y({scene:e,canvas:r,options:o,contextParts:{sizes:u,camera:m},disableRender:n}),y={sizes:u,scene:f,camera:m,cameras:c.readonly(M),renderer:C,addCamera:_,removeCamera:b,setCameraActive:w};return c.provide("useTres",y),y}function we(){const e=c.inject("useTres");if(!e)throw new Error("useTresContext must be used together with useTresContextProvider");return e}function ke(e){}let R=null,P=null;const{logError:te}=S(),ye={createElement(e,r,t,n){var l,a;if(n||(n={}),n.args||(n.args=[]),e==="template"||ue(e))return null;let o=e.replace("Tres",""),i;if(e==="primitive"){(n==null?void 0:n.object)===void 0&&te("Tres primitives need a prop 'object'");const s=n.object;o=s.type,i=Object.assign(s,{type:o,attach:n.attach,primitive:!0})}else{const s=z.value[o];s||te(`${o} is not defined on the THREE namespace. Use extend to add it to the catalog.`),i=new s(...n.args)}return i.isCamera&&(n!=null&&n.position||i.position.set(3,3,3),n!=null&&n.lookAt||i.lookAt(0,0,0)),(n==null?void 0:n.attach)===void 0&&(i.isMaterial?i.attach="material":i.isBufferGeometry&&(i.attach="geometry")),i.isObject3D&&((l=n==null?void 0:n.material)!=null&&l.isMaterial&&(i.userData.tres__materialViaProp=!0),(a=n==null?void 0:n.geometry)!=null&&a.isBufferGeometry&&(i.userData.tres__geometryViaProp=!0)),i},insert(e,r){var t,n,o,i,l,a,s,u,f;if(r&&r.isScene&&(P=r),(((t=e==null?void 0:e.__vnode)==null?void 0:t.type)==="TresGroup"||((n=e==null?void 0:e.__vnode)==null?void 0:n.type)==="TresObject3D")&&r===null&&!((i=(o=e==null?void 0:e.__vnode)==null?void 0:o.ctx)!=null&&i.asyncResolved)){R=e;return}else(l=e==null?void 0:e.__vnode)!=null&&l.type.includes("Controls")&&r===null&&(R=P);if(r||(r=R),e!=null&&e.isObject3D){if(e!=null&&e.isCamera){if(!(P!=null&&P.userData.tres__registerCamera))throw"could not find tres__registerCamera on scene's userData";(s=P==null?void 0:(a=P.userData).tres__registerCamera)==null||s.call(a,e)}if(e!=null&&e.onClick||e!=null&&e.onPointerMove||e!=null&&e.onPointerEnter||e!=null&&e.onPointerLeave){if(!(P!=null&&P.userData.tres__registerAtPointerEventHandler))throw"could not find tres__registerAtPointerEventHandler on scene's userData";(f=P==null?void 0:(u=P.userData).tres__registerAtPointerEventHandler)==null||f.call(u,e)}}e!=null&&e.isObject3D&&(r!=null&&r.isObject3D)?(r.add(e),e.dispatchEvent({type:"added"})):e!=null&&e.isFog?r.fog=e:typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[r==null?void 0:r.attach],r&&(r[e.attach]=e))},remove(e){var r,t;if(e){if(e.isObject3D){const n=e,o=s=>{var f,m;const u=s;s.userData.tres__materialViaProp||(f=u.material)==null||f.dispose(),s.userData.tres__geometryViaProp||(m=u.geometry)==null||m.dispose()},i=P==null?void 0:P.userData.tres__deregisterAtPointerEventHandler,l=s=>{if(!i)throw"could not find tres__deregisterAtPointerEventHandler on scene's userData";(s!=null&&s.onClick||s!=null&&s.onPointerMove||s!=null&&s.onPointerEnter||s!=null&&s.onPointerLeave)&&(i==null||i(s))},a=s=>{const u=P==null?void 0:P.userData.tres__deregisterCamera;if(!u)throw"could not find tres__deregisterCamera on scene's userData";s.isCamera&&(u==null||u(s))};n.traverse(s=>{o(s),a(s),l==null||l(s)}),o(n),a(n),l==null||l(n)}(r=e.removeFromParent)==null||r.call(e),(t=e.dispose)==null||t.call(e)}},patchProp(e,r,t,n){if(e){let o=e,i=r,l=T(i),a=o==null?void 0:o[l];if(o.type==="BufferGeometry"){if(i==="args")return;o.setAttribute(T(i),new g.BufferAttribute(...n));return}if(i.includes("-")&&a===void 0){const u=i.split("-");a=u.reduce((f,m)=>f[T(m)],o),i=u.pop(),l=i.toLowerCase(),a!=null&&a.set||(o=u.reduce((f,m)=>f[T(m)],o))}let s=n;if(s===""&&(s=!0),W(a)){Array.isArray(s)?e[l](...s):e[l](s);return}!(a!=null&&a.set)&&!W(a)?o[l]=s:a.constructor===s.constructor&&(a!=null&&a.copy)?a==null||a.copy(s):Array.isArray(s)?a.set(...s):!a.isColor&&a.setScalar?a.setScalar(s):a.set(s)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:Ce}=c.createRenderer(ye),Pe=e=>{const r=Ce(t);function t(){return e&&e.default?e.default():[]}return r};j(ae);const Me=["data-scene"],ne=c.defineComponent({__name:"TresCanvas",props:{shadows:{type:Boolean},clearColor:{},toneMapping:{},shadowMapType:{},useLegacyLights:{type:Boolean},outputColorSpace:{},toneMappingExposure:{},windowSize:{type:Boolean},preset:{},disableRender:{type:Boolean},camera:{},context:{},precision:{},alpha:{type:Boolean,default:!1},premultipliedAlpha:{type:Boolean},antialias:{type:Boolean,default:!0},stencil:{type:Boolean,default:!0},preserveDrawingBuffer:{type:Boolean,default:!1},powerPreference:{},depth:{type:Boolean,default:!0},logarithmicDepthBuffer:{type:Boolean},failIfMajorPerformanceCaveat:{type:Boolean}},setup(e){const r=e,{logWarning:t}=S(),n=c.ref(),o=c.shallowRef(new g.Scene);G();const i=c.useSlots();let l;const a=u=>{l=Pe(i),l.provide("useTres",u),l.provide("extend",j),l.mount(o.value)},s=c.computed(()=>r.disableRender);return c.onMounted(()=>{const u=n,f=ee({scene:o.value,canvas:u,windowSize:r.windowSize,disableRender:s,rendererOptions:r});H({scene:o.value,contextParts:f});const{addCamera:m,camera:M,cameras:_,removeCamera:b}=f;a(f);const w=()=>{const C=new g.PerspectiveCamera(45,window.innerWidth/window.innerHeight,.1,1e3);C.position.set(3,3,3),C.lookAt(0,0,0),m(C);const y=c.watchEffect(()=>{_.value.length>=2&&(C.removeFromParent(),b(C),y==null||y())})};c.watch(()=>r.camera,(C,y)=>{C?m(C):y&&(y.removeFromParent(),b(y))},{immediate:!0}),M.value||(t("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene."),w())}),(u,f)=>(c.openBlock(),c.createElementBlock("canvas",{ref_key:"canvas",ref:n,"data-scene":o.value.uuid,style:c.normalizeStyle({display:"block",width:"100%",height:"100%",position:u.windowSize?"fixed":"relative",top:0,left:0,pointerEvents:"auto",touchAction:"none",zIndex:1})},null,12,Me))}}),_e=["TresCanvas","TresLeches","TresScene"],Le={template:{compilerOptions:{isCustomElement:e=>e.startsWith("Tres")&&!_e.includes(e)||e==="primitive"}}},be={install(e){e.component("TresCanvas",ne)}};v.TresCanvas=ne,v.catalogue=z,v.default=be,v.extend=j,v.isProd=me,v.normalizeColor=X,v.normalizeVectorFlexibleParam=pe,v.templateCompilerOptions=Le,v.trasverseObjects=Q,v.useCamera=q,v.useLoader=de,v.useLogger=S,v.usePointerEventHandler=H,v.useRaycaster=Z,v.useRenderLoop=G,v.useRenderer=Y,v.useSeek=ge,v.useTexture=ve,v.useTresContext=we,v.useTresContextProvider=ee,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,5 +1,6 @@
1
- import type * as THREE from 'three';
2
1
  import { DefineComponent, Ref, VNode } from 'vue';
2
+ import type * as THREE from 'three';
3
+ import type { EventProps as PointerEventHandlerEventProps } from '../composables/usePointerEventHandler';
3
4
  export type AttachFnType<O = any> = (parent: any, self: O) => () => void;
4
5
  export type AttachType<O = any> = string | AttachFnType<O>;
5
6
  export type ConstructorRepresentation = new (...args: any[]) => any;
@@ -33,13 +34,21 @@ export interface TresObject3D extends THREE.Object3D {
33
34
  geometry?: THREE.BufferGeometry & TresBaseObject;
34
35
  material?: THREE.Material & TresBaseObject;
35
36
  userData: {
36
- MATERIAL_VIA_PROP: boolean;
37
- GEOMETRY_VIA_PROP: boolean;
38
- } & {
37
+ tres__materialViaProp: boolean;
38
+ tres__geometryViaProp: boolean;
39
39
  [key: string]: any;
40
40
  };
41
41
  }
42
42
  export type TresObject = TresBaseObject & (TresObject3D | THREE.BufferGeometry | THREE.Material | THREE.Fog);
43
+ export interface TresScene extends THREE.Scene {
44
+ userData: {
45
+ tres__registerCamera?: (newCamera: THREE.Camera, active?: boolean) => void;
46
+ tres__deregisterCamera?: (camera: THREE.Camera) => void;
47
+ tres__registerAtPointerEventHandler?: (object: THREE.Object3D & PointerEventHandlerEventProps) => void;
48
+ tres__deregisterAtPointerEventHandler?: (object: THREE.Object3D) => void;
49
+ [key: string]: any;
50
+ };
51
+ }
43
52
  export interface Intersection extends THREE.Intersection {
44
53
  /** The event source (the object which registered the handler) */
45
54
  eventObject: TresObject;
@@ -4,3 +4,5 @@ export declare const isHTMLTag: (key: string) => boolean;
4
4
  export declare function kebabToCamel(str: string): string;
5
5
  export declare function makeMap(str: string, expectsLowerCase?: boolean): (key: string) => boolean;
6
6
  export declare const uniqueBy: <T, K>(array: T[], iteratee: (value: T) => K) => T[];
7
+ export declare const get: <T>(obj: any, path: string | string[]) => T | undefined;
8
+ export declare const set: (obj: any, path: string | string[], value: any) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tresjs/core",
3
3
  "description": "Declarative ThreeJS using Vue Components",
4
- "version": "2.4.0-next.1",
4
+ "version": "2.4.0-next.10",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.3.1",
7
7
  "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
@@ -1,98 +0,0 @@
1
- import { TresCamera } from 'src/types';
2
- import { PerspectiveCamera, OrthographicCamera } from 'three';
3
- import { Ref } from 'vue';
4
- export declare enum CameraType {
5
- Perspective = "Perspective",
6
- Orthographic = "Orthographic"
7
- }
8
- export type Camera = PerspectiveCamera | OrthographicCamera;
9
- export interface PerspectiveCameraOptions {
10
- /**
11
- * Camera frustum vertical field of view, from bottom to top of view, in degrees.
12
- *
13
- * @type {number}
14
- * @memberof PerspectiveCameraOptions
15
- */
16
- fov?: number;
17
- /**
18
- * Camera frustum near plane.
19
- *
20
- * @type {number}
21
- * @memberof PerspectiveCameraOptions
22
- */
23
- near?: number;
24
- /**
25
- * Camera frustum far plane.
26
- *
27
- * @type {number}
28
- * @memberof PerspectiveCameraOptions
29
- */
30
- far?: number;
31
- }
32
- export interface OrthographicCameraOptions {
33
- /**
34
- * Camera frustum left plane.
35
- *
36
- * @type {number}
37
- * @memberof OrthographicCameraOptions
38
- */
39
- left?: number;
40
- /**
41
- * Camera frustum right plane.
42
- *
43
- * @type {number}
44
- * @memberof OrthographicCameraOptions
45
- */
46
- right?: number;
47
- /**
48
- * Camera frustum top plane.
49
- *
50
- * @type {number}
51
- * @memberof OrthographicCameraOptions
52
- */
53
- top?: number;
54
- /**
55
- * Camera frustum bottom plane.
56
- *
57
- * @type {number}
58
- * @memberof OrthographicCameraOptions
59
- */
60
- bottom?: number;
61
- /**
62
- * Camera frustum near plane.
63
- *
64
- * @type {number}
65
- * @memberof OrthographicCameraOptions
66
- */
67
- near?: number;
68
- /**
69
- * Camera frustum far plane.
70
- *
71
- * @type {number}
72
- * @memberof OrthographicCameraOptions
73
- */
74
- far?: number;
75
- }
76
- interface UseCameraReturn {
77
- activeCamera: Ref<TresCamera | undefined>;
78
- createCamera: (cameraType?: CameraType, options?: PerspectiveCameraOptions | OrthographicCameraOptions) => Camera;
79
- updateCamera: () => void;
80
- pushCamera: (camera: TresCamera) => void;
81
- clearCameras: () => void;
82
- setFirstCamera: (camera: TresCamera) => void;
83
- }
84
- /**
85
- * Create and update cameras
86
- *
87
- * ```ts
88
- * import { useCamera } from '@tresjs/core'
89
- * const { createCamera, updateCamera } = useCamera()
90
- * const camera = createCamera(new PerspectiveCamera(45, 1, 0.1, 1000))
91
- * updateCamera()
92
- * ```
93
- *
94
- * @export
95
- * @return {*} {UseCameraReturn}
96
- */
97
- export declare function useCamera(): UseCameraReturn;
98
- export {};
@@ -1,142 +0,0 @@
1
- import { Clock, EventDispatcher, Raycaster, Scene, Vector2, WebGLRenderer } from 'three';
2
- import { ComputedRef, Ref } from 'vue';
3
- import { Camera } from '../useCamera/old';
4
- import type { usePointerEventHandler } from '../usePointerEventHandler';
5
- export interface TresState {
6
- /**
7
- * The active camera used for rendering the scene.
8
- *
9
- * @see https://threejs.org/docs/index.html?q=camera#api/en/cameras/Camera
10
- *
11
- * @type {Camera}
12
- * @memberof TresState
13
- */
14
- camera?: Camera;
15
- /**
16
- * All cameras available in the scene.
17
- *
18
- * @see https://threejs.org/docs/index.html?q=camera#api/en/cameras/Camera
19
- *
20
- * @type {Camera[]}
21
- * @memberof TresState
22
- */
23
- cameras?: Camera[];
24
- /**
25
- * The aspect ratio of the scene.
26
- *
27
- * @type {ComputedRef<number>}
28
- * @memberof TresState
29
- */
30
- aspectRatio?: ComputedRef<number>;
31
- /**
32
- * The WebGLRenderer used to display the scene using WebGL.
33
- *
34
- * @see https://threejs.org/docs/index.html?q=webglren#api/en/renderers/WebGLRenderer
35
- *
36
- * @type {WebGLRenderer}
37
- * @memberof TresState
38
- */
39
- renderer?: WebGLRenderer;
40
- /**
41
- * The scene. This is the place where you place objects, lights and cameras.
42
- *
43
- * @see https://threejs.org/docs/index.html?q=scene#api/en/scenes/Scene
44
- *
45
- * @type {Scene}
46
- * @memberof TresState
47
- */
48
- scene?: Scene;
49
- /**
50
- * The raycaster.
51
- *
52
- * @see https://threejs.org/docs/index.html?q=raycas#api/en/core/Raycaster
53
- *
54
- * @type {Raycaster}
55
- * @memberof TresState
56
- */
57
- raycaster?: Raycaster;
58
- /**
59
- * Object for keeping track of time. This uses `performance.now` if it is available,
60
- * otherwise it reverts to the less accurate `Date.now`.
61
- *
62
- * @see https://threejs.org/docs/index.html?q=clock#api/en/core/Clock
63
- *
64
- * @type {Clock}
65
- * @memberof TresState
66
- */
67
- clock?: Clock;
68
- /**
69
- * The current mouse position.
70
- *
71
- * @type {Vector2}
72
- * @memberof TresState
73
- */
74
- pointer?: Vector2;
75
- /**
76
- * The current instance of the component.
77
- *
78
- * @type {*}
79
- * @memberof TresState
80
- */
81
- currentInstance?: any;
82
- /**
83
- * The current active scene control
84
- *
85
- * @type {((EventDispatcher & { enabled: boolean }) | null)}
86
- * @memberof TresState
87
- */
88
- controls?: (EventDispatcher & {
89
- enabled: boolean;
90
- }) | null;
91
- canvas?: Ref<HTMLElement>;
92
- /**
93
- * The entity that handles pointer events
94
- * @type {ReturnType<typeof usePointerEventHandler>}
95
- * @memberof TresState
96
- */
97
- pointerEventHandler?: ReturnType<typeof usePointerEventHandler>;
98
- [key: string]: any;
99
- }
100
- export type UseTresReturn = {
101
- state: TresState;
102
- getState: (key: string) => void;
103
- setState: (key: string, value: any) => void;
104
- aspectRatio: ComputedRef<number>;
105
- };
106
- export declare const TRES_CONTEXT_KEY: unique symbol;
107
- /**
108
- * The Tres state.
109
- *
110
- * @see https://threejs.org/docs/index.html?q=scene#api/en/scenes/Scene
111
- *
112
- * @export
113
- * @return {*} {TresState, getState, setState}
114
- */
115
- export declare function useTresProvider(): {
116
- getState: (key: string) => any;
117
- setState: (key: string, value: any) => void;
118
- camera?: Ref<Camera | undefined> | undefined;
119
- cameras?: Ref<Camera[] | undefined> | undefined;
120
- aspectRatio?: Ref<ComputedRef<number> | undefined> | undefined;
121
- renderer?: Ref<WebGLRenderer | undefined> | undefined;
122
- scene?: Ref<Scene | undefined> | undefined;
123
- raycaster?: Ref<Raycaster | undefined> | undefined;
124
- clock?: Ref<Clock | undefined> | undefined;
125
- pointer?: Ref<Vector2 | undefined> | undefined;
126
- currentInstance?: Ref<any> | undefined;
127
- controls?: Ref<(EventDispatcher<import("three").Event> & {
128
- enabled: boolean;
129
- }) | null | undefined> | undefined;
130
- canvas?: Ref<Ref<HTMLElement> | undefined> | undefined;
131
- pointerEventHandler?: Ref<{
132
- registerObject: (object: import("three").Object3D<import("three").Event> & {
133
- onClick?: ((intersection: import("three").Intersection<import("three").Object3D<import("three").Event>>, event: PointerEvent) => void) | undefined;
134
- onPointerEnter?: ((intersection: import("three").Intersection<import("three").Object3D<import("three").Event>>, event: PointerEvent) => void) | undefined;
135
- onPointerMove?: ((intersection: import("three").Intersection<import("three").Object3D<import("three").Event>>, event: PointerEvent) => void) | undefined;
136
- onPointerLeave?: ((object: import("three").Object3D<import("three").Event>, event: PointerEvent) => void) | undefined;
137
- }) => void;
138
- deregisterObject: (object: import("three").Object3D<import("three").Event>) => void;
139
- } | undefined> | undefined;
140
- state: TresState;
141
- };
142
- export declare const useTres: () => UseTresReturn;
package/dist/keys.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare const UseTresStateSymbol: unique symbol;
2
- export declare const OBJECT_3D_USER_DATA_KEYS: {
3
- GEOMETRY_VIA_PROP: string;
4
- MATERIAL_VIA_PROP: string;
5
- REGISTER_AT_POINTER_EVENT_HANDLER: string;
6
- };
@@ -1,20 +0,0 @@
1
- import { Scene, WebGLRenderer } from 'three';
2
- import type { ComputedRef, Ref, ShallowRef } from 'vue';
3
- import { TresCamera } from '../types';
4
- export type TresState = {
5
- scene: Readonly<ShallowRef<Scene>>;
6
- cameras: Readonly<ShallowRef<TresCamera[]>>;
7
- camera: ComputedRef<TresCamera | undefined>;
8
- renderer?: Readonly<ShallowRef<WebGLRenderer | null>>;
9
- addCamera: (camera: TresCamera) => void;
10
- setCameraToActive: (cameraId: string) => void;
11
- clearCameras: () => void;
12
- setRenderer: (renderer: WebGLRenderer) => void;
13
- sizes: {
14
- height: Ref<number>;
15
- width: Ref<number>;
16
- aspectRatio: ComputedRef<number>;
17
- };
18
- };
19
- export declare function useTresContextProvider(scene: Scene, canvas: Ref<HTMLCanvasElement | undefined>, props: any): TresState;
20
- export declare function useTresContext(): TresState;
@@ -1 +0,0 @@
1
- export declare function withSetup(composable: any): (import("vue").App<Element> | undefined)[];