ploxion-3d/app.blade.php

228 lines
14 KiB
PHP
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.

{{-- PL0XI0N 3d — LE SITE EN 3D (mandat RS-7 : « le site en 3d et 4d »). Embryon
site-side du rally flotte : on rend le XERB0XI0N comme un espace navigable.
Three.js (ESM depuis unpkg, autorisé par la CSP). Chaque ploxion = un nœud,
forme/couleur selon son type (réel/cubion/domaine/concept), cubions reliés à
leurs membres. Orbite custom (drag = tourner, molette = zoom), clic = label.
Données LOCALES (/ploxions/registry.json) ; la 4D (events live + replay tsoin)
viendra du xion via le relais Phase B. window.jOSApps['3d']. mount->{unmount}.
IN bus : ploxion.3d.node (jOSWire route forge.add → ici) = un ploxion tout juste
forgé naît comme nouveau nœud brillant dans le graphe.
3D = l'espace (structure), 4D = le temps (à venir). --}}
<style>
.x3 { position:relative; height:100%; background:radial-gradient(circle at 50% 40%, #0a1424, #04060a 75%); overflow:hidden; }
.x3 canvas { display:block; }
.x3__hud { position:absolute; top:9px; left:11px; z-index:3; font-family:ui-sans-serif,system-ui,sans-serif;
color:rgba(200,220,240,.9); font-size:.78rem; pointer-events:none; }
.x3__hud b { color:rgba(150,200,255,.95); letter-spacing:.04em; }
.x3__sub { font-size:.64rem; color:rgba(160,185,215,.55); margin-top:2px; }
.x3__leg { position:absolute; bottom:9px; left:11px; z-index:3; display:flex; flex-wrap:wrap; gap:7px;
font-size:.64rem; color:rgba(190,210,232,.8); font-family:ui-sans-serif,system-ui,sans-serif; }
.x3__lg { display:flex; align-items:center; gap:4px; }
.x3__sw { width:9px; height:9px; border-radius:2px; }
.x3__tip { position:absolute; z-index:4; padding:3px 9px; border-radius:7px; background:rgba(10,16,28,.9);
border:1px solid rgba(120,170,255,.5); color:#fff; font-size:.74rem; font-family:ui-sans-serif,system-ui,sans-serif;
pointer-events:none; transform:translate(-50%,-140%); white-space:nowrap; opacity:0; transition:opacity .1s; }
.x3__msg { position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
color:rgba(190,212,228,.6); font-family:ui-sans-serif,system-ui,sans-serif; font-size:.84rem; }
</style>
<script>
(function () {
var THREE_URL = '/vendor/js/three.module.js';
function colorFor(k) {
return k === 'cubion' ? 0x5aaaff : k === 'domaine' ? 0xc890ff : k === 'concept' ? 0x8aa0bc : 0x5adc8c;
}
// payload du port 3d.node -> {id,name,kind,icon,url} ; gère la string du hook forge
// ("<id> (<template>)"), sa forme routée {value,__wired,__via} (métadonnées ignorées) et l'objet direct.
function nodeFromPayload(payload) {
var p = payload;
if (p && typeof p === 'object' && typeof p.value === 'string' && !p.id && !p.name) p = p.value;
if (typeof p === 'string') {
var m = p.trim().match(/^([\w.\-]+)(?:\s*\((.+)\))?/);
return m ? { id: m[1], name: m[1] + (m[2] ? ' · ' + m[2] : ''), kind: 'forged' } : null;
}
if (!p || typeof p !== 'object') return null;
var id = p.id || p.ploxion || p.name;
return id ? { id: String(id), name: String(p.name || id), kind: p.kind || 'forged', icon: p.icon, url: p.url } : null;
}
function mount(container, ctx) {
var alive = true, raf = 0, ro = null, THREE = null, renderer = null;
var busOffs = [], addNodeFn = null, pendingNodes = [];
container.innerHTML =
'<div class="x3">'
+ ' <div class="x3__hud"><b>XERB0XI0N · 3D</b><div class="x3__sub">l’espace des ploxions · drag = tourner · molette = zoom</div></div>'
+ ' <div class="x3__leg">'
+ ' <span class="x3__lg"><span class="x3__sw" style="background:#5adc8c"></span>ploxion réel</span>'
+ ' <span class="x3__lg"><span class="x3__sw" style="background:#5aaaff"></span>cubion</span>'
+ ' <span class="x3__lg"><span class="x3__sw" style="background:#c890ff"></span>domaine</span>'
+ ' <span class="x3__lg"><span class="x3__sw" style="background:#8aa0bc"></span>concept</span></div>'
+ ' <div class="x3__tip"></div>'
+ ' <div class="x3__msg">chargement de la 3D…</div>'
+ '</div>';
var root = container.querySelector('.x3'), tip = container.querySelector('.x3__tip');
var msg = container.querySelector('.x3__msg');
// IN bus : ploxion.3d.node — un ploxion forgé (forge.add, routé par jOSWire) devient un nœud du graphe.
// Abonné dès le mount ; tant que la scène n'est pas construite, on met en file.
try {
if (window.jOSPorts && window.jOSPorts.on) {
busOffs.push(window.jOSPorts.on('ploxion.3d.node', function (payload) {
try {
var p = nodeFromPayload(payload);
if (!p || !p.id) return;
if (addNodeFn) addNodeFn(p); else pendingNodes.push(p);
} catch (e) {}
}));
}
} catch (e) {}
Promise.all([
import(THREE_URL),
fetch('/xion/snapshot', { headers: { Accept: 'application/json' } }).then(function (r) { return r.ok ? r.json() : { ploxions: [], bus: [] }; }).catch(function () { return { ploxions: [], bus: [] }; })
]).then(function (res) {
if (!alive) return;
THREE = res[0];
var snap = res[1] || { ploxions: [], bus: [] };
if (!snap.ploxions || !snap.ploxions.length) { msg.textContent = 'snapshot vide'; return; }
msg.remove();
build(THREE, snap);
}).catch(function (e) { if (alive) msg.textContent = '3D indisponible (' + (e && e.message ? e.message : 'erreur') + ')'; });
function build(THREE, snap) {
var data = snap.ploxions || [];
var sub = root.querySelector('.x3__sub'); if (sub) { sub.textContent += ' · source: ' + (snap.source || 'local'); if (snap.counts) sub.textContent += ' · ' + (snap.counts.running || 0) + ' running / ' + (snap.counts.total || data.length); }
var W = root.clientWidth || 600, H = root.clientHeight || 400;
var scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x04060a, 0.0085);
var camera = new THREE.PerspectiveCamera(55, W / H, 0.1, 2000);
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(W, H);
root.appendChild(renderer.domElement);
scene.add(new THREE.AmbientLight(0x88aaff, 0.7));
var dl = new THREE.DirectionalLight(0xffffff, 0.9); dl.position.set(40, 60, 50); scene.add(dl);
// distribution sur une sphère de Fibonacci
var R = 60, idx = {}, nodes = [];
var geoP = new THREE.IcosahedronGeometry(1.5, 0); // ploxion réel
var geoCu = new THREE.BoxGeometry(2.4, 2.4, 2.4); // cubion
var geoD = new THREE.TetrahedronGeometry(1.7, 0); // domaine
var geoCo = new THREE.IcosahedronGeometry(1.2, 0); // concept
var N = data.length;
data.forEach(function (p, i) {
var y = 1 - (i / Math.max(1, N - 1)) * 2, r = Math.sqrt(1 - y * y);
var th = i * 2.399963229728653; // angle d'or
var pos = new THREE.Vector3(Math.cos(th) * r * R, y * R, Math.sin(th) * r * R);
var isC = p.kind === 'concept';
var geo = p.kind === 'cubion' ? geoCu : p.kind === 'domaine' ? geoD : (!isC ? geoP : geoCo);
var col = colorFor(p.kind);
// état live du xion (contrat #144) : running=vif, registered=fantôme, deployed=brillant
var emi = isC ? 0.12 : 0.34, op = isC ? 0.7 : 1;
if (p.state === 'running') { emi = 0.78; }
else if (p.state === 'registered') { emi = 0.16; op = 0.5; }
else if (p.state === 'deployed') { emi = 0.5; }
var mat = new THREE.MeshStandardMaterial({ color: col, emissive: col, emissiveIntensity: emi, roughness: 0.5, metalness: 0.3, transparent: isC || op < 1, opacity: op });
var m = new THREE.Mesh(geo, mat); m.position.copy(pos); m.userData = p;
scene.add(m); nodes.push(m); idx[p.id] = pos;
});
// arêtes du bus (contrat 3D #139) : from -> to[]
var lmat = new THREE.LineBasicMaterial({ color: 0x3a6cff, transparent: true, opacity: 0.22 });
(snap.bus || []).forEach(function (e) {
if (!idx[e.from]) return;
(e.to || []).forEach(function (t) {
if (!idx[t]) return;
var g = new THREE.BufferGeometry().setFromPoints([idx[e.from], idx[t]]);
scene.add(new THREE.Line(g, lmat));
});
});
// IN 3d.node : un ploxion tout juste forgé naît comme nœud brillant sur la sphère
var born = 0;
addNodeFn = function (p) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].userData && nodes[i].userData.id === p.id) { nodes[i].material.emissiveIntensity = 0.9; return; } // déjà là : le raviver
}
var y2 = Math.random() * 2 - 1, r2 = Math.sqrt(Math.max(0, 1 - y2 * y2)), th2 = Math.random() * Math.PI * 2;
var pos2 = new THREE.Vector3(Math.cos(th2) * r2 * R, y2 * R, Math.sin(th2) * r2 * R);
var col2 = colorFor(p.kind);
var m2 = new THREE.Mesh(geoP, new THREE.MeshStandardMaterial({ color: col2, emissive: col2, emissiveIntensity: 0.85, roughness: 0.5, metalness: 0.3 }));
m2.position.copy(pos2); m2.userData = p;
scene.add(m2); nodes.push(m2); idx[p.id] = pos2;
born++;
if (sub) sub.textContent = sub.textContent.replace(/ · \+\d+ forgés?$/, '') + ' · +' + born + ' forgé' + (born > 1 ? 's' : '');
};
pendingNodes.splice(0).forEach(addNodeFn);
// caméra orbitale (custom)
var tgt = new THREE.Vector3(0, 0, 0), yaw = 0.4, pitch = 0.3, dist = 150;
function place() {
camera.position.set(
tgt.x + dist * Math.cos(pitch) * Math.sin(yaw),
tgt.y + dist * Math.sin(pitch),
tgt.z + dist * Math.cos(pitch) * Math.cos(yaw));
camera.lookAt(tgt);
}
var drag = null;
renderer.domElement.addEventListener('pointerdown', function (e) { drag = { x: e.clientX, y: e.clientY }; renderer.domElement.setPointerCapture(e.pointerId); });
renderer.domElement.addEventListener('pointermove', function (e) {
var rect = renderer.domElement.getBoundingClientRect();
if (drag) {
yaw -= (e.clientX - drag.x) * 0.006; pitch += (e.clientY - drag.y) * 0.006;
pitch = Math.max(-1.4, Math.min(1.4, pitch)); drag = { x: e.clientX, y: e.clientY };
} else { hover(e.clientX - rect.left, e.clientY - rect.top, rect); }
});
renderer.domElement.addEventListener('pointerup', function () { drag = null; });
renderer.domElement.addEventListener('wheel', function (e) { e.preventDefault(); dist = Math.max(40, Math.min(420, dist * (1 + (e.deltaY > 0 ? 0.1 : -0.1)))); }, { passive: false });
// hover/clic → label
var ray = new THREE.Raycaster(), mouse = new THREE.Vector2();
function hover(x, y, rect) {
mouse.x = (x / rect.width) * 2 - 1; mouse.y = -(y / rect.height) * 2 + 1;
ray.setFromCamera(mouse, camera);
var hit = ray.intersectObjects(nodes, false)[0];
if (hit) {
var p = hit.object.userData;
tip.textContent = (p.icon ? p.icon + ' ' : '') + p.name;
tip.style.left = x + 'px'; tip.style.top = y + 'px'; tip.style.opacity = '1';
renderer.domElement.style.cursor = 'pointer';
} else { tip.style.opacity = '0'; renderer.domElement.style.cursor = 'grab'; }
}
renderer.domElement.addEventListener('click', function (e) {
var rect = renderer.domElement.getBoundingClientRect();
mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1; mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;
ray.setFromCamera(mouse, camera);
var hit = ray.intersectObjects(nodes, false)[0];
if (hit && hit.object.userData.url) window.open(hit.object.userData.url, '_blank');
});
function resize() {
var w = root.clientWidth || 600, h = root.clientHeight || 400;
camera.aspect = w / h; camera.updateProjectionMatrix(); renderer.setSize(w, h);
}
if ('ResizeObserver' in window) { ro = new ResizeObserver(resize); ro.observe(root); }
(function loop() {
if (!alive) return;
raf = requestAnimationFrame(loop);
yaw += 0.0009; // dérive lente
scene.rotation.y = 0;
nodes.forEach(function (m) { m.rotation.y += 0.004; m.rotation.x += 0.002; });
place(); renderer.render(scene, camera);
})();
}
return { unmount: function () {
alive = false; if (raf) cancelAnimationFrame(raf); if (ro) try { ro.disconnect(); } catch (e) {}
busOffs.forEach(function (off) { try { off(); } catch (e) {} }); busOffs = []; addNodeFn = null;
if (renderer) { try { renderer.dispose(); renderer.forceContextLoss(); } catch (e) {} }
container.innerHTML = '';
} };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['3d'] = { manifest: { id: '3d', name: '3D', icon: '🧊' }, mount: mount };
})();
</script>