webxos commited on
Commit
fdd4cbd
·
verified ·
1 Parent(s): e91bb63

Upload webXOS_underworld_v1.html

Browse files
Files changed (1) hide show
  1. webXOS_underworld_v1.html +763 -0
webXOS_underworld_v1.html ADDED
@@ -0,0 +1,763 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>WEBXOS UNDERWORLD - Micro-Scale Wireframe Viewer</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ padding: 0;
11
+ overflow: hidden;
12
+ background: #111;
13
+ font-family: monospace;
14
+ }
15
+ canvas {
16
+ display: block;
17
+ cursor: grab;
18
+ }
19
+ canvas:active {
20
+ cursor: grabbing;
21
+ }
22
+ #info {
23
+ position: absolute;
24
+ top: 10px;
25
+ left: 10px;
26
+ color: #0f0;
27
+ font-family: monospace;
28
+ font-size: 12px;
29
+ background: rgba(0,0,0,0.7);
30
+ padding: 8px;
31
+ border-radius: 4px;
32
+ user-select: none;
33
+ z-index: 100;
34
+ backdrop-filter: blur(2px);
35
+ max-width: 300px;
36
+ line-height: 1.4;
37
+ }
38
+ #controls {
39
+ position: absolute;
40
+ bottom: 10px;
41
+ left: 50%;
42
+ transform: translateX(-50%);
43
+ color: #0ff;
44
+ font-size: 11px;
45
+ background: rgba(0,0,0,0.7);
46
+ padding: 8px 12px;
47
+ border-radius: 4px;
48
+ user-select: none;
49
+ z-index: 100;
50
+ backdrop-filter: blur(2px);
51
+ text-align: center;
52
+ }
53
+ #export-btn {
54
+ position: absolute;
55
+ top: 10px;
56
+ right: 10px;
57
+ background: rgba(0, 100, 0, 0.7);
58
+ color: #0f0;
59
+ border: 1px solid #0f0;
60
+ padding: 8px 16px;
61
+ border-radius: 4px;
62
+ cursor: pointer;
63
+ font-family: monospace;
64
+ font-size: 12px;
65
+ z-index: 100;
66
+ backdrop-filter: blur(2px);
67
+ }
68
+ #export-btn:hover {
69
+ background: rgba(0, 150, 0, 0.8);
70
+ }
71
+ #export-btn.recording {
72
+ background: rgba(150, 0, 0, 0.7);
73
+ color: #f00;
74
+ border-color: #f00;
75
+ animation: pulse 1s infinite;
76
+ }
77
+ @keyframes pulse {
78
+ 0% { opacity: 1; }
79
+ 50% { opacity: 0.7; }
80
+ 100% { opacity: 1; }
81
+ }
82
+ </style>
83
+ <script src="https://unpkg.com/three@0.157.0/build/three.min.js"></script>
84
+ <script src="https://unpkg.com/jszip@3.10.1/dist/jszip.min.js"></script>
85
+ </head>
86
+ <body>
87
+ <div id="info">Loading WEBXOS UNDERWORLD...</div>
88
+ <button id="export-btn" title="Press R or click to record">RECORD (R)</button>
89
+ <div id="controls">Drag to rotate • Scroll to zoom • R to record</div>
90
+
91
+ <script>
92
+ class MicroWireframeViewer {
93
+ constructor() {
94
+ this.scene = null;
95
+ this.camera = null;
96
+ this.renderer = null;
97
+ this.frameCount = 0;
98
+ this.fps = 60;
99
+ this.triangleCount = 0;
100
+ this.lastTime = performance.now();
101
+ this.isDragging = false;
102
+ this.previousMouse = { x: 0, y: 0 };
103
+ this.objects = [];
104
+ this.rotationSpeed = 0.002;
105
+
106
+ // Recording properties
107
+ this.recording = false;
108
+ this.frames = [];
109
+ this.frameIndex = 0;
110
+ this.maxFrames = 256; // ~8.5s @30fps
111
+ this.frameRate = 30;
112
+ this.recordingStartTime = 0;
113
+
114
+ this.init();
115
+ this.createSampleStructures();
116
+ this.animate();
117
+ }
118
+
119
+ init() {
120
+ // Scene
121
+ this.scene = new THREE.Scene();
122
+ this.scene.background = new THREE.Color(0x0a0a0a);
123
+
124
+ // Camera
125
+ this.camera = new THREE.PerspectiveCamera(
126
+ 75,
127
+ window.innerWidth / window.innerHeight,
128
+ 0.1,
129
+ 1000
130
+ );
131
+ this.camera.position.set(8, 8, 8);
132
+ this.camera.lookAt(0, 0, 0);
133
+
134
+ // Renderer - Optimized for mobile/low-end
135
+ this.renderer = new THREE.WebGLRenderer({
136
+ antialias: false,
137
+ powerPreference: "low-power",
138
+ alpha: false,
139
+ stencil: false,
140
+ depth: true,
141
+ preserveDrawingBuffer: true // Required for toDataURL
142
+ });
143
+ this.renderer.setSize(window.innerWidth, window.innerHeight);
144
+ this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
145
+ document.body.appendChild(this.renderer.domElement);
146
+
147
+ // Basic lighting
148
+ const ambient = new THREE.AmbientLight(0x404040);
149
+ this.scene.add(ambient);
150
+
151
+ // Handle window resize
152
+ window.addEventListener('resize', () => this.onWindowResize(), false);
153
+
154
+ // Setup controls
155
+ this.setupControls();
156
+
157
+ // Setup export button
158
+ this.setupExportButton();
159
+
160
+ // Performance monitoring
161
+ this.setupPerformanceMonitor();
162
+ }
163
+
164
+ setupControls() {
165
+ const canvas = this.renderer.domElement;
166
+
167
+ // Mouse controls
168
+ canvas.addEventListener('mousedown', (e) => {
169
+ this.isDragging = true;
170
+ this.previousMouse = { x: e.clientX, y: e.clientY };
171
+ });
172
+
173
+ canvas.addEventListener('mousemove', (e) => {
174
+ if (!this.isDragging) return;
175
+
176
+ const deltaX = e.clientX - this.previousMouse.x;
177
+ const deltaY = e.clientY - this.previousMouse.y;
178
+
179
+ // Rotate camera around the center
180
+ const angleX = deltaX * 0.01;
181
+ const angleY = deltaY * 0.01;
182
+
183
+ // Rotate camera position around Y axis
184
+ const radius = Math.sqrt(
185
+ this.camera.position.x * this.camera.position.x +
186
+ this.camera.position.z * this.camera.position.z
187
+ );
188
+ const theta = Math.atan2(this.camera.position.z, this.camera.position.x) + angleX;
189
+ const phi = Math.atan2(
190
+ Math.sqrt(this.camera.position.x * this.camera.position.x +
191
+ this.camera.position.z * this.camera.position.z),
192
+ this.camera.position.y
193
+ ) + angleY;
194
+
195
+ // Clamp phi to prevent flipping
196
+ const clampedPhi = Math.max(0.1, Math.min(Math.PI - 0.1, phi));
197
+
198
+ this.camera.position.x = radius * Math.sin(clampedPhi) * Math.cos(theta);
199
+ this.camera.position.y = radius * Math.cos(clampedPhi);
200
+ this.camera.position.z = radius * Math.sin(clampedPhi) * Math.sin(theta);
201
+
202
+ this.camera.lookAt(0, 0, 0);
203
+ this.previousMouse = { x: e.clientX, y: e.clientY };
204
+ });
205
+
206
+ canvas.addEventListener('mouseup', () => {
207
+ this.isDragging = false;
208
+ });
209
+
210
+ canvas.addEventListener('mouseleave', () => {
211
+ this.isDragging = false;
212
+ });
213
+
214
+ // Touch controls for mobile
215
+ canvas.addEventListener('touchstart', (e) => {
216
+ if (e.touches.length === 1) {
217
+ this.isDragging = true;
218
+ this.previousMouse = {
219
+ x: e.touches[0].clientX,
220
+ y: e.touches[0].clientY
221
+ };
222
+ e.preventDefault();
223
+ }
224
+ }, { passive: false });
225
+
226
+ canvas.addEventListener('touchmove', (e) => {
227
+ if (!this.isDragging || e.touches.length !== 1) return;
228
+
229
+ const deltaX = e.touches[0].clientX - this.previousMouse.x;
230
+ const deltaY = e.touches[0].clientY - this.previousMouse.y;
231
+
232
+ const angleX = deltaX * 0.02;
233
+ const angleY = deltaY * 0.02;
234
+
235
+ const radius = Math.sqrt(
236
+ this.camera.position.x * this.camera.position.x +
237
+ this.camera.position.z * this.camera.position.z
238
+ );
239
+ const theta = Math.atan2(this.camera.position.z, this.camera.position.x) + angleX;
240
+ const phi = Math.atan2(
241
+ Math.sqrt(this.camera.position.x * this.camera.position.x +
242
+ this.camera.position.z * this.camera.position.z),
243
+ this.camera.position.y
244
+ ) + angleY;
245
+
246
+ const clampedPhi = Math.max(0.1, Math.min(Math.PI - 0.1, phi));
247
+
248
+ this.camera.position.x = radius * Math.sin(clampedPhi) * Math.cos(theta);
249
+ this.camera.position.y = radius * Math.cos(clampedPhi);
250
+ this.camera.position.z = radius * Math.sin(clampedPhi) * Math.sin(theta);
251
+
252
+ this.camera.lookAt(0, 0, 0);
253
+ this.previousMouse = {
254
+ x: e.touches[0].clientX,
255
+ y: e.touches[0].clientY
256
+ };
257
+ e.preventDefault();
258
+ }, { passive: false });
259
+
260
+ canvas.addEventListener('touchend', () => {
261
+ this.isDragging = false;
262
+ });
263
+
264
+ // Zoom with wheel
265
+ canvas.addEventListener('wheel', (e) => {
266
+ const zoomFactor = 0.001;
267
+ this.camera.position.multiplyScalar(1 + e.deltaY * zoomFactor);
268
+ this.camera.position.clampLength(3, 30);
269
+ this.camera.lookAt(0, 0, 0);
270
+ });
271
+ }
272
+
273
+ setupExportButton() {
274
+ const exportBtn = document.getElementById('export-btn');
275
+ exportBtn.addEventListener('click', () => {
276
+ if (!this.recording) {
277
+ this.startRecording();
278
+ } else {
279
+ this.stopRecording();
280
+ }
281
+ });
282
+ }
283
+
284
+ createWireframeCube(position, scale = 1, color = 0x00ff00) {
285
+ const geometry = new THREE.BoxGeometry(scale, scale, scale, 1, 1, 1);
286
+ const edges = new THREE.EdgesGeometry(geometry);
287
+
288
+ const material = new THREE.LineBasicMaterial({
289
+ color: color,
290
+ linewidth: 1,
291
+ transparent: true,
292
+ opacity: 0.8
293
+ });
294
+
295
+ const wireframe = new THREE.LineSegments(edges, material);
296
+ wireframe.position.copy(position);
297
+ wireframe.userData.originalPosition = position.clone();
298
+ wireframe.userData.originalScale = scale;
299
+ wireframe.userData.pulsePhase = Math.random() * Math.PI * 2;
300
+ wireframe.userData.originalQuaternion = wireframe.quaternion.clone();
301
+
302
+ this.objects.push(wireframe);
303
+ return wireframe;
304
+ }
305
+
306
+ createWireframeSphere(position, radius = 1, color = 0xff6600) {
307
+ const geometry = new THREE.SphereGeometry(radius, 8, 6); // Low poly
308
+ const edges = new THREE.EdgesGeometry(geometry);
309
+
310
+ const material = new THREE.LineBasicMaterial({
311
+ color: color,
312
+ linewidth: 1,
313
+ transparent: true,
314
+ opacity: 0.7
315
+ });
316
+
317
+ const wireframe = new THREE.LineSegments(edges, material);
318
+ wireframe.position.copy(position);
319
+ wireframe.userData.originalPosition = position.clone();
320
+ wireframe.userData.originalScale = radius;
321
+ wireframe.userData.pulsePhase = Math.random() * Math.PI * 2;
322
+ wireframe.userData.originalQuaternion = wireframe.quaternion.clone();
323
+
324
+ this.objects.push(wireframe);
325
+ return wireframe;
326
+ }
327
+
328
+ createWireframeTorus(position, radius = 1, tube = 0.3, color = 0x00ffff) {
329
+ const geometry = new THREE.TorusGeometry(radius, tube, 8, 12);
330
+ const edges = new THREE.EdgesGeometry(geometry);
331
+
332
+ const material = new THREE.LineBasicMaterial({
333
+ color: color,
334
+ linewidth: 1,
335
+ transparent: true,
336
+ opacity: 0.6
337
+ });
338
+
339
+ const wireframe = new THREE.LineSegments(edges, material);
340
+ wireframe.position.copy(position);
341
+ wireframe.userData.originalPosition = position.clone();
342
+ wireframe.userData.rotationSpeed = (Math.random() - 0.5) * 0.01;
343
+ wireframe.userData.originalQuaternion = wireframe.quaternion.clone();
344
+
345
+ this.objects.push(wireframe);
346
+ return wireframe;
347
+ }
348
+
349
+ createSpatialGrid(size = 20, divisions = 20) {
350
+ const grid = new THREE.GridHelper(size, divisions, 0x333333, 0x222222);
351
+ grid.material.transparent = true;
352
+ grid.material.opacity = 0.3;
353
+ return grid;
354
+ }
355
+
356
+ createSampleStructures() {
357
+ // Create spatial grid
358
+ const grid = this.createSpatialGrid(30, 30);
359
+ this.scene.add(grid);
360
+
361
+ // Central structure - Complex wireframe
362
+ const centerGroup = new THREE.Group();
363
+
364
+ // Main cube
365
+ const mainCube = this.createWireframeCube(new THREE.Vector3(0, 0, 0), 3, 0x00ff00);
366
+ centerGroup.add(mainCube);
367
+
368
+ // Inner structures
369
+ for (let i = 0; i < 6; i++) {
370
+ const angle = (i / 6) * Math.PI * 2;
371
+ const radius = 1.8;
372
+ const x = Math.cos(angle) * radius;
373
+ const y = Math.sin(angle) * radius;
374
+ const sphere = this.createWireframeSphere(new THREE.Vector3(x, y, 0), 0.5, 0xff6600);
375
+ centerGroup.add(sphere);
376
+ }
377
+
378
+ // Top and bottom spheres
379
+ const topSphere = this.createWireframeSphere(new THREE.Vector3(0, 0, 2), 0.8, 0xff00ff);
380
+ const bottomSphere = this.createWireframeSphere(new THREE.Vector3(0, 0, -2), 0.8, 0xff00ff);
381
+ centerGroup.add(topSphere);
382
+ centerGroup.add(bottomSphere);
383
+
384
+ this.scene.add(centerGroup);
385
+
386
+ // Orbiting structures
387
+ const orbitGroup = new THREE.Group();
388
+
389
+ for (let i = 0; i < 12; i++) {
390
+ const angle = (i / 12) * Math.PI * 2;
391
+ const radius = 8;
392
+ const height = (Math.random() - 0.5) * 4;
393
+
394
+ const x = Math.cos(angle) * radius;
395
+ const y = height;
396
+ const z = Math.sin(angle) * radius;
397
+
398
+ const shapeType = Math.floor(Math.random() * 3);
399
+ let shape;
400
+
401
+ switch(shapeType) {
402
+ case 0:
403
+ shape = this.createWireframeCube(
404
+ new THREE.Vector3(x, y, z),
405
+ 0.7 + Math.random() * 0.5,
406
+ 0x00aaff
407
+ );
408
+ break;
409
+ case 1:
410
+ shape = this.createWireframeSphere(
411
+ new THREE.Vector3(x, y, z),
412
+ 0.4 + Math.random() * 0.4,
413
+ 0xffaa00
414
+ );
415
+ break;
416
+ case 2:
417
+ shape = this.createWireframeTorus(
418
+ new THREE.Vector3(x, y, z),
419
+ 0.6 + Math.random() * 0.4,
420
+ 0.15,
421
+ 0x00ffaa
422
+ );
423
+ shape.rotation.x = Math.random() * Math.PI;
424
+ shape.rotation.y = Math.random() * Math.PI;
425
+ shape.userData.originalQuaternion = shape.quaternion.clone();
426
+ break;
427
+ }
428
+
429
+ shape.userData.orbitRadius = radius;
430
+ shape.userData.orbitAngle = angle;
431
+ shape.userData.orbitSpeed = 0.001 + Math.random() * 0.002;
432
+ shape.userData.orbitHeight = height;
433
+ orbitGroup.add(shape);
434
+ }
435
+
436
+ this.scene.add(orbitGroup);
437
+
438
+ // Random scattered objects
439
+ for (let i = 0; i < 40; i++) {
440
+ const x = (Math.random() - 0.5) * 25;
441
+ const y = (Math.random() - 0.5) * 25;
442
+ const z = (Math.random() - 0.5) * 25;
443
+
444
+ const cube = this.createWireframeCube(
445
+ new THREE.Vector3(x, y, z),
446
+ 0.2 + Math.random() * 0.4,
447
+ 0x666666
448
+ );
449
+ cube.userData.floatSpeed = Math.random() * 0.005;
450
+ cube.userData.floatDirection = new THREE.Vector3(
451
+ Math.random() - 0.5,
452
+ Math.random() - 0.5,
453
+ Math.random() - 0.5
454
+ ).normalize();
455
+ cube.userData.originalPosition = cube.position.clone();
456
+
457
+ this.scene.add(cube);
458
+ }
459
+
460
+ this.updateTriangleCount();
461
+ }
462
+
463
+ updateTriangleCount() {
464
+ this.triangleCount = 0;
465
+ this.scene.traverse((object) => {
466
+ if (object.isLineSegments || object.isLine) {
467
+ if (object.geometry && object.geometry.attributes && object.geometry.attributes.position) {
468
+ this.triangleCount += object.geometry.attributes.position.count / 3;
469
+ }
470
+ }
471
+ });
472
+ }
473
+
474
+ onWindowResize() {
475
+ this.camera.aspect = window.innerWidth / window.innerHeight;
476
+ this.camera.updateProjectionMatrix();
477
+ this.renderer.setSize(window.innerWidth, window.innerHeight);
478
+ }
479
+
480
+ setupPerformanceMonitor() {
481
+ // Update FPS every second
482
+ setInterval(() => {
483
+ const currentTime = performance.now();
484
+ const elapsed = currentTime - this.lastTime;
485
+ const fps = Math.round((this.frameCount * 1000) / elapsed);
486
+
487
+ this.frameCount = 0;
488
+ this.lastTime = currentTime;
489
+
490
+ const memory = performance.memory ?
491
+ ` | Mem: ${Math.round(performance.memory.usedJSHeapSize / 1048576)}MB` : '';
492
+
493
+ let infoText = `FPS: ${fps} | Tris: ${this.triangleCount}${memory}<br>` +
494
+ `Objects: ${this.objects.length} | DPR: ${this.renderer.getPixelRatio().toFixed(1)}`;
495
+
496
+ if (this.recording) {
497
+ const progress = Math.round((this.frameIndex / this.maxFrames) * 100);
498
+ infoText += `<br>RECORDING: ${this.frameIndex}/${this.maxFrames} (${progress}%)`;
499
+ }
500
+
501
+ document.getElementById('info').innerHTML = infoText;
502
+ }, 1000);
503
+ }
504
+
505
+ animateObjects(time) {
506
+ // Animate orbiting objects
507
+ this.scene.traverse((object) => {
508
+ if (object.userData.orbitRadius !== undefined) {
509
+ object.userData.orbitAngle += object.userData.orbitSpeed;
510
+ const x = Math.cos(object.userData.orbitAngle) * object.userData.orbitRadius;
511
+ const z = Math.sin(object.userData.orbitAngle) * object.userData.orbitRadius;
512
+ object.position.x = x;
513
+ object.position.z = z;
514
+ object.position.y = object.userData.orbitHeight + Math.sin(time * 0.001 + object.userData.orbitAngle) * 0.5;
515
+ }
516
+
517
+ // Pulsing animation
518
+ if (object.userData.pulsePhase !== undefined) {
519
+ const pulse = Math.sin(time * 0.001 + object.userData.pulsePhase) * 0.1 + 1;
520
+ object.scale.set(pulse, pulse, pulse);
521
+ }
522
+
523
+ // Floating animation
524
+ if (object.userData.floatSpeed) {
525
+ object.position.add(
526
+ object.userData.floatDirection.clone()
527
+ .multiplyScalar(object.userData.floatSpeed)
528
+ );
529
+
530
+ // Bounce off imaginary boundaries
531
+ if (object.position.length() > 15) {
532
+ object.userData.floatDirection.multiplyScalar(-1);
533
+ }
534
+ }
535
+
536
+ // Rotate torus shapes
537
+ if (object.userData.rotationSpeed) {
538
+ object.rotation.x += object.userData.rotationSpeed;
539
+ object.rotation.y += object.userData.rotationSpeed * 0.7;
540
+ }
541
+ });
542
+
543
+ // Slowly rotate entire scene
544
+ this.scene.rotation.y += this.rotationSpeed;
545
+ this.scene.rotation.x += this.rotationSpeed * 0.3;
546
+ }
547
+
548
+ // ==================== RECORDING METHODS ====================
549
+
550
+ startRecording() {
551
+ this.recording = true;
552
+ this.frames = [];
553
+ this.frameIndex = 0;
554
+ this.recordingStartTime = performance.now();
555
+
556
+ const exportBtn = document.getElementById('export-btn');
557
+ exportBtn.textContent = 'STOP REC (R)';
558
+ exportBtn.classList.add('recording');
559
+
560
+ console.log('Started recording. Press R again or click stop to export.');
561
+ }
562
+
563
+ stopRecording() {
564
+ this.recording = false;
565
+ const exportBtn = document.getElementById('export-btn');
566
+ exportBtn.textContent = 'EXPORTING...';
567
+ exportBtn.disabled = true;
568
+
569
+ console.log('Stopped recording. Exporting ZIP...');
570
+ this.exportToZip();
571
+ }
572
+
573
+ exportToZip() {
574
+ const zip = new JSZip();
575
+ const ds = zip.folder('dataset');
576
+
577
+ // Create metadata
578
+ const meta = {
579
+ version: "underworld-alpha-v1",
580
+ seed: Date.now().toString(),
581
+ fps: this.frameRate,
582
+ duration_sec: this.maxFrames / this.frameRate,
583
+ resolution: [this.renderer.domElement.width, this.renderer.domElement.height],
584
+ recording_time: new Date().toISOString(),
585
+ camera: {
586
+ start_pos: this.camera.position.toArray(),
587
+ start_quat: this.camera.quaternion.toArray(),
588
+ fov: this.camera.fov,
589
+ aspect: this.camera.aspect
590
+ },
591
+ objects: this.objects.map((obj, idx) => ({
592
+ id: idx,
593
+ type: obj.type,
594
+ geometry_type: obj.geometry?.type.replace('Geometry', '') || 'unknown',
595
+ init_pos: obj.userData.originalPosition?.toArray() || [0, 0, 0],
596
+ init_scale: obj.userData.originalScale || 1,
597
+ init_quat: obj.userData.originalQuaternion?.toArray() || [0, 0, 0, 1],
598
+ pulse_phase: obj.userData.pulsePhase || 0,
599
+ orbit: obj.userData.orbitRadius ? {
600
+ radius: obj.userData.orbitRadius,
601
+ speed: obj.userData.orbitSpeed,
602
+ start_angle: obj.userData.orbitAngle,
603
+ height: obj.userData.orbitHeight
604
+ } : null,
605
+ float_speed: obj.userData.floatSpeed || null,
606
+ float_direction: obj.userData.floatDirection?.toArray() || null,
607
+ rotation_speed: obj.userData.rotationSpeed || null
608
+ })),
609
+ scene: {
610
+ rotation_speed: this.rotationSpeed,
611
+ background_color: this.scene.background.getHex()
612
+ },
613
+ note: "grayscale wireframe synthetic motion for world-model pretraining",
614
+ app: "WEBXOS UNDERWORLD",
615
+ sync_with: "huggingface.co/overworld"
616
+ };
617
+
618
+ // Add frames to ZIP
619
+ const addFrameToZip = (index) => {
620
+ if (index >= this.frames.length) {
621
+ // All frames added, now add metadata
622
+ ds.file('metadata.json', JSON.stringify(meta, null, 2));
623
+
624
+ // Add control signals
625
+ const controls = Array.from({length: this.frames.length}, (_, i) => ({
626
+ frame: i,
627
+ time: i / this.frameRate,
628
+ scene_rotation: [
629
+ this.scene.rotation.x + (i * this.rotationSpeed * 0.3),
630
+ this.scene.rotation.y + (i * this.rotationSpeed),
631
+ this.scene.rotation.z
632
+ ],
633
+ harmonic_signal: Math.sin(i * 0.1), // Example harmonic oscillator
634
+ camera_distance: this.camera.position.length(),
635
+ object_count: this.objects.length
636
+ }));
637
+ ds.file('controls.json', JSON.stringify(controls, null, 2));
638
+
639
+ // Add README
640
+ ds.file('README.txt', `WEBXOS UNDERWORLD Dataset Export
641
+ Generated: ${new Date().toISOString()}
642
+ Frames: ${this.frames.length}
643
+ FPS: ${this.frameRate}
644
+ Resolution: ${this.renderer.domElement.width}x${this.renderer.domElement.height}
645
+ Objects: ${this.objects.length}
646
+ Triangles: ${this.triangleCount}
647
+
648
+ Usage for Overworld-style training:
649
+ 1. Convert PNG sequence to video: ffmpeg -i %05d.png -c:v libx264 clip.mp4
650
+ 2. Use metadata.json for camera pose conditioning
651
+ 3. Use controls.json for temporal conditioning
652
+ 4. Train with diffusion models like Waypoint-1-Small
653
+
654
+ This dataset is optimized for low-end device simulation and micro-scale spatial studies.`);
655
+
656
+ // Generate and download ZIP
657
+ zip.generateAsync({type: 'blob'}).then(blob => {
658
+ const url = URL.createObjectURL(blob);
659
+ const a = document.createElement('a');
660
+ a.href = url;
661
+ a.download = `underworld_export_${Date.now()}.zip`;
662
+ a.click();
663
+
664
+ setTimeout(() => {
665
+ URL.revokeObjectURL(url);
666
+ exportBtn.textContent = 'RECORD (R)';
667
+ exportBtn.classList.remove('recording');
668
+ exportBtn.disabled = false;
669
+
670
+ document.getElementById('info').innerHTML += '<br>Export complete!';
671
+ console.log('Export complete. Download started.');
672
+ }, 100);
673
+ }).catch(err => {
674
+ console.error('ZIP export error:', err);
675
+ exportBtn.textContent = 'ERROR - RETRY';
676
+ exportBtn.classList.remove('recording');
677
+ exportBtn.disabled = false;
678
+ });
679
+
680
+ return;
681
+ }
682
+
683
+ const dataUrl = this.frames[index];
684
+ const base64 = dataUrl.split(',')[1];
685
+ const filename = `${String(index).padStart(5, '0')}.png`;
686
+
687
+ ds.file(filename, base64, {base64: true});
688
+
689
+ // Process next frame
690
+ setTimeout(() => addFrameToZip(index + 1), 0);
691
+ };
692
+
693
+ // Start adding frames
694
+ addFrameToZip(0);
695
+ }
696
+
697
+ animate() {
698
+ this.frameCount++;
699
+ const time = performance.now();
700
+
701
+ // Animate objects
702
+ this.animateObjects(time);
703
+
704
+ // Capture frame if recording
705
+ if (this.recording && this.frameIndex < this.maxFrames) {
706
+ // Ensure we render before capturing
707
+ this.renderer.render(this.scene, this.camera);
708
+
709
+ // Capture frame
710
+ const dataURL = this.renderer.domElement.toDataURL('image/png', 0.85);
711
+ this.frames.push(dataURL);
712
+ this.frameIndex++;
713
+
714
+ // Auto-stop when max frames reached
715
+ if (this.frameIndex >= this.maxFrames) {
716
+ this.stopRecording();
717
+ }
718
+ } else {
719
+ // Normal rendering when not recording
720
+ this.renderer.render(this.scene, this.camera);
721
+ }
722
+
723
+ // Continue animation loop
724
+ requestAnimationFrame(() => this.animate());
725
+ }
726
+ }
727
+
728
+ // Initialize when page loads
729
+ let viewer = null;
730
+ window.addEventListener('load', () => {
731
+ try {
732
+ viewer = new MicroWireframeViewer();
733
+ // Store reference for keyboard access
734
+ window.viewer = viewer;
735
+ } catch (error) {
736
+ document.getElementById('info').innerHTML =
737
+ `Error: ${error.message}<br>Please try a different browser`;
738
+ console.error(error);
739
+ }
740
+ });
741
+
742
+ // Keyboard trigger for recording
743
+ window.addEventListener('keydown', e => {
744
+ if (e.key.toLowerCase() === 'r' && !e.repeat) {
745
+ e.preventDefault();
746
+ if (!viewer) return;
747
+ if (!viewer.recording) {
748
+ viewer.startRecording();
749
+ } else {
750
+ viewer.stopRecording();
751
+ }
752
+ }
753
+ });
754
+
755
+ // Pause animation when tab is not visible
756
+ document.addEventListener('visibilitychange', () => {
757
+ if (document.hidden) {
758
+ console.log('Tab hidden - performance optimized');
759
+ }
760
+ });
761
+ </script>
762
+ </body>
763
+ </html>