synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
110
app.blade.php
Normal file
110
app.blade.php
Normal file
@@ -0,0 +1,110 @@
|
||||
{{-- PL0XI0N cubions — les cubions transformés en OBJETS 3D (RS-7 : « transforme
|
||||
les cubions en objets / cube draggable »). Chaque cubion = un cube 3D ; ses 6
|
||||
faces = ses ploxions membres ; drag pour tourner la scène ; clic sur une face
|
||||
= lance le ploxion (window.jOS.openPloxion). Three.js ESM (unpkg, CSP-ok).
|
||||
Contrat jOSApps. --}}
|
||||
<style>
|
||||
.pcb{position:relative;height:100%;background:radial-gradient(circle at 50% 40%,#0a1622,#04060a);overflow:hidden}
|
||||
.pcb canvas{display:block}
|
||||
.pcb__tip{position:absolute;pointer-events:none;background:rgba(6,11,9,.92);border:1px solid var(--xr-accent,#3fe0d0);
|
||||
color:#fff;font:0.78rem ui-sans-serif,system-ui;padding:3px 9px;border-radius:7px;opacity:0;transform:translate(-50%,-130%);transition:opacity .12s;white-space:nowrap;z-index:3}
|
||||
.pcb__hd{position:absolute;top:10px;left:12px;z-index:2;color:var(--xr-muted,#8aa0c0);font:0.74rem ui-sans-serif,system-ui;pointer-events:none}
|
||||
.pcb__hd b{color:var(--xr-accent,#3fe0d0)}
|
||||
.pcb__msg{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;color:var(--xr-muted,#8aa0c0);font:0.85rem ui-sans-serif,system-ui}
|
||||
</style>
|
||||
<script>
|
||||
(function(){
|
||||
var ID='cubions';
|
||||
var THREE_URL='/vendor/js/three.module.js';
|
||||
|
||||
var LIVE=null; // posé au mount : {count:function()}
|
||||
function describe(){
|
||||
var n = LIVE ? LIVE.count() : 0;
|
||||
return { v:1, id:ID, title:'Cubions', icon:'🧊', items:[
|
||||
{ p:1, kind:'stat', label:'cubions chargés', value:n }
|
||||
]};
|
||||
}
|
||||
|
||||
function mount(container){
|
||||
var alive=true, raf=0, ro=null, renderer=null, cubCount=0;
|
||||
LIVE = { count: function () { return cubCount; } };
|
||||
container.innerHTML='<div class="pcb"><div class="pcb__hd">🧊 <b>cubions</b> — glisse pour tourner · clic sur une face = lance le ploxion</div><div class="pcb__tip"></div><div class="pcb__msg">chargement de l\'espace 3D…</div></div>';
|
||||
var root=container.querySelector('.pcb'), tip=root.querySelector('.pcb__tip'), msg=root.querySelector('.pcb__msg');
|
||||
var manifest={}; (window.__PLOXIONS__||[]).forEach(function(p){ manifest[p.id]=p; });
|
||||
|
||||
Promise.all([ import(THREE_URL), fetch('/cubions.json').then(function(r){return r.json();}) ])
|
||||
.then(function(res){ if(!alive)return; var THREE=res[0]; var cubions=(res[1].cubions||[]); cubCount=cubions.length; if(!cubions.length){msg.textContent='aucun cubion';return;} msg.remove(); build(THREE,cubions); })
|
||||
.catch(function(e){ if(alive) msg.textContent='3D indisponible ('+(e&&e.message||e)+')'; });
|
||||
|
||||
function faceTex(THREE, mid){
|
||||
var p=manifest[mid]||{}; var icon=p.icon||'▣'; var name=p.name||mid; var real=!!manifest[mid];
|
||||
var c=document.createElement('canvas'); c.width=c.height=256; var x=c.getContext('2d');
|
||||
x.fillStyle=real?'#0a1614':'#15100a'; x.fillRect(0,0,256,256);
|
||||
x.strokeStyle=real?'#3fe0d0':'#7a6a3a'; x.lineWidth=8; x.strokeRect(10,10,236,236);
|
||||
x.textAlign='center'; x.fillStyle='#fff'; x.font='110px serif'; x.fillText(icon,128,130);
|
||||
x.fillStyle=real?'#dffbe9':'#bbaa77'; x.font='30px ui-sans-serif,sans-serif';
|
||||
x.fillText(String(name).slice(0,16),128,200);
|
||||
if(!real){ x.fillStyle='#7a6a3a'; x.font='18px ui-sans-serif'; x.fillText('(concept)',128,228); }
|
||||
var t=new THREE.CanvasTexture(c); t.anisotropy=4; return t;
|
||||
}
|
||||
|
||||
function build(THREE, cubions){
|
||||
var W=root.clientWidth||600, H=root.clientHeight||400;
|
||||
var scene=new THREE.Scene(); scene.fog=new THREE.FogExp2(0x04060a,0.012);
|
||||
var camera=new THREE.PerspectiveCamera(55,W/H,0.1,2000);
|
||||
renderer=new THREE.WebGLRenderer({antialias:true,alpha:true});
|
||||
renderer.setSize(W,H); renderer.setPixelRatio(Math.min(2,window.devicePixelRatio||1));
|
||||
root.appendChild(renderer.domElement);
|
||||
scene.add(new THREE.AmbientLight(0x99bbff,0.85));
|
||||
var dl=new THREE.DirectionalLight(0xffffff,0.8); dl.position.set(30,50,40); scene.add(dl);
|
||||
|
||||
var cubes=[], geo=new THREE.BoxGeometry(3,3,3);
|
||||
var cols=Math.ceil(Math.sqrt(cubions.length)), gap=5.5;
|
||||
cubions.forEach(function(cb,i){
|
||||
var members=(cb.members||[]).slice(0,6);
|
||||
var mats=[]; var faceMembers=[];
|
||||
for(var f=0;f<6;f++){ var mid=members[f]; faceMembers.push(mid||null);
|
||||
mats.push(new THREE.MeshStandardMaterial({ map: mid?faceTex(THREE,mid):null, color: mid?0xffffff:0x0a1410, roughness:0.55, metalness:0.25, emissive:0x0a1f1a, emissiveIntensity:0.25 })); }
|
||||
var cube=new THREE.Mesh(geo,mats);
|
||||
var cx=(i%cols)-(cols-1)/2, cz=Math.floor(i/cols)-(Math.ceil(cubions.length/cols)-1)/2;
|
||||
cube.position.set(cx*gap, 0, cz*gap);
|
||||
cube.userData={ cubion:cb, faceMembers:faceMembers, spin:0.002+Math.random()*0.004 };
|
||||
scene.add(cube); cubes.push(cube);
|
||||
});
|
||||
|
||||
// caméra orbitale (drag) + zoom molette
|
||||
var tgt=new THREE.Vector3(0,0,0), yaw=0.5, pitch=0.5, dist=Math.max(16, cols*7);
|
||||
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, moved=0, el=renderer.domElement;
|
||||
el.style.cursor='grab';
|
||||
el.addEventListener('pointerdown',function(e){ drag={x:e.clientX,y:e.clientY}; moved=0; el.setPointerCapture(e.pointerId); el.style.cursor='grabbing'; });
|
||||
el.addEventListener('pointermove',function(e){ var rect=el.getBoundingClientRect();
|
||||
if(drag){ var dx=e.clientX-drag.x, dy=e.clientY-drag.y; moved+=Math.abs(dx)+Math.abs(dy); yaw-=dx*0.006; pitch+=dy*0.006; pitch=Math.max(-1.45,Math.min(1.45,pitch)); drag={x:e.clientX,y:e.clientY}; }
|
||||
else hover(e.clientX-rect.left,e.clientY-rect.top,rect); });
|
||||
el.addEventListener('pointerup',function(){ drag=null; el.style.cursor='grab'; });
|
||||
el.addEventListener('wheel',function(e){ e.preventDefault(); dist=Math.max(10,Math.min(120,dist*(1+(e.deltaY>0?0.12:-0.12)))); },{passive:false});
|
||||
|
||||
var ray=new THREE.Raycaster(), mouse=new THREE.Vector2();
|
||||
function pick(x,y,rect){ mouse.x=(x/rect.width)*2-1; mouse.y=-(y/rect.height)*2+1; ray.setFromCamera(mouse,camera); return ray.intersectObjects(cubes,false)[0]; }
|
||||
function hover(x,y,rect){ var hit=pick(x,y,rect);
|
||||
if(hit){ var fm=hit.object.userData.faceMembers[hit.face.materialIndex];
|
||||
var label=fm?((manifest[fm]&&manifest[fm].name)||fm):('— '+hit.object.userData.cubion.name);
|
||||
tip.textContent=(hit.object.userData.cubion.name)+' › '+label; tip.style.left=x+'px'; tip.style.top=y+'px'; tip.style.opacity='1'; el.style.cursor=fm?'pointer':'grab'; }
|
||||
else { tip.style.opacity='0'; el.style.cursor=drag?'grabbing':'grab'; } }
|
||||
el.addEventListener('click',function(e){ if(moved>6)return; var rect=el.getBoundingClientRect(); var hit=pick(e.clientX-rect.left,e.clientY-rect.top,rect);
|
||||
if(!hit)return; var fm=hit.object.userData.faceMembers[hit.face.materialIndex];
|
||||
if(fm && manifest[fm] && window.jOS && window.jOS.openPloxion){ window.jOS.openPloxion(fm); }
|
||||
else if(fm){ tip.textContent=fm+' — pas branché'; tip.style.opacity='1'; } });
|
||||
|
||||
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); cubes.forEach(function(c){ c.rotation.y+=c.userData.spin; }); place(); renderer.render(scene,camera); })();
|
||||
}
|
||||
|
||||
return { unmount:function(){ alive=false; LIVE=null; if(raf)cancelAnimationFrame(raf); if(ro)ro.disconnect(); if(renderer){ try{renderer.dispose();}catch(e){} } container.innerHTML=''; } };
|
||||
}
|
||||
window.jOSApps=window.jOSApps||{};
|
||||
window.jOSApps[ID]={manifest:{id:ID,name:'Cubions',icon:'🧊'},mount:mount,describe:describe};
|
||||
})();
|
||||
</script>
|
||||
Reference in New Issue
Block a user