Files
workinf_Blender_Wasm/web/app/public/teach/teach.js
mes123456 c47fa79102
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): viewport transform parity — offscreen backend, per-island pivots, ortho sizing
- Offscreen worker backend publishes the camera probe, so the G/R/S modal's
  pointer basis, transform gizmo and wireframe work on both renderers.
- Edit-mode INDIVIDUAL_ORIGINS pivots every connected island on its own centre,
  committed as one grouped transaction (T(P)·R·S·T(-P) in object space).
- Gizmo hits carry the pivot index; orthographic views size the axes from the
  visible world height instead of the 45° fov fallback.
- View-menu navigation no longer switches workspace when a viewport is already
  on screen (the engine workspace transaction dropped the editor out of Edit).
- Modal commits queue behind the shared command tail, so a trailing
  editEditorContext cannot consume the user's first Ctrl+Z.
- Floating sidebar rotation field confirmed in degrees; headed cases for the
  offscreen path, per-island pivots and the sidebar unit, plus receipts/docs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 07:48:17 +08:00

203 lines
8.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Catalogue page for the 31-chapter teaching hub.
*
* Reads the generated `catalog.json` (never a hand-maintained list) and the
* progress mirror the in-app coach writes to localStorage, then links each
* chapter into the real product with `?ui=web&teach=chNN&mode=...`.
* External file only: the deployment CSP forbids inline scripts.
*/
(function () {
"use strict";
var PROGRESS_KEY = "blender-web:teach-progress:v1";
/* The PBR course reuses this page against its own generated catalogue. */
var catalogUrl = document.body.dataset.catalog || "/teach/catalog.json";
var unit = document.body.dataset.unit || "章";
var catalogEl = document.getElementById("teach-catalog");
var searchEl = document.getElementById("teach-search");
var continueEl = document.getElementById("teach-continue");
var versionEl = document.getElementById("teach-version");
var modeInputs = Array.prototype.slice.call(document.querySelectorAll("input[name=mode]"));
var chapters = [];
var progress = { chapters: {} };
function selectedMode() {
for (var i = 0; i < modeInputs.length; i += 1) if (modeInputs[i].checked) return modeInputs[i].value;
return "guide";
}
function readProgress() {
try {
var raw = window.localStorage.getItem(PROGRESS_KEY);
var parsed = raw ? JSON.parse(raw) : null;
if (parsed && parsed.version === 1 && parsed.chapters && typeof parsed.chapters === "object") return parsed;
} catch (error) { /* Storage disabled: show a clean catalogue. */ }
return { chapters: {} };
}
function chapterHref(chapter, mode, withStep) {
var href = (chapter.entry === "native" ? "/?teach=" : "/?ui=web&teach=") + encodeURIComponent(chapter.id) + "&mode=" + encodeURIComponent(mode);
var entry = progress.chapters[chapter.id];
if (withStep && entry && entry.currentStepId) href += "&step=" + encodeURIComponent(entry.currentStepId);
return href;
}
function statusOf(chapter) {
var entry = progress.chapters[chapter.id];
var done = entry && Array.isArray(entry.completedStepIds) ? entry.completedStepIds.length : 0;
var total = chapter.steps || 1;
return { done: Math.min(done, total), total: total, entry: entry };
}
function card(chapter) {
var status = statusOf(chapter);
var percent = Math.round((status.done / status.total) * 100);
var article = document.createElement("article");
article.className = "teach-card" + (status.done >= status.total && status.total > 0 ? " is-done" : "");
article.dataset.chapter = chapter.id;
article.dataset.search = (chapter.id + " " + chapter.title + " " + chapter.summary + " " + chapter.partTitle).toLowerCase();
var top = document.createElement("div");
top.className = "teach-card-top";
var heading = document.createElement("h3");
var number = document.createElement("span");
number.className = "teach-number";
number.textContent = String(chapter.number).padStart(2, "0");
heading.appendChild(number);
heading.appendChild(document.createTextNode(chapter.title));
var ring = document.createElement("div");
ring.className = "teach-ring";
ring.style.setProperty("--done", String(percent));
ring.dataset.label = status.done + "/" + status.total;
ring.setAttribute("role", "img");
ring.setAttribute("aria-label", "本章进度 " + percent + "%");
top.appendChild(heading);
top.appendChild(ring);
var summary = document.createElement("p");
summary.textContent = chapter.summary;
var meta = document.createElement("div");
meta.className = "teach-meta";
[chapter.level, chapter.minutes + " 分钟", chapter.steps + " 步", chapter.workspace].forEach(function (text) {
var chip = document.createElement("span");
chip.textContent = text;
meta.appendChild(chip);
});
var actions = document.createElement("div");
actions.className = "teach-card-actions";
var start = document.createElement("a");
start.className = "teach-start";
start.href = chapterHref(chapter, selectedMode(), status.done > 0);
start.textContent = status.done > 0 && status.done < status.total ? "继续" : status.done >= status.total ? "复习" : "开始";
start.dataset.chapterStart = chapter.id;
var manual = document.createElement("a");
manual.className = "teach-manual";
manual.href = chapter.manual;
manual.textContent = "图文详解";
actions.appendChild(start);
actions.appendChild(manual);
article.appendChild(top);
article.appendChild(summary);
article.appendChild(meta);
article.appendChild(actions);
return article;
}
function render(catalog) {
chapters = catalog.chapters;
catalogEl.textContent = "";
catalog.parts.forEach(function (part) {
var section = document.createElement("section");
section.className = "teach-part";
var heading = document.createElement("h2");
heading.textContent = part.title;
var grid = document.createElement("div");
grid.className = "teach-grid";
part.chapters.forEach(function (id) {
var chapter = chapters.filter(function (item) { return item.id === id; })[0];
if (chapter) grid.appendChild(card(chapter));
});
section.appendChild(heading);
section.appendChild(grid);
catalogEl.appendChild(section);
});
refreshContinue();
applyFilter();
}
function refreshContinue() {
var latest = null;
Object.keys(progress.chapters).forEach(function (id) {
var entry = progress.chapters[id];
if (!entry || !entry.updatedAt) return;
if (!latest || entry.updatedAt > latest.entry.updatedAt) {
var chapter = chapters.filter(function (item) { return item.id === id; })[0];
if (chapter) latest = { chapter: chapter, entry: entry };
}
});
if (!latest) { continueEl.hidden = true; return; }
var status = statusOf(latest.chapter);
continueEl.hidden = false;
continueEl.textContent = "继续第 " + latest.chapter.number + " " + unit + ":" + latest.chapter.title + "(" + status.done + "/" + status.total + ")";
continueEl.dataset.href = chapterHref(latest.chapter, latest.entry.mode || selectedMode(), true);
}
function applyFilter() {
var query = (searchEl.value || "").trim().toLowerCase();
var cards = catalogEl.querySelectorAll(".teach-card");
for (var i = 0; i < cards.length; i += 1) {
cards[i].hidden = query.length > 0 && cards[i].dataset.search.indexOf(query) === -1;
}
var sections = catalogEl.querySelectorAll(".teach-part");
for (var j = 0; j < sections.length; j += 1) {
var visible = sections[j].querySelector(".teach-card:not([hidden])");
sections[j].hidden = !visible;
}
}
function showVersion() {
fetch("/wasm-module-manifest.json", { cache: "no-store" })
.then(function (response) { return response.ok ? response.json() : null; })
.then(function (manifest) {
if (!manifest) throw new Error("no manifest");
var release = manifest.releaseId || manifest.release || manifest.version || "unknown";
var wasm = manifest.wasmSha256 || manifest.sha256 || manifest.wasmHash || "";
versionEl.textContent = "当前线上版本身份:" + release + (wasm ? " · wasm " + String(wasm).slice(0, 12) : "");
})
.catch(function () { versionEl.textContent = "版本身份读取失败;教学目录仍可正常使用。"; });
}
continueEl.addEventListener("click", function () {
if (continueEl.dataset.href) window.location.href = continueEl.dataset.href;
});
searchEl.addEventListener("input", applyFilter);
modeInputs.forEach(function (input) {
input.addEventListener("change", function () {
var mode = selectedMode();
var starts = catalogEl.querySelectorAll("[data-chapter-start]");
for (var i = 0; i < starts.length; i += 1) {
var chapter = chapters.filter(function (item) { return item.id === starts[i].dataset.chapterStart; })[0];
if (chapter) starts[i].href = chapterHref(chapter, mode, starts[i].textContent === "继续");
}
});
});
progress = readProgress();
fetch(catalogUrl, { cache: "no-store" })
.then(function (response) {
if (!response.ok) throw new Error("HTTP " + response.status);
return response.json();
})
.then(render)
.catch(function (error) {
catalogEl.textContent = "";
var message = document.createElement("p");
message.className = "teach-error";
message.textContent = "教学目录加载失败:" + error.message;
catalogEl.appendChild(message);
});
showVersion();
})();