@@ -4,10 +4,9 @@ import { PointerLockControls } from 'three/examples/jsm/controls/PointerLockCont
4
4
import { Reflector } from 'three/examples/jsm/objects/Reflector.js' ;
5
5
import * as CANNON from 'cannon-es' ;
6
6
import Stats from 'three/examples/jsm/libs/stats.module.js' ;
7
- import glslangModule from 'https://cdn.jsdelivr.net/npm/ @webgpu/glslang@0.0.15 /dist/web-devel/glslang.js' ;
7
+ import glslangModule from '@webgpu/glslang/dist/web-devel/glslang.js' ;
8
8
9
-
10
- // Main variables
9
+ // Основные переменные
11
10
let isGameRunning = false ;
12
11
let paused = false ;
13
12
let menuVisible = true ;
@@ -65,8 +64,10 @@ async function initWebGPU() {
65
64
const adapter = await navigator . gpu . requestAdapter ( ) ;
66
65
const device = await adapter . requestDevice ( ) ;
67
66
68
- // Load GLSLang
69
- const glslang = await glslangModule ( ) ;
67
+ // Load GLSLang and specify the correct wasm path for GitHub Pages
68
+ const glslang = await glslangModule ( {
69
+ wasmPath : './wasm/glslang.wasm' // Correct relative path to the .wasm file
70
+ } ) ;
70
71
71
72
// Initialize WebGPU Renderer
72
73
const renderer = new WebGPURenderer ( { device, glslang } ) ;
@@ -81,16 +82,16 @@ async function initWebGPU() {
81
82
initWebGPU ( ) . then ( ( renderer ) => {
82
83
if ( ! renderer ) return ;
83
84
84
- // Scene and camera
85
+ // Сцена и камера
85
86
const scene = new THREE . Scene ( ) ;
86
87
const camera = new THREE . PerspectiveCamera ( 75 , window . innerWidth / window . innerHeight , 0.1 , 1000 ) ;
87
88
camera . position . set ( 0 , 1.8 , 5 ) ;
88
89
89
- // FPS counter
90
+ // Счетчик FPS
90
91
const stats = new Stats ( ) ;
91
92
document . body . appendChild ( stats . dom ) ;
92
93
93
- // Camera controls
94
+ // Контролы камеры
94
95
const controls = new PointerLockControls ( camera , document . body ) ;
95
96
document . body . addEventListener ( 'click' , ( ) => {
96
97
if ( ! isGameRunning ) return ;
@@ -122,7 +123,7 @@ initWebGPU().then((renderer) => {
122
123
] ) ;
123
124
scene . background = skyboxTexture ;
124
125
125
- // Physics world (Cannon.js)
126
+ // Мир физики (Cannon.js)
126
127
const world = new CANNON . World ( ) ;
127
128
world . gravity . set ( 0 , - 9.82 , 0 ) ;
128
129
world . broadphase = new CANNON . NaiveBroadphase ( ) ;
@@ -131,7 +132,7 @@ initWebGPU().then((renderer) => {
131
132
const fixedTimeStep = 1 / 60 ;
132
133
const maxSubSteps = 3 ;
133
134
134
- // Ground
135
+ // Пол
135
136
const textureLoader = new THREE . TextureLoader ( ) ;
136
137
const groundTexture = textureLoader . load ( 'https://threejsfundamentals.org/threejs/resources/images/checker.png' ) ;
137
138
groundTexture . wrapS = groundTexture . wrapT = THREE . RepeatWrapping ;
@@ -150,7 +151,7 @@ initWebGPU().then((renderer) => {
150
151
groundBody . quaternion . setFromEuler ( - Math . PI / 2 , 0 , 0 ) ;
151
152
world . addBody ( groundBody ) ;
152
153
153
- // Wall
154
+ // Стены
154
155
const wallTexture = textureLoader . load ( 'https://dl.polyhaven.org/file/ph-assets/Textures/jpg/2k/brick_wall_006/brick_wall_006_diff_2k.jpg' ) ;
155
156
const wallMaterial = new THREE . MeshStandardMaterial ( { map : wallTexture , metalness : 0.0 , roughness : 0.8 } ) ;
156
157
@@ -166,7 +167,26 @@ initWebGPU().then((renderer) => {
166
167
wall1Body . position . set ( 0 , 2.5 , - 5 ) ;
167
168
world . addBody ( wall1Body ) ;
168
169
169
- // Cube with dynamic physics
170
+ // Освещение
171
+ const hemisphereLight = new THREE . HemisphereLight ( 0xddeeff , 0x0f0e0d , 1 ) ;
172
+ scene . add ( hemisphereLight ) ;
173
+
174
+ const directionalLight = new THREE . DirectionalLight ( 0xffffff , 1.5 ) ;
175
+ directionalLight . position . set ( 10 , 20 , 10 ) ;
176
+ directionalLight . castShadow = true ;
177
+ scene . add ( directionalLight ) ;
178
+
179
+ // Зеркальная поверхность (отражения)
180
+ const mirror = new Reflector ( new THREE . PlaneGeometry ( 10 , 10 ) , {
181
+ color : new THREE . Color ( 0x7f7f7f ) ,
182
+ textureWidth : window . innerWidth * window . devicePixelRatio ,
183
+ textureHeight : window . innerHeight * window . devicePixelRatio ,
184
+ } ) ;
185
+ mirror . position . set ( 0 , 5 , - 10 ) ;
186
+ mirror . rotation . y = Math . PI / 2 ;
187
+ scene . add ( mirror ) ;
188
+
189
+ // Объект куба с динамической физикой
170
190
const cubeMaterial = new THREE . MeshStandardMaterial ( { color : 0xff0000 } ) ;
171
191
const cube = new THREE . Mesh ( new THREE . BoxGeometry ( 1 , 1 , 1 ) , cubeMaterial ) ;
172
192
cube . position . set ( 0 , 1 , 0 ) ;
@@ -180,7 +200,7 @@ initWebGPU().then((renderer) => {
180
200
cubeBody . position . set ( 0 , 1 , 0 ) ;
181
201
world . addBody ( cubeBody ) ;
182
202
183
- // Sphere with dynamic physics
203
+ // Объект сферы с динамической физикой
184
204
const sphere = new THREE . Mesh ( new THREE . SphereGeometry ( 0.5 , 32 , 32 ) , new THREE . MeshStandardMaterial ( { color : 0x00ff00 } ) ) ;
185
205
sphere . position . set ( 3 , 1 , 0 ) ;
186
206
sphere . castShadow = true ;
@@ -193,7 +213,7 @@ initWebGPU().then((renderer) => {
193
213
sphereBody . position . set ( 3 , 1 , 0 ) ;
194
214
world . addBody ( sphereBody ) ;
195
215
196
- // Player physics
216
+ // Физика игрока
197
217
const playerBody = new CANNON . Body ( {
198
218
mass : 5 ,
199
219
shape : new CANNON . Sphere ( 1 ) ,
0 commit comments