@tresjs/core 1.1.0 → 1.2.1
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/core/useInstanceCreator/index.d.ts +1 -1
- package/dist/env.d.ts +1 -0
- package/dist/tres.js +246 -226
- package/dist/tres.umd.cjs +2 -2
- package/dist/types/index.d.ts +11 -0
- package/package.json +2 -2
- package/dist/favicon-16x16.png +0 -0
- package/dist/favicon-32x32.png +0 -0
- package/dist/favicon-dark.svg +0 -6
- package/dist/favicon.ico +0 -0
- package/dist/favicon.svg +0 -5
- package/dist/logo-dark.svg +0 -5
- package/dist/logo.svg +0 -5
- package/dist/models/AkuAku.gltf +0 -1177
- package/dist/pwa-192x192.png +0 -0
- package/dist/pwa-512x512.png +0 -0
- package/dist/safari-pinned-tab.svg +0 -5
- package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_ambientOcclusion.jpg +0 -0
- package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_basecolor.jpg +0 -0
- package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_height.png +0 -0
- package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_normal.jpg +0 -0
- package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_roughness.jpg +0 -0
- package/dist/vite.svg +0 -1
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v1.
|
|
3
|
+
* version: v1.2.0
|
|
4
4
|
* (c) 2022
|
|
5
5
|
* description: Declarative ThreeJS using Vue Components
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
(function(
|
|
8
|
+
(function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("@vueuse/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","three"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.tres={},d.Vue,d.VueUseCore,d.Three))})(this,function(d,i,h,g){"use strict";function re(e){if(e&&e.__esModule)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const W=re(g);var q=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(q||{});const O={cameras:[]},ae=45;let P;function A(){const{width:e,height:t}=h.useWindowSize(),{setState:n}=D();function r(a="Perspective",l){if(a==="Perspective"){const{near:s,far:u,fov:m}=l||{near:.1,far:1e3,fov:ae};P=new g.PerspectiveCamera(m,c.value,s,u),O.cameras.push(P)}else{const{left:s,right:u,top:m,bottom:C,near:y,far:M}=l||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};P=new g.OrthographicCamera(s,u,m,C,y,M),O.cameras.push(P)}return O.cameras.push(P),P}const c=i.computed(()=>e.value/t.value),f=i.computed(()=>O.cameras[0]);function p(){f.value instanceof g.PerspectiveCamera&&(f.value.aspect=c.value),f.value.updateProjectionMatrix()}function o(a){const l=i.inject("camera");a&&l&&(l.value=a,n("camera",l.value)),O.cameras.push(a),a instanceof g.PerspectiveCamera&&(a.aspect=c.value),a.updateProjectionMatrix()}return i.watch(c,p),{activeCamera:f,createCamera:r,updateCamera:p,pushCamera:o}}const G="[TresJS \u25B2 \u25A0 \u25CF] ";function _(){function e(r,c){console.error(`${G} ${r}`,c||"")}function t(r){console.warn(`${G} ${r}`)}function n(r,c){}return{logError:e,logWarning:t,logMessage:n}}const b=i.ref({...W,uuid:W.MathUtils.generateUUID()});delete b.value.Scene;let L;function I(e,t="Tres"){const{logMessage:n,logError:r}=_();!L&&e&&(L=e);const{createComponentInstances:c}=B(t);return{extend:p=>{if(!p){r("No objects provided to extend catalogue");return}b.value=Object.assign(b.value,p);const o=c(i.ref(p));n("Adding objects to catalogue",{objects:p,catalogue:b.value.uuid}),L&&o.forEach(([a,l])=>{L._context.components[a]||L.component(a,l)})},catalogue:b}}const $=e=>typeof e<"u",oe=e=>typeof e=="function",j=e=>!!e&&e.constructor===Array;function se(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 ie=["rotation","scale","position"];function B(e){const{logMessage:t,logError:n}=_();function r(o,a){!$(o)||!$(a)||Object.entries(o).forEach(([l,s])=>{const u=l.replace(/(-\w)/g,m=>m[1].toUpperCase());if(!(u==="args"||s===void 0)){ie.includes(u)&&s&&(s=se(s)),o.ref&&(o.ref=a);try{if(a[u]&&$(a[u].set))a[u].set(...j(s)?s:[s]);else{if(s===""&&(s=!0),oe(a[u])){a[u](...j(s)?s:[s]);return}a[u]=s}}catch(m){n(`There was an error setting ${u} property`,m)}}})}function c(o){var s;const a=/^Symbol\(Fragment\)$/g,l=/^Symbol\(Text\)$/g;if(a.test(o.type.toString()))return o.children.map(u=>c(u));if(l.test(o.type.toString()))return;{const u=o.type.name.replace(e,""),{catalogue:m}=I(),C=i.inject("catalogue")||m;let y;return C&&((s=o==null?void 0:o.props)!=null&&s.args?C!=null&&C.value[u]?y=new C.value[u](...o.props.args):n(`There is no ${u} in the catalogue`,C==null?void 0:C.value.uuid):y=new C.value[u]),o!=null&&o.props&&r(o.props,y),y}}function f(o,a,l){if(l.default&&(l==null?void 0:l.default())){const s=l.default().map(u=>c(u));return new o(...s.flat().filter(Boolean))}else return a.args?new o(...a.args):new o}function p(o){return Object.entries(o.value).filter(([a,l])=>{var s,u;return(u=(s=l==null?void 0:l.prototype)==null?void 0:s.constructor)==null?void 0:u.toString().includes("class")}).map(([a,l])=>{const s=`${e}${a}`,u=i.defineComponent({name:s,setup(m,{slots:C,attrs:y,...M}){const{scene:T}=F(),v=i.inject("local-scene")||T,x=i.inject("catalogue"),{pushCamera:R}=A();let S=f(l,y,C);return r(y,S),(S instanceof g.PerspectiveCamera||S instanceof g.OrthographicCamera)&&R(S),S.isObject3D&&(v==null||v.value.add(S)),M.expose(S),t(s,{sceneuuid:v==null?void 0:v.value.uuid,catalogue:x==null?void 0:x.value.uuid,props:m,slots:C.default?C.default():void 0,attrs:y,ctx:M,scene:v}),()=>{}}});return[s,u]})}return{createComponentInstances:p,processProps:r,createInstanceFromVNode:c}}const K=h.createEventHook(),Q=h.createEventHook(),X=h.createEventHook(),Y=new g.Clock,{pause:ce,resume:ue,isActive:le}=h.useRafFn(()=>{const e=Y.getElapsedTime(),t=Y.getDelta();K.trigger({delta:t,elapsed:e}),Q.trigger({delta:t,elapsed:e}),X.trigger({delta:t,elapsed:e})},{immediate:!1});function z(){return{onBeforeLoop:K.on,onLoop:Q.on,onAfterLoop:X.on,pause:ce,resume:ue,isActive:le}}const fe=i.shallowRef(new g.Scene);function F(){return{scene:fe}}function Z(e){const t={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(t.nodes[n.name]=n),n.material&&!t.materials[n.material.name]&&(t.materials[n.material.name]=n.material)}),t}async function pe(e,t,n,r,c){const{logError:f}=_(),p=new e;c&&c(p),n&&n(e);const a=(Array.isArray(t)?t:[t]).map(l=>new Promise((s,u)=>{p.load(l,m=>{m.scene&&Object.assign(m,Z(m.scene)),s(m)},r,m=>u(f("[useLoader] - Failed to load resource",m)))}));return j(t)?await Promise.all(a):await a[0]}async function de(e){const t=new g.LoadingManager,n=new g.TextureLoader(t),r=c=>new Promise((f,p)=>{n.load(c,o=>f(o),()=>null,()=>{p(new Error("[useTextures] - Failed to load texture"))})});if(j(e)){const c=await Promise.all(e.map(f=>r(f)));return e.length>1?c:c[0]}else{const{map:c,displacementMap:f,normalMap:p,roughnessMap:o,metalnessMap:a,aoMap:l}=e;return{map:c?await r(c):null,displacementMap:f?await r(f):null,normalMap:p?await r(p):null,roughnessMap:o?await r(o):null,metalnessMap:a?await r(a):null,aoMap:l?await r(l):null}}}const U=i.reactive({});function D(){function e(n){return U[n]}function t(n,r){U[n]=r}return{state:U,...i.toRefs(U),getState:e,setState:t}}const w=i.shallowRef(),k=i.ref(!1);function E(e,t,n){const{alpha:r=!1,antialias:c,depth:f,logarithmicDepthBuffer:p,failIfMajorPerformanceCaveat:o,precision:a,premultipliedAlpha:l,stencil:s,shadows:u=!1,shadowMapType:m=g.PCFShadowMap,physicallyCorrectLights:C=!1,outputEncoding:y=g.LinearEncoding,toneMapping:M=g.NoToneMapping,toneMappingExposure:T=1,context:v=void 0,powerPreference:x="default",preserveDrawingBuffer:R=!1,clearColor:S=J("#000000"),windowSize:ye=!1}=n,{width:V,height:N}=ye?h.useWindowSize():h.useElementSize(t),{pixelRatio:H}=h.useDevicePixelRatio(),{pause:Se,resume:ve}=z(),Me=i.computed(()=>V.value/N.value),ee=()=>{!w.value||(w.value.setSize(V.value,N.value),w.value.setPixelRatio(Math.min(H.value,2)))},te=()=>{!w.value||(w.value.shadowMap.enabled=h.resolveUnref(u),w.value.outputEncoding=h.resolveUnref(y),w.value.shadowMap.type=h.resolveUnref(m),w.value.physicallyCorrectLights=h.resolveUnref(C),w.value.toneMapping=h.resolveUnref(M),w.value.toneMappingExposure=h.resolveUnref(T),w.value.setClearColor(J(h.resolveUnref(S))))},Pe=()=>{const ne=h.unrefElement(e);if(w.value||!ne)return;w.value=new g.WebGLRenderer({canvas:ne,alpha:r,antialias:c,context:v,depth:f,failIfMajorPerformanceCaveat:o,logarithmicDepthBuffer:p,powerPreference:x,precision:a,stencil:s,preserveDrawingBuffer:R,premultipliedAlpha:l});const{setState:be}=D();be("renderer",w.value),te(),ee(),ve(),k.value=!0},Oe=()=>{!w.value||(w.value.dispose(),w.value=void 0,k.value=!1,Se())};return i.watch([V,N,H],ee),i.watch(()=>[u,m,y,C,M,T,S],te),i.watch(()=>[e,t],()=>{h.unrefElement(e)&&h.unrefElement(t)&&Pe()},{immediate:!0,deep:!0}),{renderer:w,isReady:k,dispose:Oe,aspectRatio:Me}}const me=i.defineComponent({name:"TresCanvas",props:{shadows:Boolean,shadowMapType:Object,physicallyCorrectLights:Boolean,outputEncoding:Object,toneMapping:Object,toneMappingExposure:Number,context:Object,powerPreference:Object,preserveDrawingBuffer:Boolean,clearColor:String,windowSize:Boolean},setup(e,{slots:t,attrs:n}){const{logError:r}=_(),c=i.ref(),f=i.ref(),{renderer:p,dispose:o,aspectRatio:a}=E(c,f,e),l=i.shallowRef();return i.provide("camera",l),i.provide("renderer",p),i.provide("aspect-ratio",a),t.default&&!t.default().some(s=>s.type.name==="Scene")&&r("TresCanvas must contain a Scene component."),t.default&&!t.default().some(s=>{var u;return(u=s.type.name)==null?void 0:u.includes("Camera")})&&r("Scene must contain a Camera component."),i.onBeforeUnmount(()=>o()),()=>{if(t.default)return i.h("div",{ref:f,style:{position:"relative",width:"100%",height:"100vh",...n.style}},[i.h("canvas",{ref:c,style:{width:"100%",height:"100%",position:"absolute",top:0,left:0}}),t.default()])}}}),ge=i.defineComponent({name:"Scene",setup(e,{slots:t}){const{scene:n}=F(),r=i.inject("renderer"),{activeCamera:c}=A(),{onLoop:f}=z();return i.provide("local-scene",n),f(()=>{(r==null?void 0:r.value)&&(c==null?void 0:c.value)&&(n==null?void 0:n.value)&&r.value.render(n==null?void 0:n.value,c.value)}),()=>{if(t.default)return t.default()}}}),he=Symbol("UseTresState"),we="1.2.0",Ce={install(e,t){const n=(t==null?void 0:t.prefix)||"Tres";e.component(`${n}Canvas`,me),e.component(`${n}Scene`,ge);const{catalogue:r,extend:c}=I(e,n);e.provide("catalogue",r),e.provide("extend",c);const{createComponentInstances:f}=B(n);f(r).forEach(([o,a])=>{e.component(o,a)}),window.__TRES__={app:e,version:we}}};d.CameraType=q,d.UseTresStateSymbol=he,d.default=Ce,d.trasverseObjects=Z,d.useCamera=A,d.useCatalogue=I,d.useInstanceCreator=B,d.useLoader=pe,d.useRenderLoop=z,d.useRenderer=E,d.useScene=F,d.useTexture=de,d.useTres=D,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,3 +11,14 @@ export type TresVNodeType = VNodeTypes & {
|
|
|
11
11
|
}
|
|
12
12
|
export type TresVNode = VNode & { children?: Array<VNode>; type: TresVNodeType }
|
|
13
13
|
export type TresAttributes = Record<string, any> & { args?: number[] }
|
|
14
|
+
|
|
15
|
+
declare global {
|
|
16
|
+
// Define the window interface, with type annotations for the properties and methods of the window object
|
|
17
|
+
interface Window {
|
|
18
|
+
// Define the location property, with a type of Location
|
|
19
|
+
__TRES__: {
|
|
20
|
+
app: App
|
|
21
|
+
version: string
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
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": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@alvarosabu/utils": "^2.2.0",
|
|
41
41
|
"@histoire/plugin-vue": "0.11.7",
|
|
42
|
-
"@tresjs/cientos": "^1.
|
|
42
|
+
"@tresjs/cientos": "^1.1.0",
|
|
43
43
|
"@types/three": "^0.146.0",
|
|
44
44
|
"@vitejs/plugin-vue": "^3.2.0",
|
|
45
45
|
"@vitest/coverage-c8": "^0.25.1",
|
package/dist/favicon-16x16.png
DELETED
|
Binary file
|
package/dist/favicon-32x32.png
DELETED
|
Binary file
|
package/dist/favicon-dark.svg
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<rect width="32" height="32" fill="white"/>
|
|
3
|
-
<path d="M11.6854 4.42916C12.0738 3.78182 13.012 3.78182 13.4004 4.42915L19.1771 14.0569C19.577 14.7235 19.0969 15.5714 18.3196 15.5714H6.76624C5.98894 15.5714 5.50883 14.7235 5.90875 14.0569L11.6854 4.42916Z" fill="#82DBC5"/>
|
|
4
|
-
<path d="M15.6857 11.5429C15.6857 10.9906 16.1334 10.5429 16.6857 10.5429H26C26.5522 10.5429 27 10.9906 27 11.5429V20.8572C27 21.4094 26.5522 21.8572 26 21.8572H16.6857C16.1334 21.8572 15.6857 21.4094 15.6857 20.8572V11.5429Z" fill="#4F4F4F"/>
|
|
5
|
-
<circle cx="16" cy="23" r="6" fill="#EFAC35"/>
|
|
6
|
-
</svg>
|
package/dist/favicon.ico
DELETED
|
Binary file
|
package/dist/favicon.svg
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<path d="M11.6854 3.42916C12.0738 2.78182 13.012 2.78182 13.4004 3.42915L19.1771 13.0569C19.577 13.7235 19.0969 14.5714 18.3196 14.5714H6.76624C5.98894 14.5714 5.50883 13.7235 5.90875 13.0569L11.6854 3.42916Z" fill="#82DBC5"/>
|
|
3
|
-
<path d="M15.6857 10.5429C15.6857 9.99059 16.1334 9.54288 16.6857 9.54288H26C26.5522 9.54288 27 9.99059 27 10.5429V19.8572C27 20.4094 26.5522 20.8572 26 20.8572H16.6857C16.1334 20.8572 15.6857 20.4094 15.6857 19.8572V10.5429Z" fill="#4F4F4F"/>
|
|
4
|
-
<circle cx="16" cy="22" r="6" fill="#EFAC35"/>
|
|
5
|
-
</svg>
|
package/dist/logo-dark.svg
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<svg width="44" height="10" viewBox="0 0 44 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<path d="M5.14255 1.42916C5.53095 0.781817 6.46913 0.781816 6.85753 1.42915L11.0913 8.4855C11.4913 9.15203 11.0111 10 10.2338 10H1.76623C0.988935 10 0.508822 9.15203 0.908736 8.4855L5.14255 1.42916Z" fill="#82DBC5"/>
|
|
3
|
-
<rect x="19" y="1" width="9" height="9" rx="1" fill="#f2f2f2"/>
|
|
4
|
-
<circle cx="39.5" cy="5.5" r="4.5" fill="#EFAC35"/>
|
|
5
|
-
</svg>
|
package/dist/logo.svg
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<svg width="44" height="10" viewBox="0 0 44 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<path d="M5.14255 1.42916C5.53095 0.781817 6.46913 0.781816 6.85753 1.42915L11.0913 8.4855C11.4913 9.15203 11.0111 10 10.2338 10H1.76623C0.988935 10 0.508822 9.15203 0.908736 8.4855L5.14255 1.42916Z" fill="#82DBC5"/>
|
|
3
|
-
<rect x="19" y="1" width="9" height="9" rx="1" fill="#4F4F4F"/>
|
|
4
|
-
<circle cx="39.5" cy="5.5" r="4.5" fill="#EFAC35"/>
|
|
5
|
-
</svg>
|