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 图
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useEffect, useMemo, useRef } from "react";
|
||||
import { useFrame, useThree } from "@react-three/fiber";
|
||||
import * as THREE from "three";
|
||||
import { StickerLayer } from "@/components/webgl/StickerLayer";
|
||||
import { scrollBus } from "@/lib/scrollBus";
|
||||
import { loadingBus } from "@/lib/loadingBus";
|
||||
import { usePointer } from "@/lib/pointer";
|
||||
import { useIsMobile } from "@/lib/useIsMobile";
|
||||
import { customCubic } from "@/lib/customCubic";
|
||||
|
||||
const STICKER_IMAGES = Array.from(
|
||||
{ length: 12 },
|
||||
@@ -27,11 +31,15 @@ export function StickerDrop() {
|
||||
const camera = useThree((s) => s.camera);
|
||||
const gl = useThree((s) => s.gl);
|
||||
const layerRef = useRef<StickerLayer | null>(null);
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
useEffect(() => {
|
||||
const layer = new StickerLayer(scene);
|
||||
layerRef.current = layer;
|
||||
layer.load(STICKER_IMAGES).catch(() => {});
|
||||
layer
|
||||
.load(STICKER_IMAGES)
|
||||
.then(() => loadingBus.mark("stickers"))
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
layer.dispose();
|
||||
layerRef.current = null;
|
||||
@@ -39,6 +47,7 @@ export function StickerDrop() {
|
||||
}, [scene]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isMobile) return; // original: pointer bursts are desktop-only
|
||||
const raycaster = new THREE.Raycaster();
|
||||
const ndc = new THREE.Vector2();
|
||||
const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
|
||||
@@ -110,7 +119,7 @@ export function StickerDrop() {
|
||||
window.removeEventListener("pointerup", onPointerUp, true);
|
||||
window.removeEventListener("pointercancel", onPointerCancel, true);
|
||||
};
|
||||
}, [camera, gl]);
|
||||
}, [camera, gl, isMobile]);
|
||||
|
||||
useFrame((_, delta) => {
|
||||
layerRef.current?.update(delta);
|
||||
@@ -120,24 +129,78 @@ export function StickerDrop() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Camera rig matching the original: horizontal FOV 60° (desktop) / 38°
|
||||
* (mobile) converted to vertical FOV per aspect, and camera distance
|
||||
* lerp(24, 32) driven by page scroll progress.
|
||||
* Camera rig matching the original cK:
|
||||
* - horizontal FOV 60° (desktop) / 38° (mobile) converted to vertical FOV
|
||||
* - distance A = lerp(24, 32, sP); position.z = lerp(A + 8, A,
|
||||
* customCubic(introT)) where introT ramps 0→1 over 1.2s once `ready`
|
||||
* (the entrance dolly from z+8)
|
||||
* - mouse parallax (desktop, ready only): offset = ((.5-uv)*2) * (1.4, .84),
|
||||
* rotated around the base position by lookAt(gyro*-.12), lerp lag .18
|
||||
* (.05 when the pointer leaves)
|
||||
* - sP is the original camera progress (banner/footer geometry), updated
|
||||
* from scrollBus.sP written by the page's scroll-geometry effect
|
||||
*/
|
||||
export function StickerCamera() {
|
||||
export function StickerCamera({ ready }: { ready: boolean }) {
|
||||
const camera = useThree((s) => s.camera) as THREE.PerspectiveCamera;
|
||||
const size = useThree((s) => s.size);
|
||||
const { uv, insideRef } = usePointer();
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
useFrame(() => {
|
||||
const baseRef = useRef<THREE.Vector2 | null>(null);
|
||||
const posLagRef = useRef(new THREE.Vector3());
|
||||
const rotLagRef = useRef(new THREE.Vector3());
|
||||
const introRef = useRef(0);
|
||||
const distanceRef = useRef(24);
|
||||
const parallaxVec = useMemo(() => new THREE.Vector3(), []);
|
||||
|
||||
useFrame((_state, rawDelta) => {
|
||||
const delta = Math.min(rawDelta, 0.1);
|
||||
const aspect = size.width / Math.max(1, size.height);
|
||||
const horizontalFov = size.width >= 1024 ? 60 : 38;
|
||||
const verticalFov =
|
||||
2 * Math.atan(Math.tan(THREE.MathUtils.degToRad(horizontalFov) / 2) / aspect);
|
||||
camera.fov = THREE.MathUtils.radToDeg(verticalFov);
|
||||
camera.aspect = aspect;
|
||||
const progress = THREE.MathUtils.clamp(scrollBus.progress, 0, 1);
|
||||
camera.position.z = THREE.MathUtils.lerp(24, 32, progress);
|
||||
camera.updateProjectionMatrix();
|
||||
if (
|
||||
Math.abs(camera.fov - THREE.MathUtils.radToDeg(verticalFov)) > 1e-4 ||
|
||||
Math.abs(camera.aspect - aspect) > 1e-6
|
||||
) {
|
||||
camera.fov = THREE.MathUtils.radToDeg(verticalFov);
|
||||
camera.aspect = aspect;
|
||||
camera.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
const progress = THREE.MathUtils.clamp(scrollBus.sP, 0, 1);
|
||||
const distance = THREE.MathUtils.lerp(24, 32, progress);
|
||||
distanceRef.current = distance;
|
||||
|
||||
if (!baseRef.current) {
|
||||
baseRef.current = new THREE.Vector2(camera.position.x, camera.position.y);
|
||||
}
|
||||
introRef.current = ready
|
||||
? Math.min(introRef.current + delta / 1.2, 1)
|
||||
: 0;
|
||||
camera.position.z = THREE.MathUtils.lerp(
|
||||
distance + 8,
|
||||
distance,
|
||||
customCubic(introRef.current)
|
||||
);
|
||||
|
||||
if (!isMobile) {
|
||||
const px = (0.5 - uv.x) * 2;
|
||||
const py = (0.5 - uv.y) * 2;
|
||||
const offset = posLagRef.current;
|
||||
const rot = rotLagRef.current;
|
||||
offset.lerp(parallaxVec.set(px * 1.4, py * 0.84, 0), insideRef.current ? 0.18 : 0.05);
|
||||
rot.lerp(parallaxVec.set(-offset.x * 0.12, -offset.y * 0.12, 0), insideRef.current ? 0.18 : 0.05);
|
||||
camera.position.x = baseRef.current.x + offset.x;
|
||||
camera.position.y = baseRef.current.y + offset.y;
|
||||
camera.lookAt(rot);
|
||||
} else {
|
||||
posLagRef.current.lerp(parallaxVec.set(0, 0, 0), 0.18);
|
||||
rotLagRef.current.lerp(parallaxVec.set(0, 0, 0), 0.18);
|
||||
camera.position.x = baseRef.current.x;
|
||||
camera.position.y = baseRef.current.y;
|
||||
camera.lookAt(0, 0, 0);
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user