Spaces:
Running
Running
Update index.html
Browse files- index.html +192 -74
index.html
CHANGED
@@ -3,88 +3,206 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
7 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
</head>
|
9 |
<body>
|
10 |
-
<h1>Choose Your Own Procedural Adventure</h1>
|
11 |
-
|
12 |
-
<div class="game-container">
|
13 |
|
|
|
14 |
<div id="scene-container">
|
15 |
</div>
|
16 |
|
17 |
-
<div
|
18 |
-
|
19 |
-
<div id="story-
|
20 |
-
<
|
21 |
-
<
|
22 |
-
<p>Please wait while the adventure loads.</p>
|
23 |
-
</div>
|
24 |
-
<div id="choices">
|
25 |
-
</div>
|
26 |
</div>
|
|
|
|
|
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 |
-
</div> </div> <script src="script.js" type="module"></script>
|
89 |
</body>
|
90 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Basic 3D Setup Test</title>
|
7 |
+
<style>
|
8 |
+
/* --- Minimal Base Styles --- */
|
9 |
+
body {
|
10 |
+
font-family: 'Courier New', monospace;
|
11 |
+
background-color: #222;
|
12 |
+
color: #eee;
|
13 |
+
margin: 0;
|
14 |
+
padding: 0;
|
15 |
+
overflow: hidden; /* Prevent scrollbars */
|
16 |
+
display: flex;
|
17 |
+
flex-direction: column;
|
18 |
+
height: 100vh; /* Full viewport height */
|
19 |
+
}
|
20 |
+
|
21 |
+
/* --- Layout --- */
|
22 |
+
#game-container {
|
23 |
+
display: flex;
|
24 |
+
flex-grow: 1; /* Fill remaining vertical space */
|
25 |
+
overflow: hidden;
|
26 |
+
}
|
27 |
+
|
28 |
+
#scene-container {
|
29 |
+
flex-grow: 3; /* Give more space to 3D view */
|
30 |
+
position: relative;
|
31 |
+
border-right: 2px solid #555;
|
32 |
+
min-width: 200px;
|
33 |
+
background-color: #1a1a1a;
|
34 |
+
height: 100%; /* Ensure it takes full height of flex parent */
|
35 |
+
box-sizing: border-box; /* Include border in size */
|
36 |
+
}
|
37 |
+
|
38 |
+
#ui-container {
|
39 |
+
flex-grow: 2; /* Space for UI elements */
|
40 |
+
padding: 20px;
|
41 |
+
overflow-y: auto; /* Allow scrolling if content overflows */
|
42 |
+
background-color: #333;
|
43 |
+
min-width: 280px;
|
44 |
+
height: 100%; /* Ensure it takes full height of flex parent */
|
45 |
+
box-sizing: border-box; /* Include padding in size */
|
46 |
+
}
|
47 |
+
|
48 |
+
#scene-container canvas {
|
49 |
+
display: block; /* Remove extra space below canvas */
|
50 |
+
}
|
51 |
+
|
52 |
+
/* --- Basic UI Placeholders --- */
|
53 |
+
#ui-container h2 {
|
54 |
+
color: #ffcc66;
|
55 |
+
margin-top: 0;
|
56 |
+
margin-bottom: 15px;
|
57 |
+
border-bottom: 1px solid #555;
|
58 |
+
padding-bottom: 10px;
|
59 |
+
}
|
60 |
+
|
61 |
+
</style>
|
62 |
</head>
|
63 |
<body>
|
|
|
|
|
|
|
64 |
|
65 |
+
<div id="game-container">
|
66 |
<div id="scene-container">
|
67 |
</div>
|
68 |
|
69 |
+
<div id="ui-container">
|
70 |
+
<h2 id="story-title">UI Panel</h2>
|
71 |
+
<div id="story-content">
|
72 |
+
<p>This panel will hold the story text, choices, and character sheet later.</p>
|
73 |
+
<p>Focus is on getting the 3D cube rendering in the left panel.</p>
|
|
|
|
|
|
|
|
|
74 |
</div>
|
75 |
+
</div>
|
76 |
+
</div>
|
77 |
|
78 |
+
<script type="importmap">
|
79 |
+
{
|
80 |
+
"imports": {
|
81 |
+
"three": "https://unpkg.com/[email protected]/build/three.module.js",
|
82 |
+
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
|
83 |
+
}
|
84 |
+
}
|
85 |
+
</script>
|
86 |
+
|
87 |
+
<script type="module">
|
88 |
+
import * as THREE from 'three';
|
89 |
+
// OrbitControls is not used in this minimal version
|
90 |
+
// import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
91 |
+
|
92 |
+
// --- DOM Elements ---
|
93 |
+
const sceneContainer = document.getElementById('scene-container');
|
94 |
+
// References to UI elements (not used in this version, but kept for context)
|
95 |
+
// const storyTitleElement = document.getElementById('story-title');
|
96 |
+
// const storyContentElement = document.getElementById('story-content');
|
97 |
+
// const choicesElement = document.getElementById('choices');
|
98 |
+
// const statsElement = document.getElementById('stats-display');
|
99 |
+
// const inventoryElement = document.getElementById('inventory-display');
|
100 |
+
|
101 |
+
// --- Three.js Setup ---
|
102 |
+
let scene, camera, renderer, cube; // Basic scene objects
|
103 |
+
|
104 |
+
function initThreeJS() {
|
105 |
+
console.log("Attempting to initialize Three.js..."); // Debug log
|
106 |
+
|
107 |
+
if (!sceneContainer) {
|
108 |
+
console.error("Scene container not found!");
|
109 |
+
return; // Stop if container doesn't exist
|
110 |
+
}
|
111 |
+
|
112 |
+
// Scene
|
113 |
+
scene = new THREE.Scene();
|
114 |
+
scene.background = new THREE.Color(0x222222); // Dark grey background
|
115 |
+
|
116 |
+
// Camera
|
117 |
+
// Use container dimensions for aspect ratio calculation
|
118 |
+
const width = sceneContainer.clientWidth;
|
119 |
+
const height = sceneContainer.clientHeight;
|
120 |
+
if (width === 0 || height === 0) {
|
121 |
+
console.warn("Scene container has zero dimensions on init. Renderer/Camera might be sized incorrectly.");
|
122 |
+
}
|
123 |
+
camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
|
124 |
+
camera.position.z = 5; // Position camera back
|
125 |
+
|
126 |
+
// Renderer
|
127 |
+
renderer = new THREE.WebGLRenderer({ antialias: true });
|
128 |
+
// Set size explicitly, fallback if container size is 0 initially
|
129 |
+
renderer.setSize(width || 400, height || 300); // Use fallback size if needed
|
130 |
+
sceneContainer.appendChild(renderer.domElement); // Add canvas to the container
|
131 |
+
console.log("Renderer initialized and added to DOM.");
|
132 |
+
|
133 |
+
// Basic Lighting
|
134 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6); // Soft white light
|
135 |
+
scene.add(ambientLight);
|
136 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
|
137 |
+
directionalLight.position.set(5, 10, 7.5); // Position the light
|
138 |
+
scene.add(directionalLight);
|
139 |
+
|
140 |
+
// Basic Cube Object
|
141 |
+
const geometry = new THREE.BoxGeometry(1, 1, 1); // 1x1x1 cube
|
142 |
+
const material = new THREE.MeshStandardMaterial({ color: 0xcccccc }); // Light grey color
|
143 |
+
cube = new THREE.Mesh(geometry, material);
|
144 |
+
scene.add(cube); // Add cube to the scene
|
145 |
+
console.log("Cube created and added to scene.");
|
146 |
+
|
147 |
+
// Handle Resize
|
148 |
+
window.addEventListener('resize', onWindowResize, false);
|
149 |
+
// Initial resize call in case the flexbox layout takes a moment
|
150 |
+
setTimeout(onWindowResize, 100); // Delay slightly to help layout settle
|
151 |
+
|
152 |
+
// Start Animation Loop
|
153 |
+
animate();
|
154 |
+
console.log("Animation loop started.");
|
155 |
+
}
|
156 |
+
|
157 |
+
function onWindowResize() {
|
158 |
+
if (!renderer || !camera || !sceneContainer) return;
|
159 |
+
|
160 |
+
const width = sceneContainer.clientWidth;
|
161 |
+
const height = sceneContainer.clientHeight;
|
162 |
+
|
163 |
+
// Only resize if dimensions are valid
|
164 |
+
if (width > 0 && height > 0) {
|
165 |
+
camera.aspect = width / height;
|
166 |
+
camera.updateProjectionMatrix(); // Important after changing aspect
|
167 |
+
renderer.setSize(width, height);
|
168 |
+
// console.log(`Resized to ${width}x${height}`); // Debug log for resize
|
169 |
+
} else {
|
170 |
+
console.warn("onWindowResize called with zero dimensions.");
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
function animate() {
|
175 |
+
requestAnimationFrame(animate); // Loop the animation
|
176 |
+
|
177 |
+
// Simple cube rotation
|
178 |
+
if (cube) {
|
179 |
+
cube.rotation.x += 0.005;
|
180 |
+
cube.rotation.y += 0.005;
|
181 |
+
}
|
182 |
+
|
183 |
+
// Render the scene
|
184 |
+
if (renderer && scene && camera) {
|
185 |
+
renderer.render(scene, camera);
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
// --- Initialization ---
|
190 |
+
// Wait for the basic HTML structure to be ready before running the script
|
191 |
+
document.addEventListener('DOMContentLoaded', () => {
|
192 |
+
console.log("DOM Content Loaded. Initializing...");
|
193 |
+
try {
|
194 |
+
initThreeJS();
|
195 |
+
} catch (error) {
|
196 |
+
console.error("Error during initialization:", error);
|
197 |
+
// Display error to user in the UI panel
|
198 |
+
const uiContainer = document.getElementById('ui-container');
|
199 |
+
if (uiContainer) {
|
200 |
+
uiContainer.innerHTML = `<h2>Error</h2><p>Failed to initialize 3D scene. Please check the browser console (F12) for details.</p><pre>${error.message}\n${error.stack}</pre>`;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
});
|
204 |
+
|
205 |
+
</script>
|
206 |
|
|
|
207 |
</body>
|
208 |
</html>
|