Skip to content

Commit c718464

Browse files
committed
33
1 parent 2c1d3c0 commit c718464

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/index.js

+34-14
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { PointerLockControls } from 'three/examples/jsm/controls/PointerLockCont
44
import { Reflector } from 'three/examples/jsm/objects/Reflector.js';
55
import * as CANNON from 'cannon-es';
66
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';
88

9-
10-
// Main variables
9+
// Основные переменные
1110
let isGameRunning = false;
1211
let paused = false;
1312
let menuVisible = true;
@@ -65,8 +64,10 @@ async function initWebGPU() {
6564
const adapter = await navigator.gpu.requestAdapter();
6665
const device = await adapter.requestDevice();
6766

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+
});
7071

7172
// Initialize WebGPU Renderer
7273
const renderer = new WebGPURenderer({ device, glslang });
@@ -81,16 +82,16 @@ async function initWebGPU() {
8182
initWebGPU().then((renderer) => {
8283
if (!renderer) return;
8384

84-
// Scene and camera
85+
// Сцена и камера
8586
const scene = new THREE.Scene();
8687
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
8788
camera.position.set(0, 1.8, 5);
8889

89-
// FPS counter
90+
// Счетчик FPS
9091
const stats = new Stats();
9192
document.body.appendChild(stats.dom);
9293

93-
// Camera controls
94+
// Контролы камеры
9495
const controls = new PointerLockControls(camera, document.body);
9596
document.body.addEventListener('click', () => {
9697
if (!isGameRunning) return;
@@ -122,7 +123,7 @@ initWebGPU().then((renderer) => {
122123
]);
123124
scene.background = skyboxTexture;
124125

125-
// Physics world (Cannon.js)
126+
// Мир физики (Cannon.js)
126127
const world = new CANNON.World();
127128
world.gravity.set(0, -9.82, 0);
128129
world.broadphase = new CANNON.NaiveBroadphase();
@@ -131,7 +132,7 @@ initWebGPU().then((renderer) => {
131132
const fixedTimeStep = 1 / 60;
132133
const maxSubSteps = 3;
133134

134-
// Ground
135+
// Пол
135136
const textureLoader = new THREE.TextureLoader();
136137
const groundTexture = textureLoader.load('https://threejsfundamentals.org/threejs/resources/images/checker.png');
137138
groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
@@ -150,7 +151,7 @@ initWebGPU().then((renderer) => {
150151
groundBody.quaternion.setFromEuler(-Math.PI / 2, 0, 0);
151152
world.addBody(groundBody);
152153

153-
// Wall
154+
// Стены
154155
const wallTexture = textureLoader.load('https://dl.polyhaven.org/file/ph-assets/Textures/jpg/2k/brick_wall_006/brick_wall_006_diff_2k.jpg');
155156
const wallMaterial = new THREE.MeshStandardMaterial({ map: wallTexture, metalness: 0.0, roughness: 0.8 });
156157

@@ -166,7 +167,26 @@ initWebGPU().then((renderer) => {
166167
wall1Body.position.set(0, 2.5, -5);
167168
world.addBody(wall1Body);
168169

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+
// Объект куба с динамической физикой
170190
const cubeMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
171191
const cube = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), cubeMaterial);
172192
cube.position.set(0, 1, 0);
@@ -180,7 +200,7 @@ initWebGPU().then((renderer) => {
180200
cubeBody.position.set(0, 1, 0);
181201
world.addBody(cubeBody);
182202

183-
// Sphere with dynamic physics
203+
// Объект сферы с динамической физикой
184204
const sphere = new THREE.Mesh(new THREE.SphereGeometry(0.5, 32, 32), new THREE.MeshStandardMaterial({ color: 0x00ff00 }));
185205
sphere.position.set(3, 1, 0);
186206
sphere.castShadow = true;
@@ -193,7 +213,7 @@ initWebGPU().then((renderer) => {
193213
sphereBody.position.set(3, 1, 0);
194214
world.addBody(sphereBody);
195215

196-
// Player physics
216+
// Физика игрока
197217
const playerBody = new CANNON.Body({
198218
mass: 5,
199219
shape: new CANNON.Sphere(1),

0 commit comments

Comments
 (0)