feat(web): draggable floating panels and a non-hanging tutorial demo open
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

- add a shared useDraggablePanel hook (pointer capture, clamping, offset
  persistence in localStorage, double-click / button / menu reset) and use it
  for the tutorial step panel, the quick toolbar, the adjust-last-operation
  panel and the robot tool drawer
- quick toolbar drags out of the dock into a compact floating bar and can be
  folded; robot tool scrim is transparent and click-through so the 3D scene
  stays visible and usable while the tool is open
- 窗口 > 恢复默认面板位置 clears every stored panel offset
- fix a pre-existing hang: tutorial demo scene opens went through the
  "save current project?" prompt and waited forever; course demos now persist
  the current OPFS project like the dialog's 保存后继续 and continue
- PBR tutorial spec: demos must not auto-download .blend (OPFS-only rule)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-23 21:43:40 +08:00
parent cb2829cad1
commit 2c8449f422
15 changed files with 716 additions and 92 deletions

View File

@@ -0,0 +1,67 @@
#!/usr/bin/env node
/**
* Build a self-contained offline copy of the Web Blender user manual.
*
* node tools/web/build-offline-manual.mjs [outputDir]
*
* The manual's search is client-side (`data-search` attributes) so no server
* is needed: rewriting the absolute paths to relative ones makes the page work
* from file://. Step images that the manual embeds from /tutorial/full/steps
* are copied alongside; links into the running app or the online course are
* neutralised because they cannot resolve offline.
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const source = path.join(repoRoot, "web/dist/manuals");
const output = path.resolve(process.argv[2] ?? path.join(repoRoot, "web/manual-offline"));
if (!fs.existsSync(path.join(source, "index.html"))) {
throw new Error(`manual source missing: ${source} (run the web build first)`);
}
if (output === source || output.startsWith(`${source}${path.sep}`)) throw new Error("refusing to build into the source directory");
fs.rmSync(output, { recursive: true, force: true });
fs.mkdirSync(output, { recursive: true });
fs.cpSync(source, output, { recursive: true });
let html = fs.readFileSync(path.join(output, "index.html"), "utf8");
const copied = new Set();
/* Local manual assets and step images referenced from the tutorial tree. */
/* Attributes are preceded by whitespace, not a quote: match the name and the
* opening quote only. */
html = html.replace(/\b(src|href)="\/manuals\//g, '$1="./');
html = html.replace(/\b(src|href)="\/tutorial\/full\/steps\/([^"]+)"/g, (match, name, file) => {
const from = path.join(repoRoot, "web/dist/tutorial/full/steps", file);
const to = path.join(output, "tutorial/full/steps", file);
if (fs.existsSync(from)) {
fs.mkdirSync(path.dirname(to), { recursive: true });
if (!copied.has(file)) { fs.copyFileSync(from, to); copied.add(file); }
}
return `${name}="./tutorial/full/steps/${file}"`;
});
/* Offline mode has no web app or online course to open. */
const before = html;
html = html.replace(/href="\/(?:\?ui=web|tutorial\/[^"]*)"/g, 'href="#" data-offline-link="unavailable" title="离线手册不含该在线页面"');
html = html.replace(/href="\/"/g, 'href="#" data-offline-link="unavailable" title="离线手册不含在线应用"');
if (html !== before) html = html.replace("<body", '<body data-offline="1"');
fs.writeFileSync(path.join(output, "index.html"), html);
const files = [];
const walk = (dir) => {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full);
else files.push(full);
}
};
walk(output);
const bytes = files.reduce((sum, file) => sum + fs.statSync(file).size, 0);
fs.writeFileSync(path.join(output, "OFFLINE.txt"),
`Web Blender 用户手册(离线版)\n\n双击 index.html 即可使用,无需联网或启动服务器。\n` +
`搜索框在页面顶部,支持章节全文过滤。\nPDF 手册位于本目录根下。\n\n构建来源:web/dist/manuals\n`);
console.log(`offline-manual-ok dir=${output} files=${files.length} bytes=${bytes}`);

166
tools/web/deploy-58014.sh Executable file
View File

