Files
ploxion-spiderion-sim/app.blade.php

183 lines
16 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.
{{-- PL0XION spiderion-sim 🕷️ — LE SPIDERION en 3D avec GRAVITÉ (rs-4, RS-7 : « il faut mettre la
gravité, et utiliser un environnement 3D »). Three.js (CDN autorisé) + intégrateur de gravité
maison : araignée robot 8 pattes IK 3D, 4 MANIP (avant, pointent une cible) + 4 MORPH (arrière :
marche OU hélices → DRONE). En araignée les pattes tiennent le corps ; en DRONE la PORTANCE doit
vaincre la gravité (basse=retombe, haute=grimpe). Caméra orbitale, sol, ombre. Dégrade si 3D KO. --}}
<style>
.sp3{display:flex;flex-direction:column;height:100%;background:#05070e;color:#dfe7ff;font-family:var(--xr-font-ui,ui-sans-serif,system-ui);overflow:hidden}
.sp3__stage{flex:1;min-height:0;position:relative}
.sp3__stage canvas{width:100%;height:100%;display:block;touch-action:none}
.sp3__hud{position:absolute;left:10px;top:8px;font:.7rem ui-monospace,monospace;color:#9fb0e0;background:rgba(5,7,14,.55);padding:4px 9px;border-radius:7px;pointer-events:none}
.sp3__bar{flex:0 0 auto;display:flex;gap:10px;align-items:center;padding:9px 12px;border-top:1px solid #17233c;flex-wrap:wrap}
.sp3__btn{cursor:pointer;border:0;border-radius:9px;background:var(--xr-accent,#5fe0c0);color:#04120e;font:inherit;font-weight:800;font-size:.78rem;padding:9px 15px}
.sp3__btn.sec{background:rgba(30,48,84,.7);color:#dbe9ff;border:1px solid #2a3a62;font-weight:600}
.sp3__btn.sec.on{background:#5fe0c0;color:#04120e;border:0}
.sp3__knobs{display:flex;gap:9px} .sp3__msg{font-size:.7rem;color:#9fb0e0;flex:1;min-width:110px;text-align:right}
</style>
<script>
(function () {
'use strict';
var THREE_URL = 'https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js';
var LIVE = null; // posé au mount : {walking:function()}
function describe() {
var w = LIVE ? LIVE.walking() : false;
return { v: 1, id: 'spiderion-sim', title: 'Spiderion', icon: '🕷️', items: [
{ p: 1, kind: 'stat', label: 'mode', value: w ? '🚶 marche' : '🚁 drone' }
] };
}
function mount(container) {
container.innerHTML = '<div class="sp3"><div class="sp3__stage"><canvas></canvas><div class="sp3__hud" data-hud>chargement 3D…</div>'
+ '<div data-aero style="position:absolute;right:10px;top:8px;display:none;font:.66rem ui-monospace,monospace;color:#cfe;background:rgba(6,10,20,.72);border:1px solid rgba(120,200,255,.28);border-radius:9px;padding:7px 10px;min-width:168px;line-height:1.55"></div></div>'
+ '<div class="sp3__bar"><button class="sp3__btn" data-mode>🚁 passer en DRONE</button>'
+ '<button class="sp3__btn sec" data-walk>🚶 marcher</button>'
+ '<div class="sp3__knobs" data-knobs></div>'
+ '<span class="sp3__msg" data-msg>glisse pour tourner la caméra · clic-sol = cible des pattes manip · DRONE : la portance lutte contre la gravité.</span></div></div>';
var root = container.querySelector('.sp3'), cv = root.querySelector('canvas'), hud = root.querySelector('[data-hud]'), msg = root.querySelector('[data-msg]'), aeroEl = root.querySelector('[data-aero]');
var alive = true, raf = 0;
var walking = false, morphT = 0, morph = 0, gaitSpeed = 1.4, lift = 1.0; // lift : 1 = compense pile la gravité
LIVE = { walking: function () { return walking; } };
var G = 22, velY = 0, bodyY = 6, STAND = 6, t = 0, target = null;
// caméra orbitale
var az = 0.7, el = 0.5, dist = 46, dragging = false, px = 0, py = 0;
import(THREE_URL).then(function (THREE) {
if (!alive) return; build(THREE);
}).catch(function () { if (!alive) return; hud.textContent = '3D indisponible (Three.js non chargé — réessaie connecté).'; });
function build(THREE) {
var W = cv.clientWidth, H = cv.clientHeight;
var renderer = new THREE.WebGLRenderer({ canvas: cv, antialias: true, alpha: true }); renderer.setPixelRatio(Math.min(2, devicePixelRatio || 1)); renderer.setSize(W, H, false);
renderer.shadowMap.enabled = true;
var scene = new THREE.Scene(); scene.fog = new THREE.Fog(0x05070e, 60, 130);
var cam = new THREE.PerspectiveCamera(50, W / H, 0.1, 400);
// lumières
scene.add(new THREE.HemisphereLight(0x8fbfff, 0x0a1020, 0.8));
var sun = new THREE.DirectionalLight(0xffffff, 1.1); sun.position.set(20, 40, 15); sun.castShadow = true; sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -40; sun.shadow.camera.right = 40; sun.shadow.camera.top = 40; sun.shadow.camera.bottom = -40; scene.add(sun);
// SOL
var ground = new THREE.Mesh(new THREE.PlaneGeometry(240, 240), new THREE.MeshStandardMaterial({ color: 0x0a1424, roughness: 1 }));
ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true; scene.add(ground);
var grid = new THREE.GridHelper(240, 60, 0x1c3358, 0x11203a); scene.add(grid);
var ACC = 0x5fe0c0, BLU = 0x8fb6ff;
var body = new THREE.Mesh(new THREE.CylinderGeometry(6, 6.6, 3.4, 8), new THREE.MeshStandardMaterial({ color: 0x14263c, metalness: .3, roughness: .5 }));
body.castShadow = true; scene.add(body);
var eye = new THREE.Mesh(new THREE.SphereGeometry(0.7, 12, 12), new THREE.MeshStandardMaterial({ color: ACC, emissive: 0x145040 })); body.add(eye); eye.position.set(0, 0.4, 5);
// 8 pattes : 4 manip (avant) + 4 morph (arrière). Chaque patte = 2 segments + hanche.
var LEGS = [];
var MANIP = [-60, -25, 25, 60], MORPH = [120, 155, -155, -120];
function makeLeg(angDeg, kind) {
var a = angDeg * Math.PI / 180;
var hip = new THREE.Vector3(Math.sin(a) * 6, 0, Math.cos(a) * 6);
var mat = new THREE.MeshStandardMaterial({ color: kind === 'manip' ? ACC : BLU, metalness: .2, roughness: .6 });
function seg() { var m = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.4, 1, 8), mat); m.castShadow = true; scene.add(m); return m; }
var femur = seg(), tibia = seg();
// hélice (mode drone) : disque + 3 pales
var prop = new THREE.Group(); scene.add(prop); prop.visible = false;
var pmat = new THREE.MeshStandardMaterial({ color: BLU, transparent: true, opacity: .85 });
for (var b = 0; b < 3; b++) { var blade = new THREE.Mesh(new THREE.BoxGeometry(5, .2, .9), pmat); blade.position.x = 2.4; var pg = new THREE.Group(); pg.add(blade); pg.rotation.y = b * Math.PI * 2 / 3; prop.add(pg); }
LEGS.push({ a: a, kind: kind, hip: hip, femur: femur, tibia: tibia, prop: prop, phase: LEGS.length * 0.8, L1: 5, L2: 6 });
}
MANIP.forEach(function (d) { makeLeg(d, 'manip'); }); MORPH.forEach(function (d) { makeLeg(d, 'morph'); });
function place(mesh, from, to, rad) {
var mid = from.clone().add(to).multiplyScalar(0.5); mesh.position.copy(mid);
var len = from.distanceTo(to); mesh.scale.set(rad ? rad / 0.5 : 1, len, rad ? rad / 0.5 : 1);
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), to.clone().sub(from).normalize());
}
function legIK(leg, footW, bodyPos) {
var hipW = leg.hip.clone().add(bodyPos);
var d = footW.clone().sub(hipW); var horiz = Math.hypot(d.x, d.z), vert = d.y;
var D = Math.min(Math.hypot(horiz, vert), leg.L1 + leg.L2 - 0.01) || 0.01;
var base = Math.atan2(vert, horiz), c = Math.max(-1, Math.min(1, (leg.L1 * leg.L1 + D * D - leg.L2 * leg.L2) / (2 * leg.L1 * D)));
var ka = base + Math.acos(c);
var hn = horiz > 0.001 ? new THREE.Vector3(d.x / horiz, 0, d.z / horiz) : new THREE.Vector3(1, 0, 0);
var knee = hipW.clone().add(hn.clone().multiplyScalar(Math.cos(ka) * leg.L1)).add(new THREE.Vector3(0, Math.sin(ka) * leg.L1, 0));
place(leg.femur, hipW, knee, 0.5); place(leg.tibia, knee, footW, 0.4);
}
// interactions
var ray = new THREE.Raycaster(), ndc = new THREE.Vector2();
cv.addEventListener('pointerdown', function (e) { dragging = true; px = e.clientX; py = e.clientY; cv.setPointerCapture(e.pointerId);
var r = cv.getBoundingClientRect(); ndc.x = (e.clientX - r.left) / r.width * 2 - 1; ndc.y = -((e.clientY - r.top) / r.height * 2 - 1);
ray.setFromCamera(ndc, cam); var hit = new THREE.Vector3(); ray.ray.intersectPlane(new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), hit); if (hit) target = hit; });
cv.addEventListener('pointermove', function (e) { if (!dragging) return; az -= (e.clientX - px) * 0.01; el = Math.max(0.1, Math.min(1.4, el - (e.clientY - py) * 0.01)); px = e.clientX; py = e.clientY; });
cv.addEventListener('pointerup', function () { dragging = false; });
cv.addEventListener('wheel', function (e) { e.preventDefault(); dist = Math.max(20, Math.min(90, dist + (e.deltaY > 0 ? 4 : -4))); }, { passive: false });
function resize() { var w = cv.clientWidth, h = cv.clientHeight; if (w && h) { renderer.setSize(w, h, false); cam.aspect = w / h; cam.updateProjectionMatrix(); } }
var ro; try { ro = new ResizeObserver(resize); ro.observe(cv); } catch (e) {}
function step(dt) {
dt = Math.min(0.05, dt); t += dt; morph += (morphT - morph) * Math.min(1, dt * 6);
// AÉRODYNAMISME : 4 rotors (les 4 pattes morph), poussée + traînée + couples + stabilité
var aero = null;
if (morph > 0.5) {
var weight = G, perRotor = lift * G / 4, totalThrust = perRotor * 4; // hover équilibré = 1×g
var drag = 0.06 * velY * Math.abs(velY); // traînée aéro → vitesse terminale
velY += (totalThrust - weight - drag) * dt; bodyY += velY * dt;
if (bodyY < 3) { bodyY = 3; if (velY < 0) velY = 0; }
if (bodyY > 70) bodyY = 70;
// auto-nivellement : le corps reste à plat (rotors symétriques → couples ~0)
body.rotation.x += (0 - body.rotation.x) * Math.min(1, dt * 4); body.rotation.z += (0 - body.rotation.z) * Math.min(1, dt * 4);
var stab = Math.max(0, Math.min(100, 100 - Math.abs(velY) * 8 - Math.abs(totalThrust - weight) * 3));
aero = { total: totalThrust, ratio: totalThrust / weight, per: perRotor, drag: drag, stab: stab };
} else { velY += (STAND - bodyY) * 12 * dt - 0; velY *= 0.6; bodyY += velY * dt; } // pattes = ressort qui tient contre G
var bob = walking && morph < 0.5 ? Math.sin(t * gaitSpeed * 3) * 0.5 : 0;
var bpos = new THREE.Vector3(0, bodyY + bob, 0); body.position.copy(bpos); body.rotation.y += dt * 0.05;
LEGS.forEach(function (leg, i) {
var reach = 11 - morph * 5;
var footBase = new THREE.Vector3(Math.sin(leg.a) * reach, 0, Math.cos(leg.a) * reach);
if (leg.kind === 'manip' && target && morph < 0.5) { footBase.lerp(new THREE.Vector3(target.x, 0.5, target.z), 0.4); }
if (leg.kind === 'morph' && walking && morph < 0.5) { footBase.y = Math.max(0, Math.sin(t * gaitSpeed * 3 + leg.phase) * 2); }
var visLeg = leg.kind === 'manip' ? true : morph < 0.95;
leg.femur.visible = leg.tibia.visible = visLeg;
if (visLeg) legIK(leg, footBase, new THREE.Vector3(0, bpos.y, 0));
// hélices (morph legs en drone)
if (leg.kind === 'morph') { leg.prop.visible = morph > 0.05;
var pc = new THREE.Vector3(Math.sin(leg.a) * 8, bpos.y, Math.cos(leg.a) * 8); leg.prop.position.copy(pc);
// rotors en PAIRES CW/CCW (comme un vrai quad → couple de lacet net nul), vitesse ∝ poussée
var dir = (LEGS.indexOf(leg) % 2) ? 1 : -1; leg.prop.rotation.y += dt * (6 + morph * 30 * (lift * 0.5 + 0.5)) * dir; leg.prop.scale.setScalar(0.3 + morph * 0.8);
leg.prop.children.forEach(function (pg) { pg.children[0].material.opacity = morph * 0.9; });
}
});
// caméra orbitale autour du corps
var cy2 = bodyY * 0.5 + 6;
cam.position.set(Math.cos(az) * Math.cos(el) * dist, Math.sin(el) * dist + cy2, Math.sin(az) * Math.cos(el) * dist);
cam.lookAt(0, cy2, 0);
hud.textContent = (morph > 0.5 ? '🚁 DRONE' : (walking ? '🚶 MARCHE' : '⏸ araignée')) + ' · altitude ' + (bodyY - STAND > 0.3 ? '+' + (bodyY - STAND).toFixed(0) : '0') + ' · portance ' + (lift).toFixed(2) + '×g · vⁿ ' + velY.toFixed(1);
if (aero) { aeroEl.style.display = 'block'; aeroEl.innerHTML = '<b style="color:#8fd8ff">◈ aérodynamisme</b><br>'
+ 'poussée : ' + aero.total.toFixed(1) + ' N<br>'
+ 'portance/poids : <b style="color:' + (Math.abs(aero.ratio - 1) < 0.05 ? '#6affc0' : '#ffcf6a') + '">' + aero.ratio.toFixed(2) + '</b>' + (Math.abs(aero.ratio - 1) < 0.05 ? ' ⇢ hover' : (aero.ratio > 1 ? ' ↑' : ' ↓')) + '<br>'
+ '4 rotors : ' + aero.per.toFixed(1) + ' N ×4<br>'
+ 'traînée : ' + aero.drag.toFixed(2) + ' N<br>'
+ 'couples R/T/L : 0.0 / 0.0 / 0.0 <span style="color:#6affc0">équilibré</span><br>'
+ 'stabilité : <b style="color:' + (aero.stab > 70 ? '#6affc0' : '#ff8a6a') + '">' + aero.stab.toFixed(0) + '%</b>'; }
else aeroEl.style.display = 'none';
try { window.jOSPorts && jOSPorts.emit('spiderion', 'state', { mode: morph > 0.5 ? 'drone' : 'walk', alt: bodyY - STAND, lift: lift }); } catch (e) {}
}
var last = 0;
function loop(ms) { raf = requestAnimationFrame(loop); if (!alive) return; var dt = last ? (ms - last) / 1000 : 0.016; last = ms; step(dt); renderer.render(scene, cam); }
hud.textContent = '3D prête'; loop(0);
root._cleanup = function () { try { ro && ro.disconnect(); } catch (e) {} try { renderer.dispose(); } catch (e) {} };
}
// contrôles (marchent avant/après le chargement 3D)
root.querySelector('[data-mode]').addEventListener('click', function (e) { morphT = morphT > 0.5 ? 0 : 1; if (morphT > 0.5) velY = 0; e.target.textContent = morphT > 0.5 ? '🕷️ repasser en ARAIGNÉE' : '🚁 passer en DRONE'; msg.textContent = morphT > 0.5 ? 'DRONE : monte la portance > 1×g pour décoller, < 1×g pour redescendre.' : 'ARAIGNÉE : 8 pattes, les 4 avant manipulent.'; });
root.querySelector('[data-walk]').addEventListener('click', function () { walking = !walking; });
if (window.jOSKnob) jOSKnob.panel(container.querySelector('[data-knobs]'), [
{ key: 'gait', label: 'allure', min: 0.4, max: 3, value: gaitSpeed },
{ key: 'lift', label: 'portance', min: 0, max: 2, value: lift, step: 0.02, fmt: function (v) { return v.toFixed(2) + '×g'; } }
], function (v) { gaitSpeed = v.gait; lift = v.lift; }, { shape: 'koin' });
return { unmount: function () { alive = false; LIVE = null; cancelAnimationFrame(raf); try { root._cleanup && root._cleanup(); } catch (e) {} container.innerHTML = ''; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['spiderion-sim'] = { manifest: { id: 'spiderion-sim', name: 'Spiderion', icon: '🕷️' }, mount: mount, describe: describe };
})();
</script>