mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-avatar.git
synced 2026-11-29 06:02:06 +00:00
209 lines
26 KiB
PHP
209 lines
26 KiB
PHP
{{-- PL0XION avatar ◍ — CRÉER SON AVATAR (rs-4, RS-7 : « créer son avatar du nexus et son avatar
|
|
xerion »). Éditeur 3D sur jOSEngine : deux avatars — NEXUS (le perso qui marche dans le monde
|
|
partagé) et XERION (la représentation d'identité, plus énergétique/glyphique). Personnalise
|
|
corps/tête/couleurs/visage/aura, sauve sur ton boxion. Utilisé par monde-os/moteur/map-amis.
|
|
Réutilise jOSEngine (le moteur du xer) + jOSBoxion.
|
|
(21.10, RS-7) quatre avatars : nexus, xerion, Josion, xeroction ; en 3D ou en 2D (une photo, un dessin) ; les xers installés
|
|
dessus (Xerax, xereye, xerboxion…) orbitent autour ; « ◎ me mapper » = se scanner (photos, vidéo, ou en direct à la caméra),
|
|
les prises vont sur le boxion et le modèle reconstruit (photogrammétrie, Object Capture dans ploxi0n) revient par l'import. --}}
|
|
<style>
|
|
.av{display:flex;flex-direction:column;height:100%;background:#05070e;color:#dfe7ff;font-family:var(--xr-font-ui,ui-sans-serif,system-ui);overflow:hidden}
|
|
.av__tabs{flex:0 0 auto;display:flex;gap:6px;padding:8px 11px;border-bottom:1px solid #17233c}
|
|
.av__tab{cursor:pointer;background:rgba(30,42,74,.5);border:1px solid #24345c;color:#cdd8f5;border-radius:8px;padding:5px 12px;font:inherit;font-size:.78rem}
|
|
.av__tab.on{background:#5fe0c0;color:#04120e;border:0;font-weight:800}
|
|
.av__tab.on.xer{background:#b06aff}
|
|
.av__stage{flex:1;min-height:0;position:relative}.av__stage canvas{width:100%;height:100%;display:block}
|
|
.av__ctrl{flex:0 0 auto;display:flex;gap:9px;align-items:center;padding:9px 12px;border-top:1px solid #17233c;flex-wrap:wrap}
|
|
.av__ctrl label{font-size:.66rem;color:#8fa0c8;display:flex;flex-direction:column;gap:2px}
|
|
.av__ctrl input[type=color]{width:34px;height:26px;border:0;background:none;cursor:pointer}
|
|
.av__ctrl input[type=text]{background:#0b1626;border:1px solid #22344f;color:#cfe;border-radius:7px;padding:5px 8px;font:inherit;font-size:.76rem;width:110px}
|
|
.av__ctrl select{background:#0b1626;border:1px solid #22344f;color:#cfe;border-radius:7px;padding:5px;font:inherit;font-size:.72rem}
|
|
.av__emo{cursor:pointer;font-size:1.2rem}
|
|
.av__stage .av__2d{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#05070e}
|
|
.av__2d img,.av__2d canvas{max-width:62%;max-height:70%;border-radius:14px;border:2px solid var(--av-acc,#5fe0c0);background:#0b1626;touch-action:none}
|
|
.av__ring{position:absolute;inset:0;pointer-events:none;animation:avrot 40s linear infinite}
|
|
.av__ring span{position:absolute;width:34px;height:34px;margin:-17px;pointer-events:auto}
|
|
@keyframes avrot{to{transform:rotate(360deg)}}
|
|
.av__ring span>*{animation:avrot 40s linear infinite reverse}
|
|
.av__pan{position:absolute;left:8px;right:8px;bottom:8px;max-height:60%;overflow:auto;background:#0a1222f2;border:1px solid #24345c;border-radius:12px;padding:10px;font-size:.74rem}
|
|
.av__chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:6px}
|
|
.av__chip{cursor:pointer;display:flex;align-items:center;gap:5px;background:#101a30;border:1px solid #24345c;color:#cdd8f5;border-radius:9px;padding:4px 8px;font:inherit;font-size:.7rem}
|
|
.av__chip.on{border-color:#5fe0c0;background:#123028}
|
|
.av__b{cursor:pointer;border:0;border-radius:9px;background:#5fe0c0;color:#04120e;font:inherit;font-weight:800;font-size:.76rem;padding:8px 13px;margin-left:auto}
|
|
</style>
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
// les visages = des glyphes du xerboxion, jamais d'emoji (un vieux visage emoji enregistré est remplacé au chargement)
|
|
var FACES = ['◉', '◎', '◐', '△', '▢', '✦', '⬡', '⧗', '∴', '✶'];
|
|
var KINDS = [['nexus', '◍', 'nexus'], ['xerion', '✦', 'xerion'], ['josion', '◈', 'Josion'], ['xeroction', '⬡', 'xeroction']];
|
|
var DEF = { nexus: { body: '#5fe0c0', accent: '#8fb6ff', shape: 'capsule', style: 'lisse', face: '◉', aura: false, name: '' },
|
|
xerion: { body: '#b06aff', accent: '#ff6ad5', shape: 'sphere', style: 'neon', face: '✦', aura: true, name: '' },
|
|
josion: { body: '#e0b25f', accent: '#ffe08a', shape: 'capsule', style: 'lowpoly', face: '◐', aura: true, name: '' },
|
|
xeroction: { body: '#3a6cff', accent: '#5fe0c0', shape: 'box', style: 'neon', face: '⬡', aura: true, name: '' } };
|
|
// les xers qu'on peut installer sur un avatar (proposés en premier ; tout ploxion du registre peut l'être)
|
|
var XERS = ['xerax', 'xereye', 'xerboxion', 'terrax', 'clickion', 'xp', 'message', 'agora', 'boite', 'glyphed'];
|
|
function load(kind) { var s; try { s = Object.assign({}, DEF[kind], JSON.parse(localStorage.getItem('avatar:' + kind) || '{}')); } catch (e) { s = Object.assign({}, DEF[kind]); }
|
|
if (FACES.indexOf(s.face) < 0) s.face = DEF[kind].face; if (!Array.isArray(s.xers)) s.xers = []; if (s.dim !== '2d') s.dim = '3d'; return s; }
|
|
function esc(s) { return window.jOSb.esc(s); }
|
|
function ic(id, n) { return window.jOSIcone && jOSIcone.px ? jOSIcone.px(id, { fond: false, size: n || 30 }) : '◇'; }
|
|
function nomPx(id) { var m = (window.__PLOXIONS__ || []).filter(function (p) { return p.id === id; })[0]; return m ? m.name : id; }
|
|
// une image (photo, dessin) réduite à 512 px pour tenir dans le stockage local
|
|
function reduire(src, cb) { var im = new Image(); im.onload = function () { var k = Math.min(1, 512 / Math.max(im.width, im.height)), c = document.createElement('canvas'); c.width = Math.round(im.width * k); c.height = Math.round(im.height * k); c.getContext('2d').drawImage(im, 0, 0, c.width, c.height); cb(c.toDataURL('image/jpeg', .85)); }; im.onerror = function () { cb(null); }; im.src = src; }
|
|
|
|
function describe() {
|
|
return { v: 1, id: 'avatar', title: 'Avatar', icon: '◍', items: KINDS.map(function (k, i) { var s = load(k[0]);
|
|
return { p: i + 1, kind: 'stat', label: 'avatar ' + k[2], value: (s.name || s.shape) + ' ' + s.face + ' · ' + s.dim + (s.xers.length ? ' · ' + s.xers.length + ' xers' : '') }; }) };
|
|
}
|
|
|
|
function mount(container) {
|
|
container.innerHTML = '<div class="av"><div class="av__tabs">' + KINDS.map(function (k, i) { return '<button class="av__tab' + (i ? ' xer' : ' on') + '" data-t="' + k[0] + '">' + k[1] + ' ' + k[2] + '</button>'; }).join('')
|
|
+ '<span style="margin-left:auto;display:flex;gap:6px"><button class="av__tab" data-dim>3D</button><button class="av__tab" data-pan="xers">⬢ xers</button><button class="av__tab" data-pan="map">◎ me mapper</button></span></div>'
|
|
+ '<div class="av__stage"><canvas></canvas><div class="av__2d" hidden></div><div class="av__ring"></div><div class="av__pan" hidden></div></div>'
|
|
+ '<div class="av__ctrl"><label>nom<input type="text" data-name></label>'
|
|
+ '<label>corps<input type="color" data-body></label><label>accent<input type="color" data-accent></label>'
|
|
+ '<label>style<select data-style><option value="lisse">lisse</option><option value="voxel">Minecraft/voxel</option><option value="lowpoly">low-poly</option><option value="neon">cyberpunk néon</option></select></label>'
|
|
+ '<label>forme<select data-shape><option value="capsule">humanoïde</option><option value="box">bloc</option><option value="sphere">sphère</option><option value="cone">cône</option></select></label>'
|
|
+ '<label>visage<span class="av__emo" data-face>◉</span></label>'
|
|
+ '<label>aura<input type="checkbox" data-aura></label>'
|
|
+ '<button class="av__b" style="margin-left:0;background:rgba(30,48,84,.7);color:#dbe9ff;border:1px solid #2a3a62" data-import>⤓ importer (GLB/VRM/FBX)</button>'
|
|
+ '<button class="av__b" style="margin-left:0;background:rgba(30,48,84,.7);color:#dbe9ff;border:1px solid #2a3a62" data-img>▣ photo / dessin</button>'
|
|
+ '<input type="file" data-file accept=".glb,.gltf,.vrm,.fbx,.obj" style="display:none"><input type="file" data-imgfile accept="image/*" style="display:none">'
|
|
+ '<button class="av__b" data-save>▣ sauver mon avatar</button></div></div>';
|
|
var cv = container.querySelector('canvas'), tabs = container.querySelector('.av__tabs');
|
|
var kind = 'nexus', spec = load('nexus'), avatar = null, auraSys = null, e = null;
|
|
// (21.10) sans moteur 3D (jOS3D absent, pas de WebGL : l'app ploxi0n) l'avatar vit en 2D au lieu de casser
|
|
try { e = window.jOSEngine ? jOSEngine.create(cv, { ground: true, grid: true, groundColor: 0x0a1220, dist: 6, targetY: 1, onReady: function (en) { rebuild(); } }) : null; } catch (x) { e = null; }
|
|
var sans3d = !e;
|
|
|
|
function rebuild() { var T = e && e.THREE; if (!T) return;
|
|
if (avatar) { try { e.world.scene.remove(avatar); } catch (x) {} } if (auraSys) { try { e.remove(auraSys); } catch (x) {} auraSys = null; }
|
|
avatar = new T.Group();
|
|
var stl = spec.style || 'lisse', flat = stl === 'voxel' || stl === 'lowpoly', neon = stl === 'neon', voxel = stl === 'voxel';
|
|
var bmat = new T.MeshStandardMaterial({ color: parseInt(spec.body.slice(1), 16), metalness: neon ? .85 : .2, roughness: neon ? .2 : .6, flatShading: flat, emissive: parseInt(spec.body.slice(1), 16), emissiveIntensity: neon ? 1.1 : (kind === 'xerion' ? .35 : .08) });
|
|
var amat = new T.MeshStandardMaterial({ color: parseInt(spec.accent.slice(1), 16), metalness: neon ? .85 : .3, roughness: neon ? .2 : .5, flatShading: flat, emissive: parseInt(spec.accent.slice(1), 16), emissiveIntensity: neon ? 1 : 0 });
|
|
var bodyGeo = voxel ? new T.BoxGeometry(0.7, 1.1, 0.5) : spec.shape === 'box' ? new T.BoxGeometry(0.7, 1.1, 0.5) : spec.shape === 'sphere' ? new T.SphereGeometry(0.6, stl === 'lowpoly' ? 6 : 20, stl === 'lowpoly' ? 5 : 20) : spec.shape === 'cone' ? new T.ConeGeometry(0.6, 1.3, stl === 'lowpoly' ? 5 : 12) : new T.CapsuleGeometry(0.32, 0.7, stl === 'lowpoly' ? 2 : 6, stl === 'lowpoly' ? 4 : 12);
|
|
var body = new T.Mesh(bodyGeo, bmat); body.position.y = 0.9; body.castShadow = true; avatar.add(body);
|
|
// tête + visage
|
|
var headGeo = voxel ? new T.BoxGeometry(0.4, 0.4, 0.4) : new T.SphereGeometry(0.32, stl === 'lowpoly' ? 6 : 20, stl === 'lowpoly' ? 5 : 20);
|
|
var head = new T.Mesh(headGeo, amat); head.position.y = spec.shape === 'sphere' ? 1.5 : 1.7; head.castShadow = true; avatar.add(head);
|
|
var tex = e.canvasTexture(function (g, s) { g.clearRect(0, 0, s, s); g.font = (s * 0.7) + 'px serif'; g.textAlign = 'center'; g.textBaseline = 'middle'; g.fillText(spec.face, s / 2, s * 0.54); }, 64);
|
|
var face = new T.Sprite(new T.SpriteMaterial({ map: tex, transparent: true })); face.scale.set(0.5, 0.5, 1); face.position.set(0, head.position.y, 0.33); avatar.add(face);
|
|
// xerion : glyphe flottant + halo
|
|
if (kind !== 'nexus') { var halo = new T.Mesh(new T.TorusGeometry(0.55, 0.05, 8, 32), new T.MeshStandardMaterial({ color: parseInt(spec.accent.slice(1), 16), emissive: parseInt(spec.accent.slice(1), 16), emissiveIntensity: 1 })); halo.position.y = 2.15; halo.rotation.x = Math.PI / 2; avatar.add(halo); avatar._halo = halo; }
|
|
e.world.scene.add(avatar); e.world.cam.target.set(0, 1.1, 0);
|
|
if (spec.aura) auraSys = e.particles({ x: 0, y: 1, z: 0, count: 50, spread: 2.5, life: 999, color: parseInt(spec.accent.slice(1), 16), size: .12 });
|
|
}
|
|
// rotation lente de l'avatar (via une entité)
|
|
if (e) e.onUpdate(function (dt) { if (avatar) avatar.rotation.y += dt * 0.5; if (avatar && avatar._halo) avatar._halo.rotation.z += dt; });
|
|
|
|
// ── les xers installés : ils orbitent autour de l'avatar (en 3D comme en 2D) ──
|
|
var ring = container.querySelector('.av__ring'), pan = container.querySelector('.av__pan'), d2 = container.querySelector('.av__2d');
|
|
function anneau() { var n = spec.xers.length; ring.innerHTML = spec.xers.map(function (id, i) { var a = i / n * Math.PI * 2 - Math.PI / 2;
|
|
return '<span title="' + esc(nomPx(id)) + '" style="left:' + (50 + 38 * Math.cos(a)) + '%;top:' + (48 + 40 * Math.sin(a)) + '%"><span style="display:block">' + ic(id, 34) + '</span></span>'; }).join(''); }
|
|
// ── 2D : une photo ou un dessin à la place du corps ──
|
|
function vue2d() { if (sans3d) spec.dim = '2d'; var is2 = spec.dim === '2d'; container.querySelector('[data-dim]').hidden = sans3d; container.querySelector('[data-import]').hidden = sans3d; d2.hidden = !is2; cv.style.visibility = is2 ? 'hidden' : ''; container.querySelector('[data-dim]').textContent = is2 ? '2D' : '3D';
|
|
d2.style.setProperty('--av-acc', spec.accent);
|
|
if (!is2) return; d2.innerHTML = spec.img ? '<img alt="" src="' + esc(spec.img) + '">' : '<div style="text-align:center;color:#8fa0c8;font-size:.8rem"><div style="font-size:3rem;color:' + esc(spec.accent) + '">' + esc(spec.face) + '</div>▣ une photo, ou ✎ dessine-le<br><button class="av__chip" data-dessin style="margin:10px auto 0">✎ dessiner</button></div>'; }
|
|
function dessiner() { var c = document.createElement('canvas'); c.width = c.height = 512; var g = c.getContext('2d'); g.fillStyle = '#0b1626'; g.fillRect(0, 0, 512, 512); g.strokeStyle = spec.accent; g.lineWidth = 6; g.lineCap = g.lineJoin = 'round';
|
|
if (spec.img) { var im = new Image(); im.onload = function () { g.drawImage(im, 0, 0, 512, 512); }; im.src = spec.img; }
|
|
d2.innerHTML = ''; d2.appendChild(c); var bar = document.createElement('div'); bar.style.cssText = 'position:absolute;bottom:10px;display:flex;gap:6px';
|
|
bar.innerHTML = '<input type="color" value="' + esc(spec.accent) + '"><button class="av__chip" data-ok>✓ garder le dessin</button><button class="av__chip" data-eff>◌ effacer</button>'; d2.appendChild(bar);
|
|
var on = false; function pt(ev) { var r = c.getBoundingClientRect(); return [(ev.clientX - r.left) * 512 / r.width, (ev.clientY - r.top) * 512 / r.height]; }
|
|
c.addEventListener('pointerdown', function (ev) { on = true; var p = pt(ev); g.beginPath(); g.moveTo(p[0], p[1]); try { c.setPointerCapture(ev.pointerId); } catch (x) {} });
|
|
c.addEventListener('pointermove', function (ev) { if (!on) return; var p = pt(ev); g.lineTo(p[0], p[1]); g.stroke(); });
|
|
c.addEventListener('pointerup', function () { on = false; });
|
|
bar.querySelector('input').addEventListener('input', function (ev) { g.strokeStyle = ev.target.value; });
|
|
bar.querySelector('[data-eff]').addEventListener('click', function () { g.fillStyle = '#0b1626'; g.fillRect(0, 0, 512, 512); });
|
|
bar.querySelector('[data-ok]').addEventListener('click', function () { spec.img = c.toDataURL('image/jpeg', .85); spec.imgSrc = 'dessin'; vue2d(); }); }
|
|
d2.addEventListener('click', function (ev) { if (ev.target.closest('[data-dessin]')) dessiner(); });
|
|
container.querySelector('[data-dim]').addEventListener('click', function () { spec.dim = spec.dim === '2d' ? '3d' : '2d'; vue2d(); });
|
|
var imgEl = container.querySelector('[data-imgfile]');
|
|
container.querySelector('[data-img]').addEventListener('click', function () { imgEl.click(); });
|
|
imgEl.addEventListener('change', function () { var f = imgEl.files[0]; if (!f) return; var u = URL.createObjectURL(f);
|
|
reduire(u, function (d) { URL.revokeObjectURL(u); if (!d) return; spec.img = d; spec.imgSrc = 'photo'; spec.dim = '2d'; vue2d(); }); imgEl.value = ''; });
|
|
// ── les panneaux : ⬢ xers installés · ◎ me mapper ──
|
|
var panOuvert = '';
|
|
function panXers() { var reg = (window.__PLOXIONS__ || []).filter(function (p) { return p && p.id && !p.admin; }).map(function (p) { return p.id; });
|
|
var ids = XERS.filter(function (id) { return reg.indexOf(id) >= 0 || !reg.length; }).concat(reg.filter(function (id) { return XERS.indexOf(id) < 0; }).slice(0, 40));
|
|
spec.xers.forEach(function (id) { if (ids.indexOf(id) < 0) ids.unshift(id); });
|
|
pan.innerHTML = '<b>⬢ les xers installés sur ' + esc(spec.name || KINDS.filter(function (k) { return k[0] === kind; })[0][2]) + '</b> <small style="color:#8fa0c8">· ils orbitent autour de lui</small><div class="av__chips">'
|
|
+ ids.map(function (id) { return '<button class="av__chip' + (spec.xers.indexOf(id) >= 0 ? ' on' : '') + '" data-xer="' + esc(id) + '">' + ic(id, 20) + esc(nomPx(id)) + '</button>'; }).join('') + '</div>'; }
|
|
function panMap() { var sc = spec.scan;
|
|
pan.innerHTML = '<b>◎ me mapper en 3D</b> <small style="color:#8fa0c8">· le Terrax : des prises de toi sous tous les angles → un modèle 3D</small><div class="av__chips">'
|
|
+ '<button class="av__chip" data-scan="photos">▣ plein de photos</button><button class="av__chip" data-scan="video">▶ une vidéo</button><button class="av__chip" data-scan="live">◐ en direct (caméra)</button></div>'
|
|
+ '<input type="file" data-scanfile multiple hidden><div data-scanzone style="margin-top:8px;color:#8fa0c8">Tourne lentement autour (ou fais-toi tourner) : 30 à 80 prises, lumière égale, fond calme. '
|
|
+ 'Les prises vont sur ton boxion ; la reconstruction se fait dans ploxi0n (Object Capture, sur iPhone) ou avec un outil de photogrammétrie, puis ⤓ importer le .glb.</div>'
|
|
+ (sc ? '<div style="margin-top:6px">dernier scan : ' + esc(sc.source) + ' · ' + sc.n + ' prise(s) · ' + esc(sc.statut) + '</div>' : ''); }
|
|
function ouvrirPan(q) { panOuvert = panOuvert === q ? '' : q; pan.hidden = !panOuvert; if (panOuvert === 'xers') panXers(); else if (panOuvert === 'map') panMap(); }
|
|
tabs.addEventListener('click', function (ev) { var b = ev.target.closest('[data-pan]'); if (b) ouvrirPan(b.getAttribute('data-pan')); });
|
|
function envoyerScan(source, fichiers) { var z = pan.querySelector('[data-scanzone]'), n = fichiers.length, fait = 0, quand = new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-');
|
|
spec.scan = { source: source, n: n, quand: quand, statut: 'gardé sur l\'appareil' };
|
|
var up = window.jOSBoxion && jOSBoxion.authed && jOSBoxion.authed() && jOSBoxion.uploadFile;
|
|
if (!up) { z.textContent = '◌ ' + n + ' prise(s) — connecte ton boxion pour les y garder.'; return; }
|
|
z.textContent = '⧗ envoi 0/' + n;
|
|
fichiers.forEach(function (f, i) { jOSBoxion.uploadFile(f, 'avatars/scan-' + kind + '-' + quand, (f.name || ('prise-' + i + '.jpg'))).then(function () { fait++; z.textContent = '⧗ envoi ' + fait + '/' + n;
|
|
if (fait === n) { spec.scan.statut = 'sur le boxion · à reconstruire'; z.textContent = '✓ ' + n + ' prise(s) sur ton boxion (avatars/scan-' + kind + '-' + quand + '). Reconstruis, puis ⤓ importer.'; try { window.jOSPorts && jOSPorts.emit('avatar', 'scan', { kind: kind, n: n, source: source }); } catch (x) {} } }); }); }
|
|
var live = null;
|
|
function scanLive() { var z = pan.querySelector('[data-scanzone]'); if (!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)) { z.textContent = '✗ pas de caméra ici.'; return; }
|
|
navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } }).then(function (st) { var v = document.createElement('video'); v.muted = true; v.playsInline = true; v.srcObject = st; v.play(); v.style.cssText = 'width:100%;max-height:160px;border-radius:9px;margin-top:6px';
|
|
z.innerHTML = ''; z.appendChild(v); var info = document.createElement('div'); z.appendChild(info); var prises = [], t0 = Date.now();
|
|
live = { st: st, id: setInterval(function () { if (!v.videoWidth) return; var c = document.createElement('canvas'), k = Math.min(1, 1280 / v.videoWidth); c.width = v.videoWidth * k; c.height = v.videoHeight * k; c.getContext('2d').drawImage(v, 0, 0, c.width, c.height);
|
|
c.toBlob(function (b) { if (b) prises.push(new File([b], 'prise-' + String(prises.length).padStart(3, '0') + '.jpg', { type: 'image/jpeg' })); }, 'image/jpeg', .9);
|
|
var s = Math.round((Date.now() - t0) / 1000); info.textContent = '◐ ' + prises.length + ' prises · ' + s + ' s / 40 · tourne lentement';
|
|
if (s >= 40) fin(); }, 600) };
|
|
function fin() { if (!live) return; clearInterval(live.id); live.st.getTracks().forEach(function (t) { t.stop(); }); live = null; envoyerScan('direct', prises); }
|
|
}).catch(function () { z.textContent = '✗ caméra refusée.'; }); }
|
|
function stopLive() { if (live) { clearInterval(live.id); live.st.getTracks().forEach(function (t) { t.stop(); }); live = null; } }
|
|
pan.addEventListener('click', function (ev) { var x = ev.target.closest('[data-xer]');
|
|
if (x) { var id = x.getAttribute('data-xer'), i = spec.xers.indexOf(id); if (i >= 0) spec.xers.splice(i, 1); else spec.xers.push(id); x.classList.toggle('on', i < 0); anneau(); return; }
|
|
var s = ev.target.closest('[data-scan]'); if (!s) return; var q = s.getAttribute('data-scan'), fe = pan.querySelector('[data-scanfile]');
|
|
if (q === 'live') return scanLive();
|
|
fe.accept = q === 'video' ? 'video/*' : 'image/*'; fe.multiple = q !== 'video'; fe.onchange = function () { var l = [].slice.call(fe.files || []); if (l.length) envoyerScan(q === 'video' ? 'vidéo' : 'photos', l); fe.value = ''; }; fe.click(); });
|
|
|
|
function syncControls() { anneau(); vue2d(); if (panOuvert === 'xers') panXers(); else if (panOuvert === 'map') panMap(); container.querySelector('[data-name]').value = spec.name || ''; container.querySelector('[data-body]').value = spec.body; container.querySelector('[data-accent]').value = spec.accent; container.querySelector('[data-shape]').value = spec.shape; container.querySelector('[data-style]').value = spec.style || 'lisse'; container.querySelector('[data-face]').textContent = spec.face; container.querySelector('[data-aura]').checked = !!spec.aura; }
|
|
syncControls();
|
|
|
|
tabs.addEventListener('click', function (ev) { var t = ev.target.closest('[data-t]'); if (!t) return; kind = t.getAttribute('data-t'); spec = load(kind); tabs.querySelectorAll('.av__tab').forEach(function (x) { x.classList.toggle('on', x === t); }); syncControls(); rebuild(); });
|
|
container.querySelector('[data-name]').addEventListener('input', function (ev) { spec.name = ev.target.value; });
|
|
container.querySelector('[data-body]').addEventListener('input', function (ev) { spec.body = ev.target.value; rebuild(); });
|
|
container.querySelector('[data-accent]').addEventListener('input', function (ev) { spec.accent = ev.target.value; rebuild(); });
|
|
container.querySelector('[data-shape]').addEventListener('change', function (ev) { spec.shape = ev.target.value; rebuild(); });
|
|
container.querySelector('[data-style]').addEventListener('change', function (ev) { spec.style = ev.target.value; rebuild(); });
|
|
container.querySelector('[data-face]').addEventListener('click', function (ev) { var i = (FACES.indexOf(spec.face) + 1) % FACES.length; spec.face = FACES[i]; ev.target.textContent = spec.face; rebuild(); });
|
|
container.querySelector('[data-aura]').addEventListener('change', function (ev) { spec.aura = ev.target.checked; rebuild(); });
|
|
// IMPORT d'un avatar 3D de n'importe quel jeu (GLB/GLTF/VRM/FBX/OBJ)
|
|
var fileEl = container.querySelector('[data-file]');
|
|
container.querySelector('[data-import]').addEventListener('click', function () { fileEl.click(); });
|
|
fileEl.addEventListener('change', function () { var f = fileEl.files[0]; if (!f || !e) return; var ext = (f.name.split('.').pop() || '').toLowerCase();
|
|
var btn = container.querySelector('[data-import]'); btn.textContent = '⏳ ' + f.name;
|
|
var url = URL.createObjectURL(f);
|
|
e.load(url, ext).then(function (obj) { URL.revokeObjectURL(url);
|
|
if (avatar) { try { e.world.scene.remove(avatar); } catch (x) {} } var T = e.THREE;
|
|
// recentre + met à ~1.8 de haut
|
|
var box = new T.Box3().setFromObject(obj), sz = new T.Vector3(); box.getSize(sz); var s = 1.8 / (sz.y || 1); obj.scale.multiplyScalar(s);
|
|
box.setFromObject(obj); var c = new T.Vector3(); box.getCenter(c); obj.position.x -= c.x; obj.position.z -= c.z; obj.position.y -= box.min.y;
|
|
obj.traverse(function (m) { if (m.isMesh) m.castShadow = true; });
|
|
avatar = new T.Group(); avatar.add(obj); e.world.scene.add(avatar); e.world.cam.target.set(0, 0.9, 0);
|
|
spec.imported = f.name; spec.dim = '3d'; vue2d(); if (spec.scan) spec.scan.statut = 'reconstruit · ' + f.name; spec.ext = ext; btn.textContent = '✓ ' + f.name;
|
|
// archive le fichier sur le boxion (pour que le monde puisse le charger)
|
|
try { if (window.jOSBoxion && jOSBoxion.authed && jOSBoxion.authed() && jOSBoxion.uploadFile) jOSBoxion.uploadFile(f, 'avatars', kind + '.' + ext).then(function (r) { if (r && r.url) spec.url = r.url; }); } catch (x) {}
|
|
try { window.jOSPorts && jOSPorts.emit('avatar', 'imported', { kind: kind, name: f.name }); } catch (x) {}
|
|
}).catch(function (err) { URL.revokeObjectURL(url); btn.textContent = '✗ ' + (err && err.message || 'import raté'); setTimeout(function () { btn.textContent = '⤓ importer (GLB/VRM/FBX)'; }, 2000); });
|
|
fileEl.value = ''; });
|
|
|
|
container.querySelector('[data-save]').addEventListener('click', function () {
|
|
try { localStorage.setItem('avatar:' + kind, JSON.stringify(spec)); } catch (er) {}
|
|
try { window.jOSBoxion && jOSBoxion.saveSoon && jOSBoxion.saveSoon('avatar', kind, spec, 'avatar ' + kind); } catch (er) {}
|
|
try { window.jOSNexus && jOSNexus.push('avatar:' + kind, spec); } catch (er) {}
|
|
try { window.jOSPorts && jOSPorts.emit('avatar', 'saved', { kind: kind }); } catch (er) {}
|
|
container.querySelector('[data-save]').textContent = '✓ ' + kind + ' sauvé'; setTimeout(function () { container.querySelector('[data-save]').textContent = '▣ sauver mon avatar'; }, 1200);
|
|
});
|
|
|
|
return { unmount: function () { stopLive(); try { e && e.dispose(); } catch (x) {} container.innerHTML = ''; } };
|
|
}
|
|
window.jOSApps = window.jOSApps || {};
|
|
window.jOSApps['avatar'] = { manifest: { id: 'avatar', name: 'Avatar', icon: '◍' }, mount: mount, describe: describe };
|
|
})();
|
|
</script>
|