@ev-ry/fx 0.1.0-rc.2 → 0.1.0-rc.3
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/QUICKSTART.fa.md +99 -87
- package/README.md +6 -2
- package/build-report.json +36 -31
- package/docs/GUIDE.md +8 -2
- package/docs/RELEASE-NOTES.md +23 -0
- package/examples/evry-website.md +58 -0
- package/package.json +1 -1
- package/src/dom-attachment.d.ts +1 -1
- package/src/dom-free.d.ts +14 -14
- package/src/dom-free.js +61 -38
- package/src/dom-image-surface.js +150 -103
- package/src/dom-image-swap.js +5 -2
- package/src/dom-once.js +39 -34
- package/src/dom-reveal.js +83 -73
- package/src/dom-svg-surface.js +41 -39
- package/src/dom-text-paint-mask.js +24 -0
- package/src/dom-text-surface.js +63 -32
- package/src/image-surface.js +161 -157
- package/src/render-owner.js +17 -12
- package/src/text-motion-primitives.js +7 -0
- package/src/triangle-effect.js +2 -1
- package/src/viewport-render-owner.js +322 -316
package/src/image-surface.js
CHANGED
|
@@ -1,160 +1,164 @@
|
|
|
1
|
-
import {imageMotionPixels} from './motion-envelope.js';
|
|
2
|
-
import {loadImageRaster} from './image-source.js';
|
|
3
|
-
import {rasterToTextureMesh} from './raster-texture-mesh.js';
|
|
4
|
-
import {attachRasterTexture,applyRasterSamplingShader} from './raster-texture-material.js';
|
|
5
|
-
import {textDivisionsForSize,createProjectedTextSize} from './text-mesh-density.js';
|
|
6
|
-
import {TriangleEffect} from './triangle-effect.js';
|
|
7
|
-
import {normalizeTextEffectOptions} from './text-effect-options.js';
|
|
8
|
-
import {textEditMotions} from './text-edit-motions.js';
|
|
9
|
-
|
|
10
|
-
export const IMAGE_EFFECT_MODES=Object.freeze(Object.keys(textEditMotions));
|
|
11
|
-
// Images share motion recipes with text, but preserve source color by default.
|
|
12
|
-
export function normalizeImageEffectOptions(settings={},mode='dust-wind'){
|
|
13
|
-
const normalized=normalizeTextEffectOptions({formation:-1,...settings},mode);
|
|
14
|
-
return Object.freeze({...normalized,recipe:Object.freeze({...normalized.recipe,glow:settings.recipe?.glow??0})});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Images use twice the text-derived rows: half-size cells, with a bounded grid.
|
|
18
|
-
export function imageDivisions(width,height,displayHeight,current=null,maxTriangles=80000){
|
|
19
|
-
let rows=2*textDivisionsForSize(displayHeight,current===null?null:current/2);
|
|
20
|
-
while(rows>1&&2*rows*Math.max(1,Math.round(width*rows/height))>maxTriangles)rows--;
|
|
21
|
-
if(2*rows*Math.max(1,Math.round(width*rows/height))>maxTriangles)throw Error('Image aspect ratio exceeds the triangle budget');
|
|
22
|
-
return rows;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const vertexShader=`
|
|
26
|
-
attribute vec2 rasterUV;
|
|
27
|
-
attribute vec2 glyphOffset;
|
|
28
|
-
varying vec2 vRasterUV;
|
|
29
|
-
void main(){
|
|
30
|
-
vRasterUV=rasterUV;
|
|
31
|
-
vec3 p=position+vec3(glyphOffset,0.0);
|
|
32
|
-
/* THD_TRIANGLE_MOTION */
|
|
33
|
-
gl_Position=projectionMatrix*modelViewMatrix*vec4(p,1.0);
|
|
34
|
-
}`;
|
|
35
|
-
const fragmentShader=`
|
|
36
|
-
uniform
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
validMode(
|
|
52
|
-
const {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
let
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
asset.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
material.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
motion.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
1
|
+
import {imageMotionPixels} from './motion-envelope.js';
|
|
2
|
+
import {loadImageRaster} from './image-source.js';
|
|
3
|
+
import {rasterToTextureMesh} from './raster-texture-mesh.js';
|
|
4
|
+
import {attachRasterTexture,applyRasterSamplingShader} from './raster-texture-material.js';
|
|
5
|
+
import {textDivisionsForSize,createProjectedTextSize} from './text-mesh-density.js';
|
|
6
|
+
import {TriangleEffect} from './triangle-effect.js';
|
|
7
|
+
import {normalizeTextEffectOptions} from './text-effect-options.js';
|
|
8
|
+
import {textEditMotions} from './text-edit-motions.js';
|
|
9
|
+
|
|
10
|
+
export const IMAGE_EFFECT_MODES=Object.freeze(Object.keys(textEditMotions));
|
|
11
|
+
// Images share motion recipes with text, but preserve source color by default.
|
|
12
|
+
export function normalizeImageEffectOptions(settings={},mode='dust-wind'){
|
|
13
|
+
const normalized=normalizeTextEffectOptions({formation:-1,...settings},mode);
|
|
14
|
+
return Object.freeze({...normalized,recipe:Object.freeze({...normalized.recipe,glow:settings.recipe?.glow??0})});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Images use twice the text-derived rows: half-size cells, with a bounded grid.
|
|
18
|
+
export function imageDivisions(width,height,displayHeight,current=null,maxTriangles=80000){
|
|
19
|
+
let rows=2*textDivisionsForSize(displayHeight,current===null?null:current/2);
|
|
20
|
+
while(rows>1&&2*rows*Math.max(1,Math.round(width*rows/height))>maxTriangles)rows--;
|
|
21
|
+
if(2*rows*Math.max(1,Math.round(width*rows/height))>maxTriangles)throw Error('Image aspect ratio exceeds the triangle budget');
|
|
22
|
+
return rows;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const vertexShader=`
|
|
26
|
+
attribute vec2 rasterUV;
|
|
27
|
+
attribute vec2 glyphOffset;
|
|
28
|
+
varying vec2 vRasterUV;
|
|
29
|
+
void main(){
|
|
30
|
+
vRasterUV=rasterUV;
|
|
31
|
+
vec3 p=position+vec3(glyphOffset,0.0);
|
|
32
|
+
/* THD_TRIANGLE_MOTION */
|
|
33
|
+
gl_Position=projectionMatrix*modelViewMatrix*vec4(p,1.0);
|
|
34
|
+
}`;
|
|
35
|
+
const fragmentShader=`
|
|
36
|
+
uniform float presentationOpacity;
|
|
37
|
+
uniform sampler2D rasterMap;
|
|
38
|
+
varying vec2 vRasterUV;
|
|
39
|
+
void main(){
|
|
40
|
+
vec4 rasterSample=texture2D(rasterMap,vRasterUV);
|
|
41
|
+
float coverage=rasterSample.a;
|
|
42
|
+
gl_FragColor=vec4(rasterSample.rgb, coverage);
|
|
43
|
+
#include <colorspace_fragment>
|
|
44
|
+
gl_FragColor.a *= presentationOpacity;
|
|
45
|
+
}`;
|
|
46
|
+
|
|
47
|
+
// One image object in an existing runtime. No renderer, input or font ownership.
|
|
48
|
+
export function createImageSurface(runtime,{source,width=6,height=3.8,effect='dust-wind',settings={},direction='ltr'}={}){
|
|
49
|
+
if(runtime.disposed)throw Error('Spatial runtime disposed');
|
|
50
|
+
if(!Number.isFinite(width)||!Number.isFinite(height)||width<=0||height<=0)throw RangeError('Positive image bounds required');
|
|
51
|
+
const validMode=mode=>{if(!IMAGE_EFFECT_MODES.includes(mode))throw TypeError('Unsupported image effect');};
|
|
52
|
+
const validDirection=value=>{if(!['ltr','rtl'].includes(value))throw TypeError('Invalid direction');};
|
|
53
|
+
validMode(effect);validDirection(direction);
|
|
54
|
+
const {THREE}=runtime,document=runtime.renderer.domElement.ownerDocument,object=new THREE.Group();
|
|
55
|
+
const motion=new TriangleEffect(THREE,{mode:effect,settings:normalizeImageEffectOptions(settings,effect)}),measure=createProjectedTextSize(THREE);
|
|
56
|
+
let requestedSettings=settings,entryMode=effect,entrySettings=motion.settings;
|
|
57
|
+
let disposed=false,asset=null,controller=null,revision=0,loading=false,error=null,state='empty',intent=null;
|
|
58
|
+
let displaySize=null;
|
|
59
|
+
let lastSeed=null,builds=0,loadMs=0,buildMs=0;
|
|
60
|
+
const view={sharedGroups:new Map(),version:0};
|
|
61
|
+
function releaseAsset(){
|
|
62
|
+
motion.cancel();motion.uniforms.dustMaskOnly.value=0;motion.materials.clear();view.sharedGroups.clear();
|
|
63
|
+
if(asset){object.remove(asset.mesh);asset.mesh.geometry.dispose();asset.mesh.material.dispose();asset.releaseTexture();asset=null;}
|
|
64
|
+
}
|
|
65
|
+
function geometry(raster,rows,w,h,filterRadius,aspect){
|
|
66
|
+
const mesh=rasterToTextureMesh(raster.rgba,raster.width,raster.height,rows,{filterRadius,aspect}),positions=new Float32Array(mesh.triangleCount*9);
|
|
67
|
+
for(let i=0;i<mesh.coordinates.length;i+=2){const at=i/2*3;positions[at]=(mesh.coordinates[i]/raster.width-.5)*w;positions[at+1]=(.5-mesh.coordinates[i+1]/raster.height)*h;}
|
|
68
|
+
const result=new THREE.BufferGeometry();result.setAttribute('position',new THREE.BufferAttribute(positions,3));
|
|
69
|
+
result.setAttribute('rasterUV',new THREE.BufferAttribute(mesh.uvs,2));result.computeBoundingBox();
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
function meshSettings(raster,h,current=null){
|
|
73
|
+
const displayHeight=displaySize?.height??measure(object,runtime.camera,runtime.renderer.domElement,h);
|
|
74
|
+
const aspect=displaySize?displaySize.width/displaySize.height:raster.width/raster.height;
|
|
75
|
+
// Mipmap/bilinear filtering sees beyond the original opaque texel. Retain
|
|
76
|
+
// that support too, especially when a wide image is displayed very small.
|
|
77
|
+
const ratio=raster.height/Math.max(1,displayHeight*(runtime.renderer.getPixelRatio?.()||1));
|
|
78
|
+
const filterRadius=displayHeight>0?Math.max(.5,2**Math.ceil(Math.log2(Math.max(1,ratio)))):.5;
|
|
79
|
+
return {rows:imageDivisions(aspect,1,displayHeight,current),filterRadius,aspect};
|
|
80
|
+
}
|
|
81
|
+
function resizeMesh(){
|
|
82
|
+
if(!asset||motion.active)return;
|
|
83
|
+
const next=meshSettings(asset.raster,asset.h,asset.rows);if(next.rows===asset.rows&&next.filterRadius===asset.filterRadius&&next.aspect===asset.aspect)return;
|
|
84
|
+
const start=performance.now(),replacement=geometry(asset.raster,next.rows,asset.w,asset.h,next.filterRadius,next.aspect);
|
|
85
|
+
asset.mesh.geometry.dispose();asset.mesh.geometry=replacement;asset.rows=next.rows;asset.aspect=next.aspect;asset.filterRadius=next.filterRadius;view.version++;builds++;buildMs=performance.now()-start;
|
|
86
|
+
motion.decorate(view);
|
|
87
|
+
}
|
|
88
|
+
async function setSource(value,{preserveMotion=false,bounds=null}={}){
|
|
89
|
+
if(disposed)throw Error('Image surface disposed');
|
|
90
|
+
const token=++revision;controller?.abort();controller=new AbortController();loading=true;error=null;
|
|
91
|
+
try{
|
|
92
|
+
const raster=await loadImageRaster(value,{document,signal:controller.signal,maxSide:Math.min(2048,runtime.renderer.capabilities?.maxTextureSize||2048)});
|
|
93
|
+
if(disposed||token!==revision)return false;
|
|
94
|
+
if(bounds){width=bounds.width;height=bounds.height;}
|
|
95
|
+
const start=performance.now(),factor=Math.min(width/raster.width,height/raster.height),w=raster.width*factor,h=raster.height*factor;
|
|
96
|
+
const {rows,filterRadius,aspect}=meshSettings(raster,h),g=geometry(raster,rows,w,h,filterRadius,aspect);
|
|
97
|
+
const material=new THREE.ShaderMaterial({vertexShader,fragmentShader,side:THREE.DoubleSide,transparent:true,depthWrite:false,toneMapped:false,extensions:{derivatives:true}});
|
|
98
|
+
material.uniforms.presentationOpacity={value:1};
|
|
99
|
+
applyRasterSamplingShader(material);
|
|
100
|
+
material.defaultAttributeValues.glyphOffset=[0,0];
|
|
101
|
+
const releaseTexture=attachRasterTexture(THREE,material,raster),mesh=new THREE.Mesh(g,material);mesh.frustumCulled=false;
|
|
102
|
+
// Replacement of DOM pixels/size must not restart an existing effect or
|
|
103
|
+
// reveal an image that has already completed its exit.
|
|
104
|
+
const previousState=state,job=motion.jobs[0],seed=lastSeed;
|
|
105
|
+
const previousIntent=preserveMotion?(intent??(motion.active&&job?{departing:motion.departing,fromAge:job.fromAge,started:job.started,seed}:null)):null;
|
|
106
|
+
releaseAsset();asset={raster,w,h,rows,filterRadius,aspect,mesh,releaseTexture};object.add(mesh);view.sharedGroups.set('image',{mesh});view.version++;
|
|
107
|
+
view.motionFrame={x:-w/2,y:-h/2,width:w,height:h};
|
|
108
|
+
state=preserveMotion?previousState:'visible';intent=previousIntent;lastSeed=preserveMotion?seed:null;mesh.visible=state!=='hidden';builds++;loadMs=raster.decodeMs;buildMs=performance.now()-start;runtime.requestRender();return true;
|
|
109
|
+
}catch(e){if(disposed||token!==revision||e.name==='AbortError')return false;error=e.message;throw e;}
|
|
110
|
+
finally{if(token===revision){loading=false;runtime.requestRender();}}
|
|
111
|
+
}
|
|
112
|
+
function play(departing,started){
|
|
113
|
+
if(disposed||!asset)return false;
|
|
114
|
+
if(departing&&(state==='hidden'||state==='leaving'||intent?.departing))return false;
|
|
115
|
+
const fromAge=state==='entering'&&motion.jobs[0]?Math.max(0,Math.min(1,((motion.lastTime??motion.jobs[0].started)-motion.jobs[0].started)/motion.duration)):1;
|
|
116
|
+
intent={departing,fromAge,started};runtime.requestRender();return true;
|
|
117
|
+
}
|
|
118
|
+
const control={object,
|
|
119
|
+
frame(now,reducedMotion){
|
|
120
|
+
if(disposed||!asset)return;
|
|
121
|
+
resizeMesh();
|
|
122
|
+
if(intent){
|
|
123
|
+
const {departing,fromAge,started,seed}=intent;intent=null;asset.mesh.visible=true;state=departing?'leaving':'entering';
|
|
124
|
+
const exitMode=entrySettings.exitEffect==='same'?entryMode:entrySettings.exitEffect;
|
|
125
|
+
const activeMode=departing?exitMode:entryMode;
|
|
126
|
+
motion.setMode(activeMode);motion.configure(normalizeImageEffectOptions(requestedSettings,activeMode));
|
|
127
|
+
if(seed!==undefined)lastSeed=seed;else if(!departing||lastSeed===null)lastSeed=motion.randomSeed();
|
|
128
|
+
// DOM image coordinates are source pixels, unlike the spatial runtime's
|
|
129
|
+
// world units. Keep travel at a stable 32 CSS px for DOM presentations.
|
|
130
|
+
const shownHeight=displaySize?.height??measure(object,runtime.camera,runtime.renderer.domElement,asset.h);
|
|
131
|
+
const shownWidth=displaySize?.width??shownHeight*asset.w/asset.h;
|
|
132
|
+
const motionUnit=shownHeight>0?imageMotionPixels(shownWidth,shownHeight)*asset.h/shownHeight:.65;
|
|
133
|
+
motion.playRegion(view,{x:-asset.w/2,y:-asset.h/2,width:asset.w,height:asset.h,direction},motionUnit,started??now,{departing,seed:lastSeed,fromAge:departing&&exitMode!==entryMode?1:fromAge});
|
|
134
|
+
}
|
|
135
|
+
if(motion.active){
|
|
136
|
+
motion.step(now,reducedMotion);
|
|
137
|
+
// This surface reuses one material for both directions. Refresh its
|
|
138
|
+
// dynamic clock/mask uniforms on the first draw after a transition too.
|
|
139
|
+
asset.mesh.material.uniformsNeedUpdate=true;
|
|
140
|
+
// Upload this frame's region data before reusing the same sampler.
|
|
141
|
+
runtime.renderer.initTexture?.(motion.uniforms.dustData.value);
|
|
142
|
+
if(motion.active)runtime.requestRender();
|
|
143
|
+
else{state=motion.departing?'hidden':'visible';asset.mesh.visible=!motion.departing;}
|
|
144
|
+
}
|
|
145
|
+
resizeMesh();
|
|
146
|
+
},
|
|
147
|
+
invalidate(){runtime.requestRender();},
|
|
148
|
+
destroy(){if(disposed)return;disposed=true;revision++;controller?.abort();unregister();releaseAsset();motion.dispose();state='disposed';},
|
|
149
|
+
};
|
|
150
|
+
const unregister=runtime.register(control);
|
|
151
|
+
return {object,ready:source===undefined?Promise.resolve(false):setSource(source),setSource,
|
|
152
|
+
enter:started=>play(false,started),exit:started=>play(true,started),
|
|
153
|
+
setEffect(mode,options={}){validMode(mode);const next=normalizeImageEffectOptions(options,mode);if(disposed)return;requestedSettings=options;entryMode=mode;entrySettings=next;motion.setMode(mode);motion.configure(next);motion.cancel();motion.uniforms.dustMaskOnly.value=0;intent=null;if(asset){asset.mesh.visible=true;state='visible';}runtime.requestRender();},
|
|
154
|
+
setDisplaySize(width,height){if(!(Number.isFinite(width)&&Number.isFinite(height)&&width>0&&height>0))throw RangeError('Positive display dimensions required');displaySize={width,height};},
|
|
155
|
+
setDirection(value){validDirection(value);direction=value;},
|
|
156
|
+
setPresentationOpacity(value){if(asset)asset.mesh.material.uniforms.presentationOpacity.value=value;},
|
|
157
|
+
show(){if(disposed||!asset)return;intent=null;motion.cancel();motion.uniforms.dustMaskOnly.value=0;asset.mesh.visible=true;state='visible';runtime.requestRender();},
|
|
158
|
+
frame:control.frame,destroy:control.destroy,
|
|
159
|
+
stats(){const raster=asset?.raster,g=asset?.mesh.geometry;return {disposed,loading,error,state,active:motion.active,mode:entryMode,activeMode:motion.mode,exitMode:entrySettings.exitEffect==='same'?entryMode:entrySettings.exitEffect,duration:motion.duration,settings:{...motion.settings,recipe:{...motion.settings.recipe}},direction,motionFrame:asset?{...view.motionFrame}:null,divisions:asset?.rows,gridAspect:asset?.aspect,gridColumns:asset?Math.max(1,Math.round(asset.rows*asset.aspect)):0,triangles:g?g.getAttribute('position').count/3:0,builds,loadMs,buildMs,rasterBytes:raster?.rgba.byteLength||0,estimatedTextureBytes:raster?Math.ceil(raster.rgba.byteLength*4/3):0,geometryBytes:g?Object.values(g.attributes).reduce((n,a)=>n+a.array.byteLength,0):0,source:raster?{type:raster.type,width:raster.width,height:raster.height,originalWidth:raster.originalWidth,originalHeight:raster.originalHeight}:null};},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
158
162
|
|
|
159
163
|
|
|
160
164
|
|
package/src/render-owner.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {createViewportRenderOwner} from './viewport-render-owner.js';
|
|
2
|
-
|
|
3
|
-
// Shared GPU ownership, independent of component factories. Local 2D
|
|
4
|
-
// presentation canvases preserve DOM stacking and clipping of each surface.
|
|
5
|
-
export function createRenderOwner(THREE,document,{presentation='local',...options}={}){
|
|
6
|
-
if(presentation==='viewport')return createViewportRenderOwner(THREE,document,options);
|
|
7
|
-
if(presentation!=='local')throw TypeError('Invalid canvas presentation');
|
|
1
|
+
import {createViewportRenderOwner} from './viewport-render-owner.js';
|
|
2
|
+
|
|
3
|
+
// Shared GPU ownership, independent of component factories. Local 2D
|
|
4
|
+
// presentation canvases preserve DOM stacking and clipping of each surface.
|
|
5
|
+
export function createRenderOwner(THREE,document,{presentation='local',...options}={}){
|
|
6
|
+
if(presentation==='viewport')return createViewportRenderOwner(THREE,document,options);
|
|
7
|
+
if(presentation!=='local')throw TypeError('Invalid canvas presentation');
|
|
8
8
|
if(!THREE?.WebGLRenderer||!document?.defaultView)throw TypeError('THREE and a window document required');
|
|
9
9
|
let renderer=null,disposed=false,lost=false,w=0,h=0,dpr=0,copies=0,copyMs=0,renderMs=0,created=0;
|
|
10
10
|
const leases=new Set(),handles=new Set();
|
|
@@ -29,11 +29,16 @@ export function createRenderOwner(THREE,document,{presentation='local',...option
|
|
|
29
29
|
}
|
|
30
30
|
render(scene,camera){
|
|
31
31
|
ensure();if(this.dead)throw Error('Presentation disposed');
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Keep a high-water scratch buffer: alternating differently sized leases
|
|
33
|
+
// must not reallocate the GPU drawing buffer on every text frame.
|
|
34
|
+
const pw=this.domElement.width,ph=this.domElement.height;
|
|
35
|
+
if(pw>w||ph>h){w=Math.max(w,pw);h=Math.max(h,ph);renderer.setSize(w,h,false);}
|
|
36
|
+
renderer.setScissorTest(false);renderer.clear(true,true,true);
|
|
37
|
+
renderer.setViewport(0,0,pw,ph);
|
|
38
|
+
renderer.setScissor(0,0,pw,ph);renderer.setScissorTest(true);
|
|
34
39
|
const t=performance.now();renderer.render(scene,camera);renderMs+=performance.now()-t;
|
|
35
40
|
const start=performance.now();this.context.clearRect(0,0,this.domElement.width,this.domElement.height);
|
|
36
|
-
this.context.drawImage(renderer.domElement,0,0);copyMs+=performance.now()-start;copies++;
|
|
41
|
+
this.context.drawImage(renderer.domElement,0,h-ph,pw,ph,0,0,pw,ph);copyMs+=performance.now()-start;copies++;
|
|
37
42
|
}
|
|
38
43
|
dispose(){if(this.dead)return;this.dead=true;leases.delete(this);this.domElement.width=this.domElement.height=0;}
|
|
39
44
|
forceContextLoss(){} // A lease cannot destroy a peer's context.
|
|
@@ -44,8 +49,8 @@ export function createRenderOwner(THREE,document,{presentation='local',...option
|
|
|
44
49
|
const control=factory(host,Namespace,options),destroy=control.destroy;
|
|
45
50
|
handles.add(control);control.destroy=()=>{handles.delete(control);destroy();};return control;
|
|
46
51
|
}
|
|
47
|
-
return {create,
|
|
48
|
-
refresh(){if(disposed)throw Error('Shared owner disposed');for(const control of handles)control.refresh?.();},
|
|
52
|
+
return {create,
|
|
53
|
+
refresh(){if(disposed)throw Error('Shared owner disposed');for(const control of handles)control.refresh?.();},
|
|
49
54
|
stats:()=>({disposed,lost,contexts:renderer&&!disposed?1:0,created,controls:handles.size,leases:leases.size,copies,copyMs,renderMs,geometries:renderer?.info.memory.geometries||0}),
|
|
50
55
|
destroy(){
|
|
51
56
|
if(disposed)return;disposed=true;
|
|
@@ -33,6 +33,13 @@ export const textMotionPrimitives=`
|
|
|
33
33
|
float delay=clamp(order,0.0,1.0)*spread;
|
|
34
34
|
return clamp((t-delay)/max(1.0-delay,0.001),0.0,1.0);
|
|
35
35
|
}
|
|
36
|
+
// Continuous per-particle appearance: sparse at first, progressively denser.
|
|
37
|
+
// Use the existing reversible motion phase so exit follows the same envelope.
|
|
38
|
+
float thdParticleAppearance(float t,float order){
|
|
39
|
+
float start=0.55*sqrt(clamp(order,0.0,1.0));
|
|
40
|
+
float fade=clamp((t-start)/0.25,0.0,1.0);
|
|
41
|
+
return fade*fade;
|
|
42
|
+
}
|
|
36
43
|
vec2 thdTurn(vec2 v,float angle){
|
|
37
44
|
return vec2(v.x*cos(angle)-v.y*sin(angle),v.x*sin(angle)+v.y*cos(angle));
|
|
38
45
|
}
|
package/src/triangle-effect.js
CHANGED
|
@@ -139,8 +139,9 @@ export class TriangleEffect {
|
|
|
139
139
|
pace=clamp(mix(0.5,pace,dustChaos),0.0,1.0);
|
|
140
140
|
}
|
|
141
141
|
float remain=1.0-t;
|
|
142
|
-
dustOpacity=
|
|
142
|
+
dustOpacity=1.0;
|
|
143
143
|
${textEffectApplicationShader}
|
|
144
|
+
dustOpacity*=thdParticleAppearance(t,fract(seed*17.17+drift*3.13));
|
|
144
145
|
p.z=thdFrontDepth(position.z,p.z);
|
|
145
146
|
break;
|
|
146
147
|
}
|