feat: mode debug, objets des zones actives teintés et nommés

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PAZVXsUH5YDVmMp46Bii1C
This commit is contained in:
Julien Quiaios 2026-10-24 16:43:46 +00:00
parent 12406dd0d5
commit 815644144c
2 changed files with 100 additions and 1 deletions

View File

@ -77,6 +77,9 @@ export class ThreeRenderer extends BaseRenderer {
private wasAnimating = false; private wasAnimating = false;
private downAt: [number, number] = [0, 0]; private downAt: [number, number] = [0, 0];
private debugHit = ''; private debugHit = '';
/** Mode debug : objets des zones actives redessinés teintés (voir renderDebugZones). */
private zoneLabels: HTMLElement | null = null;
private debugMats = new Map<string, THREE.Material>();
private loadingEl: HTMLElement; private loadingEl: HTMLElement;
/** Préchargement GPU en cours (écran de chargement affiché). */ /** Préchargement GPU en cours (écran de chargement affiché). */
private warming = true; private warming = true;
@ -345,6 +348,7 @@ export class ThreeRenderer extends BaseRenderer {
for (const name of ([] as string[]).concat(hs.object ?? [])) this.hotspotByName.set(name, hs); for (const name of ([] as string[]).concat(hs.object ?? [])) this.hotspotByName.set(name, hs);
} }
if (this.hovered && ![...this.hotspotByName.values()].includes(this.hovered)) this.setHovered(null, null); if (this.hovered && ![...this.hotspotByName.values()].includes(this.hovered)) this.setHovered(null, null);
this.dirty = true;
// Règles d'état (équivalent 3D des calques) // Règles d'état (équivalent 3D des calques)
for (const [name, p] of this.props) { for (const [name, p] of this.props) {
@ -531,7 +535,91 @@ export class ThreeRenderer extends BaseRenderer {
// --- Mode debug : caméra libre + copie du point de vue ---------------------------------------- // --- Mode debug : caméra libre + copie du point de vue ----------------------------------------
/** Debug : active ou retire la surcouche des zones (objets teintés + étiquettes). */
private showDebugZones(on: boolean): void {
if (on && !this.zoneLabels) {
this.zoneLabels = document.createElement('div');
this.zoneLabels.className = 'debug-zones';
}
if (on) this.sceneLayer.appendChild(this.zoneLabels!);
else this.zoneLabels?.remove();
this.dirty = true;
}
/** Matériau de debug mis en cache (une couleur par zone, même face visible que l'original). */
private debugMat(color: string | null, side: THREE.Side): THREE.Material {
const key = `${color ?? 'depth'}|${side}`;
let m = this.debugMats.get(key);
if (!m) {
m = color
? new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.5, side, depthWrite: true, toneMapped: false })
: new THREE.MeshBasicMaterial({ colorWrite: false, side });
this.debugMats.set(key, m);
}
return m;
}
/**
* Surcouche debug : les objets 3D nommés par les zones actives du JSON, redessinés teintés par-dessus
* l'image. Ce sont les mêmes maillages que ceux touchés par le rayon du clic (zones invisibles
* `pickZone` comprises) ; les autres objets n'écrivent que la profondeur, donc ce qui cache un objet
* le cache aussi ici, comme pour le clic.
*/
private renderDebugZones(): void {
const owner = new Map<THREE.Object3D, string>();
for (const [name, hs] of this.hotspotByName) {
const obj = this.world.root.getObjectByName(name);
if (obj) owner.set(obj, hs.id);
}
const swapped: [THREE.Mesh, THREE.Material | THREE.Material[]][] = [];
const centers = new Map<string, THREE.Box3>();
const visit = (o: THREE.Object3D, zone: string | null): void => {
const z = owner.get(o) ?? zone;
if (o instanceof THREE.Mesh) {
const side = (Array.isArray(o.material) ? o.material[0] : o.material).side;
swapped.push([o, o.material]);
o.material = this.debugMat(z ? zoneColor(z) : null, side);
if (z && o.visible) (centers.get(z) ?? centers.set(z, new THREE.Box3()).get(z)!).expandByObject(o);
}
for (const c of o.children) visit(c, z);
};
visit(this.world.root, null);
const bg = this.scene3d.background;
const shadowAuto = this.gl.shadowMap.autoUpdate;
this.scene3d.background = null;
this.gl.shadowMap.autoUpdate = false;
this.camera.layers.enable(PICK_LAYER);
this.gl.setRenderTarget(null);
this.gl.autoClear = false;
this.gl.clearDepth();
this.gl.render(this.scene3d, this.camera);
this.gl.autoClear = true;
this.camera.layers.disable(PICK_LAYER);
this.gl.shadowMap.autoUpdate = shadowAuto;
this.scene3d.background = bg;
for (const [m, mat] of swapped) m.material = mat;
// Étiquettes (nom de la zone, posé au centre de ses objets : simple repère de lecture).
const layer = this.zoneLabels!;
layer.replaceChildren();
const r = this.gl.domElement.getBoundingClientRect();
const v = new THREE.Vector3();
for (const [id, box] of centers) {
box.getCenter(v).project(this.camera);
if (v.z > 1) continue;
const d = document.createElement('div');
d.className = 'debug-zone-label';
d.style.left = `${((v.x + 1) / 2) * r.width}px`;
d.style.top = `${((1 - v.y) / 2) * r.height}px`;
d.style.color = zoneColor(id);
d.textContent = id;
layer.appendChild(d);
}
}
protected onDebugChanged(): void { protected onDebugChanged(): void {
this.showDebugZones(this.debug);
if (this.debug) { if (this.debug) {
this.camAnim = null; this.camAnim = null;
this.controls = new OrbitControls(this.camera, this.gl.domElement); this.controls = new OrbitControls(this.camera, this.gl.domElement);
@ -550,7 +638,7 @@ export class ThreeRenderer extends BaseRenderer {
} }
private copyHint(): void { private copyHint(): void {
this.showMessage('Debug 3D : glisser = orbiter, molette = zoom, clic droit + glisser = déplacer · C = copier le point de vue · D = quitter', 'info'); this.showMessage('Debug 3D : zones cliquables en rose · glisser = orbiter, molette = zoom, clic droit + glisser = déplacer · C = copier le point de vue · D = quitter', 'info');
} }
protected onExtraKey(e: KeyboardEvent): void { protected onExtraKey(e: KeyboardEvent): void {
@ -601,6 +689,14 @@ export class ThreeRenderer extends BaseRenderer {
if (!animating && !this.dirty) return; if (!animating && !this.dirty) return;
this.dirty = false; this.dirty = false;
this.composer.render(dt); this.composer.render(dt);
if (this.debug) this.renderDebugZones();
}; };
} }
/** Couleur stable par zone (teinte dérivée de l'identifiant). */
function zoneColor(id: string): string {
let h = 0;
for (const c of id) h = (h * 31 + c.charCodeAt(0)) >>> 0;
return `hsl(${h % 360}, 90%, 60%)`;
}

View File

@ -190,6 +190,9 @@ button.primary:hover { background: #dbb55c; }
z-index: 30; z-index: 30;
} }
.debug .debug-info { display: block; } .debug .debug-info { display: block; }
/* Mode debug : étiquettes des zones (les objets eux-mêmes sont teintés dans le rendu 3D). */
.debug-zones { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.debug-zone-label { position: absolute; transform: translate(-50%, -50%); font: 12px/1 ui-monospace, monospace; white-space: nowrap; text-shadow: 0 0 3px #000, 0 0 3px #000; }
.drag-box { position: absolute; border: 2px solid #ffe14d; background: rgba(255, 225, 77, .15); pointer-events: none; z-index: 25; } .drag-box { position: absolute; border: 2px solid #ffe14d; background: rgba(255, 225, 77, .15); pointer-events: none; z-index: 25; }
/* Messages et infobulle */ /* Messages et infobulle */