-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathedtv2.html
More file actions
275 lines (275 loc) · 14.8 KB
/
edtv2.html
File metadata and controls
275 lines (275 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes, viewport-fit=cover">
<title>edTV: CHANNEL 2</title>
<meta name="theme-color" content="#000000">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/three@0.158.0/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/control_utils/control_utils.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js"></script>
<style>
*{margin:0;padding:0;box-sizing:border-box;font-family:'Press Start 2P',cursive;image-rendering:pixelated}
body{background:#000;color:#0f0;overflow:hidden;height:100vh;user-select:none;-webkit-tap-highlight-color:transparent}
#appContainer{position:relative;width:100%;height:100vh;overflow:hidden}
.matrix-grid{position:absolute;top:0;left:0;width:100%;height:100%;background:linear-gradient(rgba(0,255,0,0.1)1px,transparent 1px),linear-gradient(90deg,rgba(0,255,0,0.1)1px,transparent 1px);background-size:16px 16px;opacity:0.3}
.crt-overlay{position:absolute;top:0;left:0;width:100%;height:100%;background:linear-gradient(to bottom,transparent 50%,rgba(0,20,0,0.1)50%);background-size:100% 4px;z-index:5;pointer-events:none;animation:scanline 8s linear infinite}
@keyframes scanline{0%{background-position:0 0}100%{background-position:0 100%}}
#visualizationContainer{position:absolute;top:0;left:0;width:100%;height:100%;z-index:2}
.infrared-scanner{position:absolute;top:0;left:0;width:100%;height:4px;background:rgba(255,0,0,0.8);box-shadow:0 0 20px 5px rgba(255,0,0,0.8);z-index:3;animation:scanner 4s linear infinite}
@keyframes scanner{0%{top:0}50%{top:100%}100%{top:0}}
/* Top Banner */
.top-banner{position:absolute;top:0;left:0;width:100%;height:50px;background:rgba(255,0,255,0.9);border-bottom:2px solid #f0f;display:flex;align-items:center;justify-content:center;z-index:12}
.top-banner-text{font-size:13px;color:#000;text-shadow:1px 1px 0 #fff;letter-spacing:1px}
/* Top-Right Buttons */
.top-controls{position:absolute;top:52px;right:8px;display:flex;gap:8px;z-index:20}
.btn{height:38px;min-width:90px;background:#000;border:2px solid #0ff;color:#0ff;font-size:9px;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:0.2s}
.btn:hover,.btn:active{background:#0ff;color:#000}
.btn.import{border-color:#f0f;color:#f0f}
.btn.import:hover{background:#f0f;color:#000}
.btn.fullscreen{border-color:#ff0;color:#ff0}
.btn.fullscreen:hover{background:#ff0;color:#000}
.btn.disabled{opacity:0.5;pointer-events:none}
/* PIP - Top Center (webcam feed with mask overlay) */
.ppv-face-view{position:absolute;top:55px;left:50%;transform:translateX(-50%);width:260px;height:195px;background:#000;border:3px solid #f00;z-index:18;overflow:hidden;cursor:pointer;box-shadow:0 0 20px rgba(255,0,0,0.7)}
.ppv-face-view.enlarged{width:100%;height:100%;top:0;left:0;transform:none;z-index:30}
.ppv-canvas{width:100%;height:100%}
/* Scanner bar inside PIP */
.scanner{position:absolute;top:0;left:0;width:100%;height:4px;background:rgba(255,0,0,0.9);box-shadow:0 0 15px 3px #f00;z-index:19;opacity:0;animation:scanner 2s linear infinite}
.scanner.active{opacity:1}
/* Small Terminal - Bottom (smaller height) */
.terminal-panel{position:absolute;bottom:0;left:0;width:100%;height:120px;background:rgba(0,0,0,0.95);border-top:2px solid #f00;display:flex;flex-direction:column;z-index:15}
.terminal-body{flex:1;overflow-y:auto;padding:6px 8px;color:#ff5555;font-size:6px;line-height:1.3;background:repeating-linear-gradient(0deg,#000 0px,#000 1px,#0a0a0a 1px,#0a0a0a 2px);display:flex;flex-direction:column-reverse}
.log-line{margin-bottom:2px;word-break:break-all}
.log-error{color:#ff3333}
.log-success{color:#33ff33}
.log-data{color:#ffff55}
.log-hash{color:#ff55ff;font-weight:bold}
.log-badge{color:#0ff;font-weight:bold}
/* Badge Overlay (with serial for screenshot) */
.badge-overlay{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:90%;max-width:340px;padding:15px;background:rgba(0,0,0,0.9);border:3px solid #0ff;color:#0ff;font-size:8px;line-height:1.5;text-align:center;z-index:40;display:none}
@media (max-width:767px){
.top-controls{top:50px;right:5px;gap:6px}
.btn{height:36px;min-width:78px;font-size:8px}
.ppv-face-view{top:52px;width:200px;height:150px}
.terminal-panel{height:100px}
.terminal-body{font-size:5.5px;padding:5px}
}
</style>
</head>
<body>
<div id="appContainer">
<div class="matrix-grid"></div>
<div class="crt-overlay"></div>
<div class="infrared-scanner"></div>
<!-- Top Banner -->
<div class="top-banner">
<div class="top-banner-text">edTV: CHANNEL 2</div>
</div>
<!-- Top-Right Buttons -->
<div class="top-controls">
<button id="importBtn" class="btn import">IMPORT JSON</button>
<button id="validateBtn" class="btn disabled">VALIDATE</button>
<button id="fullscreenBtn" class="btn fullscreen">FULL SCREEN</button>
</div>
<!-- PIP - Top Center with Scanner Bar -->
<div class="ppv-face-view" id="ppvFaceView">
<canvas class="ppv-canvas" id="ppvCanvas"></canvas>
<div class="scanner" id="scanner"></div>
</div>
<!-- Small Terminal (oldest at top, newest at bottom for small size) -->
<div class="terminal-panel">
<div class="terminal-body" id="terminalLog">
<div class="log-line log-success">> SYSTEM ONLINE - VALIDATION MODE</div>
<div class="log-line">> DOUBLE-CLICK PIP TO ENLARGE</div>
</div>
</div>
<!-- Badge Overlay (serial tied to 3D data for screenshot) -->
<div class="badge-overlay" id="badgeOverlay">
<div class="badge-title">BADGE</div>
<div class="badge-id" id="badgeId">ID: BADGE_XXXXXX</div>
<div class="badge-serial" id="badgeSerial">SERIAL: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</div>
<div class="badge-hash" id="badgeHash">HASH: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
</div>
<!-- Large 3D Scene (main view, spinning mask) -->
<div id="visualizationContainer">
<canvas id="visualizationCanvas"></canvas>
</div>
</div>
<script>
let scene, cam, ren, clock, faceGroup;
let faceMesh, camera, stream;
let isProcessing = false, timerInterval = null;
let landmarks = [];
let wireframe = null;
let importedData = null;
const $ = s => document.querySelector(s);
const ppvFaceView = $('#ppvFaceView');
const ppvCanvas = $('#ppvCanvas');
const ppvCtx = ppvCanvas.getContext('2d');
const logEl = $('#terminalLog');
const importBtn = $('#importBtn');
const validateBtn = $('#validateBtn');
const fullscreenBtn = $('#fullscreenBtn');
const scannerBar = $('#scanner');
const badgeOverlay = $('#badgeOverlay');
const badgeId = $('#badgeId');
const badgeSerial = $('#badgeSerial');
const badgeHash = $('#badgeHash');
function init() {
init3D(); setupFaceDetection(); setupEventListeners(); animate();
log('FACE VALIDATION SYSTEM READY', 'log-success');
}
function init3D() {
scene = new THREE.Scene(); scene.background = new THREE.Color(0x000000);
cam = new THREE.PerspectiveCamera(45, innerWidth/innerHeight, 0.1, 100);
cam.position.set(0,0,1.5);
ren = new THREE.WebGLRenderer({canvas: $('#visualizationCanvas'), antialias:false});
ren.setSize(innerWidth, innerHeight); ren.setPixelRatio(1);
clock = new THREE.Clock();
scene.add(new THREE.AmbientLight(0x404040));
scene.add(new THREE.DirectionalLight(0xffffff,1).position.set(5,5,5));
faceGroup = new THREE.Group(); scene.add(faceGroup);
}
function setupFaceDetection() {
faceMesh = new FaceMesh({locateFile: f => `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${f}`});
faceMesh.setOptions({maxNumFaces:1, refineLandmarks:true, minDetectionConfidence:0.5, minTrackingConfidence:0.5});
faceMesh.onResults(onFaceMeshResults);
}
function onFaceMeshResults(results) {
ppvCtx.clearRect(0,0,ppvCanvas.width,ppvCanvas.height);
if (results.image) ppvCtx.drawImage(results.image,0,0,ppvCanvas.width,ppvCanvas.height);
if (results.multiFaceLandmarks?.[0]) {
const lm = results.multiFaceLandmarks[0];
drawConnectors(ppvCtx, lm, FACEMESH_TESSELATION, {color:'#C0C0C070',lineWidth:1});
drawConnectors(ppvCtx, lm, FACEMESH_RIGHT_EYE, {color:'#FF3030',lineWidth:1});
drawConnectors(ppvCtx, lm, FACEMESH_LEFT_EYE, {color:'#30FF30',lineWidth:1});
drawConnectors(ppvCtx, lm, FACEMESH_FACE_OVAL, {color:'#E0E0E0',lineWidth:2});
if (isProcessing) processLandmarks(lm);
}
}
function processLandmarks(lm) {
landmarks = lm.map(l => ({x: (l.x - 0.5) * 2, y: (0.5 - l.y) * 2, z: l.z * -0.5}));
update3DMask();
}
function update3DMask() {
if (wireframe) faceGroup.remove(wireframe);
const geo = new THREE.BufferGeometry();
const pos = new Float32Array(landmarks.length * 3);
landmarks.forEach((l, i) => { pos[i*3] = l.x; pos[i*3+1] = l.y; pos[i*3+2] = l.z; });
geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
const indices = []; FACEMESH_TESSELATION.forEach(([a,b]) => indices.push(a,b));
geo.setIndex(indices);
wireframe = new THREE.LineSegments(geo, new THREE.LineBasicMaterial({color: 0x00ff00}));
faceGroup.add(wireframe);
}
function startWebcam() {
if (stream) return;
navigator.mediaDevices.getUserMedia({video:{facingMode:'user',width:{ideal:640},height:{ideal:480}}}).then(s=>{
stream=s;
const v=document.createElement('video'); v.srcObject=s; v.autoplay=v.playsInline=true; v.style.display='none'; document.body.appendChild(v);
camera = new Camera(v,{onFrame:()=>faceMesh.send({image:v})}); camera.start();
ppvCanvas.width=ppvFaceView.clientWidth; ppvCanvas.height=ppvFaceView.clientHeight;
log('WEBCAM ACTIVE', 'log-success');
});
}
function stopWebcam() {
if (stream) stream.getTracks().forEach(t=>t.stop()); stream=null;
if (camera) camera.stop();
$('#webcamVideo')?.remove();
}
function startProcessing() {
if (!importedData) { log('NO JSON IMPORTED', 'log-error'); return; }
badgeOverlay.style.display = 'none';
landmarks=[]; isProcessing=true;
validateBtn.classList.add('disabled'); validateBtn.textContent='VALIDATING...';
scannerBar.classList.add('active');
log('SCAN ACTIVE - CENTER FACE', 'log-success');
startWebcam();
let sec=0; timerInterval=setInterval(()=>{ if(++sec>=5) finishProcessing(); },1000);
}
function finishProcessing() {
clearInterval(timerInterval); isProcessing=false; stopWebcam();
scannerBar.classList.remove('active');
if (!landmarks.length) { log('NO FACE DATA', 'log-error'); resetScan(); return; }
if (!importedData.landmarks) { log('NO LANDMARKS IN JSON', 'log-error'); resetScan(); return; }
if (landmarks.length !== importedData.landmarks.length) { log('INVALID: MISMATCH COUNT', 'log-error'); resetScan(); return; }
let totalDist = 0;
for (let i = 0; i < landmarks.length; i++) {
const dx = landmarks[i].x - importedData.landmarks[i].x;
const dy = landmarks[i].y - importedData.landmarks[i].y;
const dz = landmarks[i].z - importedData.landmarks[i].z;
totalDist += Math.sqrt(dx*dx + dy*dy + dz*dz);
}
const avgDist = totalDist / landmarks.length;
const threshold = 0.01;
if (avgDist < threshold) {
log(`VALIDATION: VALID (Dist: ${avgDist.toFixed(4)})`, 'log-success');
badgeId.textContent = importedData.badgeId;
badgeSerial.textContent = `SERIAL: ${importedData.serial}`;
badgeHash.textContent = `HASH: ${importedData.hash}`;
badgeOverlay.style.display = 'block';
} else {
log(`VALIDATION: INVALID (Dist: ${avgDist.toFixed(4)})`, 'log-error');
}
resetScan();
}
function resetScan() {
isProcessing=false; validateBtn.textContent='VALIDATE'; validateBtn.classList.remove('disabled');
scannerBar.classList.remove('active');
landmarks=[]; if (wireframe) faceGroup.remove(wireframe); wireframe=null;
}
function log(msg, type='') {
const line = document.createElement('div');
line.className = `log-line ${type}`;
line.textContent = '> ' + msg;
logEl.appendChild(line);
logEl.scrollTop = logEl.scrollHeight;
}
function importJson() {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.onchange = e => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = ev => {
try {
importedData = JSON.parse(ev.target.result);
log('JSON IMPORTED', 'log-success');
validateBtn.classList.remove('disabled');
} catch (err) {
log('INVALID JSON', 'log-error');
}
};
reader.readAsText(file);
};
input.click();
}
function toggleFullscreen() {
if (!document.fullscreenElement) document.documentElement.requestFullscreen();
else document.exitFullscreen();
}
function setupEventListeners() {
importBtn.onclick = importJson;
validateBtn.onclick = () => !isProcessing && startProcessing();
fullscreenBtn.onclick = toggleFullscreen;
ppvFaceView.ondblclick = () => ppvFaceView.classList.toggle('enlarged');
window.onresize = () => {
cam.aspect = innerWidth/innerHeight; cam.updateProjectionMatrix();
ren.setSize(innerWidth,innerHeight);
ppvCanvas.width=ppvFaceView.clientWidth; ppvCanvas.height=ppvFaceView.clientHeight;
};
}
function animate() {
requestAnimationFrame(animate);
if (wireframe) faceGroup.rotation.y += 0.005;
ren.render(scene,cam);
}
window.onload = init;
</script>
</body>
</html>