Web template: adopt session-evolved features + render-on-demand everywhere
Ported from the test3d-5 session build: in-page variant switching, share
link (full state in URL hash), auto tour, toast, building-grouped floor
toggles, per-(floor,category) geometry merge (draw calls), progressive
overview->standard loading. Hardened during the port: {{BUILD}} placeholder
restored (Date.now() defeated caching), single-GLB deployments skip the
phantom overview.glb phase, building-group fallback now derives from
floor-key prefixes (assemble_campus convention) instead of a hardcoded "A"
test, bookmarks completed (list + restore + remove + hash persistence).
Render-on-demand lands in BOTH the template and the offline viewer: static
scenes rendered at 60fps pegged the GPU/fans for identical frames —
invalidate()-driven rendering + shadowMap.autoUpdate=false (bake per
change). 27号 measured: template web 0 frames over 3s idle, offline viewer
25 frames total through load; features browser-verified (tour, bookmarks,
hash restore), zero console errors. window.__renders is the diagnostic
counter — idle growth must be 0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,6 +65,7 @@ MAIN_JS = r'''
|
||||
renderer.outputEncoding = THREE.sRGBEncoding;
|
||||
renderer.physicallyCorrectLights = true;
|
||||
renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
||||
renderer.shadowMap.autoUpdate = false; renderer.shadowMap.needsUpdate = true; // static scene: bake shadows on change only
|
||||
document.body.appendChild(renderer.domElement);
|
||||
const scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x23272d);
|
||||
@@ -73,6 +74,10 @@ MAIN_JS = r'''
|
||||
scene.environment = pmrem.fromScene(new THREE.RoomEnvironment(), 0.04).texture;
|
||||
const cam = new THREE.PerspectiveCamera(48, innerWidth/innerHeight, 0.5, 4000);
|
||||
const controls = new THREE.OrbitControls(cam, renderer.domElement); controls.enableDamping = true;
|
||||
// Render on demand: identical frames at 60fps peg the GPU/fans on a static scene.
|
||||
let renderPending = true; window.__renders = 0;
|
||||
const invalidate = (shadows) => { if (shadows) renderer.shadowMap.needsUpdate = true; renderPending = true; };
|
||||
controls.addEventListener('change', () => invalidate());
|
||||
const sun = new THREE.DirectionalLight(0xfff3e0, 3.2);
|
||||
sun.position.set(-120, 180, 140); sun.castShadow = true;
|
||||
sun.shadow.mapSize.set(2048,2048); sun.shadow.bias = -0.0004;
|
||||
@@ -129,8 +134,8 @@ MAIN_JS = r'''
|
||||
}
|
||||
const tg = document.getElementById('tg');
|
||||
const state = {fl:{}, ct:{}};
|
||||
const apply = () => nodes.forEach(o => { const p=(o.name||'').split('__');
|
||||
o.visible = (state.fl[p[0]]!==false) && (state.ct[p[1]]!==false) && p[1]!=='trees'; });
|
||||
const apply = () => { nodes.forEach(o => { const p=(o.name||'').split('__');
|
||||
o.visible = (state.fl[p[0]]!==false) && (state.ct[p[1]]!==false) && p[1]!=='trees'; }); invalidate(true); };
|
||||
for (const gname in GROUPS) {
|
||||
const head = document.createElement('div'); head.className='grp';
|
||||
const btn = document.createElement('button'); btn.textContent='开/关';
|
||||
@@ -164,7 +169,7 @@ MAIN_JS = r'''
|
||||
ptr.x=(e.clientX/innerWidth)*2-1; ptr.y=-(e.clientY/innerHeight)*2+1;
|
||||
ray.setFromCamera(ptr, cam);
|
||||
const hit = ray.intersectObjects(nodes.filter(o=>o.visible), false)[0];
|
||||
if (hi) { hi.material = hiMat; hi = null; }
|
||||
if (hi) { hi.material = hiMat; hi = null; invalidate(); }
|
||||
if (!hit) { info.style.display='none'; return; }
|
||||
hi = hit.object; hiMat = hi.material;
|
||||
hi.material = hiMat.clone(); hi.material.emissive = new THREE.Color(0x2a6bd4); hi.material.emissiveIntensity = 0.55;
|
||||
@@ -172,10 +177,15 @@ MAIN_JS = r'''
|
||||
let fname=''; for (const gname in GROUPS) GROUPS[gname].forEach(f => { if (f[0]===p[0]) fname=f[1]; });
|
||||
info.innerHTML = '<b>'+p[0]+'</b> '+fname+'<br>构件:'+(CATS[p[1]]||p[1])+' 节点:'+hi.name;
|
||||
info.style.display = 'block';
|
||||
invalidate();
|
||||
});
|
||||
invalidate(true);
|
||||
renderer.setAnimationLoop(() => {
|
||||
const moved = controls.update();
|
||||
if (moved || renderPending) { renderer.render(scene, cam); window.__renders += 1; renderPending = false; }
|
||||
});
|
||||
renderer.setAnimationLoop(() => { controls.update(); renderer.render(scene, cam); });
|
||||
}, e => fail('GLB 解析错误 '+(e && e.message || e)));
|
||||
addEventListener('resize', () => { cam.aspect=innerWidth/innerHeight; cam.updateProjectionMatrix(); renderer.setSize(innerWidth,innerHeight); });
|
||||
addEventListener('resize', () => { cam.aspect=innerWidth/innerHeight; cam.updateProjectionMatrix(); renderer.setSize(innerWidth,innerHeight); invalidate(); });
|
||||
} catch (err) { fail(err.message || String(err)); }
|
||||
})();
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user