-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathARXIV_AI_Bifrost_Simulator.html
More file actions
157 lines (135 loc) · 6.09 KB
/
Copy pathARXIV_AI_Bifrost_Simulator.html
File metadata and controls
157 lines (135 loc) · 6.09 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bifrost-1 Concept Demo</title>
<style>
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; background-color: #111; color: #eee; text-align: center; }
canvas { display: block; }
#info { position: absolute; top: 10px; width: 100%; padding: 10px; box-sizing: border-box; }
h2 { margin: 0; font-weight: 500; }
p { font-size: 0.9em; color: #bbb; }
#controls { position: absolute; bottom: 20px; width: 100%; }
input { padding: 12px; width: 300px; border-radius: 8px; border: 1px solid #555; background-color: #222; color: #eee; font-size: 1em; }
button { padding: 12px 20px; border-radius: 8px; border: none; background-color: #007bff; color: white; font-size: 1em; cursor: pointer; margin-left: 10px; }
button:hover { background-color: #0056b3; }
</style>
</head>
<body>
<div id="info">
<h2>Bifrost-1 Conceptual Demo</h2>
<p>Use text commands to modify the 3D object.</p>
</div>
<canvas id="c"></canvas>
<div id="controls">
<input type="text" id="promptInput" placeholder="e.g., 'make it a blue sphere'">
<button id="submitBtn">Generate</button>
</div>
<script async src="https://unpkg.com/es-module-shims@1.10.0/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.165.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.165.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
// --- Basic Scene Setup ---
const canvas = document.querySelector('#c');
const renderer = new THREE.WebGLRenderer({ antialias: true, canvas, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.z = 5;
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.autoRotate = false;
// --- Lighting ---
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xffffff, 1.5);
pointLight.position.set(5, 5, 5);
scene.add(pointLight);
// --- 3D Object (The "Model") ---
let currentObject;
const material = new THREE.MeshStandardMaterial({ color: 0x007bff, roughness: 0.3, metalness: 0.1 });
function createObject(geometryType) {
if (currentObject) {
scene.remove(currentObject);
currentObject.geometry.dispose();
}
let geometry;
switch(geometryType) {
case 'sphere':
geometry = new THREE.SphereGeometry(1, 32, 32);
break;
case 'torus':
geometry = new THREE.TorusGeometry(0.8, 0.3, 16, 100);
break;
case 'box':
default:
geometry = new THREE.BoxGeometry(1.5, 1.5, 1.5);
break;
}
currentObject = new THREE.Mesh(geometry, material);
scene.add(currentObject);
}
createObject('box'); // Initial shape
// --- "LLM" Command Parser ---
// This function simulates the LLM interpreting the user's text prompt.
function parseCommand(prompt) {
const p = prompt.toLowerCase();
console.log(`Interpreting: "${p}"`);
// Color Commands
if (p.includes('red')) material.color.set(0xff0000);
else if (p.includes('green')) material.color.set(0x00ff00);
else if (p.includes('blue')) material.color.set(0x007bff);
else if (p.includes('yellow')) material.color.set(0xffff00);
else if (p.includes('purple')) material.color.set(0x800080);
// Shape Commands
if (p.includes('sphere')) createObject('sphere');
else if (p.includes('box') || p.includes('cube')) createObject('box');
else if (p.includes('torus') || p.includes('donut')) createObject('torus');
// Size Commands
if (p.includes('bigger') || p.includes('larger')) currentObject.scale.multiplyScalar(1.2);
if (p.includes('smaller')) currentObject.scale.multiplyScalar(0.8);
// Animation Commands
if (p.includes('rotate')) controls.autoRotate = true;
if (p.includes('stop')) controls.autoRotate = false;
}
// --- User Interface Logic ---
const promptInput = document.getElementById('promptInput');
const submitBtn = document.getElementById('submitBtn');
function handleGeneration() {
const promptText = promptInput.value;
if (promptText) {
parseCommand(promptText);
}
}
submitBtn.addEventListener('click', handleGeneration);
promptInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
handleGeneration();
}
});
// --- Animation Loop ---
function animate() {
requestAnimationFrame(animate);
controls.update(); // for damping and auto-rotate
renderer.render(scene, camera);
}
animate();
// --- Handle Window Resizing ---
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>