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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439import * as THREE from "three"
import { createNonEuclideanMaterial, createHolographicMaterial, createNeonMaterial } from "./shaders"
// Graph node representing a room
interface RoomNode {
id: number
position: THREE.Vector3
connections: number[] // IDs of connected rooms
size: THREE.Vector3
type: "standard" | "atrium" | "data-hub" | "anomaly"
}
// Generate a graph representing the museum layout
export function generateMuseumGraph(roomCount: number): RoomNode[] {
const rooms: RoomNode[] = []
// Define room types
const roomTypes = ["standard", "atrium", "data-hub", "anomaly"]
// Create initial room at the center - make it larger as an atrium
rooms.push({
id: 0,
position: new THREE.Vector3(0, 0, 0),
connections: [],
size: new THREE.Vector3(8, 4, 8),
type: "atrium",
})
// Generate additional rooms
for (let i = 1; i < roomCount; i++) {
// Choose a random existing room to connect to
const connectToIndex = Math.floor(Math.random() * i)
const connectToRoom = rooms[connectToIndex]
// Determine new room position (with some randomization)
const direction = new THREE.Vector3(
Math.random() - 0.5,
0, // Keep rooms on the same y-level
Math.random() - 0.5,
).normalize()
// Calculate distance between rooms (corridor length)
const distance = 12 + Math.random() * 5
// Calculate new room position
const newPosition = connectToRoom.position.clone().add(direction.multiplyScalar(distance))
// Determine room type
let roomType: "standard" | "atrium" | "data-hub" | "anomaly"
if (i === 1) {
roomType = "data-hub" // Make the second room a data hub
} else if (i === roomCount - 1) {
roomType = "anomaly" // Make the last room an anomaly zone
} else {
roomType = roomTypes[Math.floor(Math.random() * 2)] as any // Mostly standard rooms with some special ones
}
// Determine room size based on type
let roomSize
switch (roomType) {
case "atrium":
roomSize = new THREE.Vector3(8 + Math.random() * 2, 4 + Math.random() * 1, 8 + Math.random() * 2)
break
case "data-hub":
roomSize = new THREE.Vector3(6 + Math.random() * 2, 3.5 + Math.random() * 0.5, 6 + Math.random() * 2)
break
case "anomaly":
roomSize = new THREE.Vector3(7 + Math.random() * 3, 5 + Math.random() * 2, 7 + Math.random() * 3)
break
default:
roomSize = new THREE.Vector3(5 + Math.random() * 2, 3 + Math.random() * 1, 5 + Math.random() * 2)
}
// Create new room
const newRoom: RoomNode = {
id: i,
position: newPosition,
connections: [connectToIndex],
size: roomSize,
type: roomType,
}
// Add connection to the existing room
connectToRoom.connections.push(i)
// Add the new room
rooms.push(newRoom)
}
// Add some non-Euclidean connections (loops)
if (roomCount > 3) {
// Add 1-2 non-Euclidean connections
const nonEuclideanConnections = 1 + Math.floor(Math.random() * 2)
for (let i = 0; i < nonEuclideanConnections; i++) {
// Choose two random rooms that aren't already connected
let room1Index, room2Index
do {
room1Index = Math.floor(Math.random() * roomCount)
room2Index = Math.floor(Math.random() * roomCount)
} while (room1Index === room2Index || rooms[room1Index].connections.includes(room2Index))
// Connect the rooms
rooms[room1Index].connections.push(room2Index)
rooms[room2Index].connections.push(room1Index)
}
}
return rooms
}
// Convert graph to 3D geometry
export function createMuseumLayout(roomCount: number): THREE.Group {
const museumGroup = new THREE.Group()
// Generate museum graph
const roomNodes = generateMuseumGraph(roomCount)
// Create cyberpunk materials
const createMaterialsForRoomType = (type: string) => {
switch (type) {
case "atrium":
return {
wall: createNonEuclideanMaterial(new THREE.Color(0x101624), new THREE.Color(0x00ffff), 1.0),
floor: createNonEuclideanMaterial(new THREE.Color(0x080a12), new THREE.Color(0x00ffaa), 0.8),
ceiling: createNonEuclideanMaterial(new THREE.Color(0x121a2c), new THREE.Color(0x00aaff), 0.9),
}
case "data-hub":
return {
wall: createNonEuclideanMaterial(new THREE.Color(0x1a0a20), new THREE.Color(0xff00ff), 1.2),
floor: createNonEuclideanMaterial(new THREE.Color(0x0a0a14), new THREE.Color(0xaa00ff), 0.7),
ceiling: createNonEuclideanMaterial(new THREE.Color(0x1a1a2c), new THREE.Color(0xff00aa), 1.0),
}
case "anomaly":
return {
wall: createNonEuclideanMaterial(new THREE.Color(0x200a0a), new THREE.Color(0xff3300), 1.5),
floor: createNonEuclideanMaterial(new THREE.Color(0x120505), new THREE.Color(0xff5500), 1.2),
ceiling: createNonEuclideanMaterial(new THREE.Color(0x1a0a0a), new THREE.Color(0xff0000), 1.3),
}
default: // standard
return {
wall: createNonEuclideanMaterial(new THREE.Color(0x0a0f18), new THREE.Color(0x0088ff), 0.8),
floor: createNonEuclideanMaterial(new THREE.Color(0x05080f), new THREE.Color(0x0055aa), 0.6),
ceiling: createNonEuclideanMaterial(new THREE.Color(0x0f1520), new THREE.Color(0x00aaff), 0.7),
}
}
}
// Create rooms
roomNodes.forEach((room) => {
const roomGroup = new THREE.Group()
roomGroup.position.copy(room.position)
// Get materials based on room type
const materials = createMaterialsForRoomType(room.type)
// Floor
const floor = new THREE.Mesh(new THREE.BoxGeometry(room.size.x, 0.2, room.size.z), materials.floor)
floor.position.y = -room.size.y / 2
floor.receiveShadow = true
roomGroup.add(floor)
// Add floor patterns/grid for cyberpunk feel
const floorGrid = new THREE.GridHelper(
room.size.x,
Math.floor(room.size.x),
new THREE.Color(0x00ffff),
new THREE.Color(0x004466),
)
floorGrid.position.y = -room.size.y / 2 + 0.11
roomGroup.add(floorGrid)
// Ceiling
const ceiling = new THREE.Mesh(new THREE.BoxGeometry(room.size.x, 0.2, room.size.z), materials.ceiling)
ceiling.position.y = room.size.y / 2
ceiling.castShadow = true
roomGroup.add(ceiling)
// Walls with dynamic cyberpunk paneling
const wallThickness = 0.2
// Helper to create stylized wall with panels
const createStylizedWall = (
width: number,
height: number,
depth: number,
x: number,
y: number,
z: number,
rotationY = 0,
) => {
// Main wall
const wall = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), materials.wall)
wall.position.set(x, y, z)
wall.rotation.y = rotationY
wall.castShadow = true
wall.receiveShadow = true
roomGroup.add(wall)
// Add cyberpunk panels and details
const panelCount = Math.floor(width / 2)
const panelWidth = width / panelCount
for (let i = 0; i < panelCount; i++) {
// Skip some panels randomly
if (Math.random() > 0.7) continue
// Create panel
const panelMaterial = createNeonMaterial(new THREE.Color(Math.random() > 0.5 ? 0x00ffff : 0xff00ff))
const panel = new THREE.Mesh(new THREE.BoxGeometry(panelWidth * 0.8, height * 0.3, 0.05), panelMaterial)
// Position panel along the wall
const offsetX = i * panelWidth - width / 2 + panelWidth / 2
const offsetY = Math.random() * (height * 0.5) - height * 0.25
panel.position.set(x + Math.cos(rotationY) * offsetX, y + offsetY, z + Math.sin(rotationY) * offsetX)
panel.rotation.y = rotationY
// Move panel slightly forward
const forwardDir = new THREE.Vector3(Math.sin(rotationY), 0, Math.cos(rotationY))
panel.position.add(forwardDir.multiplyScalar(-0.1))
roomGroup.add(panel)
}
}
// Front wall with opening
if (room.type !== "standard") {
// For special rooms, create a more elaborate entrance
const wallLeft = new THREE.Mesh(
new THREE.BoxGeometry((room.size.x - 3) / 2, room.size.y, wallThickness),
materials.wall,
)
wallLeft.position.z = room.size.z / 2
wallLeft.position.x = -(room.size.x + 3) / 4
wallLeft.castShadow = true
wallLeft.receiveShadow = true
roomGroup.add(wallLeft)
const wallRight = new THREE.Mesh(
new THREE.BoxGeometry((room.size.x - 3) / 2, room.size.y, wallThickness),
materials.wall,
)
wallRight.position.z = room.size.z / 2
wallRight.position.x = (room.size.x + 3) / 4
wallRight.castShadow = true
wallRight.receiveShadow = true
roomGroup.add(wallRight)
// Add stylized door frame with neon
const doorFrame = new THREE.Mesh(
new THREE.BoxGeometry(3.5, 0.2, 0.3),
createNeonMaterial(new THREE.Color(room.type === "data-hub" ? 0xff00ff : 0x00ffff)),
)
doorFrame.position.z = room.size.z / 2
doorFrame.position.y = room.size.y / 2 - 0.1
roomGroup.add(doorFrame)
} else {
// Standard room with stylized wall
createStylizedWall(room.size.x, room.size.y, wallThickness, 0, 0, room.size.z / 2, 0)
}
// Back wall
createStylizedWall(room.size.x, room.size.y, wallThickness, 0, 0, -room.size.z / 2, 0)
// Left wall
createStylizedWall(room.size.z, room.size.y, wallThickness, -room.size.x / 2, 0, 0, Math.PI / 2)
// Right wall
createStylizedWall(room.size.z, room.size.y, wallThickness, room.size.x / 2, 0, 0, Math.PI / 2)
// Add room-specific features
if (room.type === "data-hub") {
// Add holographic terminal
const terminalBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.5, 0.6, 1, 16),
createNeonMaterial(new THREE.Color(0xff00ff)),
)
terminalBase.position.set(0, -room.size.y / 2 + 0.5, 0)
terminalBase.name = "terminal"
roomGroup.add(terminalBase)
const hologram = new THREE.Mesh(
new THREE.CylinderGeometry(1.5, 1.5, 2, 32, 1, true),
createHolographicMaterial(new THREE.Color(0xff00ff)),
)
hologram.position.set(0, 1, 0)
hologram.name = "terminal-hologram"
roomGroup.add(hologram)
// Add floating data cubes
for (let i = 0; i < 6; i++) {
const size = 0.3 + Math.random() * 0.2
const cube = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
createHolographicMaterial(new THREE.Color(0xff00ff), 0.4 + Math.random() * 0.3),
)
// Position in a circle around the terminal
const angle = (i / 6) * Math.PI * 2
const radius = 2 + Math.random() * 0.5
cube.position.set(Math.cos(angle) * radius, 1 + Math.random() * 0.5, Math.sin(angle) * radius)
// Random rotation
cube.rotation.set(Math.random() * Math.PI, Math.random() * Math.PI, Math.random() * Math.PI)
cube.name = "data-cube-" + i
roomGroup.add(cube)
}
} else if (room.type === "atrium") {
// Add central feature
const centralColumn = new THREE.Mesh(
new THREE.CylinderGeometry(0.8, 0.8, room.size.y - 0.5, 16),
createNonEuclideanMaterial(new THREE.Color(0x1a1a2c), new THREE.Color(0x00ffff), 1.2),
)
centralColumn.position.y = 0
roomGroup.add(centralColumn)
// Add rings around the column
for (let i = 0; i < 3; i++) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.5, 0.1, 16, 32),
createNeonMaterial(new THREE.Color(0x00ffff)),
)
ring.position.y = -room.size.y / 3 + (i * room.size.y) / 3
roomGroup.add(ring)
}
} else if (room.type === "anomaly") {
// Add distortion effect in center
const anomalySphere = new THREE.Mesh(
new THREE.SphereGeometry(1.5, 32, 32),
createHolographicMaterial(new THREE.Color(0xff3300), 0.6),
)
anomalySphere.position.y = 0
anomalySphere.name = "anomaly-core"
roomGroup.add(anomalySphere)
// Add floating debris
for (let i = 0; i < 8; i++) {
const debris = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.2 + Math.random() * 0.3),
createNonEuclideanMaterial(new THREE.Color(0x331100), new THREE.Color(0xff5500), 1.0),
)
// Position in a sphere around the anomaly
const phi = Math.acos(2 * Math.random() - 1)
const theta = Math.random() * Math.PI * 2
const radius = 2 + Math.random() * 1
debris.position.set(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta),
)
// Random rotation
debris.rotation.set(Math.random() * Math.PI * 2, Math.random() * Math.PI * 2, Math.random() * Math.PI * 2)
roomGroup.add(debris)
}
}
museumGroup.add(roomGroup)
// Create corridors to connected rooms
room.connections.forEach((connectedRoomId) => {
// Only create corridors for higher IDs to avoid duplicates
if (connectedRoomId > room.id) {
const connectedRoom = roomNodes[connectedRoomId]
// Calculate corridor direction and length
const direction = new THREE.Vector3().subVectors(connectedRoom.position, room.position)
const distance = direction.length()
direction.normalize()
// Create corridor
const corridorWidth = 3
const corridorHeight = 3
const corridorLength = distance - room.size.z / 2 - connectedRoom.size.z / 2
// Create corridor group
const corridorGroup = new THREE.Group()
// Create corridor walls and floor
const corridorMaterial = createNonEuclideanMaterial(new THREE.Color(0x080a12), new THREE.Color(0x0066aa), 0.6)
// Floor
const floor = new THREE.Mesh(new THREE.BoxGeometry(corridorWidth, 0.2, corridorLength), corridorMaterial)
floor.position.y = -corridorHeight / 2
corridorGroup.add(floor)
// Ceiling
const ceiling = new THREE.Mesh(new THREE.BoxGeometry(corridorWidth, 0.2, corridorLength), corridorMaterial)
ceiling.position.y = corridorHeight / 2
corridorGroup.add(ceiling)
// Left wall
const leftWall = new THREE.Mesh(new THREE.BoxGeometry(0.2, corridorHeight, corridorLength), corridorMaterial)
leftWall.position.x = -corridorWidth / 2
corridorGroup.add(leftWall)
// Right wall
const rightWall = new THREE.Mesh(new THREE.BoxGeometry(0.2, corridorHeight, corridorLength), corridorMaterial)
rightWall.position.x = corridorWidth / 2
corridorGroup.add(rightWall)
// Add neon strips along the corridor
const neonTop = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.1, corridorLength),
createNeonMaterial(new THREE.Color(0x00ffff)),
)
neonTop.position.set(0, corridorHeight / 2 - 0.2, 0)
corridorGroup.add(neonTop)
// Add neon strips along the corridor floor
const neonFloor = new THREE.Mesh(
new THREE.BoxGeometry(corridorWidth - 1, 0.05, corridorLength),
createNeonMaterial(new THREE.Color(0x00aaff)),
)
neonFloor.position.set(0, -corridorHeight / 2 + 0.12, 0)
corridorGroup.add(neonFloor)
// Position corridor between rooms
corridorGroup.position.copy(room.position)
corridorGroup.position.add(direction.clone().multiplyScalar(room.size.z / 2 + corridorLength / 2))
// Rotate corridor to face the connected room
corridorGroup.lookAt(connectedRoom.position)
// Add corridor to museum
museumGroup.add(corridorGroup)
}
})
})
return museumGroup
}