@tresjs/post-processing 0.3.0 → 0.5.0
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/README.md +5 -12
- package/dist/core/EffectComposer.vue.d.ts +51 -97
- package/dist/core/composables/effect.d.ts +6 -0
- package/dist/core/effects/Bloom.vue.d.ts +37 -100
- package/dist/core/effects/DepthOfField.vue.d.ts +45 -0
- package/dist/core/effects/Glitch.vue.d.ts +18 -96
- package/dist/core/effects/Outline.vue.d.ts +32 -125
- package/dist/core/effects/Pixelation.vue.d.ts +21 -0
- package/dist/core/injectionKeys.d.ts +2 -2
- package/dist/index.d.ts +4 -2
- package/dist/tres-postprocessing.js +260 -341
- package/dist/tres-postprocessing.umd.cjs +2 -2
- package/dist/util/object.d.ts +55 -0
- package/dist/util/prop.d.ts +40 -0
- package/package.json +23 -23
- package/dist/core/useCore.d.ts +0 -11
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/post-processing
|
|
3
|
-
* version: v0.
|
|
3
|
+
* version: v0.5.0
|
|
4
4
|
* (c) 2023
|
|
5
5
|
* description: Post-processing library for TresJS
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
(function(
|
|
8
|
+
(function(c,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("postprocessing"),require("@tresjs/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","postprocessing","@tresjs/core","three"],i):(c=typeof globalThis<"u"?globalThis:c||self,i(c["tres-postprocessing"]={},c.Vue,c.Postprocessing,c.TresjsCore,c.Three))})(this,function(c,i,u,m,E){"use strict";const b=Symbol(),v=a=>{const t=i.inject(b),e=i.shallowRef(null),n=i.shallowRef(null),{scene:l,camera:o}=m.useTresContext();i.watchEffect(()=>{!o.value||!(n!=null&&n.value)||(n.value.mainCamera=o.value)});let r=()=>{};return r=i.watchEffect(()=>{!o.value||!(t!=null&&t.value)||!l.value||(r(),!n.value&&(n.value=a(),e.value=new u.EffectPass(o.value,n.value),t.value.addPass(e.value)))}),i.onUnmounted(()=>{var s,f,h;e.value&&((s=t==null?void 0:t.value)==null||s.removePass(e.value)),(f=n.value)==null||f.dispose(),(h=e.value)==null||h.dispose()}),{pass:e,effect:n}},_=/([^[.\]])+/g,F=(a,t)=>{if(!t)return;const e=Array.isArray(t)?t:t.match(_);return e==null?void 0:e.reduce((n,l)=>n&&n[l],a)},B=(a,t,e)=>{const n=Array.isArray(t)?t:t.match(_);n&&n.reduce((l,o,r)=>(l[o]===void 0&&(l[o]={}),r===n.length-1&&(l[o]=e),l[o]),a)},O=(a,t)=>{const e={...a};return t.forEach(n=>delete e[n]),e},y=(a,t,e,n,l={})=>i.watch(a,o=>{var r;if(t.value)if(o===void 0){const s=n();B(t.value,e,F(s,e)),(r=s.dispose)==null||r.call(s)}else B(t.value,e,a())},l),S=(a,t,e)=>a.map(([n,l])=>y(n,t,l,e)),x=(a,t,e)=>Object.keys(a).map(n=>y(()=>a[n],t,n,e)),R=i.defineComponent({__name:"Bloom",props:{blendFunction:{},intensity:{},kernelSize:{},luminanceThreshold:{},luminanceSmoothing:{},mipmapBlur:{type:Boolean,default:void 0}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.BloomEffect(e));return t({pass:n,effect:l}),S([[()=>e.intensity,"intensity"],[()=>e.kernelSize,"kernelSize"],[()=>e.luminanceSmoothing,"luminanceMaterial.smoothing"],[()=>e.luminanceThreshold,"luminanceMaterial.threshold"]],l,()=>new u.BloomEffect),(o,r)=>null}}),z=i.defineComponent({__name:"Glitch",props:{blendFunction:{},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{},columns:{},chromaticAberrationOffset:{},perturbationMap:{},dtSize:{}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.GlitchEffect(e));return t({pass:n,effect:l}),i.watchEffect(()=>{const o=()=>{if(e.mode!==void 0)return e.active===!1?u.GlitchMode.DISABLED:e.mode;const r=new u.GlitchEffect,s=r.mode;return r.dispose(),s};l.value&&(l.value.mode=o())}),x(O(e,["active","mode","blendFunction"]),l,()=>new u.GlitchEffect),(o,r)=>null}}),D=i.defineComponent({__name:"Outline",props:{outlinedObjects:{},blur:{type:Boolean,default:void 0},xRay:{type:Boolean,default:void 0},kernelSize:{},pulseSpeed:{},resolutionX:{},resolutionY:{},edgeStrength:{},patternScale:{},multisampling:{},blendFunction:{},patternTexture:{},resolutionScale:{},hiddenEdgeColor:{},visibleEdgeColor:{}},setup(a,{expose:t}){const e=a,n=p=>p!==void 0?m.normalizeColor(p).getHex():void 0,{camera:l,scene:o}=m.useTresContext(),r={blur:e.blur,xRay:e.xRay,kernelSize:e.kernelSize,pulseSpeed:e.pulseSpeed,resolutionX:e.resolutionX,resolutionY:e.resolutionY,patternScale:e.patternScale,edgeStrength:e.edgeStrength,blendFunction:e.blendFunction,multisampling:e.multisampling,patternTexture:e.patternTexture,resolutionScale:e.resolutionScale,hiddenEdgeColor:n(e.hiddenEdgeColor),visibleEdgeColor:n(e.visibleEdgeColor)},{pass:s,effect:f}=v(()=>new u.OutlineEffect(o.value,l.value,r));t({pass:s,effect:f}),i.watch([()=>e.outlinedObjects,f],()=>{var p;(p=f.value)==null||p.selection.set(e.outlinedObjects||[])},{immediate:!0});const h=i.computed(()=>({hiddenEdgeColor:e.hiddenEdgeColor?m.normalizeColor(e.hiddenEdgeColor):void 0,visibleEdgeColor:e.visibleEdgeColor?m.normalizeColor(e.visibleEdgeColor):void 0}));return S([[()=>e.blur,"blur"],[()=>e.xRay,"xRay"],[()=>e.pulseSpeed,"pulseSpeed"],[()=>e.kernelSize,"kernelSize"],[()=>e.edgeStrength,"edgeStrength"],[()=>e.patternScale,"patternScale"],[()=>e.multisampling,"multisampling"],[()=>h.value.hiddenEdgeColor,"hiddenEdgeColor"],[()=>h.value.visibleEdgeColor,"visibleEdgeColor"]],f,()=>new u.OutlineEffect),(p,T)=>null}}),k=i.defineComponent({__name:"Pixelation",props:{granularity:{}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.PixelationEffect(e.granularity));return t({pass:n,effect:l}),x(e,l,()=>new u.PixelationEffect),(o,r)=>null}}),M=i.defineComponent({__name:"DepthOfField",props:{blendFunction:{},worldFocusDistance:{},worldFocusRange:{},focusDistance:{},focusRange:{},bokehScale:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(a,{expose:t}){const e=a,{camera:n}=m.useTresContext(),{pass:l,effect:o}=v(()=>new u.DepthOfFieldEffect(n.value,e));return t({pass:l,effect:o}),S([[()=>e.worldFocusDistance,"circleOfConfusionMaterial.worldFocusDistance"],[()=>e.focusDistance,"circleOfConfusionMaterial.focusDistance"],[()=>e.worldFocusRange,"circleOfConfusionMaterial.worldFocusRange"],[()=>e.focusRange,"circleOfConfusionMaterial.focusRange"],[()=>e.bokehScale,"bokehScale"],[()=>e.resolutionScale,"blurPass.resolution.scale"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"]],o,()=>new u.DepthOfFieldEffect),(r,s)=>null}});let C;function P(){var a;if(C!==void 0)return C;try{let t;const e=document.createElement("canvas");return C=!!(window.WebGL2RenderingContext&&(t=e.getContext("webgl2"))),t&&((a=t.getExtension("WEBGL_lose_context"))==null||a.loseContext()),C}catch{return C=!1}}const j=i.defineComponent({__name:"EffectComposer",props:{enabled:{type:Boolean,default:!0},children:{},depthBuffer:{type:Boolean,default:void 0},disableNormalPass:{type:Boolean,default:!1},stencilBuffer:{type:Boolean,default:void 0},resolutionScale:{},autoClear:{type:Boolean,default:!0},multisampling:{default:0},frameBufferType:{default:E.HalfFloatType}},setup(a){const t=a,{scene:e,camera:n,renderer:l,sizes:o}=m.useTresContext(),r=i.shallowRef(null);let s=null,f=null;i.provide(b,r);const h=()=>{r.value&&(f=new u.NormalPass(e.value,n.value),f.enabled=!1,r.value.addPass(f),t.resolutionScale!==void 0&&P()&&(s=new u.DepthDownsamplingPass({normalBuffer:f.texture,resolutionScale:t.resolutionScale}),s.enabled=!1,r.value.addPass(s)))};i.watchEffect(()=>{r.value&&o.width.value&&o.height.value&&r.value.setSize(o.width.value,o.height.value)});const p=i.computed(()=>{const d=new u.EffectComposer,w={depthBuffer:t.depthBuffer!==void 0?t.depthBuffer:d.inputBuffer.depthBuffer,stencilBuffer:t.stencilBuffer!==void 0?t.stencilBuffer:d.inputBuffer.stencilBuffer,multisampling:P()?0:t.multisampling!==void 0?t.multisampling:d.multisampling,frameBufferType:t.frameBufferType!==void 0?t.frameBufferType:E.HalfFloatType};return d.dispose(),w}),T=()=>{!l.value&&!e.value&&!n.value||(r.value=new u.EffectComposer(l.value,p.value),r.value.addPass(new u.RenderPass(e.value,n.value)),t.disableNormalPass||h())};let g=()=>{};g=i.watch([o.height,o.width],()=>{!o.height.value&&!o.width.value||(i.watchEffect(T),g==null||g())},{immediate:!0});const{onLoop:A}=m.useRenderLoop();return A(({delta:d})=>{if(t.enabled&&l.value&&r.value&&o.width.value&&o.height.value){const w=l.value.autoClear;l.value.autoClear=t.autoClear,t.stencilBuffer&&!t.autoClear&&l.value.clearStencil(),r.value.render(d),l.value.autoClear=w}}),i.onUnmounted(()=>{var d;(d=r.value)==null||d.dispose()}),(d,w)=>i.renderSlot(d.$slots,"default")}});c.Bloom=R,c.DepthOfField=M,c.EffectComposer=j,c.Glitch=z,c.Outline=D,c.Pixelation=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the value at a given path within a provided object.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of value to be returned
|
|
5
|
+
*
|
|
6
|
+
* @param {any} obj - The object to extract value from
|
|
7
|
+
* @param {string | string[]} path - A path or an array of path where the value should be get from
|
|
8
|
+
*
|
|
9
|
+
* @returns {T | undefined} - The value at the given path in the object, or undefined if path is not found
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* const obj = { a: { b: { c: 1 } } }
|
|
14
|
+
*
|
|
15
|
+
* const result = get(obj, 'a.b.c')
|
|
16
|
+
*
|
|
17
|
+
* console.log(result) // 1
|
|
18
|
+
*/
|
|
19
|
+
export declare const get: <T>(obj: any, path: string | string[]) => T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Sets a value at a given path within a provided object. If the path does not exist, nested objects will be created.
|
|
22
|
+
*
|
|
23
|
+
* @param {any} obj - The original object to set value in
|
|
24
|
+
* @param {string | string[]} path - A path or an array of path where the value should be set
|
|
25
|
+
* @param {any} value - The value to be set at the provided path
|
|
26
|
+
*
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const obj = { a: { b: { c: 1 } } }
|
|
31
|
+
*
|
|
32
|
+
* set(obj, 'a.b.c', 2)
|
|
33
|
+
*
|
|
34
|
+
* console.log(obj) // { a: { b: { c: 2 } } }
|
|
35
|
+
*/
|
|
36
|
+
export declare const set: (obj: any, path: string | string[], value: any) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Omits given properties from a provided object.
|
|
39
|
+
*
|
|
40
|
+
* @template T - An object with string keys and any type of values
|
|
41
|
+
*
|
|
42
|
+
* @param {T} obj - The original object to omit properties from
|
|
43
|
+
* @param {(keyof T)[]} properties - An array of property key names to omit from the base object
|
|
44
|
+
*
|
|
45
|
+
* @returns {Partial<T>} The new object with omitted properties
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const obj = { a: 1, b: 2, c: 3 }
|
|
49
|
+
* const propsToOmit = ['b', 'c']
|
|
50
|
+
*
|
|
51
|
+
* const newObj = omit(obj, propsToOmit)
|
|
52
|
+
*
|
|
53
|
+
* console.log(newObj) // { a: 1 }
|
|
54
|
+
*/
|
|
55
|
+
export declare const omit: <T extends Record<string, any>>(obj: T, properties: (keyof T)[]) => Partial<T>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Ref, WatchOptions } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a prop watcher function that monitors changes to a property and updates a target object.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the property being watched.
|
|
6
|
+
* @template E - The type of the target object.
|
|
7
|
+
* @param {() => T} propGetter - A function that retrieves the prop value to be watched.
|
|
8
|
+
* @param {Ref<E>} target - A Ref representing the target object to be updated.
|
|
9
|
+
* @param {string} propertyPath - The dot-separated path to the property within the target object.
|
|
10
|
+
* @param {() => E & { dispose?(): void }} newPlainObjectFunction - A function that creates a new plain object to retrieve the defaults from with an optional "dispose" method for cleanup.
|
|
11
|
+
* @param {WatchOptions} watchOptions - The options for watch.
|
|
12
|
+
*/
|
|
13
|
+
export declare const makePropWatcher: <T, E>(propGetter: () => T, target: Ref<E>, propertyPath: string, newPlainObjectFunction: () => E & {
|
|
14
|
+
dispose?(): void;
|
|
15
|
+
}, watchOptions?: WatchOptions) => import("vue").WatchStopHandle;
|
|
16
|
+
/**
|
|
17
|
+
* Creates multiple prop watchers for monitoring changes to multiple properties and updating a target object.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the property being watched.
|
|
20
|
+
* @template E - The type of the target object.
|
|
21
|
+
* @param {(string | (() => T))[][]} propGettersAndPropertyPaths - An array of arrays containing pairs of prop getters and their corresponding property paths within the target object.
|
|
22
|
+
* @param {Ref<E>} target - A Ref representing the target object to be updated.
|
|
23
|
+
* @param {() => E & { dispose?(): void }} newPlainObjectFunction - A function that creates a new plain object to retrieve the defaults from with an optional "dispose" method for cleanup.
|
|
24
|
+
*/
|
|
25
|
+
export declare const makePropWatchers: <E>(propGettersAndPropertyPaths: (string | (() => any))[][], target: Ref<E>, newPlainObjectFunction: () => E & {
|
|
26
|
+
dispose?(): void;
|
|
27
|
+
}) => import("vue").WatchStopHandle[];
|
|
28
|
+
/**
|
|
29
|
+
* Creates multiple prop watchers via the props object for monitoring changes to multiple properties and updating a target object.
|
|
30
|
+
* Use this method in case the prop names match the names of the properties you want to set on your target object.
|
|
31
|
+
*
|
|
32
|
+
* @param props - The props object. Usually created via defineProps.
|
|
33
|
+
* @param {Ref<E>} target - A Ref representing the target object to be updated.
|
|
34
|
+
* @param {() => E & { dispose?(): void }} newPlainObjectFunction - A function that creates a new plain object to retrieve the defaults from with an optional "dispose" method for cleanup.
|
|
35
|
+
*/
|
|
36
|
+
export declare const makePropWatchersUsingAllProps: <E>(props: {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}, target: Ref<E>, newPlainObjectFunction: () => E & {
|
|
39
|
+
dispose?(): void;
|
|
40
|
+
}) => import("vue").WatchStopHandle[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tresjs/post-processing",
|
|
3
3
|
"description": "Post-processing library for TresJS",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -37,43 +37,43 @@
|
|
|
37
37
|
"preview": "vite preview",
|
|
38
38
|
"release": "release-it",
|
|
39
39
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue",
|
|
40
|
+
"lint:fix": "pnpm run lint --fix",
|
|
40
41
|
"docs:dev": "vitepress dev docs",
|
|
41
42
|
"docs:build": "vitepress build docs",
|
|
42
43
|
"docs:preview": "vitepress preview docs"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
|
-
"@tresjs/core": ">=2.3.0",
|
|
46
46
|
"three": ">=0.133",
|
|
47
47
|
"vue": ">=3.3"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"
|
|
50
|
+
"@tresjs/core": "^3.4.1",
|
|
51
|
+
"@unocss/core": "^0.57.1",
|
|
52
|
+
"@vueuse/core": "^10.5.0",
|
|
53
|
+
"postprocessing": "^6.33.2",
|
|
54
|
+
"three-stdlib": "^2.28.3"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"
|
|
60
|
-
"@vitejs/plugin-vue": "^4.2.3",
|
|
61
|
-
"gsap": "^3.12.1",
|
|
57
|
+
"@release-it/conventional-changelog": "^7.0.2",
|
|
58
|
+
"@tresjs/eslint-config-vue": "^0.2.1",
|
|
59
|
+
"@types/three": "^0.157.2",
|
|
60
|
+
"@vitejs/plugin-vue": "^4.4.0",
|
|
61
|
+
"gsap": "^3.12.2",
|
|
62
62
|
"kolorist": "^1.8.0",
|
|
63
63
|
"pathe": "^1.1.1",
|
|
64
|
-
"prettier": "^
|
|
65
|
-
"release-it": "^
|
|
64
|
+
"prettier": "^3.0.3",
|
|
65
|
+
"release-it": "^16.2.1",
|
|
66
66
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
67
67
|
"rollup-plugin-visualizer": "^5.9.2",
|
|
68
|
-
"three": "^0.
|
|
69
|
-
"typescript": "^5.
|
|
70
|
-
"unocss": "^0.
|
|
71
|
-
"vite": "^4.
|
|
72
|
-
"vite-plugin-banner": "^0.7.
|
|
73
|
-
"vite-plugin-dts": "
|
|
68
|
+
"three": "^0.158.0",
|
|
69
|
+
"typescript": "^5.2.2",
|
|
70
|
+
"unocss": "^0.57.1",
|
|
71
|
+
"vite": "^4.5.0",
|
|
72
|
+
"vite-plugin-banner": "^0.7.1",
|
|
73
|
+
"vite-plugin-dts": "3.6.2",
|
|
74
74
|
"vite-svg-loader": "^4.0.0",
|
|
75
|
-
"vitepress": "1.0.0-
|
|
76
|
-
"vue": "^3.3.
|
|
77
|
-
"vue-tsc": "^1.8.
|
|
75
|
+
"vitepress": "1.0.0-rc.24",
|
|
76
|
+
"vue": "^3.3.7",
|
|
77
|
+
"vue-tsc": "^1.8.22"
|
|
78
78
|
}
|
|
79
79
|
}
|
package/dist/core/useCore.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Allows to use and extend the state of the core package.
|
|
3
|
-
*
|
|
4
|
-
* @export
|
|
5
|
-
* @return {*}
|
|
6
|
-
*/
|
|
7
|
-
export declare function useCore(): {
|
|
8
|
-
state: import("@tresjs/core").TresState;
|
|
9
|
-
setState: (key: string, value: any) => void;
|
|
10
|
-
extend: (objects: any) => void;
|
|
11
|
-
};
|