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
427import * as THREE from "three"
import { createNonEuclideanMaterial, createHolographicMaterial, createNeonMaterial } from "./shaders"
// Create museum puzzles
export function createPuzzles(): THREE.Group {
const puzzlesGroup = new THREE.Group()
// Create a perspective shift puzzle
const perspectiveShiftPuzzle = createPerspectiveShiftPuzzle()
perspectiveShiftPuzzle.position.set(12, 0, 12)
puzzlesGroup.add(perspectiveShiftPuzzle)
// Create a looping corridor puzzle
const loopingCorridorPuzzle = createLoopingCorridorPuzzle()
loopingCorridorPuzzle.position.set(-12, 0, -12)
puzzlesGroup.add(loopingCorridorPuzzle)
// Create a mechanism activation puzzle
const mechanismPuzzle = createMechanismPuzzle()
mechanismPuzzle.position.set(-12, 0, 12)
puzzlesGroup.add(mechanismPuzzle)
return puzzlesGroup
}
// Create a perspective shift puzzle
function createPerspectiveShiftPuzzle(): THREE.Group {
const puzzleGroup = new THREE.Group()
puzzleGroup.name = "puzzle-perspective"
// Create a puzzle where a path is only visible from a specific viewpoint
const platformMaterial = createNonEuclideanMaterial(new THREE.Color(0x1a0a20), new THREE.Color(0x9c27b0), 1.2)
// Create the main platform
const platform = new THREE.Mesh(new THREE.BoxGeometry(5, 0.5, 5), platformMaterial)
platform.receiveShadow = true
puzzleGroup.add(platform)
// Add neon trim to the platform
const platformTrim = new THREE.Mesh(
new THREE.BoxGeometry(5.2, 0.1, 5.2),
createNeonMaterial(new THREE.Color(0xff00ff)),
)
platformTrim.position.y = -0.2
puzzleGroup.add(platformTrim)
// Create floating path pieces that only align from a specific angle
const pathPieces = []
for (let i = 0; i < 5; i++) {
const pieceGeometry = new THREE.BoxGeometry(1, 0.2, 1)
const pieceMaterial = createHolographicMaterial(new THREE.Color(0xff00ff), 0.7)
const piece = new THREE.Mesh(pieceGeometry, pieceMaterial)
// Position pieces in a way that they only form a path from one angle
const angle = Math.PI / 4 + (i * Math.PI) / 10
const radius = 3 + i * 0.5
piece.position.set(Math.cos(angle) * radius, 1 + i * 0.5, Math.sin(angle) * radius)
// Rotate each piece differently
piece.rotation.set((Math.random() * Math.PI) / 4, (Math.random() * Math.PI) / 2, (Math.random() * Math.PI) / 4)
pathPieces.push(piece)
puzzleGroup.add(piece)
// Add glowing edges
const edgesGeometry = new THREE.EdgesGeometry(pieceGeometry)
const edgesMaterial = new THREE.LineBasicMaterial({
color: 0xff00ff,
linewidth: 2,
})
const edges = new THREE.LineSegments(edgesGeometry, edgesMaterial)
edges.position.copy(piece.position)
edges.rotation.copy(piece.rotation)
puzzleGroup.add(edges)
}
// Add a goal platform with special material
const goalMaterial = createNeonMaterial(new THREE.Color(0x00ff99))
const goalPlatform = new THREE.Mesh(new THREE.BoxGeometry(2, 0.5, 2), goalMaterial)
goalPlatform.position.set(8, 3, 8)
goalPlatform.receiveShadow = true
puzzleGroup.add(goalPlatform)
// Add puzzle marker/hologram
const markerGeometry = new THREE.SphereGeometry(0.5, 16, 16)
const markerMaterial = createHolographicMaterial(new THREE.Color(0xff00ff), 0.5)
const marker = new THREE.Mesh(markerGeometry, markerMaterial)
marker.position.set(0, 2, 0)
// Add animation to marker
const animateMarker = () => {
marker.position.y = 2 + Math.sin(Date.now() * 0.001) * 0.3
marker.rotation.y += 0.02
requestAnimationFrame(animateMarker)
}
animateMarker()
puzzleGroup.add(marker)
return puzzleGroup
}
// Create a looping corridor puzzle
function createLoopingCorridorPuzzle(): THREE.Group {
const puzzleGroup = new THREE.Group()
puzzleGroup.name = "puzzle-corridor"
const corridorMaterial = createNonEuclideanMaterial(new THREE.Color(0x1a0a05), new THREE.Color(0xff9800), 1.0)
// Create a corridor that appears to loop back on itself
const corridorLength = 20
const corridorWidth = 3
const corridorHeight = 3
// Create the main corridor
const corridorGeometry = new THREE.BoxGeometry(corridorWidth, corridorHeight, corridorLength)
// Remove one end cap to create an open corridor
const corridorPositions = corridorGeometry.attributes.position.array as Float32Array
for (let i = 0; i < corridorPositions.length; i += 3) {
if (corridorPositions[i + 2] < -corridorLength / 2 + 0.1) {
corridorPositions[i + 2] = -corridorLength / 2 + 0.1
}
}
const corridor = new THREE.Mesh(corridorGeometry, corridorMaterial)
corridor.position.z = -corridorLength / 2
puzzleGroup.add(corridor)
// Add neon strips along the corridor
const createNeonStrip = (x: number, y: number, z: number, length: number, color: THREE.Color) => {
const stripGeometry = new THREE.BoxGeometry(0.05, 0.05, length)
const stripMaterial = createNeonMaterial(color)
const strip = new THREE.Mesh(stripGeometry, stripMaterial)
strip.position.set(x, y, z)
return strip
}
// Add strips to corridor
puzzleGroup.add(
createNeonStrip(
corridorWidth / 2 - 0.1,
corridorHeight / 2 - 0.1,
-corridorLength / 2,
corridorLength,
new THREE.Color(0xff9800),
),
)
puzzleGroup.add(
createNeonStrip(
-corridorWidth / 2 + 0.1,
corridorHeight / 2 - 0.1,
-corridorLength / 2,
corridorLength,
new THREE.Color(0xff9800),
),
)
puzzleGroup.add(
createNeonStrip(
corridorWidth / 2 - 0.1,
-corridorHeight / 2 + 0.1,
-corridorLength / 2,
corridorLength,
new THREE.Color(0xff5500),
),
)
puzzleGroup.add(
createNeonStrip(
-corridorWidth / 2 + 0.1,
-corridorHeight / 2 + 0.1,
-corridorLength / 2,
corridorLength,
new THREE.Color(0xff5500),
),
)
// Create "fake" corridors to create the illusion of looping
const fakeCorridor1 = new THREE.Mesh(
new THREE.BoxGeometry(corridorWidth, corridorHeight, corridorLength / 4),
corridorMaterial,
)
fakeCorridor1.position.set(0, 0, -corridorLength)
puzzleGroup.add(fakeCorridor1)
// Add holographic barrier effect at the "loop" point
const barrierGeometry = new THREE.PlaneGeometry(corridorWidth, corridorHeight)
const barrierMaterial = createHolographicMaterial(new THREE.Color(0xff5500), 0.3)
const barrier = new THREE.Mesh(barrierGeometry, barrierMaterial)
barrier.position.set(0, 0, -corridorLength + 0.1)
barrier.rotation.y = Math.PI
// Animate the barrier
const animateBarrier = () => {
const time = Date.now() * 0.001
if (barrier.material.uniforms) {
// Update holographic effect
barrier.material.uniforms.time.value = time
}
requestAnimationFrame(animateBarrier)
}
animateBarrier()
puzzleGroup.add(barrier)
// Create the "true" exit that's hidden
const trueExitMaterial = createNeonMaterial(new THREE.Color(0x00ff99))
const trueExit = new THREE.Mesh(
new THREE.BoxGeometry(corridorWidth, corridorHeight, corridorLength / 4),
trueExitMaterial,
)
trueExit.position.set(corridorWidth * 2, 0, -corridorLength * 0.75)
trueExit.rotation.y = Math.PI / 2
puzzleGroup.add(trueExit)
// Add hidden door to true exit
const doorGeometry = new THREE.PlaneGeometry(corridorHeight, corridorHeight)
const doorMaterial = createHolographicMaterial(new THREE.Color(0xff5500), 0.1)
const hiddenDoor = new THREE.Mesh(doorGeometry, doorMaterial)
hiddenDoor.position.set(corridorWidth / 2 + 0.1, 0, -corridorLength * 0.75)
hiddenDoor.rotation.y = Math.PI / 2
// Make door pulse
const animateDoor = () => {
if (hiddenDoor.material.uniforms) {
const opacity = 0.05 + 0.05 * Math.sin(Date.now() * 0.001)
hiddenDoor.material.opacity = opacity
}
requestAnimationFrame(animateDoor)
}
animateDoor()
puzzleGroup.add(hiddenDoor)
return puzzleGroup
}
// Create a mechanism activation puzzle
function createMechanismPuzzle(): THREE.Group {
const puzzleGroup = new THREE.Group()
puzzleGroup.name = "puzzle-mechanism"
// Create a button that activates a mechanism in a distant location
const buttonGeometry = new THREE.CylinderGeometry(0.5, 0.5, 0.2, 32)
const buttonMaterial = createNeonMaterial(new THREE.Color(0xff0000))
const button = new THREE.Mesh(buttonGeometry, buttonMaterial)
button.position.set(0, 1, 0)
button.name = "mechanism-button"
puzzleGroup.add(button)
// Create a pedestal for the button
const pedestalGeometry = new THREE.CylinderGeometry(0.3, 0.5, 1, 32)
const pedestalMaterial = createNonEuclideanMaterial(new THREE.Color(0x1a1a1a), new THREE.Color(0xff3366), 0.8)
const pedestal = new THREE.Mesh(pedestalGeometry, pedestalMaterial)
pedestal.position.set(0, 0.5, 0)
puzzleGroup.add(pedestal)
// Add holographic display above button
const displayGeometry = new THREE.CylinderGeometry(0.8, 0.8, 1.5, 32, 1, true)
const displayMaterial = createHolographicMaterial(new THREE.Color(0xff3366), 0.5)
const display = new THREE.Mesh(displayGeometry, displayMaterial)
display.position.set(0, 2, 0)
puzzleGroup.add(display)
// Create holographic text labels
const textElement = document.createElement("div")
textElement.style.position = "absolute"
textElement.style.width = "200px"
textElement.style.textAlign = "center"
textElement.style.color = "#ff3366"
textElement.style.fontFamily = "monospace"
textElement.style.fontSize = "14px"
textElement.style.padding = "10px"
textElement.style.backgroundColor = "rgba(0, 0, 0, 0.7)"
textElement.style.border = "1px solid #ff3366"
textElement.style.boxShadow = "0 0 10px #ff3366"
textElement.style.borderRadius = "5px"
textElement.style.transform = "translate(-50%, -50%)"
textElement.innerHTML = `
<div style="text-transform: uppercase; font-weight: bold; margin-bottom: 5px;">SYSTEM OVERRIDE</div>
<div>PRESS [E] TO ACTIVATE</div>
`
document.body.appendChild(textElement)
// Position the text element in 3D space
const updateTextPosition = () => {
const vector = new THREE.Vector3()
button.updateMatrixWorld()
vector.setFromMatrixPosition(button.matrixWorld)
const widthHalf = window.innerWidth / 2
const heightHalf = window.innerHeight / 2
vector.project(new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000))
vector.x = vector.x * widthHalf + widthHalf
vector.y = -(vector.y * heightHalf) + heightHalf
textElement.style.left = `${vector.x}px`
textElement.style.top = `${vector.y - 80}px`
// Only show when in view and close
const distance = puzzleGroup.position.distanceTo(new THREE.Vector3(0, 0, 0))
if (distance < 15 && vector.z < 1) {
textElement.style.display = "block"
textElement.style.opacity = (1 - distance / 15).toString()
} else {
textElement.style.display = "none"
}
requestAnimationFrame(updateTextPosition)
}
updateTextPosition()
// Create a door that opens when the button is pressed
const doorGeometry = new THREE.BoxGeometry(2, 3, 0.2)
const doorMaterial = createNonEuclideanMaterial(new THREE.Color(0x330000), new THREE.Color(0xff3366), 1.0)
const door = new THREE.Mesh(doorGeometry, doorMaterial)
door.position.set(5, 1.5, 5)
puzzleGroup.add(door)
// Add neon frame around door
const doorFrameGeometry = new THREE.BoxGeometry(2.4, 3.2, 0.1)
const doorFrameMaterial = createNeonMaterial(new THREE.Color(0xff3366))
const doorFrame = new THREE.Mesh(doorFrameGeometry, doorFrameMaterial)
doorFrame.position.set(5, 1.5, 5.1)
puzzleGroup.add(doorFrame)
// Add data cables connecting button to door
const createCable = (start: THREE.Vector3, end: THREE.Vector3, color: THREE.Color) => {
const points = []
// Create a curved path for the cable
const curvePoints = 10
for (let i = 0; i <= curvePoints; i++) {
const t = i / curvePoints
// Create a curve with some height variation
const pt = new THREE.Vector3()
pt.x = start.x + (end.x - start.x) * t
pt.z = start.z + (end.z - start.z) * t
// Add some height variation to make it look like a real cable
if (i > 0 && i < curvePoints) {
const height = Math.sin(t * Math.PI) * 0.5
pt.y = start.y + (end.y - start.y) * t + height
} else {
pt.y = start.y + (end.y - start.y) * t
}
points.push(pt)
}
const curve = new THREE.CatmullRomCurve3(points)
const tubeGeometry = new THREE.TubeGeometry(curve, 20, 0.05, 8, false)
const tubeMaterial = createNeonMaterial(color)
const tube = new THREE.Mesh(tubeGeometry, tubeMaterial)
return tube
}
// Add cables
puzzleGroup.add(createCable(new THREE.Vector3(0, 0.5, 0), new THREE.Vector3(5, 3, 5), new THREE.Color(0xff3366)))
puzzleGroup.add(createCable(new THREE.Vector3(0, 0.3, 0), new THREE.Vector3(5, 0, 5), new THREE.Color(0xff5500)))
// Add interactivity to the button
const raycaster = new THREE.Raycaster()
const mouse = new THREE.Vector2()
window.addEventListener("click", (event) => {
// Calculate mouse position in normalized device coordinates
mouse.x = (event.clientX / window.innerWidth) * 2 - 1
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1
// Update the picking ray with the camera and mouse position
raycaster.setFromCamera(mouse, new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000))
// Calculate objects intersecting the picking ray
const intersects = raycaster.intersectObject(button, true)
if (intersects.length > 0) {
// Button was clicked, animate the door opening
const doorAnimation = () => {
if (door.rotation.y < Math.PI / 2) {
door.rotation.y += 0.05
requestAnimationFrame(doorAnimation)
}
}
doorAnimation()
// Change button color to green
button.material.color.set(0x00ff99)
// Update text
textElement.innerHTML = `
<div style="text-transform: uppercase; font-weight: bold; margin-bottom: 5px; color: #00ff99;">SYSTEM ACTIVATED</div>
<div>ACCESS GRANTED</div>
`
// Add light burst effect
const burstGeometry = new THREE.SphereGeometry(0.1, 16, 16)
const burstMaterial = createNeonMaterial(new THREE.Color(0x00ff99))
const burst = new THREE.Mesh(burstGeometry, burstMaterial)
burst.position.copy(button.position)
puzzleGroup.add(burst)
// Animate the burst
const animateBurst = () => {
if (burst.scale.x < 20) {
burst.scale.x += 0.5
burst.scale.y += 0.5
burst.scale.z += 0.5
burst.material.opacity = 1 - burst.scale.x / 20
requestAnimationFrame(animateBurst)
} else {
puzzleGroup.remove(burst)
}
}
animateBurst()
}
})
return puzzleGroup
}