feat(web): studio worlds, camera-view/offscreen environment parity, material and undo coverage
Environment lighting: - ship all eight desktop studiolights/world datasets (WBENV1 float32) and a shared loader used by both the main viewport and the offscreen worker - add the N-panel "studio 环境" selector - rotate the world background together with the environment (backgroundRotation/backgroundIntensity), so camera view and offscreen renders match the desktop Mapping-node behaviour Verification (Chromium, OPFS, NOT_CLAIMED): - environment lighting + 8 world pixel identity - camera-view rotation correspondence (camera matrices, 207 samples) - offscreen vs on-screen background parity after hiding geometry (1305 samples) - metals case extended with material-field OPFS roundtrip - material Principled edits and rename undo/redo - eight studio worlds: pairwise frame differences + luminance rank correlation - undo history depth capped at 64 steps and undo across OPFS save/reopen Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -38,7 +38,7 @@ export function TutorialLanding({ course }: { course: TutorialCourse }) {
|
||||
return <main className="parts-tutorial-landing" data-course={course.id}>
|
||||
<header className="parts-landing-top">
|
||||
<a className="parts-landing-brand" href="/" aria-label="返回 Web Blender"><span className="brand-mark" aria-hidden="true"><span className="brand-orbit" /></span><span>Blender Web</span></a>
|
||||
<nav aria-label="教程导航"><a href="/manuals/index.html" target="_blank" rel="noopener">使用手册</a><a href="/manuals/WEB_Blender_Function_User_Guide.pdf" target="_blank" rel="noopener">PDF 版</a><a href="/tutorial/full/index.html" target="_blank" rel="noopener">全站入门课程</a><a href="/tutorial/complete/index.html" target="_blank" rel="noopener">完整初学者课程</a>{course.lessonUrl ? <a href={course.lessonUrl} target="_blank" rel="noopener">渲染图文/视频教案</a> : null}<a href="/" className="parts-landing-return">直接打开 Blender</a></nav>
|
||||
<nav aria-label="教程导航"><a href="/manuals/index.html" target="_blank" rel="noopener">使用手册</a><a href="/manuals/WEB_Blender_Function_User_Guide.pdf" target="_blank" rel="noopener">PDF 版</a><a href="/tutorial/full/index.html" target="_blank" rel="noopener">全站入门课程</a><a href="/tutorial/complete/index.html" target="_blank" rel="noopener">完整初学者课程</a><a href="/?tutorial=rendering" target="_blank" rel="noopener">渲染全流程实训</a><a href="/tutorial/rendering/index.html" target="_blank" rel="noopener">渲染入门课程</a><a href="/tutorial/rendering/monkey-render-lesson.html" target="_blank" rel="noopener">猴头渲染视频课</a><a href="/tutorial/render-basics/index.html" target="_blank" rel="noopener">渲染四条通路实走</a>{course.lessonUrl ? <a href={course.lessonUrl} target="_blank" rel="noopener">渲染图文/视频教案</a> : null}<a href="/" className="parts-landing-return">直接打开 Blender</a></nav>
|
||||
</header>
|
||||
<section className="parts-landing-hero">
|
||||
<div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useEffect, useMemo, useRef, useState, type PointerEvent as ReactPointerEvent } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import type { TutorialCourse } from "./course";
|
||||
import { sceneHierarchyTree } from "./scene-tree";
|
||||
import { TutorialTreeView } from "./TutorialTreeView";
|
||||
@@ -19,6 +20,8 @@ async function delay(ms: number): Promise<void> {
|
||||
/* A React remount must not re-open the last checkpoint over newer unsaved
|
||||
* edits in the same page session; a real reload resets this module state. */
|
||||
const preparedCourseIds = new Set<string>();
|
||||
/** Where the learner last dragged the panel, as a pixel offset from its CSS home. */
|
||||
const PANEL_OFFSET_KEY = "web-blender.tutorial-panel-offset.v1";
|
||||
|
||||
export function TutorialOverlay({ course, api, context }: { course: TutorialCourse; api: TutorialApi; context: TutorialContext }) {
|
||||
const { progress, hydrated, setCurrentStep, completeStep, recordProject, recordSavedProject, reset, completedRequired } = useTutorialProgress(course);
|
||||
@@ -30,6 +33,25 @@ export function TutorialOverlay({ course, api, context }: { course: TutorialCour
|
||||
const [projectState, setProjectState] = useState<"idle" | "preparing" | "ready" | "failed">("idle");
|
||||
const projectReadyRef = useRef<Promise<boolean> | null>(null);
|
||||
const checkpointInFlightRef = useRef(false);
|
||||
/* The panel floats over the real viewport, so the learner must be able to move
|
||||
* it off whatever the current step is demonstrating. Position is page-level
|
||||
* (not per-course): it is a comfort setting, keyed by nothing but the app. */
|
||||
const [offset, setOffset] = useState<{ x: number; y: number }>(() => {
|
||||
try {
|
||||
const raw = JSON.parse(window.localStorage.getItem(PANEL_OFFSET_KEY) ?? "null") as { x?: unknown; y?: unknown } | null;
|
||||
return typeof raw?.x === "number" && typeof raw?.y === "number" && Number.isFinite(raw.x) && Number.isFinite(raw.y)
|
||||
? { x: raw.x, y: raw.y }
|
||||
: { x: 0, y: 0 };
|
||||
}
|
||||
catch { return { x: 0, y: 0 }; }
|
||||
});
|
||||
const dragRef = useRef<{ pointerId: number; startX: number; startY: number; originX: number; originY: number } | null>(null);
|
||||
const panelRef = useRef<HTMLElement | null>(null);
|
||||
/* Everything drawn in this page is clipped to the browser viewport, so a DOM
|
||||
* panel can never sit outside the window. A separate Document PiP window can:
|
||||
* it is a real OS window the learner can park on a second screen while the
|
||||
* demo runs unobstructed. */
|
||||
const [pipWindow, setPipWindow] = useState<Window | null>(null);
|
||||
const index = Math.max(0, course.steps.findIndex((step) => step.id === progress.currentStepId));
|
||||
const step = course.steps[index] ?? course.steps[0];
|
||||
const checks = useMemo(() => step.validate(context), [step, context]);
|
||||
@@ -127,6 +149,104 @@ export function TutorialOverlay({ course, api, context }: { course: TutorialCour
|
||||
setDemoRunning(false);
|
||||
}
|
||||
};
|
||||
const commitOffset = (next: { x: number; y: number }) => {
|
||||
setOffset(next);
|
||||
try { window.localStorage.setItem(PANEL_OFFSET_KEY, JSON.stringify(next)); }
|
||||
catch { /* A read-only profile keeps the drag for this page only. */ }
|
||||
};
|
||||
/* Pop the panel into its own OS window so it can live outside the browser.
|
||||
* Falls back to a plain popup window on browsers without Document PiP. */
|
||||
const openFloatingWindow = async () => {
|
||||
/* Button is a toggle: a second press brings the panel back into the page. */
|
||||
if (pipWindow && !pipWindow.closed) { pipWindow.close(); setPipWindow(null); return; }
|
||||
const pip = (window as unknown as { documentPictureInPicture?: { requestWindow: (options: { width: number; height: number; disallowReturnToOpener?: boolean }) => Promise<Window> } }).documentPictureInPicture;
|
||||
try {
|
||||
const target = pip
|
||||
? await pip.requestWindow({ width: 420, height: Math.min(760, Math.round(window.screen.availHeight * 0.8)), disallowReturnToOpener: true })
|
||||
: window.open("", "web-blender-tutorial", "popup,width=420,height=760");
|
||||
if (!target) return;
|
||||
/* A PiP/popup document has no base URL to resolve our root-relative links
|
||||
* against, so mirror only the stylesheet rules that dress this panel and
|
||||
* inline them as absolute-URL links. */
|
||||
for (const sheet of Array.from(document.styleSheets)) {
|
||||
try {
|
||||
const rules = Array.from(sheet.cssRules);
|
||||
const text = rules.map((rule) => rule.cssText).join("\n");
|
||||
if (!/\.(?:parts-)?tutorial/.test(text)) continue;
|
||||
const href = (sheet.ownerNode as HTMLLinkElement | null)?.getAttribute?.("href");
|
||||
target.document.head.appendChild(href
|
||||
? Object.assign(target.document.createElement("link"), { rel: "stylesheet", href: new URL(href, document.baseURI).href })
|
||||
: Object.assign(target.document.createElement("style"), { textContent: text }));
|
||||
}
|
||||
catch { /* Cross-origin sheet: nothing readable to copy. */ }
|
||||
}
|
||||
target.document.body.style.margin = "0";
|
||||
target.document.body.style.background = "#17191a";
|
||||
target.document.title = course.overlayTitle;
|
||||
target.addEventListener("pagehide", () => setPipWindow(null));
|
||||
setPipWindow(target);
|
||||
}
|
||||
catch (error) {
|
||||
setDemoError(`无法打开独立窗口:${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
};
|
||||
const onHeaderPointerDown = (event: ReactPointerEvent<HTMLElement>) => {
|
||||
/* Never start a drag from the collapse button or a text selection inside the title. */
|
||||
if ((event.target as HTMLElement).closest("button")) return;
|
||||
if (event.button !== 0) return;
|
||||
dragRef.current = { pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, originX: offset.x, originY: offset.y };
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
};
|
||||
const onHeaderPointerMove = (event: ReactPointerEvent<HTMLElement>) => {
|
||||
const drag = dragRef.current;
|
||||
if (!drag || drag.pointerId !== event.pointerId) return;
|
||||
const panel = event.currentTarget.closest(".parts-tutorial-overlay");
|
||||
if (!(panel instanceof HTMLElement)) return;
|
||||
/* In a floating window the panel fills its own document, so a page-space
|
||||
* offset means nothing; the OS moves the window instead. */
|
||||
if (panel.dataset.tutorialFloating === "true") return;
|
||||
const rect = panel.getBoundingClientRect();
|
||||
/* Free drag, but the header must stay grabbable: it is the only handle, so
|
||||
* every clamp below is expressed in terms of "how much header is on
|
||||
* screen". A DOM panel is clipped at the window edge anyway — to actually
|
||||
* sit outside the browser, use the floating-window button. */
|
||||
const wantedLeft = rect.left + (drag.originX + event.clientX - drag.startX - offset.x);
|
||||
const wantedTop = rect.top + (drag.originY + event.clientY - drag.startY - offset.y);
|
||||
/* Never lose more than half the title, and always keep 160px of header width. */
|
||||
const left = Math.min(Math.max(wantedLeft, 8 - rect.width * 0.5), window.innerWidth - 160);
|
||||
/* Header is ~60px tall: keep at least 12px of it below the top edge and it
|
||||
* fully visible above the bottom edge. */
|
||||
const top = Math.min(Math.max(wantedTop, -48), window.innerHeight - 60);
|
||||
commitOffset({ x: Math.round(offset.x + left - rect.left), y: Math.round(offset.y + top - rect.top) });
|
||||
};
|
||||
const onHeaderPointerUp = (event: ReactPointerEvent<HTMLElement>) => {
|
||||
if (dragRef.current?.pointerId !== event.pointerId) return;
|
||||
dragRef.current = null;
|
||||
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
|
||||
};
|
||||
/* Closing the floating window must bring the panel back into the page; the
|
||||
* `pagehide` listener covers most closes, the poll covers the rest. */
|
||||
useEffect(() => {
|
||||
if (!pipWindow) return;
|
||||
const timer = window.setInterval(() => { if (pipWindow.closed) setPipWindow(null); }, 1000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [pipWindow]);
|
||||
/* Collapsing while floating closes the window so the reopen pill is in the page. */
|
||||
useEffect(() => {
|
||||
if (!collapsed || !pipWindow) return;
|
||||
pipWindow.close();
|
||||
setPipWindow(null);
|
||||
}, [collapsed, pipWindow]);
|
||||
/* The drag is deliberately unbounded, so a saved offset is honoured as-is.
|
||||
* Only the very first mount sanity-checks that the header is reachable, in
|
||||
* case the panel was parked outside a window that has since been resized. */
|
||||
useEffect(() => {
|
||||
const header = panelRef.current?.querySelector(".tutorial-head");
|
||||
if (!(header instanceof HTMLElement)) return;
|
||||
const rect = header.getBoundingClientRect();
|
||||
if (rect.bottom > 0 && rect.top < window.innerHeight && rect.right > 0 && rect.left < window.innerWidth) return;
|
||||
commitOffset({ x: 0, y: 0 });
|
||||
}, []);
|
||||
if (collapsed) {
|
||||
return <button type="button" className="tutorial-reopen" aria-label={course.reopenAria} onClick={() => setCollapsed(false)}>
|
||||
<span aria-hidden="true">?</span><span>教程</span>
|
||||
@@ -134,12 +254,19 @@ export function TutorialOverlay({ course, api, context }: { course: TutorialCour
|
||||
</button>;
|
||||
}
|
||||
const isSummary = step.id === course.summaryStepId;
|
||||
return <aside className="parts-tutorial-overlay" aria-label={course.overlayTitle} data-course={course.id} data-tutorial-step={step.id} data-tutorial-ready={ready ? "true" : "false"} data-tutorial-project={projectState}>
|
||||
<header className="tutorial-head">
|
||||
const panel = <aside ref={panelRef} className={demoRunning ? "parts-tutorial-overlay is-demoing" : "parts-tutorial-overlay"} aria-label={course.overlayTitle} data-course={course.id} data-tutorial-step={step.id} data-tutorial-ready={ready ? "true" : "false"} data-tutorial-project={projectState} data-tutorial-floating={pipWindow ? "true" : "false"} style={{ transform: `translate(${offset.x}px, ${offset.y}px)` }}>
|
||||
<header className="tutorial-head"
|
||||
onPointerDown={onHeaderPointerDown}
|
||||
onPointerMove={onHeaderPointerMove}
|
||||
onPointerUp={onHeaderPointerUp}
|
||||
onPointerCancel={onHeaderPointerUp}
|
||||
onDoubleClick={() => commitOffset({ x: 0, y: 0 })}
|
||||
title="拖动标题栏可移动面板,双击复位">
|
||||
<div>
|
||||
<p className="tutorial-kicker">{isSummary ? "课程完成" : step.chapter}</p>
|
||||
<h2>{step.title}</h2>
|
||||
</div>
|
||||
<button type="button" className="tutorial-icon-button" aria-label={pipWindow ? "将教程面板收回本页" : "在独立窗口打开教程面板"} title={pipWindow ? "收回本页" : "在独立窗口打开(可拖到浏览器之外、置于另一块屏幕)"} onClick={() => void openFloatingWindow()} data-testid="tutorial-float">{pipWindow ? "⤡" : "⧉"}</button>
|
||||
<button type="button" className="tutorial-icon-button" aria-label="收起教程侧栏" title="收起教程" onClick={() => setCollapsed(true)}>×</button>
|
||||
</header>
|
||||
<progress className="tutorial-progress" max={requiredTotal} value={completedRequired} aria-label="教程完成进度" />
|
||||
@@ -164,10 +291,10 @@ export function TutorialOverlay({ course, api, context }: { course: TutorialCour
|
||||
<p>当前场景仍可继续练习;请检查浏览器存储权限后点击“下一步”重试保存记录。</p>
|
||||
</div> : null}
|
||||
<p className="tutorial-summary">{step.summary}</p>
|
||||
<figure className="tutorial-reference">
|
||||
<img src={`${course.assetDir}/steps/${step.id}-view.jpg`} alt={`${step.title} 完成后的视口效果`} loading="lazy" />
|
||||
{step.referenceImage === "" ? null : <figure className="tutorial-reference">
|
||||
<img src={step.referenceImage ?? `${course.assetDir}/steps/${step.id}-view.jpg`} alt={`${step.title} 的目标效果`} loading="lazy" />
|
||||
<figcaption>目标效果 · 有头 Chromium 实拍</figcaption>
|
||||
</figure>
|
||||
</figure>}
|
||||
{step.hierarchy ? <section className="tutorial-hierarchy">
|
||||
<h3>实时装配树</h3>
|
||||
<TutorialTreeView ariaLabel="场景装配层级" nodes={hierarchyNodes} defaultExpandAll />
|
||||
@@ -205,6 +332,10 @@ export function TutorialOverlay({ course, api, context }: { course: TutorialCour
|
||||
</button>)}
|
||||
</nav> : null}
|
||||
</aside>;
|
||||
/* When a floating window is open the panel lives there; the page keeps no copy
|
||||
* so the learner sees exactly one set of controls. */
|
||||
if (pipWindow && !pipWindow.closed) return createPortal(panel, pipWindow.document.body);
|
||||
return panel;
|
||||
}
|
||||
|
||||
export async function runAction(action: TutorialAction, api: TutorialApi): Promise<boolean> {
|
||||
@@ -218,6 +349,7 @@ export async function runAction(action: TutorialAction, api: TutorialApi): Promi
|
||||
if (action.kind === "openScene") return api.openScene(action.url, action.fileName);
|
||||
if (action.kind === "render") return api.renderPbr(action.resolution, action.camera);
|
||||
if (action.kind === "renderDownload") return api.downloadPbrRender();
|
||||
if (action.kind === "engineRender") return api.renderEngine({ format: action.format, frameStart: action.frameStart, frameEnd: action.frameEnd, engine: action.engine });
|
||||
if (action.kind === "save") { await api.save(action.fileName); return true; }
|
||||
if (action.kind === "export") { await api.exportGLB(); return true; }
|
||||
await delay(action.ms);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { PARTS_TUTORIAL_REQUIRED_STEPS, PARTS_TUTORIAL_STEPS, PARTS_TUTORIAL_STORAGE_KEY } from "./parts/curriculum";
|
||||
import { REDUCER_TUTORIAL_REQUIRED_STEPS, REDUCER_TUTORIAL_STEPS, REDUCER_TUTORIAL_STORAGE_KEY } from "./reducer/curriculum";
|
||||
import { PBR_TUTORIAL_REQUIRED_STEPS, PBR_TUTORIAL_STEPS, PBR_TUTORIAL_STORAGE_KEY } from "./pbr/curriculum";
|
||||
import { RENDERING_TUTORIAL_REQUIRED_STEPS, RENDERING_TUTORIAL_STEPS, RENDERING_TUTORIAL_STORAGE_KEY } from "./rendering/curriculum";
|
||||
import type { TutorialStep } from "./parts/types";
|
||||
|
||||
export type CourseId = "parts" | "reducer" | "pbr";
|
||||
export type CourseId = "parts" | "reducer" | "pbr" | "rendering";
|
||||
|
||||
export interface TutorialCourseCard {
|
||||
name: string;
|
||||
@@ -233,6 +234,55 @@ export const COURSES = {
|
||||
{ step: "render-torus-emission", image: "renders/torus-emission-cyan.jpg", title: "Torus · 自发光", note: "环面自发光。" },
|
||||
],
|
||||
},
|
||||
rendering: {
|
||||
id: "rendering",
|
||||
title: "渲染全流程实训",
|
||||
heading: "把一帧渲染从头走完",
|
||||
steps: RENDERING_TUTORIAL_STEPS,
|
||||
requiredSteps: RENDERING_TUTORIAL_REQUIRED_STEPS,
|
||||
storageKey: RENDERING_TUTORIAL_STORAGE_KEY,
|
||||
opfsFile: "rendering-progress.json",
|
||||
assetDir: "/tutorial/rendering",
|
||||
lessonUrl: "/tutorial/rendering/index.html",
|
||||
// The embedded engine runs in the page, so this course needs no server.
|
||||
startUrl: "/?tutorial=rendering&start=1",
|
||||
saveStepId: "save-download",
|
||||
summaryStepId: "summary",
|
||||
checkpointEvery: 1,
|
||||
defaultProjectName: "渲染工作流实训.blend",
|
||||
pythonFileName: "RenderingTutorial.py",
|
||||
overlayTitle: "渲染全流程教程",
|
||||
reopenAria: "展开渲染全流程教程",
|
||||
heroTitle: "从按下按钮",
|
||||
heroAccent: "到拿到成片",
|
||||
eyebrow: "互动教学 · 初学者 · 约 20–30 分钟",
|
||||
lead: "在真实 Web Blender 里把渲染这件事完整走两遍:先用浏览器里的 PBR 渲染器出两张不同分辨率的图,再让 Blender 渲染引擎渲一帧和一短段动画,最后把工程与产物存进 OPFS 并手动下载。",
|
||||
partsLead: "四个环节串起一条完整链路:固定场景、两种引擎、看懂设置、交付存档。",
|
||||
galleryLead: "以下截图来自真实的渲染实测,不是示意图。",
|
||||
bottomCta: "进入渲染实训",
|
||||
bottomCtaContinue: "继续上次进度",
|
||||
parts: [
|
||||
{ name: "固定场景", note: "打开练习工程,认面板", icon: "base" },
|
||||
{ name: "浏览器 PBR", note: "512 与 1024 两张对比", icon: "ring" },
|
||||
{ name: "Blender 引擎", note: "单帧 PNG 与动画 MP4", icon: "shaft" },
|
||||
{ name: "交付", note: "OPFS 保存 + 手动下载", icon: "washer" },
|
||||
],
|
||||
summaryParts: ["练习工程 render-studio.blend", "PBR 512 × 512 一张", "PBR 1024 × 1024 一张", "Blender 引擎单帧 PNG", "工程写入 OPFS", "一张手动下载的 PNG"],
|
||||
summaryPartsTitle: "本课完成的产物",
|
||||
skills: [
|
||||
"分辨四条渲染通路:视口预览、浏览器 PBR、原生 Blender 后端、WASM 内嵌",
|
||||
"分辨率与代价:边长翻倍等于像素四倍,512 试构图、1024 查材质、2048 出图",
|
||||
"渲染设置:引擎枚举、PNG/OpenEXR/MP4 格式、帧范围与 240 帧上限",
|
||||
"交付纪律:工程与产物落 OPFS,下载是独立的手动动作",
|
||||
],
|
||||
gallery: [
|
||||
{ step: "pbr-first", image: "evidence/pbr-512-final.png", title: "PBR 512 · 最终材质", note: "浏览器显卡重绘,首张需要编译着色器。" },
|
||||
{ step: "pbr-diagnostic", image: "evidence/pbr-512-normal.png", title: "PBR 512 · 法线诊断", note: "同一帧的法线视图,用来排查表面朝向。" },
|
||||
{ step: "engine-frame", image: "evidence/native-still.png", title: "Blender 引擎 · 单帧", note: "真实渲染引擎算出的结果,不是视口重绘。" },
|
||||
{ step: "engine-embedded", image: "evidence/wasm-embedded-still.png", title: "WASM 内嵌 · 单帧", note: "同一套引擎编译进浏览器,断网也能渲。" },
|
||||
{ step: "desktop-session", image: "evidence/desktop-render-window.png", title: "桌面串流 · 渲染窗口", note: "后台 Blender 进程的画面回传。" },
|
||||
],
|
||||
},
|
||||
} satisfies Record<CourseId, TutorialCourse>;
|
||||
|
||||
export type AvailableCourseId = keyof typeof COURSES;
|
||||
|
||||
@@ -100,7 +100,9 @@
|
||||
|
||||
/* In-editor overlay */
|
||||
.parts-tutorial-overlay {
|
||||
position: fixed; left: 236px; right: auto; top: 66px; bottom: 30px; width: min(402px, 32vw); z-index: 60;
|
||||
/* Content-sized, not viewport-tall: a full-height panel cannot be dragged
|
||||
* anywhere useful, and it covers the whole column the demo runs in. */
|
||||
position: fixed; left: 236px; right: auto; top: 66px; bottom: auto; width: min(402px, 32vw); max-height: calc(100vh - 96px); z-index: 60;
|
||||
display: flex; flex-direction: column; overflow: hidden;
|
||||
background: rgba(25, 27, 29, .97); border: 1px solid #3d4247; border-radius: 12px;
|
||||
box-shadow: 0 18px 48px rgba(0, 0, 0, .5); color: #e8e9ea;
|
||||
@@ -108,7 +110,21 @@
|
||||
}
|
||||
.tutorial-loading { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 9px 11px; border: 1px solid #34495c; border-radius: 8px; background: #1c2833; color: #a9c9e6; line-height: 1.5; font-size: 12px; }
|
||||
.tutorial-loading span { color: #f28c28; }
|
||||
.tutorial-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; }
|
||||
/* The header doubles as the drag handle: the panel covers the viewport area the
|
||||
* demo drives, so the learner has to be able to park it out of the way. */
|
||||
.tutorial-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; cursor: grab; touch-action: none; user-select: none; }
|
||||
.tutorial-head:active { cursor: grabbing; }
|
||||
.tutorial-head .tutorial-icon-button { cursor: pointer; }
|
||||
/* Inside a floating PiP window the panel is the whole document: drop the
|
||||
* viewport anchoring, let it fill the window, and keep the drag handle. */
|
||||
.parts-tutorial-overlay[data-tutorial-floating="true"] {
|
||||
position: static; left: auto; top: auto; width: 100%; max-height: 100vh; height: 100vh;
|
||||
border: 0; border-radius: 0; box-shadow: none; transform: none !important;
|
||||
}
|
||||
/* While a demo drives the real Main, the panel steps aside so the learner can
|
||||
* actually watch the operator run; hovering brings it back to full opacity. */
|
||||
.parts-tutorial-overlay.is-demoing { opacity: .28; transition: opacity .18s ease; }
|
||||
.parts-tutorial-overlay.is-demoing:hover, .parts-tutorial-overlay.is-demoing:focus-within { opacity: 1; }
|
||||
.tutorial-kicker { margin: 0 0 5px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #f28c28; }
|
||||
.tutorial-head h2 { margin: 0; font-size: 18px; line-height: 1.25; }
|
||||
.tutorial-icon-button { border: 0; background: transparent; color: #a6abb0; font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
|
||||
@@ -118,7 +134,9 @@
|
||||
.tutorial-progress::-webkit-progress-value { background: linear-gradient(90deg, #f28c28, #f2b45c); border-radius: 999px; }
|
||||
.tutorial-progress::-moz-progress-bar { background: linear-gradient(90deg, #f28c28, #f2b45c); border-radius: 999px; }
|
||||
.tutorial-progress-label { margin: 8px 18px 0; color: #8f959a; font-size: 11px; }
|
||||
.tutorial-body { flex: 1; overflow-y: auto; padding: 14px 18px 18px; }
|
||||
/* min-height:0 lets the body shrink inside max-height, so its own scrollbar
|
||||
* takes over instead of the panel overflowing the window. */
|
||||
.tutorial-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 18px 18px; }
|
||||
.tutorial-summary { margin: 0 0 14px; color: #c6cacd; line-height: 1.65; }
|
||||
.tutorial-reference { margin: 0 0 12px; border: 1px solid #34383c; border-radius: 8px; overflow: hidden; background: #17191a; }
|
||||
.tutorial-reference img { display: block; width: 100%; height: auto; max-height: 150px; object-fit: cover; object-position: center; }
|
||||
|
||||
@@ -15,6 +15,16 @@ export interface TutorialRenderResult {
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface TutorialRenderSummary {
|
||||
/** Files the routed Blender engine produced in this session. */
|
||||
files: number;
|
||||
imageFiles: number;
|
||||
videoFiles: number;
|
||||
bytes: number;
|
||||
/** The panel's own status line: RUNNING / SUCCEEDED / an error message. */
|
||||
output: string;
|
||||
}
|
||||
|
||||
export interface TutorialContext {
|
||||
snapshot: SceneSnapshotIR | null;
|
||||
/** The default project has finished opening and the native Main owns a scene. */
|
||||
@@ -32,6 +42,8 @@ export interface TutorialContext {
|
||||
assetLibraryReady: boolean;
|
||||
assetCount: number;
|
||||
renderResult: TutorialRenderResult | null;
|
||||
/** Artifacts of the routed Blender engine (server backend or embedded WASM). */
|
||||
nativeRender?: TutorialRenderSummary;
|
||||
}
|
||||
|
||||
export interface StepCheck {
|
||||
@@ -61,7 +73,9 @@ export type TutorialAction =
|
||||
| { kind: "asset"; name: string; mode: "object" | "material" }
|
||||
| { kind: "openScene"; url: string; fileName: string }
|
||||
| { kind: "render"; resolution: PbrResolution; camera: PbrCameraMode }
|
||||
| { kind: "renderDownload" };
|
||||
| { kind: "renderDownload" }
|
||||
/** Runs the Blender engine the current address routes to (server backend or embedded WASM). */
|
||||
| { kind: "engineRender"; format: "PNG" | "FFMPEG"; frameStart: number; frameEnd: number; engine?: "SCENE" | "CYCLES" | "BLENDER_EEVEE" | "BLENDER_WORKBENCH" };
|
||||
|
||||
export interface TutorialStep {
|
||||
id: string;
|
||||
@@ -74,6 +88,9 @@ export interface TutorialStep {
|
||||
guide?: boolean;
|
||||
/** Shows the live SceneIR hierarchy tree (collections and object parents). */
|
||||
hierarchy?: boolean;
|
||||
/** Reference figure for this step. Defaults to `<assetDir>/steps/<id>-view.jpg`;
|
||||
* an empty string suppresses the figure for steps with no real screenshot. */
|
||||
referenceImage?: string;
|
||||
/** Demonstrates the step by driving the real Main; disabled until canDemo passes. */
|
||||
demo?: TutorialAction[];
|
||||
canDemo?: (context: TutorialContext) => boolean;
|
||||
@@ -99,6 +116,9 @@ export interface TutorialApi {
|
||||
openScene: (url: string, fileName: string) => Promise<boolean>;
|
||||
renderPbr: (resolution: PbrResolution, cameraMode: PbrCameraMode) => Promise<boolean>;
|
||||
downloadPbrRender: () => Promise<boolean>;
|
||||
/** Drives the Blender engine the current address routes to, through the same
|
||||
* product entry point the render panel uses. */
|
||||
renderEngine: (options: { format: "PNG" | "FFMPEG"; frameStart: number; frameEnd: number; engine?: "SCENE" | "CYCLES" | "BLENDER_EEVEE" | "BLENDER_WORKBENCH" }) => Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface PartsTutorialProgress {
|
||||
|
||||
290
web/app/src/tutorial/rendering/curriculum.ts
Normal file
290
web/app/src/tutorial/rendering/curriculum.ts
Normal file
@@ -0,0 +1,290 @@
|
||||
import type { SceneSnapshotIR } from "../../../../protocol/scene-ir";
|
||||
import type { TutorialContext, TutorialStep } from "../parts/types";
|
||||
import { check } from "../parts/validators";
|
||||
|
||||
/** Objects are counted rather than named: the practice file is a real .blend,
|
||||
* and a learner may rename or add objects without invalidating the lesson. */
|
||||
const sceneObjects = (snapshot: SceneSnapshotIR | null): number => snapshot?.nodes.length ?? 0;
|
||||
|
||||
const hasCamera = (snapshot: SceneSnapshotIR | null): boolean =>
|
||||
Boolean(snapshot?.nodes.some((node) => node.type === "CAMERA"));
|
||||
|
||||
const engineFiles = (context: TutorialContext, kind: "image" | "video"): number =>
|
||||
context.nativeRender ? (kind === "image" ? context.nativeRender.imageFiles : context.nativeRender.videoFiles) : 0;
|
||||
|
||||
const engineBytes = (context: TutorialContext): number => context.nativeRender?.bytes ?? 0;
|
||||
|
||||
/** F12 is the entry point for both the server backend and the in-page WASM
|
||||
* engine; which one runs is decided by the address the page was opened with,
|
||||
* so a step that drives it is described as "the routed engine", not as one
|
||||
* specific backend. */
|
||||
const RENDER_PATH_NOTE = "本页地址决定 F12 走哪个后端:不带 `ui` 参数时由编译进浏览器的 WASM Blender 执行,带 `?ui=web` 时交给本机 Blender 进程。";
|
||||
|
||||
const suiteSteps: TutorialStep[] = [
|
||||
{
|
||||
id: "intro",
|
||||
referenceImage: "",
|
||||
chapter: "开始",
|
||||
title: "欢迎:把渲染这件事一次走完",
|
||||
summary:
|
||||
"这一课不讲参数表,而是让你亲手把「一条渲染从按下按钮到拿到成片」的完整链路走两遍:一遍用浏览器里的 PBR 渲染器,一遍用真实的 Blender 渲染引擎。走完之后,你能判断屏幕上那张图是谁算的、存在哪、怎么找回来。",
|
||||
instructions: [
|
||||
{ text: "渲染在 Web Blender 里不是一个按钮,而是四条彼此独立的通路;本课动手走最常用的两条。" },
|
||||
{ text: "左侧是真实的 Web Blender,右侧是教程;每一步都会实时检查你的场景状态。" },
|
||||
{ text: "卡住时点“演示本步”,它会用同一套产品接口替你完成,然后你可以继续改。" },
|
||||
{ text: RENDER_PATH_NOTE },
|
||||
],
|
||||
guide: true,
|
||||
validate: () => [],
|
||||
},
|
||||
{
|
||||
id: "open-scene",
|
||||
referenceImage: "/tutorial/rendering/evidence/pbr-512-final.png",
|
||||
chapter: "准备",
|
||||
title: "打开练习工程 render-studio.blend",
|
||||
summary:
|
||||
"练习工程里有一台相机、几盏灯和一个带材质的摆件。固定场景很重要:只有场景不变,后面两条通路出的图才有可比性。",
|
||||
instructions: [
|
||||
{ text: "点击“演示本步”打开练习工程;它走的是真实的“打开 .blend”入口,不是伪造的场景。" },
|
||||
{ text: "打开后底栏应显示 WASM 就绪与 Engine: SceneIR,大纲里能看到对象列表。" },
|
||||
{ text: "如果场景一直空着,先看底栏状态:首次加载 WASM 需要下载较大的引擎文件。" },
|
||||
],
|
||||
hints: ["练习工程路径:web/app/public/tutorial/rendering/render-studio.blend"],
|
||||
demo: [
|
||||
{ kind: "openScene", url: "/tutorial/rendering/render-studio.blend", fileName: "render-studio.blend" },
|
||||
{ kind: "wait", ms: 2000 },
|
||||
],
|
||||
validate: (context) => [
|
||||
check(
|
||||
"scene-open",
|
||||
"练习工程已打开(场景中至少有 5 个对象)",
|
||||
sceneObjects(context.snapshot) >= 5,
|
||||
"点击“演示本步”载入练习工程",
|
||||
),
|
||||
check("scene-camera", "场景里有一台相机", hasCamera(context.snapshot), "练习工程自带相机;请载入完整工程"),
|
||||
check(
|
||||
"scene-material",
|
||||
"至少有一个材质(PBR 渲染需要有东西可算)",
|
||||
(context.snapshot?.materials.length ?? 0) >= 1,
|
||||
"载入练习工程后应至少有一个材质",
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "workspace-rendering",
|
||||
referenceImage: "",
|
||||
chapter: "准备",
|
||||
title: "进入 Rendering 工作区,认出两个面板",
|
||||
summary:
|
||||
"Rendering 工作区里有两个来源不同的面板:上半部分是浏览器用显卡重绘的 “Web PBR 渲染”,下半部分折叠起来的 “渲染结果 · 原生 Blender”。认错面板,是初学者最常见的困惑来源。",
|
||||
instructions: [
|
||||
{ text: "点击顶部工作区标签“Rendering”。" },
|
||||
{ text: "找到“Web PBR 渲染”面板:它由 three.js 在浏览器里绘制,和视口是同一套渲染器。" },
|
||||
{ text: "再找到“渲染结果 · 原生 Blender”折叠区:它调用真实 Blender 引擎,产物是真正的渲染结果。" },
|
||||
],
|
||||
hints: ["两者算出来的图会不一样:PBR 是实时渲染的近似,Blender 引擎才有完整的采样、阴影和材质响应。"],
|
||||
demo: [
|
||||
{ kind: "workspace", workspaceId: "Rendering" },
|
||||
{ kind: "wait", ms: 900 },
|
||||
],
|
||||
validate: (context) => [
|
||||
check("workspace-rendering", "当前工作区是 Rendering", context.workspace === "Rendering", "点击顶部 Rendering 标签"),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "pbr-first",
|
||||
referenceImage: "/tutorial/rendering/evidence/pbr-512-final.png",
|
||||
chapter: "通路一 · 浏览器 PBR",
|
||||
title: "第一张:512 的 PBR 渲染",
|
||||
summary:
|
||||
"PBR 面板把当前视口按你选的分辨率重画一遍。第一次渲染会明显慢,因为着色器要现场编译;之后再渲很快,所以可以放心连续比较。",
|
||||
instructions: [
|
||||
{ text: "在“Web PBR 渲染”面板把分辨率设为 512 × 512。" },
|
||||
{ text: "相机选“场景相机”,视角预设保持“场景相机对齐”。" },
|
||||
{ text: "点击“渲染 PBR”,等结果图出现在面板里。" },
|
||||
],
|
||||
hints: ["结果下方的 “OPFS …” 后面是一串哈希:那是这张图写进浏览器持久存储的地址,刷新后还能找回来。"],
|
||||
demo: [
|
||||
{ kind: "workspace", workspaceId: "Rendering" },
|
||||
{ kind: "wait", ms: 700 },
|
||||
{ kind: "render", resolution: 512, camera: "SCENE" },
|
||||
],
|
||||
validate: (context) => [
|
||||
check(
|
||||
"pbr-size",
|
||||
"渲染结果是 512 × 512",
|
||||
context.renderResult?.width === 512 && context.renderResult?.height === 512,
|
||||
"在 PBR 面板选择 512 × 512 后点“渲染 PBR”",
|
||||
),
|
||||
check(
|
||||
"pbr-camera",
|
||||
"使用的是场景相机",
|
||||
context.renderResult?.cameraMode === "SCENE",
|
||||
"把相机下拉切到“场景相机”再渲染",
|
||||
),
|
||||
check(
|
||||
"pbr-saved",
|
||||
"结果已写入 OPFS(存在持久哈希)",
|
||||
Boolean(context.renderResult?.saved),
|
||||
"等渲染完成;失败时看面板上的错误提示",
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "pbr-1024",
|
||||
referenceImage: "/tutorial/rendering/evidence/pbr-1024-final.png",
|
||||
chapter: "通路一 · 浏览器 PBR",
|
||||
title: "第二张:把分辨率提到 1024,看清代价",
|
||||
summary:
|
||||
"分辨率按平方增长:边长翻倍,像素数是四倍。512 用来快速试构图,1024 用来检查材质,2048 才用于出图。亲手渲染两张,你才会对“等多久”有直觉。",
|
||||
instructions: [
|
||||
{ text: "把分辨率改到 1024 × 1024。" },
|
||||
{ text: "再次点击“渲染 PBR”,注意这次等待时间与上一张的差别。" },
|
||||
{ text: "比较两张图在边缘和材质细节上的差别。" },
|
||||
],
|
||||
hints: ["同一场景下 2048 的 PNG 实测约 593 KB,512 只有约 92 KB:分辨率直接体现在文件大小上。"],
|
||||
demo: [
|
||||
{ kind: "render", resolution: 1024, camera: "SCENE" },
|
||||
],
|
||||
validate: (context) => [
|
||||
check(
|
||||
"pbr-1024-size",
|
||||
"渲染结果是 1024 × 1024",
|
||||
context.renderResult?.width === 1024 && context.renderResult?.height === 1024,
|
||||
"把分辨率切到 1024 后重新渲染",
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "render-settings",
|
||||
referenceImage: "",
|
||||
chapter: "设置",
|
||||
title: "渲染设置:引擎、格式、帧范围",
|
||||
summary:
|
||||
"同一套设置面板在四条通路之间是共用的:引擎决定谁算,格式决定出图还是出视频,帧范围决定算哪一段。理解了这三个词,剩下的都是细节。",
|
||||
instructions: [
|
||||
{ text: "在“渲染结果 · 原生 Blender”里展开面板,找到 Scene / Engine / Format 三组下拉。" },
|
||||
{ text: "Engine 选 SCENE 表示沿用工程自身的引擎设置;也可以显式选 Cycles CPU、Eevee 或 Workbench。" },
|
||||
{ text: "Format 选 PNG 出单帧,选 MP4 / H.264 出视频;Start 与 End 限定帧范围(单次上限 240 帧)。" },
|
||||
{ text: "先用 50% 分辨率渲一遍看运动对不对,再上全分辨率,这是最省时间的顺序。" },
|
||||
],
|
||||
guide: true,
|
||||
validate: () => [],
|
||||
},
|
||||
{
|
||||
id: "engine-frame",
|
||||
referenceImage: "/tutorial/rendering/evidence/native-still.png",
|
||||
chapter: "通路二 · 真实 Blender 引擎",
|
||||
title: "第三张:让 Blender 引擎渲染一帧",
|
||||
summary:
|
||||
"这一张不再由浏览器显卡重绘,而是交给真正的 Blender 渲染引擎:按当前地址,它要么是服务端的 Blender 进程,要么是编译进浏览器的 WASM 版本。两条路算出的是真渲染。",
|
||||
instructions: [
|
||||
{ text: "展开“渲染结果 · 原生 Blender”,Format 选 PNG。" },
|
||||
{ text: "确认 Start / End 包含当前帧,点 Render Frame。" },
|
||||
{ text: "等待状态行从 RUNNING 变成 SUCCEEDED,中间区域会出现渲染结果。" },
|
||||
{ text: "点“演示本步”会走同一条产品路径;它可能比 PBR 慢很多,这是正常的。" },
|
||||
],
|
||||
hints: [
|
||||
"如果状态行显示 EDITOR_CONTEXT_UNAVAILABLE,说明引擎的编辑器上下文还没解析完,等一两秒再试。",
|
||||
"内嵌通路(默认地址)不需要后台服务,断网也能渲染;代价是速度受浏览器算力限制。",
|
||||
],
|
||||
demo: [
|
||||
{ kind: "workspace", workspaceId: "Rendering" },
|
||||
{ kind: "wait", ms: 800 },
|
||||
{ kind: "engineRender", format: "PNG", frameStart: 1, frameEnd: 1 },
|
||||
],
|
||||
validate: (context) => [
|
||||
check(
|
||||
"engine-frame-file",
|
||||
"拿到了至少一张 PNG 渲染结果",
|
||||
engineFiles(context, "image") >= 1,
|
||||
"展开原生渲染面板,点 Render Frame;失败时看状态行的错误码",
|
||||
),
|
||||
check(
|
||||
"engine-frame-bytes",
|
||||
"产物不是空文件",
|
||||
engineBytes(context) > 0,
|
||||
"等渲染真正完成,而不是刚开始就检查",
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "engine-animation",
|
||||
referenceImage: "",
|
||||
chapter: "通路二 · 真实 Blender 引擎",
|
||||
title: "可选:渲一段动画,拿到 MP4",
|
||||
summary:
|
||||
"动画就是同样的过程重复多帧。这一步不设门槛——它很慢,而且当前默认地址走的内嵌引擎能否出 MP4 取决于浏览器算力与场景复杂度;服务端通路(?ui=web)的动画已实测可用。",
|
||||
instructions: [
|
||||
{ text: "在“渲染结果 · 原生 Blender”里把 Format 切到 MP4 / H.264。" },
|
||||
{ text: "Start 填 1、End 填 2,点 Render Animation;这一步可能要等几分钟。" },
|
||||
{ text: "想看确定可用的动画:改用 ?ui=web 打开同一页,由服务端 Blender 渲染(实测 24 帧约 388 秒)。" },
|
||||
{ text: "不急的话,直接点“下一步”继续,本课不以此步判定是否学会。" },
|
||||
],
|
||||
hints: [
|
||||
"单次上限 240 帧;超出会被直接拒绝,需要分段渲染。",
|
||||
"先用 50% 分辨率验证运动,再上全分辨率,这是最省时间的顺序。",
|
||||
],
|
||||
demo: [
|
||||
{ kind: "engineRender", format: "FFMPEG", frameStart: 1, frameEnd: 2 },
|
||||
],
|
||||
guide: true,
|
||||
validate: () => [],
|
||||
},
|
||||
{
|
||||
id: "save-download",
|
||||
referenceImage: "",
|
||||
chapter: "交付",
|
||||
title: "交付:工程进 OPFS,图片手动下载",
|
||||
summary:
|
||||
"这是本课程最重要的一条纪律:渲染完不会自动下载。工程和产物都留在浏览器的 OPFS 里,需要本地文件时,你自己点下载。",
|
||||
instructions: [
|
||||
{ text: "点击顶栏“保存项目”,把工程写进浏览器 OPFS。" },
|
||||
{ text: "点 PBR 结果下方的“下载 PNG”,这是一次独立的、由你触发的动作。" },
|
||||
{ text: "刷新页面后,工程的渲染记录仍能从 OPFS 里读回来。" },
|
||||
],
|
||||
hints: ["清除站点数据会连同 OPFS 里的工程和渲染记录一起删除;重要成果要主动下载备份。"],
|
||||
demo: [
|
||||
{ kind: "save", fileName: "渲染工作流实训.blend" },
|
||||
{ kind: "renderDownload" },
|
||||
{ kind: "wait", ms: 1200 },
|
||||
],
|
||||
validate: (context) => [
|
||||
check("saved", "工程已保存(未保存修改为 0)", context.saved, "点击顶栏“保存项目”"),
|
||||
check("downloaded", "渲染 PNG 已手动下载", Boolean(context.renderResult?.downloaded), "点击结果下方的“下载 PNG”"),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "other-paths",
|
||||
referenceImage: "",
|
||||
chapter: "其余两条通路",
|
||||
title: "另外两条:服务端原生后端与桌面串流",
|
||||
summary:
|
||||
"本页动手走的是浏览器 PBR 与当前路由指向的 Blender 引擎。另外两条通路在别的地址上:换地址就换后端,功能是一样的。",
|
||||
instructions: [
|
||||
{ text: "服务端原生后端:用 ?ui=web 打开页面,F12 会把工程打包交给本机 Blender 进程,适合出定稿成片。" },
|
||||
{ text: "桌面串流会话:用 ?ui=desktop 打开,页面连上一个长期运行的 Blender 进程,画面回传,最接近桌面版体验。" },
|
||||
{ text: "两条通路的实测过程与失败码都写在渲染教案里,可以对照着再走一遍。" },
|
||||
],
|
||||
guide: true,
|
||||
validate: () => [],
|
||||
},
|
||||
{
|
||||
id: "summary",
|
||||
referenceImage: "",
|
||||
chapter: "完成",
|
||||
title: "完成总结:你现在能判断什么",
|
||||
summary:
|
||||
"你走完了一条完整链路:打开固定场景 → 用两种不同的引擎出图 → 看懂设置项 → 把工程和产物存进 OPFS 并手动下载。以后看到一张渲染图,你会先问三个问题:谁算的、多少分辨率、存在哪。",
|
||||
instructions: [
|
||||
{ text: "四条通路的对照表、失败码和实测截图在渲染教案里:/tutorial/rendering/index.html" },
|
||||
{ text: "继续练习:把分辨率提到 2048、把相机换成“当前视口”、试着渲 24 帧动画并观察耗时。" },
|
||||
],
|
||||
guide: true,
|
||||
validate: () => [],
|
||||
},
|
||||
];
|
||||
|
||||
export const RENDERING_TUTORIAL_STEPS = suiteSteps;
|
||||
export const RENDERING_TUTORIAL_REQUIRED_STEPS = suiteSteps.filter((step) => !step.guide);
|
||||
export const RENDERING_TUTORIAL_STORAGE_KEY = "web-blender.rendering-tutorial.v1";
|
||||
Reference in New Issue
Block a user