UNDERWORLD_Dataset_v1 / underworld /webXOS_underworld_v1.html
webxos's picture
Rename webXOS_underworld_v1.html to underworld/webXOS_underworld_v1.html
3d7e931 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WEBXOS UNDERWORLD - Micro-Scale Wireframe Viewer</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #111;
font-family: monospace;
}
canvas {
display: block;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#info {
position: absolute;
top: 10px;
left: 10px;
color: #0f0;
font-family: monospace;
font-size: 12px;
background: rgba(0,0,0,0.7);
padding: 8px;
border-radius: 4px;
user-select: none;
z-index: 100;
backdrop-filter: blur(2px);
max-width: 300px;
line-height: 1.4;
}
#controls {
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
color: #0ff;
font-size: 11px;
background: rgba(0,0,0,0.7);
padding: 8px 12px;
border-radius: 4px;
user-select: none;
z-index: 100;
backdrop-filter: blur(2px);
text-align: center;
}
#export-btn {
position: absolute;
top: 10px;
right: 10px;
background: rgba(0, 100, 0, 0.7);
color: #0f0;
border: 1px solid #0f0;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-family: monospace;
font-size: 12px;
z-index: 100;
backdrop-filter: blur(2px);
}
#export-btn:hover {
background: rgba(0, 150, 0, 0.8);
}
#export-btn.recording {
background: rgba(150, 0, 0, 0.7);
color: #f00;
border-color: #f00;
animation: pulse 1s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.7; }
100% { opacity: 1; }
}
</style>
<script src="https://unpkg.com/three@0.157.0/build/three.min.js"></script>
<script src="https://unpkg.com/jszip@3.10.1/dist/jszip.min.js"></script>
</head>
<body>
<div id="info">Loading WEBXOS UNDERWORLD...</div>
<button id="export-btn" title="Press R or click to record">RECORD (R)</button>
<div id="controls">Drag to rotate • Scroll to zoom • R to record</div>
<script>
class MicroWireframeViewer {
constructor() {
this.scene = null;
this.camera = null;
this.renderer = null;
this.frameCount = 0;
this.fps = 60;
this.triangleCount = 0;
this.lastTime = performance.now();
this.isDragging = false;
this.previousMouse = { x: 0, y: 0 };
this.objects = [];
this.rotationSpeed = 0.002;
// Recording properties
this.recording = false;
this.frames = [];
this.frameIndex = 0;
this.maxFrames = 256; // ~8.5s @30fps
this.frameRate = 30;
this.recordingStartTime = 0;
this.init();
this.createSampleStructures();
this.animate();
}
init() {
// Scene
this.scene = new THREE.Scene();
this.scene.background = new THREE.Color(0x0a0a0a);
// Camera
this.camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
this.camera.position.set(8, 8, 8);
this.camera.lookAt(0, 0, 0);
// Renderer - Optimized for mobile/low-end
this.renderer = new THREE.WebGLRenderer({
antialias: false,
powerPreference: "low-power",
alpha: false,
stencil: false,
depth: true,
preserveDrawingBuffer: true // Required for toDataURL
});
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
document.body.appendChild(this.renderer.domElement);
// Basic lighting
const ambient = new THREE.AmbientLight(0x404040);
this.scene.add(ambient);
// Handle window resize
window.addEventListener('resize', () => this.onWindowResize(), false);
// Setup controls
this.setupControls();
// Setup export button
this.setupExportButton();
// Performance monitoring
this.setupPerformanceMonitor();
}
setupControls() {
const canvas = this.renderer.domElement;
// Mouse controls
canvas.addEventListener('mousedown', (e) => {
this.isDragging = true;
this.previousMouse = { x: e.clientX, y: e.clientY };
});
canvas.addEventListener('mousemove', (e) => {
if (!this.isDragging) return;
const deltaX = e.clientX - this.previousMouse.x;
const deltaY = e.clientY - this.previousMouse.y;
// Rotate camera around the center
const angleX = deltaX * 0.01;
const angleY = deltaY * 0.01;
// Rotate camera position around Y axis
const radius = Math.sqrt(
this.camera.position.x * this.camera.position.x +
this.camera.position.z * this.camera.position.z
);
const theta = Math.atan2(this.camera.position.z, this.camera.position.x) + angleX;
const phi = Math.atan2(
Math.sqrt(this.camera.position.x * this.camera.position.x +
this.camera.position.z * this.camera.position.z),
this.camera.position.y
) + angleY;
// Clamp phi to prevent flipping
const clampedPhi = Math.max(0.1, Math.min(Math.PI - 0.1, phi));
this.camera.position.x = radius * Math.sin(clampedPhi) * Math.cos(theta);
this.camera.position.y = radius * Math.cos(clampedPhi);
this.camera.position.z = radius * Math.sin(clampedPhi) * Math.sin(theta);
this.camera.lookAt(0, 0, 0);
this.previousMouse = { x: e.clientX, y: e.clientY };
});
canvas.addEventListener('mouseup', () => {
this.isDragging = false;
});
canvas.addEventListener('mouseleave', () => {
this.isDragging = false;
});
// Touch controls for mobile
canvas.addEventListener('touchstart', (e) => {
if (e.touches.length === 1) {
this.isDragging = true;
this.previousMouse = {
x: e.touches[0].clientX,
y: e.touches[0].clientY
};
e.preventDefault();
}
}, { passive: false });
canvas.addEventListener('touchmove', (e) => {
if (!this.isDragging || e.touches.length !== 1) return;
const deltaX = e.touches[0].clientX - this.previousMouse.x;
const deltaY = e.touches[0].clientY - this.previousMouse.y;
const angleX = deltaX * 0.02;
const angleY = deltaY * 0.02;
const radius = Math.sqrt(
this.camera.position.x * this.camera.position.x +
this.camera.position.z * this.camera.position.z
);
const theta = Math.atan2(this.camera.position.z, this.camera.position.x) + angleX;
const phi = Math.atan2(
Math.sqrt(this.camera.position.x * this.camera.position.x +
this.camera.position.z * this.camera.position.z),
this.camera.position.y
) + angleY;
const clampedPhi = Math.max(0.1, Math.min(Math.PI - 0.1, phi));
this.camera.position.x = radius * Math.sin(clampedPhi) * Math.cos(theta);
this.camera.position.y = radius * Math.cos(clampedPhi);
this.camera.position.z = radius * Math.sin(clampedPhi) * Math.sin(theta);
this.camera.lookAt(0, 0, 0);
this.previousMouse = {
x: e.touches[0].clientX,
y: e.touches[0].clientY
};
e.preventDefault();
}, { passive: false });
canvas.addEventListener('touchend', () => {
this.isDragging = false;
});
// Zoom with wheel
canvas.addEventListener('wheel', (e) => {
const zoomFactor = 0.001;
this.camera.position.multiplyScalar(1 + e.deltaY * zoomFactor);
this.camera.position.clampLength(3, 30);
this.camera.lookAt(0, 0, 0);
});
}
setupExportButton() {
const exportBtn = document.getElementById('export-btn');
exportBtn.addEventListener('click', () => {
if (!this.recording) {
this.startRecording();
} else {
this.stopRecording();
}
});
}
createWireframeCube(position, scale = 1, color = 0x00ff00) {
const geometry = new THREE.BoxGeometry(scale, scale, scale, 1, 1, 1);
const edges = new THREE.EdgesGeometry(geometry);
const material = new THREE.LineBasicMaterial({
color: color,
linewidth: 1,
transparent: true,
opacity: 0.8
});
const wireframe = new THREE.LineSegments(edges, material);
wireframe.position.copy(position);
wireframe.userData.originalPosition = position.clone();
wireframe.userData.originalScale = scale;
wireframe.userData.pulsePhase = Math.random() * Math.PI * 2;
wireframe.userData.originalQuaternion = wireframe.quaternion.clone();
this.objects.push(wireframe);
return wireframe;
}
createWireframeSphere(position, radius = 1, color = 0xff6600) {
const geometry = new THREE.SphereGeometry(radius, 8, 6); // Low poly
const edges = new THREE.EdgesGeometry(geometry);
const material = new THREE.LineBasicMaterial({
color: color,
linewidth: 1,
transparent: true,
opacity: 0.7
});
const wireframe = new THREE.LineSegments(edges, material);
wireframe.position.copy(position);
wireframe.userData.originalPosition = position.clone();
wireframe.userData.originalScale = radius;
wireframe.userData.pulsePhase = Math.random() * Math.PI * 2;
wireframe.userData.originalQuaternion = wireframe.quaternion.clone();
this.objects.push(wireframe);
return wireframe;
}
createWireframeTorus(position, radius = 1, tube = 0.3, color = 0x00ffff) {
const geometry = new THREE.TorusGeometry(radius, tube, 8, 12);
const edges = new THREE.EdgesGeometry(geometry);
const material = new THREE.LineBasicMaterial({
color: color,
linewidth: 1,
transparent: true,
opacity: 0.6
});
const wireframe = new THREE.LineSegments(edges, material);
wireframe.position.copy(position);
wireframe.userData.originalPosition = position.clone();
wireframe.userData.rotationSpeed = (Math.random() - 0.5) * 0.01;
wireframe.userData.originalQuaternion = wireframe.quaternion.clone();
this.objects.push(wireframe);
return wireframe;
}
createSpatialGrid(size = 20, divisions = 20) {
const grid = new THREE.GridHelper(size, divisions, 0x333333, 0x222222);
grid.material.transparent = true;
grid.material.opacity = 0.3;
return grid;
}
createSampleStructures() {
// Create spatial grid
const grid = this.createSpatialGrid(30, 30);
this.scene.add(grid);
// Central structure - Complex wireframe
const centerGroup = new THREE.Group();
// Main cube
const mainCube = this.createWireframeCube(new THREE.Vector3(0, 0, 0), 3, 0x00ff00);
centerGroup.add(mainCube);
// Inner structures
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const radius = 1.8;
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
const sphere = this.createWireframeSphere(new THREE.Vector3(x, y, 0), 0.5, 0xff6600);
centerGroup.add(sphere);
}
// Top and bottom spheres
const topSphere = this.createWireframeSphere(new THREE.Vector3(0, 0, 2), 0.8, 0xff00ff);
const bottomSphere = this.createWireframeSphere(new THREE.Vector3(0, 0, -2), 0.8, 0xff00ff);
centerGroup.add(topSphere);
centerGroup.add(bottomSphere);
this.scene.add(centerGroup);
// Orbiting structures
const orbitGroup = new THREE.Group();
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const radius = 8;
const height = (Math.random() - 0.5) * 4;
const x = Math.cos(angle) * radius;
const y = height;
const z = Math.sin(angle) * radius;
const shapeType = Math.floor(Math.random() * 3);
let shape;
switch(shapeType) {
case 0:
shape = this.createWireframeCube(
new THREE.Vector3(x, y, z),
0.7 + Math.random() * 0.5,
0x00aaff
);
break;
case 1:
shape = this.createWireframeSphere(
new THREE.Vector3(x, y, z),
0.4 + Math.random() * 0.4,
0xffaa00
);
break;
case 2:
shape = this.createWireframeTorus(
new THREE.Vector3(x, y, z),
0.6 + Math.random() * 0.4,
0.15,
0x00ffaa
);
shape.rotation.x = Math.random() * Math.PI;
shape.rotation.y = Math.random() * Math.PI;
shape.userData.originalQuaternion = shape.quaternion.clone();
break;
}
shape.userData.orbitRadius = radius;
shape.userData.orbitAngle = angle;
shape.userData.orbitSpeed = 0.001 + Math.random() * 0.002;
shape.userData.orbitHeight = height;
orbitGroup.add(shape);
}
this.scene.add(orbitGroup);
// Random scattered objects
for (let i = 0; i < 40; i++) {
const x = (Math.random() - 0.5) * 25;
const y = (Math.random() - 0.5) * 25;
const z = (Math.random() - 0.5) * 25;
const cube = this.createWireframeCube(
new THREE.Vector3(x, y, z),
0.2 + Math.random() * 0.4,
0x666666
);
cube.userData.floatSpeed = Math.random() * 0.005;
cube.userData.floatDirection = new THREE.Vector3(
Math.random() - 0.5,
Math.random() - 0.5,
Math.random() - 0.5
).normalize();
cube.userData.originalPosition = cube.position.clone();
this.scene.add(cube);
}
this.updateTriangleCount();
}
updateTriangleCount() {
this.triangleCount = 0;
this.scene.traverse((object) => {
if (object.isLineSegments || object.isLine) {
if (object.geometry && object.geometry.attributes && object.geometry.attributes.position) {
this.triangleCount += object.geometry.attributes.position.count / 3;
}
}
});
}
onWindowResize() {
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
}
setupPerformanceMonitor() {
// Update FPS every second
setInterval(() => {
const currentTime = performance.now();
const elapsed = currentTime - this.lastTime;
const fps = Math.round((this.frameCount * 1000) / elapsed);
this.frameCount = 0;
this.lastTime = currentTime;
const memory = performance.memory ?
` | Mem: ${Math.round(performance.memory.usedJSHeapSize / 1048576)}MB` : '';
let infoText = `FPS: ${fps} | Tris: ${this.triangleCount}${memory}<br>` +
`Objects: ${this.objects.length} | DPR: ${this.renderer.getPixelRatio().toFixed(1)}`;
if (this.recording) {
const progress = Math.round((this.frameIndex / this.maxFrames) * 100);
infoText += `<br>RECORDING: ${this.frameIndex}/${this.maxFrames} (${progress}%)`;
}
document.getElementById('info').innerHTML = infoText;
}, 1000);
}
animateObjects(time) {
// Animate orbiting objects
this.scene.traverse((object) => {
if (object.userData.orbitRadius !== undefined) {
object.userData.orbitAngle += object.userData.orbitSpeed;
const x = Math.cos(object.userData.orbitAngle) * object.userData.orbitRadius;
const z = Math.sin(object.userData.orbitAngle) * object.userData.orbitRadius;
object.position.x = x;
object.position.z = z;
object.position.y = object.userData.orbitHeight + Math.sin(time * 0.001 + object.userData.orbitAngle) * 0.5;
}
// Pulsing animation
if (object.userData.pulsePhase !== undefined) {
const pulse = Math.sin(time * 0.001 + object.userData.pulsePhase) * 0.1 + 1;
object.scale.set(pulse, pulse, pulse);
}
// Floating animation
if (object.userData.floatSpeed) {
object.position.add(
object.userData.floatDirection.clone()
.multiplyScalar(object.userData.floatSpeed)
);
// Bounce off imaginary boundaries
if (object.position.length() > 15) {
object.userData.floatDirection.multiplyScalar(-1);
}
}
// Rotate torus shapes
if (object.userData.rotationSpeed) {
object.rotation.x += object.userData.rotationSpeed;
object.rotation.y += object.userData.rotationSpeed * 0.7;
}
});
// Slowly rotate entire scene
this.scene.rotation.y += this.rotationSpeed;
this.scene.rotation.x += this.rotationSpeed * 0.3;
}
// ==================== RECORDING METHODS ====================
startRecording() {
this.recording = true;
this.frames = [];
this.frameIndex = 0;
this.recordingStartTime = performance.now();
const exportBtn = document.getElementById('export-btn');
exportBtn.textContent = 'STOP REC (R)';
exportBtn.classList.add('recording');
console.log('Started recording. Press R again or click stop to export.');
}
stopRecording() {
this.recording = false;
const exportBtn = document.getElementById('export-btn');
exportBtn.textContent = 'EXPORTING...';
exportBtn.disabled = true;
console.log('Stopped recording. Exporting ZIP...');
this.exportToZip();
}
exportToZip() {
const zip = new JSZip();
const ds = zip.folder('dataset');
// Create metadata
const meta = {
version: "underworld-alpha-v1",
seed: Date.now().toString(),
fps: this.frameRate,
duration_sec: this.maxFrames / this.frameRate,
resolution: [this.renderer.domElement.width, this.renderer.domElement.height],
recording_time: new Date().toISOString(),
camera: {
start_pos: this.camera.position.toArray(),
start_quat: this.camera.quaternion.toArray(),
fov: this.camera.fov,
aspect: this.camera.aspect
},
objects: this.objects.map((obj, idx) => ({
id: idx,
type: obj.type,
geometry_type: obj.geometry?.type.replace('Geometry', '') || 'unknown',
init_pos: obj.userData.originalPosition?.toArray() || [0, 0, 0],
init_scale: obj.userData.originalScale || 1,
init_quat: obj.userData.originalQuaternion?.toArray() || [0, 0, 0, 1],
pulse_phase: obj.userData.pulsePhase || 0,
orbit: obj.userData.orbitRadius ? {
radius: obj.userData.orbitRadius,
speed: obj.userData.orbitSpeed,
start_angle: obj.userData.orbitAngle,
height: obj.userData.orbitHeight
} : null,
float_speed: obj.userData.floatSpeed || null,
float_direction: obj.userData.floatDirection?.toArray() || null,
rotation_speed: obj.userData.rotationSpeed || null
})),
scene: {
rotation_speed: this.rotationSpeed,
background_color: this.scene.background.getHex()
},
note: "grayscale wireframe synthetic motion for world-model pretraining",
app: "WEBXOS UNDERWORLD",
sync_with: "huggingface.co/overworld"
};
// Add frames to ZIP
const addFrameToZip = (index) => {
if (index >= this.frames.length) {
// All frames added, now add metadata
ds.file('metadata.json', JSON.stringify(meta, null, 2));
// Add control signals
const controls = Array.from({length: this.frames.length}, (_, i) => ({
frame: i,
time: i / this.frameRate,
scene_rotation: [
this.scene.rotation.x + (i * this.rotationSpeed * 0.3),
this.scene.rotation.y + (i * this.rotationSpeed),
this.scene.rotation.z
],
harmonic_signal: Math.sin(i * 0.1), // Example harmonic oscillator
camera_distance: this.camera.position.length(),
object_count: this.objects.length
}));
ds.file('controls.json', JSON.stringify(controls, null, 2));
// Add README
ds.file('README.txt', `WEBXOS UNDERWORLD Dataset Export
Generated: ${new Date().toISOString()}
Frames: ${this.frames.length}
FPS: ${this.frameRate}
Resolution: ${this.renderer.domElement.width}x${this.renderer.domElement.height}
Objects: ${this.objects.length}
Triangles: ${this.triangleCount}
Usage for Overworld-style training:
1. Convert PNG sequence to video: ffmpeg -i %05d.png -c:v libx264 clip.mp4
2. Use metadata.json for camera pose conditioning
3. Use controls.json for temporal conditioning
4. Train with diffusion models like Waypoint-1-Small
This dataset is optimized for low-end device simulation and micro-scale spatial studies.`);
// Generate and download ZIP
zip.generateAsync({type: 'blob'}).then(blob => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `underworld_export_${Date.now()}.zip`;
a.click();
setTimeout(() => {
URL.revokeObjectURL(url);
exportBtn.textContent = 'RECORD (R)';
exportBtn.classList.remove('recording');
exportBtn.disabled = false;
document.getElementById('info').innerHTML += '<br>Export complete!';
console.log('Export complete. Download started.');
}, 100);
}).catch(err => {
console.error('ZIP export error:', err);
exportBtn.textContent = 'ERROR - RETRY';
exportBtn.classList.remove('recording');
exportBtn.disabled = false;
});
return;
}
const dataUrl = this.frames[index];
const base64 = dataUrl.split(',')[1];
const filename = `${String(index).padStart(5, '0')}.png`;
ds.file(filename, base64, {base64: true});
// Process next frame
setTimeout(() => addFrameToZip(index + 1), 0);
};
// Start adding frames
addFrameToZip(0);
}
animate() {
this.frameCount++;
const time = performance.now();
// Animate objects
this.animateObjects(time);
// Capture frame if recording
if (this.recording && this.frameIndex < this.maxFrames) {
// Ensure we render before capturing
this.renderer.render(this.scene, this.camera);
// Capture frame
const dataURL = this.renderer.domElement.toDataURL('image/png', 0.85);
this.frames.push(dataURL);
this.frameIndex++;
// Auto-stop when max frames reached
if (this.frameIndex >= this.maxFrames) {
this.stopRecording();
}
} else {
// Normal rendering when not recording
this.renderer.render(this.scene, this.camera);
}
// Continue animation loop
requestAnimationFrame(() => this.animate());
}
}
// Initialize when page loads
let viewer = null;
window.addEventListener('load', () => {
try {
viewer = new MicroWireframeViewer();
// Store reference for keyboard access
window.viewer = viewer;
} catch (error) {
document.getElementById('info').innerHTML =
`Error: ${error.message}<br>Please try a different browser`;
console.error(error);
}
});
// Keyboard trigger for recording
window.addEventListener('keydown', e => {
if (e.key.toLowerCase() === 'r' && !e.repeat) {
e.preventDefault();
if (!viewer) return;
if (!viewer.recording) {
viewer.startRecording();
} else {
viewer.stopRecording();
}
}
});
// Pause animation when tab is not visible
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
console.log('Tab hidden - performance optimized');
}
});
</script>
</body>
</html>