fix: enforce complete building and offline viewer gates

This commit is contained in:
2026-07-10 14:04:10 +08:00
parent cab4d320c0
commit a761175c09
13 changed files with 401 additions and 25 deletions

View File

@@ -27,6 +27,7 @@ import argparse
import base64
import gzip
import json
import struct
from pathlib import Path
import showcase_schema
@@ -53,6 +54,18 @@ def group_of(key: str) -> str:
return "主体"
def glb_extensions(path: Path) -> set[str]:
"""Return extensionsUsed from the GLB JSON chunk without extra dependencies."""
data = path.read_bytes()
if len(data) < 20 or data[:4] != b"glTF":
raise SystemExit(f"Not a valid GLB: {path}")
chunk_length, chunk_type = struct.unpack_from("<II", data, 12)
if chunk_type != 0x4E4F534A or 20 + chunk_length > len(data):
raise SystemExit(f"GLB JSON chunk is missing or truncated: {path}")
document = json.loads(data[20 : 20 + chunk_length].decode("utf-8").rstrip("\x00 \t\r\n"))
return set(document.get("extensionsUsed", []))
MAIN_JS = r"""
(async function(){
const $load = document.getElementById('load');
@@ -119,6 +132,7 @@ MAIN_JS = r"""
}
if (cat === 'trees') o.visible = false;
});
window.__offlineReady = {meshes:nodes.length};
if (TREES.length) {
const ti = new THREE.InstancedMesh(new THREE.CylinderGeometry(0.14,0.2,1.4,6),
new THREE.MeshStandardMaterial({color:0x6b4a2e, roughness:0.9}), TREES.length);
@@ -212,6 +226,12 @@ def main() -> int:
glb_path = Path(args.glb)
if not glb_path.exists() or glb_path.stat().st_size == 0:
raise SystemExit(f"GLB not found or empty: {glb_path}")
extensions = glb_extensions(glb_path)
if "KHR_draco_mesh_compression" in extensions:
raise SystemExit(
"Offline single-file viewer requires an uncompressed GLB; "
f"KHR_draco_mesh_compression found in {glb_path}. Pass the matching *.raw.glb instead."
)
spec = showcase_schema.normalize_spec(json.loads(spec_path.read_text(encoding="utf-8")))
try:
showcase_schema.validate_spec(spec)