Files
personal/lib/pointer.ts
T
virtheart ce08eabf62 feat: 移植原版背景/点阵遮罩/入场幕布,修复贴纸淡出与 cursor 颜色
- BackgroundFX: 1:1 移植原版 sz 多通道程序化背景(vignette→swirl→sine→shatter→bokeh→output,30% 分辨率 ping-pong,指针跟随、进度门控跳帧)
- DotOverlay: 移植原版 s1 滚动点阵遮罩(renderOrder 10,uOpacity=sT(sP))——贴纸随滚动溶入页面底色的原版机制
- LoadingCurtain+LoadingOverlay: 移植原版入场流程(径向圆洞幕布 + MaskedDots 点阵化后处理 + 居中进度条,字体/重资产 5:5 计时轴)
- sP 修正: f2 无 footer 时取 1(原版语义),相机 lerp(24,32,sP) 拉远恢复;视差 y 系数修正为 0.6
- 相机: ready 门控 intro dolly(lerp(A+8,A,customCubic),1.2s)+ 鼠标视差(lag .18/leave .05)
- GlassModels: cursor 贴色修正为亮色主题 #009dff/#009dff;新增指针跟随高光控制器 ca()
- 刷新回顶: scrollRestoration=manual + pageshow(bfcache) 双 rAF 重置 + lenis immediate
- 新增 lib/pointer.ts、lib/loadingBus.ts、lib/customCubic.ts;loadingBus 打点: 模型/贴纸/about 图
2026-09-01 02:00:54 +08:00

47 lines
1.5 KiB
TypeScript

"use client";
import { Vector2 } from "three";
/**
* Pointer tracking — 1:1 port of the original PointerProvider (module 16265):
* uv in [0,1] with y up (1 - clientY/height), `inside` false on
* blur/mouseleave/visibilitychange with a (.5,.5) reset. A module singleton
* replaces the original React context (same listeners, capture+passive).
*/
export const pointerUv = new Vector2(0.5, 0.5);
export const pointerInsideRef = { current: false };
let listenersAttached = false;
function attach() {
if (listenersAttached || typeof window === "undefined") return;
listenersAttached = true;
const set = (x: number, y: number, inside: boolean) => {
pointerUv.set(x, y);
pointerInsideRef.current = inside;
};
const onMove = (e: PointerEvent) => {
const w = Math.max(1, window.innerWidth);
const h = Math.max(1, window.innerHeight);
set(e.clientX / w, 1 - e.clientY / h, true);
};
const reset = () => set(0.5, 0.5, false);
const options = { capture: true, passive: true } as const;
window.addEventListener("pointermove", onMove, options);
window.addEventListener("pointerdown", onMove, options);
window.addEventListener("pointerover", onMove, options);
window.addEventListener("blur", reset, options);
document.addEventListener("mouseleave", reset, options);
document.addEventListener("visibilitychange", reset, options);
}
/** Same shape as the original usePointer(): { uv, insideRef }. */
export function usePointer() {
attach();
return { uv: pointerUv, insideRef: pointerInsideRef };
}