@@ -0,0 +1,166 @@
#!/usr/bin/env bash
# One-command publish of the Web Blender build to https://<host>:58014/.
#
# tools/web/deploy-58014.sh # build, upload, switch, verify
# tools/web/deploy-58014.sh --skip-build # publish the existing web/dist
# tools/web/deploy-58014.sh --release-id X # explicit release directory name
# tools/web/deploy-58014.sh --rollback ID # switch `current` to an existing release
#
# Credentials: a working SSH key for the deploy user, or the password in
# BW_DEPLOY_PASSWORD, or a 0600 file at ~/.config/blender-web/deploy.env
# containing `BW_DEPLOY_PASSWORD=...`.
set -euo pipefail
HOST="${BW_DEPLOY_HOST:-49.232.250.35}"
SSH_PORT="${BW_DEPLOY_SSH_PORT:-22}"
DEPLOY_USER="${BW_DEPLOY_USER:-ubuntu}"
WEB_PORT="${BW_DEPLOY_WEB_PORT:-58014}"
SERVICE="${BW_DEPLOY_SERVICE:-blender-web-58014}"
WEBROOT="${BW_DEPLOY_ROOT:-/var/www/blender-web}"
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$repo_root"
skip_build=0
release_id=""
rollback_id=""
while [ $# -gt 0 ]; do
case "$1" in
--skip-build) skip_build=1; shift ;;
--release-id) release_id="${2:?--release-id needs a value}"; shift 2 ;;
--rollback) rollback_id="${2:?--rollback needs a value}"; shift 2 ;;
-h|--help) sed -n '2,12p' "$0"; exit 0 ;;
*) echo "unknown option: $1" >&2; exit 2 ;;
esac
done
# ---- ssh plumbing (password via askpass when no key is authorised) ----------
ssh_base=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/tmp/blender-web-deploy-known-hosts
-o PreferredAuthentications=publickey,password -o PubkeyAuthentication=yes
-o ConnectTimeout=15 -p "$SSH_PORT")
askpass=""
cleanup() { [ -n "$askpass" ] && rm -f "$askpass"; }
trap cleanup EXIT
if ! ssh "${ssh_base[@]}" -o BatchMode=yes -o PasswordAuthentication=no "$DEPLOY_USER@$HOST" true 2>/dev/null; then
if [ -z "${BW_DEPLOY_PASSWORD:-}" ] && [ -f "$HOME/.config/blender-web/deploy.env" ]; then
# shellcheck disable=SC1090
. "$HOME/.config/blender-web/deploy.env"
fi
if [ -z "${BW_DEPLOY_PASSWORD:-}" ]; then
echo "error: no SSH key and BW_DEPLOY_PASSWORD is unset" >&2
echo " export BW_DEPLOY_PASSWORD=... or write ~/.config/blender-web/deploy.env" >&2
exit 2
fi
askpass="$(mktemp)"
# Quoted format: an unquoted `\n` would be eaten by the shell and corrupt the
# password with a trailing "n".
printf '#!/bin/sh\nexec printf "%%s\\n" %q\n' "$BW_DEPLOY_PASSWORD" > "$askpass"
chmod 700 "$askpass"
export SSH_ASKPASS="$askpass" SSH_ASKPASS_REQUIRE=force
ssh_run() { setsid -w ssh "${ssh_base[@]}" "$@"; }
scp_run() { setsid -w scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/tmp/blender-web-deploy-known-hosts \
-o PreferredAuthentications=publickey,password -P "$SSH_PORT" "$@"; }
else
ssh_run() { ssh "${ssh_base[@]}" "$@"; }
scp_run() { scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/tmp/blender-web-deploy-known-hosts -P "$SSH_PORT" "$@"; }
fi
# ---- rollback fast path -----------------------------------------------------
if [ -n "$rollback_id" ]; then
ssh_run "$DEPLOY_USER@$HOST" "
set -euo pipefail
target='$WEBROOT/releases/$rollback_id'
test -d \"\$target\"
sudo ln -sfn \"\$target\" '$WEBROOT/current'
sudo systemctl restart '$SERVICE'
sleep 3
systemctl is-active '$SERVICE'
echo current=\$(readlink -f '$WEBROOT/current')
curl -sk -o /dev/null -w 'health=%{http_code}\\n' https://127.0.0.1:$WEB_PORT/"
exit $?
fi
# ---- build ------------------------------------------------------------------
if [ "$skip_build" -eq 0 ]; then
echo "== build"
( cd web && npm run build )
fi
test -f web/dist/index.html
test -f docs/web/deployment-contract.json
short_sha="$(git rev-parse --short HEAD 2>/dev/null || echo local)"
[ -n "$release_id" ] || release_id="$(date +%Y%m%d)-$(basename "$repo_root" | tr '[:upper:]' '[:lower:]')-$short_sha"
# ---- assemble the release tree (app/, tools/, docs/, metadata) --------------
echo "== assemble $release_id"
stage="$(mktemp -d)"
trap 'rm -rf "$stage"; cleanup' EXIT
mkdir -p "$stage/app" "$stage/tools" "$stage/docs/web"
cp -a web/dist/. "$stage/app/"
cp -a tools/web "$stage/tools/"
cp docs/web/deployment-contract.json "$stage/docs/web/"
node - "$stage" "$release_id" "$short_sha" <<'NODE'
const fs = require("node:fs"), path = require("node:path"), crypto = require("node:crypto");
const [stage, releaseId, shortSha] = process.argv.slice(2);
const sha = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
const app = path.join(stage, "app");
const html = fs.readFileSync(path.join(app, "index.html"), "utf8");
const css = /href="(\/assets\/[^"]+\.css)"/.exec(html)?.[1];
const js = /src="(\/assets\/[^"]+\.js)"/.exec(html)?.[1];
const engine = JSON.parse(fs.readFileSync(path.join(app, "engine-manifest.json"), "utf8"));
fs.writeFileSync(path.join(stage, "release-metadata.json"), JSON.stringify({
schemaVersion: 1,
product: "Web Blender Modeler V1",
gitCommit: shortSha,
releaseId,
engineReleaseId: engine.releaseId ?? engine.engineVersion ?? "unknown",
webEngineWasmSha256: sha(path.join(app, "vendor/blender/web_engine.wasm")),
entryDocumentSha256: sha(path.join(app, "index.html")),
cssSha256: css ? sha(path.join(app, css.slice(1))) : "",
javascriptSha256: js ? sha(path.join(app, js.slice(1))) : "",
manual: "/manuals/index.html",
manualChapters: 28,
}, null, 2) + "\n");
NODE
archive="/tmp/blender-web-$release_id.tar.gz"
tar -czf "$archive" -C "$stage" .
# ---- upload -----------------------------------------------------------------
echo "== upload $(du -h "$archive" | cut -f1)"
scp_run "$archive" "$DEPLOY_USER@$HOST:/tmp/"
# ---- switch + restart + health ---------------------------------------------
echo "== deploy"
ssh_run "$DEPLOY_USER@$HOST" "
set -euo pipefail
target='$WEBROOT/releases/$release_id'
sudo mkdir -p \"\$target\"
sudo tar -xzf '/tmp/blender-web-$release_id.tar.gz' -C \"\$target\"
sudo chown -R root:root \"\$target\"
sudo chmod -R a+rX \"\$target\"
test -f \"\$target/app/index.html\"
test -f \"\$target/tools/web/deployment-http-server.mjs\"
test -f \"\$target/docs/web/deployment-contract.json\"
previous=\"\$(readlink -f '$WEBROOT/current' || true)\"
sudo ln -sfn \"\$target\" '$WEBROOT/current'
sudo systemctl restart '$SERVICE'
sleep 3
systemctl is-active '$SERVICE'
echo previous=\"\$previous\"
echo current=\"\$(readlink -f '$WEBROOT/current')\"
curl -sk -o /dev/null -w 'health=%{http_code}\\n' https://127.0.0.1:$WEB_PORT/"
# ---- verify the public endpoint --------------------------------------------
echo "== verify https://$HOST:$WEB_PORT/"
origin="https://$HOST:$WEB_PORT"
index_status="$(curl -sk -o /dev/null -w '%{http_code}' "$origin/")"
wasm_local="$(sha256sum web/dist/vendor/blender/web_engine.wasm | cut -d' ' -f1)"
wasm_remote="$(curl -sk "$origin/vendor/blender/web_engine.wasm" | sha256sum | cut -d' ' -f1)"
bin_status="$(curl -sk -o /dev/null -w '%{http_code}' "$origin/lights/forest.bin")"
echo "index=$index_status wasm_local=$wasm_local wasm_remote=$wasm_remote studios=$bin_status"
[ "$index_status" = "200" ] && [ "$wasm_local" = "$wasm_remote" ] && [ "$bin_status" = "200" ] || {
echo "verification failed; roll back with: $0 --rollback <previous-release>" >&2; exit 1; }
echo "published $release_id -> $origin/"