ThorAILabs commited on
Commit
1680cc8
·
verified ·
1 Parent(s): 3677c33

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +179 -19
index.html CHANGED
@@ -1,19 +1,179 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>3D Scene Editor with Raytracing</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <!-- TailWind CSS -->
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <!-- FontAwesome -->
10
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
11
+ </head>
12
+ <body class="bg-gray-900 text-white">
13
+ <!-- Header -->
14
+ <header class="p-4 flex items-center space-x-4">
15
+ <i class="fas fa-cube text-3xl"></i>
16
+ <h1 class="text-3xl font-bold">3D Scene Editor with Raytracing</h1>
17
+ </header>
18
+
19
+ <!-- Main Layout -->
20
+ <div class="flex flex-col md:flex-row">
21
+ <!-- Sidebar Controls -->
22
+ <aside class="w-full md:w-1/4 p-4 space-y-4 bg-gray-800">
23
+ <h2 class="text-xl font-semibold">Controls</h2>
24
+ <button id="toggleRaytrace" class="w-full py-2 px-4 bg-blue-600 hover:bg-blue-700 rounded">
25
+ <i class="fas fa-bolt"></i> Toggle Raytracing
26
+ </button>
27
+ <label for="sceneInput" class="block">
28
+ <span class="text-sm font-medium">Load Scene JSON:</span>
29
+ <input id="sceneInput" type="file" accept=".json" class="mt-1 block w-full p-2 text-gray-800 rounded"/>
30
+ </label>
31
+ <div id="parserOutput" class="text-sm text-green-400"></div>
32
+ </aside>
33
+
34
+ <!-- Canvas Container -->
35
+ <main class="flex-1 relative">
36
+ <canvas id="sceneCanvas" class="w-full h-screen"></canvas>
37
+ </main>
38
+ </div>
39
+
40
+ <!-- Scripts -->
41
+ <!-- Three.js Core -->
42
+ <script src="https://unpkg.com/three@0.150.0/build/three.min.js"></script>
43
+ <!-- OrbitControls -->
44
+ <script src="https://unpkg.com/three@0.150.0/examples/js/controls/OrbitControls.js"></script>
45
+ <!-- dat.GUI for interactive controls -->
46
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.9/dat.gui.min.js"></script>
47
+ <!-- Main Application Script -->
48
+ <script type="module">
49
+ // Importing OBJLoader as an example of a parser library for 3D assets
50
+ import { OBJLoader } from 'https://unpkg.com/three@0.150.0/examples/jsm/loaders/OBJLoader.js';
51
+
52
+ let scene, camera, renderer, controls, gui;
53
+ let raytraceMode = false;
54
+ const canvas = document.getElementById('sceneCanvas');
55
+
56
+ // Initialization function to set up scene, camera, renderer, and controls.
57
+ function init() {
58
+ // Create scene
59
+ scene = new THREE.Scene();
60
+ scene.background = new THREE.Color(0x222222);
61
+
62
+ // Set up camera
63
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
64
+ camera.position.set(0, 2, 5);
65
+
66
+ // Renderer setup with antialiasing
67
+ renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true });
68
+ renderer.setSize(window.innerWidth, window.innerHeight);
69
+ document.body.appendChild(renderer.domElement);
70
+
71
+ // OrbitControls for interactive scene navigation
72
+ controls = new THREE.OrbitControls(camera, renderer.domElement);
73
+
74
+ // Lighting: Ambient and directional for solid shading
75
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
76
+ scene.add(ambientLight);
77
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
78
+ directionalLight.position.set(5, 10, 7.5);
79
+ scene.add(directionalLight);
80
+
81
+ // Add a sample cube
82
+ const cubeGeometry = new THREE.BoxGeometry();
83
+ const cubeMaterial = new THREE.MeshStandardMaterial({ color: 0x00ff00 });
84
+ const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
85
+ cube.name = "Cube";
86
+ scene.add(cube);
87
+
88
+ // Add a sample plane as the floor
89
+ const planeGeometry = new THREE.PlaneGeometry(10, 10);
90
+ const planeMaterial = new THREE.MeshStandardMaterial({ color: 0x808080 });
91
+ const plane = new THREE.Mesh(planeGeometry, planeMaterial);
92
+ plane.rotation.x = -Math.PI / 2;
93
+ plane.name = "Plane";
94
+ scene.add(plane);
95
+
96
+ // Setup dat.GUI controls within a styled container
97
+ gui = new dat.GUI({ autoPlace: false, width: 300 });
98
+ const guiContainer = document.createElement('div');
99
+ guiContainer.classList.add('absolute', 'top-4', 'right-4', 'bg-gray-800', 'p-4', 'rounded');
100
+ guiContainer.appendChild(gui.domElement);
101
+ document.body.appendChild(guiContainer);
102
+
103
+ // dat.GUI folder for cube controls
104
+ const cubeFolder = gui.addFolder('Cube Transform');
105
+ cubeFolder.add(cube.position, 'x', -5, 5, 0.1).name('Position X');
106
+ cubeFolder.add(cube.position, 'y', -5, 5, 0.1).name('Position Y');
107
+ cubeFolder.add(cube.position, 'z', -5, 5, 0.1).name('Position Z');
108
+ cubeFolder.open();
109
+
110
+ animate();
111
+ }
112
+
113
+ // Animation loop for rendering the scene continuously.
114
+ function animate() {
115
+ requestAnimationFrame(animate);
116
+ controls.update();
117
+
118
+ if (!raytraceMode) {
119
+ renderer.render(scene, camera);
120
+ } else {
121
+ // Here you would integrate a proper raytracing shader or postprocessing pass.
122
+ // For demonstration, we simulate raytracing by applying a simple overlay effect.
123
+ renderer.render(scene, camera);
124
+ // Additional raytracing effects can be added here.
125
+ }
126
+ }
127
+
128
+ // Adjust canvas size on window resize
129
+ window.addEventListener('resize', () => {
130
+ camera.aspect = window.innerWidth / window.innerHeight;
131
+ camera.updateProjectionMatrix();
132
+ renderer.setSize(window.innerWidth, window.innerHeight);
133
+ });
134
+
135
+ // Toggle raytracing mode and display a simple alert (simulation).
136
+ document.getElementById('toggleRaytrace').addEventListener('click', () => {
137
+ raytraceMode = !raytraceMode;
138
+ alert('Raytracing mode ' + (raytraceMode ? 'enabled' : 'disabled') + '. (Simulation mode)');
139
+ });
140
+
141
+ // Basic scene parser: Load a JSON file and add objects to the scene.
142
+ // Expected format:
143
+ // {
144
+ // "objects": [
145
+ // { "type": "sphere", "radius": 1, "color": 16711680, "position": {"x": 0, "y": 1, "z": 0} }
146
+ // ]
147
+ // }
148
+ document.getElementById('sceneInput').addEventListener('change', (event) => {
149
+ const file = event.target.files[0];
150
+ if (!file) return;
151
+ const reader = new FileReader();
152
+ reader.onload = (e) => {
153
+ try {
154
+ const sceneData = JSON.parse(e.target.result);
155
+ document.getElementById('parserOutput').textContent = 'Scene loaded successfully!';
156
+ if (Array.isArray(sceneData.objects)) {
157
+ sceneData.objects.forEach(obj => {
158
+ if (obj.type === 'sphere') {
159
+ const sphereGeo = new THREE.SphereGeometry(obj.radius || 1, 32, 32);
160
+ const sphereMat = new THREE.MeshStandardMaterial({ color: obj.color || 0xff0000 });
161
+ const sphere = new THREE.Mesh(sphereGeo, sphereMat);
162
+ sphere.position.set(obj.position?.x || 0, obj.position?.y || 0, obj.position?.z || 0);
163
+ scene.add(sphere);
164
+ }
165
+ // Extend here with other object types and parsers as needed.
166
+ });
167
+ }
168
+ } catch (error) {
169
+ document.getElementById('parserOutput').textContent = 'Error parsing scene file!';
170
+ }
171
+ };
172
+ reader.readAsText(file);
173
+ });
174
+
175
+ // Initialize the 3D scene.
176
+ init();
177
+ </script>
178
+ </body>
179
+ </html>