4 Commits

Author SHA1 Message Date
virtheart d7b89b6d46 fix: 回首页转场软锁 — 幕布合上后永不 reveal,页面只剩背景和导航栏
startNavigation() 重置 readyToLoadHeavy,但 loadingBus 只在新 mark 时通知;首页访问过一次后 REQUIRED 资源全部已标记,mark() 被 done.has(key) 守卫挡住不再 notify,回首页(/ 开启 routeLoading 门控)的 reveal 门控永不通过。修复:导航意图产生时若 loadingBus 快照已 ready,立即恢复门控;真正未加载完的资源仍走订阅通知。
2026-09-04 15:15:41 +08:00
virtheart 6454a51fd0 fix: 移动端玻璃模型锚点漂移 — section 几何改为每帧实时读取(原版 sX)
移动端 dvh 随地址栏收起/展开变化,h-dvh 的 hero/footer 布局随之平移,部分浏览器不派发 window resize,一次性 offsetTop 测量过期导致模型漂移。FooterModel 移除 useState 测量,改传 sectionElId="contact" 由 GlassModel 每帧 getBoundingClientRect + scrollY 重算,元素缺失时回落静态 props。
2026-09-04 15:15:32 +08:00
virtheart 2cd0e007e4 fix: 首页文案微调 — Flutter 客户端改移动端、hero 大字去「我」
postfx 尾迹色随主题(dark #1600ff,对齐原版 lensFlare 控制),
随本提交一并带入:GlassModels 的 Dark 修复已在上一条提交。
2026-09-04 13:33:21 +08:00
virtheart 9c86ecc338 fix: Dark 主题玻璃模型失色 — uniforms 穿透材质 ref + FBO HalfFloatType 2026-09-04 13:23:18 +08:00
4 changed files with 107 additions and 50 deletions
+79 -43
View File
@@ -1,6 +1,6 @@
"use client"; "use client";
import { useEffect, useMemo, useRef, useState } from "react"; import { useEffect, useMemo, useRef } from "react";
import { useFrame, useLoader, useThree } from "@react-three/fiber"; import { useFrame, useLoader, useThree } from "@react-three/fiber";
import * as THREE from "three"; import * as THREE from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js"; import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
@@ -310,6 +310,16 @@ type GlassModelProps = {
*/ */
sectionTopDocY?: number; sectionTopDocY?: number;
sectionHeightPx?: number; sectionHeightPx?: number;
/**
* Live-read the section's document geometry by element id EVERY frame
* (original sX readSectionContentLayout: getBoundingClientRect +
* scrollTop). Required on mobile: dvh shrinks/grows as the URL bar
* collapses/expands, every h-dvh section (hero, footer) reflows, and some
* browsers never fire window resize for it — one-shot offsetTop
* measurements go stale and the model drifts off its section. Falls back
* to the static props above while the element is missing.
*/
sectionElId?: string;
}; };
function useFloatOffset(enabled: boolean) { function useFloatOffset(enabled: boolean) {
@@ -384,6 +394,7 @@ function GlassModel({
isMobile = false, isMobile = false,
sectionTopDocY = 0, sectionTopDocY = 0,
sectionHeightPx, sectionHeightPx,
sectionElId,
}: GlassModelProps) { }: GlassModelProps) {
const gltf = useLoader(GLTFLoader, url); const gltf = useLoader(GLTFLoader, url);
const groupRef = useRef<THREE.Group>(null!); const groupRef = useRef<THREE.Group>(null!);
@@ -452,11 +463,18 @@ function GlassModel({
// Scene-texture FBO: render layer 0 (background + stickers) at half res. // Scene-texture FBO: render layer 0 (background + stickers) at half res.
// Same as the original GlassSystem: one shared pass, camera mask forced to // Same as the original GlassSystem: one shared pass, camera mask forced to
// layer 0 so glass meshes (layer 10) are excluded from their own refraction. // layer 0 so glass meshes (layer 10) are excluded from their own refraction.
// ⚠ type: HalfFloatType —— 原版 sb() 工厂创建的所有 RT 均为 HalfFloat
// (4d3f3b68 @200877: {minFilter,magFilter,type:HalfFloatType,...})。
// UnsignedByte 的默认 RT 会让折射纹理的暗部量化/截断,Dark 主题下
// Hard-Light 着色的底色因此偏灰(模型"发透明感"而非饱和蓝)。
const fbo = useMemo(() => { const fbo = useMemo(() => {
const dpr = gl.getPixelRatio(); const dpr = gl.getPixelRatio();
const w = Math.max(2, Math.floor((size.width * dpr) / 2)); const w = Math.max(2, Math.floor((size.width * dpr) / 2));
const h = Math.max(2, Math.floor((size.height * dpr) / 2)); const h = Math.max(2, Math.floor((size.height * dpr) / 2));
const target = new THREE.WebGLRenderTarget(w, h, { const target = new THREE.WebGLRenderTarget(w, h, {
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
type: THREE.HalfFloatType,
stencilBuffer: false, stencilBuffer: false,
depthBuffer: true, depthBuffer: true,
samples: 0, samples: 0,
@@ -523,44 +541,59 @@ function GlassModel({
// flips. Per-model tingColor overrides: m[0]/m[1] light A/B, // flips. Per-model tingColor overrides: m[0]/m[1] light A/B,
// m[2]/m[3] dark A/B, missing entries fall back to the theme defaults. // m[2]/m[3] dark A/B, missing entries fall back to the theme defaults.
const isDark = useResolvedTheme() === "dark"; const isDark = useResolvedTheme() === "dark";
// ⚠ R3F 对 ShaderMaterial 的 `uniforms` prop 做的是「按键浅合并」:
// material.uniforms 是独立容器,标量按值拷贝、Vector4/Texture 共享引用,
// 且仅在 prop 引用变化时重新合并。材质创建后再改 memo 对象,标量
// (uDark、brightness、thickness alpha、loop…)永远到不了 GPU —— Dark
// 主题下 uDark 卡在 0、参数卡在 light 值,模型因此失色。原版所有
// apply 都写 T.current.uniforms(材质 ref);这里同样穿透到材质,
// 材质未挂载时回落到 memo(创建时会被拷贝进去),并以 mergedGeometry
// 作为「材质已存在」信号重跑(原版靠 tintYRange Y 的变化触发同一效果)。
const matUniforms = () =>
(materialRef.current?.uniforms ?? uniforms) as typeof uniforms;
// 原版移动端钳制 loop(apply effect: t=O?Math.min(B.loop,2):B.loop)—— // 原版移动端钳制 loop(apply effect: t=O?Math.min(B.loop,2):B.loop)——
// 折射采样少一轮,色散/亮度观感随设备宽度变化;桌面 3、移动 2。 // 折射采样少一轮,色散/亮度观感随设备宽度变化;桌面 3、移动 2。
const loop = isMobile ? Math.min(LIGHT_PARAMS.loop, 2) : LIGHT_PARAMS.loop; const loop = isMobile ? Math.min(LIGHT_PARAMS.loop, 2) : LIGHT_PARAMS.loop;
useEffect(() => { useEffect(() => {
uniforms.uLoop.value = loop; const u = matUniforms();
uniforms.uRgbRefraction.value = +(loop <= 3); u.uLoop.value = loop;
}, [loop, uniforms]); u.uRgbRefraction.value = +(loop <= 3);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [loop, uniforms, mergedGeometry]);
useEffect(() => { useEffect(() => {
const u = matUniforms();
const P = isDark ? DARK_PARAMS : LIGHT_PARAMS; const P = isDark ? DARK_PARAMS : LIGHT_PARAMS;
uniforms.uShininess.value = P.shininess; u.uShininess.value = P.shininess;
uniforms.uDiffuseness.value = P.diffuseness; u.uDiffuseness.value = P.diffuseness;
uniforms.uFresnelPower.value = P.fresnelPower; u.uFresnelPower.value = P.fresnelPower;
uniforms.uFresnelStrength.value = P.fresnelStrength; u.uFresnelStrength.value = P.fresnelStrength;
uniforms.uBrightness.value = P.brightness; u.uBrightness.value = P.brightness;
uniforms.uContrast.value = P.contrast; u.uContrast.value = P.contrast;
uniforms.uGamma.value = P.gamma; u.uGamma.value = P.gamma;
uniforms.uSaturation.value = P.saturation; u.uSaturation.value = P.saturation;
uniforms.uTintMix.value = P.tintMix; u.uTintMix.value = P.tintMix;
uniforms.uTintThicknessMinAlpha.value = P.tintThicknessMinAlpha; u.uTintThicknessMinAlpha.value = P.tintThicknessMinAlpha;
uniforms.uTintThicknessMaxAlpha.value = P.tintThicknessMaxAlpha; u.uTintThicknessMaxAlpha.value = P.tintThicknessMaxAlpha;
const tintA = isDark const tintA = isDark
? (tintColors?.[2] ?? DARK_PARAMS.tintColorA) ? (tintColors?.[2] ?? DARK_PARAMS.tintColorA)
: (tintColors?.[0] ?? LIGHT_PARAMS.tintColorA); : (tintColors?.[0] ?? LIGHT_PARAMS.tintColorA);
const tintB = isDark const tintB = isDark
? (tintColors?.[3] ?? DARK_PARAMS.tintColorB) ? (tintColors?.[3] ?? DARK_PARAMS.tintColorB)
: (tintColors?.[1] ?? LIGHT_PARAMS.tintColorB); : (tintColors?.[1] ?? LIGHT_PARAMS.tintColorB);
uniforms.uTintColorA.value.copy(hexToVec4(tintA)); u.uTintColorA.value.copy(hexToVec4(tintA));
uniforms.uTintColorB.value.copy(hexToVec4(tintB)); u.uTintColorB.value.copy(hexToVec4(tintB));
uniforms.uDark.value = isDark ? 1 : 0; u.uDark.value = isDark ? 1 : 0;
}, [isDark, tintColors, uniforms]); // eslint-disable-next-line react-hooks/exhaustive-deps
}, [isDark, tintColors, uniforms, mergedGeometry]);
useEffect(() => { useEffect(() => {
const drawingBufferSize = gl.getDrawingBufferSize(new THREE.Vector2()); const drawingBufferSize = gl.getDrawingBufferSize(new THREE.Vector2());
uniforms.uScreenResolutionPx.value.set( matUniforms().uScreenResolutionPx.value.set(
drawingBufferSize.x, drawingBufferSize.x,
drawingBufferSize.y drawingBufferSize.y
); );
}, [gl, size, uniforms]); // eslint-disable-next-line react-hooks/exhaustive-deps
}, [gl, size, uniforms, mergedGeometry]);
// Float bob: desktop only in the original (floatingMotion && !isMobileWidth) // Float bob: desktop only in the original (floatingMotion && !isMobileWidth)
const floatEnabled = floating && !isMobile; const floatEnabled = floating && !isMobile;
@@ -608,13 +641,31 @@ function GlassModel({
const spin = spinRef.current; const spin = spinRef.current;
if (!g) return; if (!g) return;
// --- Section geometry: live DOM read (original sX
// readSectionContentLayout) ---
// 原版每帧 getBoundingClientRect + scrollTop 重算 section 文档坐标。
// 移动端 dvh 随地址栏收起/展开变化,hero/footer 均为 h-dvh,布局随之
// 平移;部分浏览器不为此派发 window resize,一次性 offsetTop 测量会
// 过期导致锚点漂移(真机偏移、PC 模拟正常的根源)。元素缺失时回落
// 到静态测量值。
let secTop = sectionTopDocY;
let secHeight = sectionHeightPx;
if (sectionElId) {
const el = document.getElementById(sectionElId);
if (el) {
const rect = el.getBoundingClientRect();
secTop = rect.top + window.scrollY;
secHeight = rect.height;
}
}
// --- Section-anchored scroll state (banner: top 0, h-dvh) --- // --- Section-anchored scroll state (banner: top 0, h-dvh) ---
const vh = Math.max(1, state.size.height); const vh = Math.max(1, state.size.height);
const sectionH = Math.max(1, sectionHeightPx ?? vh); const sectionH = Math.max(1, secHeight ?? vh);
const scrollTop = Math.max(0, scrollBus.current); const scrollTop = Math.max(0, scrollBus.current);
// Original X(): hide the model once its section leaves the viewport. // Original X(): hide the model once its section leaves the viewport.
const deltaTop = sectionTopDocY - scrollTop; const deltaTop = secTop - scrollTop;
g.visible = deltaTop + sectionH > 0 && deltaTop < vh; g.visible = deltaTop + sectionH > 0 && deltaTop < vh;
// Original position sync: // Original position sync:
@@ -627,7 +678,7 @@ function GlassModel({
camera, camera,
new THREE.Vector3(0, 0, position[2]) new THREE.Vector3(0, 0, position[2])
).height; ).height;
const anchorDocY = sectionTopDocY + sectionH / 2; const anchorDocY = secTop + sectionH / 2;
const syncWorldY = const syncWorldY =
(0.5 - anchorDocY / vh) * viewportWorldHeight + (0.5 - anchorDocY / vh) * viewportWorldHeight +
(scrollTop / vh) * viewportWorldHeight * scrollSyncFactor; (scrollTop / vh) * viewportWorldHeight * scrollSyncFactor;
@@ -644,7 +695,7 @@ function GlassModel({
let entry = 1; let entry = 1;
let after = afterRotation ? 1 : 0; let after = afterRotation ? 1 : 0;
if (vh > 0) { if (vh > 0) {
const i = (scrollTop + vh - sectionTopDocY) / vh; const i = (scrollTop + vh - secTop) / vh;
entry = THREE.MathUtils.clamp(i, 0, 1); entry = THREE.MathUtils.clamp(i, 0, 1);
after = THREE.MathUtils.clamp(i - 1, 0, 1); after = THREE.MathUtils.clamp(i - 1, 0, 1);
} }
@@ -748,24 +799,10 @@ export function CursorStar({ isMobile = false }: { isMobile?: boolean }) {
* #contact footer model (original cp call: model/cnt.gltf, scale 19, * #contact footer model (original cp call: model/cnt.gltf, scale 19,
* beforeRotation [-180,0,0], scrollSyncFactor 1 — the cp default — and * beforeRotation [-180,0,0], scrollSyncFactor 1 — the cp default — and
* light-theme tingColor m[0]/m[1] = #FFFFFF/#009dff). Anchored to the * light-theme tingColor m[0]/m[1] = #FFFFFF/#009dff). Anchored to the
* footer section's document geometry, measured live so it tracks layout. * footer section via live per-frame DOM reads (original sX), so mobile
* URL-bar dvh reflows can't drift the anchor.
*/ */
export function FooterModel() { export function FooterModel() {
const [geom, setGeom] = useState({ top: 0, height: 0 });
useEffect(() => {
const measure = () => {
const el = document.getElementById("contact");
if (el) setGeom({ top: el.offsetTop, height: el.offsetHeight });
};
measure();
window.addEventListener("resize", measure);
document.fonts?.ready?.then(measure).catch(() => {});
const t = window.setTimeout(measure, 500);
return () => {
window.removeEventListener("resize", measure);
window.clearTimeout(t);
};
}, []);
return ( return (
<GlassModel <GlassModel
url="/model/cnt.gltf" url="/model/cnt.gltf"
@@ -775,8 +812,7 @@ export function FooterModel() {
scale={19} scale={19}
tintColors={["#FFFFFF", "#009dff", "#8e9dc4", "#64c3ff"]} tintColors={["#FFFFFF", "#009dff", "#8e9dc4", "#64c3ff"]}
tintEnabled tintEnabled
sectionTopDocY={geom.top} sectionElId="contact"
sectionHeightPx={geom.height}
scrollSyncFactor={1} scrollSyncFactor={1}
/> />
); );
+16 -5
View File
@@ -5,6 +5,7 @@ import { useFrame, useThree } from "@react-three/fiber";
import { EffectComposer } from "@react-three/postprocessing"; import { EffectComposer } from "@react-three/postprocessing";
import { UnsignedByteType, Vector2 } from "three"; import { UnsignedByteType, Vector2 } from "three";
import { usePointer } from "@/lib/pointer"; import { usePointer } from "@/lib/pointer";
import { useResolvedTheme } from "@/lib/shellMedia";
import { scrollBus } from "@/lib/scrollBus"; import { scrollBus } from "@/lib/scrollBus";
import { import {
FluidPushPass, FluidPushPass,
@@ -30,10 +31,15 @@ import {
* lime trail acts as a pointer indicator over the dot curtain * lime trail acts as a pointer indicator over the dot curtain
* - params: starRays 6, intensity .7, threshold .99, streakScale * - params: starRays 6, intensity .7, threshold .99, streakScale
* 8·(w/1920)·(mobile?2:1), hotspotPower 32, gate .88, * 8·(w/1920)·(mobile?2:1), hotspotPower 32, gate .88,
* tailColorLight #ffa300 * tailColor 随主题: light #ffa300 / dark #1600ff(原 lensFlare 控制
* tailColorLight/tailColorDark,resolvedTheme 切换)。
* ⚠ 尾迹色叠在玻璃高光热点上:Dark 下用橙色会把模型区域的
* r/g 抬高、显得"发灰发透明"而非原版的饱和蓝。
*/ */
const BRIGHT_SOURCE_SECTIONS = ["banner", "footer"]; const BRIGHT_SOURCE_SECTIONS = ["banner", "footer"];
const TAIL_COLOR_LIGHT = "#ffa300";
const TAIL_COLOR_DARK = "#1600ff";
const clamp01 = (v: number) => Math.min(1, Math.max(0, v)); const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
const sT = (e?: number) => (e === undefined ? 0 : clamp01(e > 1 ? e / 100 : e)); const sT = (e?: number) => (e === undefined ? 0 : clamp01(e > 1 ? e / 100 : e));
@@ -81,6 +87,9 @@ export function PostFX() {
const { uv: pointerUv, insideRef } = usePointer(); const { uv: pointerUv, insideRef } = usePointer();
const isMobile = size.width < 1024; const isMobile = size.width < 1024;
const reducedMotion = useReducedMotion(); const reducedMotion = useReducedMotion();
// 尾迹色随主题(原版: resolvedTheme → tailColorDark / tailColorLight)
const isDark = useResolvedTheme() === "dark";
const tailColor = isDark ? TAIL_COLOR_DARK : TAIL_COLOR_LIGHT;
const composerRef = useRef<any>(null); const composerRef = useRef<any>(null);
@@ -95,9 +104,11 @@ export function PostFX() {
streakScale: 8, streakScale: 8,
hotspotPower: 32, hotspotPower: 32,
gate: 0.88, gate: 0.88,
tailColor: "#ffa300", tailColor,
}), }),
[] // 尾迹色随主题切换时需重建材质 uniform —— tailColor 进依赖
// eslint-disable-next-line react-hooks/exhaustive-deps
[tailColor]
); );
const fluidPass = useMemo(() => new FluidPushPass(), []); const fluidPass = useMemo(() => new FluidPushPass(), []);
@@ -124,9 +135,9 @@ export function PostFX() {
streakScale, streakScale,
hotspotPower: 32, hotspotPower: 32,
gate: 0.88, gate: 0.88,
tailColor: "#ffa300", tailColor,
}); });
}, [flarePass, streakScale]); }, [flarePass, streakScale, tailColor]);
const dprRef = useRef(1); const dprRef = useRef(1);
useEffect(() => { useEffect(() => {
+11 -1
View File
@@ -153,10 +153,20 @@ export default function RouteTransitionOverlay() {
// Intent → cover (original effect 1). // Intent → cover (original effect 1).
useEffect(() => { useEffect(() => {
if (targetHref && mode === "idle") { if (targetHref && mode === "idle") {
// startNavigation() resets readyToLoadHeavy, but the bus only notifies
// on NEW marks. When every REQUIRED key is already done (any visit to
// "/" after the first), no notification ever fires again, so the
// route:wait reveal gate for a "/" target would never pass — the
// curtain stays covering the page (dots background + header only).
// Restore the gate immediately when the snapshot is already ready;
// genuinely-pending assets still notify through the subscription.
if (loadingBus.getSnapshot().ready) {
setReadyToLoadHeavy(true);
}
routeFrom.current = { path: pathname, coverDone: false }; routeFrom.current = { path: pathname, coverDone: false };
setTransition({ mode: "route", phase: "cover" }); setTransition({ mode: "route", phase: "cover" });
} }
}, [targetHref, mode, pathname]); }, [targetHref, mode, pathname, setReadyToLoadHeavy]);
// Entry wait → reveal (original effect 2): fires as soon as the gates // Entry wait → reveal (original effect 2): fires as soon as the gates
// pass — the reveal is NOT held for the progress-bar fade timers. // pass — the reveal is NOT held for the progress-bar fade timers.
+1 -1
View File
@@ -188,7 +188,7 @@ function seed() {
about_p2: "我相信工程塑造可靠的产品,设计赋予它们灵魂;", about_p2: "我相信工程塑造可靠的产品,设计赋予它们灵魂;",
about_p2_link_label: "我的作品", about_p2_link_label: "我的作品",
intro_prefix: intro_prefix:
"我是北极新一,一名横跨设计与工程的全栈开发者:Web 前端与后端、Flutter 客户端、AI 应用开发都有实践,也从产品设计一路做到工程落地。工作之外,我常在 ", "我是北极新一,一名横跨设计与工程的全栈开发者:Web 前端与后端、移动端、AI 应用开发都有实践,也从产品设计一路做到工程落地。工作之外,我常在 ",
intro_suffix: " 上记录与分享这些探索。", intro_suffix: " 上记录与分享这些探索。",
intro_brand: "小红书", intro_brand: "小红书",
footer_headline: "让我们|创造|一些不凡的|数字作品", footer_headline: "让我们|创造|一些不凡的|数字作品",