2 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
2 changed files with 48 additions and 24 deletions
+37 -23
View File
@@ -1,6 +1,6 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
import { useEffect, useMemo, useRef } from "react";
import { useFrame, useLoader, useThree } from "@react-three/fiber";
import * as THREE from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
@@ -310,6 +310,16 @@ type GlassModelProps = {
*/
sectionTopDocY?: 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) {
@@ -384,6 +394,7 @@ function GlassModel({
isMobile = false,
sectionTopDocY = 0,
sectionHeightPx,
sectionElId,
}: GlassModelProps) {
const gltf = useLoader(GLTFLoader, url);
const groupRef = useRef<THREE.Group>(null!);
@@ -630,13 +641,31 @@ function GlassModel({
const spin = spinRef.current;
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) ---
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);
// 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;
// Original position sync:
@@ -649,7 +678,7 @@ function GlassModel({
camera,
new THREE.Vector3(0, 0, position[2])
).height;
const anchorDocY = sectionTopDocY + sectionH / 2;
const anchorDocY = secTop + sectionH / 2;
const syncWorldY =
(0.5 - anchorDocY / vh) * viewportWorldHeight +
(scrollTop / vh) * viewportWorldHeight * scrollSyncFactor;
@@ -666,7 +695,7 @@ function GlassModel({
let entry = 1;
let after = afterRotation ? 1 : 0;
if (vh > 0) {
const i = (scrollTop + vh - sectionTopDocY) / vh;
const i = (scrollTop + vh - secTop) / vh;
entry = THREE.MathUtils.clamp(i, 0, 1);
after = THREE.MathUtils.clamp(i - 1, 0, 1);
}
@@ -770,24 +799,10 @@ export function CursorStar({ isMobile = false }: { isMobile?: boolean }) {
* #contact footer model (original cp call: model/cnt.gltf, scale 19,
* beforeRotation [-180,0,0], scrollSyncFactor 1 — the cp default — and
* 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() {
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 (
<GlassModel
url="/model/cnt.gltf"
@@ -797,8 +812,7 @@ export function FooterModel() {
scale={19}
tintColors={["#FFFFFF", "#009dff", "#8e9dc4", "#64c3ff"]}
tintEnabled
sectionTopDocY={geom.top}
sectionHeightPx={geom.height}
sectionElId="contact"
scrollSyncFactor={1}
/>
);
+11 -1
View File
@@ -153,10 +153,20 @@ export default function RouteTransitionOverlay() {
// Intent → cover (original effect 1).
useEffect(() => {
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 };
setTransition({ mode: "route", phase: "cover" });
}
}, [targetHref, mode, pathname]);
}, [targetHref, mode, pathname, setReadyToLoadHeavy]);
// Entry wait → reveal (original effect 2): fires as soon as the gates
// pass — the reveal is NOT held for the progress-bar fade timers.