Skip to content

Commit 46be2a2

Browse files
author
Parsa Azari
committed
test
1 parent 1f2e2ec commit 46be2a2

File tree

3 files changed

+108
-145
lines changed

3 files changed

+108
-145
lines changed

node_modules/.vite/deps_temp_60d775de/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/core/rendering/materials/SeveranceMaterials.js

Lines changed: 68 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ export class SeveranceMaterials {
163163
async _loadTextures() {
164164
const textureLoader = new THREE.TextureLoader();
165165
const texturePaths = {
166-
wall: getAssetPath("/assets/textures/wall.jpg"),
167-
floor: getAssetPath("/assets/textures/floor.jpg"),
168-
ceiling: getAssetPath("/assets/textures/ceiling.jpg"),
169-
trim: getAssetPath("/assets/textures/trim.jpg"),
170-
door: getAssetPath("/assets/textures/door.jpg"),
171-
outsideGround: getAssetPath("/assets/textures/wall.jpg"),
166+
wall: getAssetPath("/textures/wall.jpg"),
167+
floor: getAssetPath("/textures/floor.jpg"),
168+
ceiling: getAssetPath("/textures/ceiling.jpg"),
169+
trim: getAssetPath("/textures/trim.jpg"),
170+
door: getAssetPath("/textures/door.jpg"),
171+
outsideGround: getAssetPath("/textures/wall.jpg"),
172172
};
173173

174174
const loadTexture = (path) => {
@@ -227,7 +227,7 @@ export class SeveranceMaterials {
227227
*/
228228
async _loadShaders() {
229229
try {
230-
console.log("Loading shaders from src/shaders directory...");
230+
console.log("Loading shaders...");
231231

232232
// Create a default vertex shader if we can't load the file
233233
const defaultVertexShader = `
@@ -247,14 +247,12 @@ export class SeveranceMaterials {
247247
}
248248
`;
249249

250-
// Try to load common vertex shader explicitly from src/shaders/common/vertex.glsl
250+
// Try to load common vertex shader
251251
let commonVertexShader;
252252
try {
253-
console.log(
254-
"Attempting to load vertex shader from src/shaders/common/vertex.glsl"
255-
);
253+
console.log("Attempting to load vertex shader");
256254
commonVertexShader = await this._loadShaderFile(
257-
getAssetPath("/assets/shaders/common/vertex.glsl")
255+
getAssetPath("/shaders/common/vertex.glsl")
258256
);
259257
console.log("Successfully loaded vertex shader");
260258
} catch (e) {
@@ -265,62 +263,30 @@ export class SeveranceMaterials {
265263
// Initialize a default environment map
266264
const defaultEnvMap = this._createDefaultEnvMap();
267265

268-
// Load wall shader from src/shaders/wall.glsl - this is our primary wall shader
266+
// Load wall shader
269267
let wallFragmentShader;
270268
try {
271-
console.log(
272-
"Attempting to load wall shader from src/shaders/wall.glsl"
273-
);
269+
console.log("Attempting to load wall shader");
274270
wallFragmentShader = await this._loadShaderFile(
275-
getAssetPath("/assets/shaders/wall.glsl")
271+
getAssetPath("/shaders/wall.glsl")
276272
);
277273
console.log("Successfully loaded wall shader");
278-
console.log(
279-
"Wall shader content:",
280-
wallFragmentShader.substring(0, 50) + "..."
281-
);
282274
} catch (e) {
283275
console.error("Could not load wall shader from file", e);
284-
285-
// Second attempt from public path
286-
try {
287-
console.log(
288-
"Attempting to load wall shader from public/src/shaders/wall.glsl"
289-
);
290-
wallFragmentShader = await this._loadShaderFile(
291-
getAssetPath("/assets/shaders/wall.glsl")
292-
);
293-
console.log("Successfully loaded wall shader from public path");
294-
} catch (e2) {
295-
console.error("All attempts to load wall shader failed", e2);
296-
wallFragmentShader = null;
297-
}
276+
wallFragmentShader = null;
298277
}
299278

300-
// Load corridor shader from src/shaders/corridor.glsl
279+
// Load corridor shader
301280
let corridorFragmentShader;
302281
try {
303-
console.log(
304-
"Attempting to load corridor shader from src/shaders/corridor.glsl"
305-
);
282+
console.log("Attempting to load corridor shader");
306283
corridorFragmentShader = await this._loadShaderFile(
307-
getAssetPath("/assets/shaders/corridor.glsl")
284+
getAssetPath("/shaders/corridor.glsl")
308285
);
309286
console.log("Successfully loaded corridor shader");
310287
} catch (e) {
311-
console.warn(
312-
"Could not load corridor shader from primary location, trying alternatives",
313-
e
314-
);
315-
316-
// Try fallback from /shaders/corridor.glsl (without src prefix)
317-
try {
318-
corridorFragmentShader = await this._loadShaderFile(
319-
getAssetPath("/assets/shaders/corridor.glsl")
320-
);
321-
} catch (e2) {
322-
console.warn("Could not load corridor shader from any location");
323-
}
288+
console.warn("Could not load corridor shader", e);
289+
corridorFragmentShader = null;
324290
}
325291

326292
// Create corridor wall shader if corridor shader was loaded
@@ -338,51 +304,7 @@ export class SeveranceMaterials {
338304
this.shaders.set("corridorWall", corridorWallShader);
339305
}
340306

341-
// Load corridor wall shaders
342-
let corridorWallVertexShader;
343-
let corridorWallFragmentShader;
344-
345-
try {
346-
corridorWallVertexShader = await this._loadShaderFile(getAssetPath('./src/shaders/common/vertex.glsl'));
347-
corridorWallFragmentShader = await this._loadShaderFile(getAssetPath('./src/shaders/corridor_wall.glsl'));
348-
console.log('Successfully loaded corridor wall shaders');
349-
350-
// Create corridor wall material with uniforms
351-
const corridorWallMaterial = new THREE.ShaderMaterial({
352-
uniforms: {
353-
u_time: { value: 0.0 },
354-
u_resolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) },
355-
u_mouse: { value: new THREE.Vector2(0.5, 0.5) },
356-
u_depth: { value: 1.0 },
357-
playerPos: { value: new THREE.Vector3(0, 0, 0) },
358-
wallScale: { value: new THREE.Vector2(1, 1) },
359-
uPrevFrame: { value: null }
360-
},
361-
vertexShader: corridorWallVertexShader,
362-
fragmentShader: corridorWallFragmentShader,
363-
side: THREE.DoubleSide,
364-
transparent: false
365-
});
366-
367-
// Validate corridor wall shader compilation
368-
if (!this._checkShaderCompilation(corridorWallMaterial, 'CorridorWall')) {
369-
throw new Error('CorridorWall shader compilation failed');
370-
}
371-
372-
this.materials.set('corridorWall', corridorWallMaterial);
373-
console.log('CorridorWall shader material created successfully');
374-
375-
} catch (error) {
376-
console.warn('Failed to load corridor wall shaders, using fallback material:', error);
377-
this.materials.set('corridorWall', new THREE.MeshStandardMaterial({
378-
color: 0xe10600,
379-
roughness: 0.5,
380-
metalness: 0.2,
381-
side: THREE.DoubleSide
382-
}));
383-
}
384-
385-
await this._createShaderMaterials();
307+
await this._createShaderMaterials(commonVertexShader);
386308

387309
console.log("Shader loading complete");
388310
} catch (error) {
@@ -438,11 +360,15 @@ export class SeveranceMaterials {
438360
*/
439361
async _loadShaderFile(path) {
440362
try {
363+
console.log(`Attempting to load shader from: ${path}`);
441364
const response = await fetch(path);
442365
if (!response.ok) {
366+
console.error(`Failed to load shader at ${path}. Status: ${response.status}`);
443367
throw new Error(`Failed to load shader at ${path}`);
444368
}
445-
return await response.text();
369+
const text = await response.text();
370+
console.log(`Successfully loaded shader from: ${path} (${text.length} bytes)`);
371+
return text;
446372
} catch (error) {
447373
console.error(`Error loading shader from ${path}:`, error);
448374
throw error;
@@ -453,15 +379,14 @@ export class SeveranceMaterials {
453379
* Creates shader materials for walls and corridors
454380
* @private
455381
*/
456-
async _createShaderMaterials() {
382+
async _createShaderMaterials(commonVertexShader) {
457383
try {
458384
// Load wall shaders
459-
let wallVertexShader;
385+
let wallVertexShader = commonVertexShader;
460386
let wallFragmentShader;
461387

462388
try {
463-
wallVertexShader = await this._loadShaderFile(getAssetPath('./src/shaders/common/vertex.glsl'));
464-
wallFragmentShader = await this._loadShaderFile(getAssetPath('./src/shaders/wall.glsl'));
389+
wallFragmentShader = await this._loadShaderFile(getAssetPath('/shaders/wall.glsl'));
465390
console.log('Successfully loaded wall shaders');
466391

467392
// Create wall material with uniforms
@@ -496,12 +421,11 @@ export class SeveranceMaterials {
496421
}
497422

498423
// Load corridor shaders
499-
let corridorVertexShader;
424+
let corridorVertexShader = commonVertexShader;
500425
let corridorFragmentShader;
501426

502427
try {
503-
corridorVertexShader = await this._loadShaderFile(getAssetPath('./src/shaders/common/vertex.glsl'));
504-
corridorFragmentShader = await this._loadShaderFile(getAssetPath('./src/shaders/corridor.glsl'));
428+
corridorFragmentShader = await this._loadShaderFile(getAssetPath('/shaders/corridor.glsl'));
505429
console.log('Successfully loaded corridor shaders');
506430

507431
// Create corridor material with uniforms
@@ -536,46 +460,48 @@ export class SeveranceMaterials {
536460
}));
537461
}
538462

539-
// Create corridor wall shader if corridor shader was loaded
540-
if (corridorFragmentShader) {
541-
console.log("Creating corridor wall shader with loaded fragment shader");
542-
const corridorWallShader = {
543-
vertexShader: commonVertexShader,
544-
fragmentShader: corridorFragmentShader,
463+
// Load corridor wall shaders
464+
let corridorWallFragmentShader;
465+
466+
try {
467+
corridorWallFragmentShader = await this._loadShaderFile(getAssetPath('/shaders/corridor_wall.glsl'));
468+
console.log('Successfully loaded corridor wall shaders');
469+
470+
// Create corridor wall material with uniforms
471+
const corridorWallMaterial = new THREE.ShaderMaterial({
545472
uniforms: {
546-
lightColor: { value: new THREE.Color(0xffffff) },
547-
intensity: { value: 1.0 },
548-
time: { value: 0 },
473+
u_time: { value: 0.0 },
474+
u_resolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) },
475+
u_mouse: { value: new THREE.Vector2(0.5, 0.5) },
476+
u_depth: { value: 1.0 },
477+
playerPos: { value: new THREE.Vector3(0, 0, 0) },
478+
wallScale: { value: new THREE.Vector2(1, 1) }
549479
},
550-
};
551-
this.shaders.set("corridorWall", corridorWallShader);
552-
}
480+
vertexShader: commonVertexShader,
481+
fragmentShader: corridorWallFragmentShader,
482+
side: THREE.DoubleSide,
483+
transparent: false
484+
});
553485

554-
// Create fallback materials for shaders that don't exist
555-
console.log('Creating fallback materials for missing shaders...');
556-
557-
// Floor material (Twin Peaks-inspired)
558-
this.materials.set('floor', new THREE.MeshStandardMaterial({
559-
color: 0xf0f0f0,
560-
roughness: 0.3,
561-
metalness: 0.4,
562-
side: THREE.FrontSide
563-
}));
564-
console.log('Created fallback floor material');
565-
566-
// Sky material
567-
this.materials.set('sky', new THREE.MeshStandardMaterial({
568-
color: 0x7ec0ee,
569-
metalness: 0.0,
570-
roughness: 1.0,
571-
side: THREE.DoubleSide
572-
}));
573-
console.log('Created fallback sky material');
574-
575-
console.log('Shader material creation complete');
576-
486+
// Validate corridor wall shader compilation
487+
if (!this._checkShaderCompilation(corridorWallMaterial, 'CorridorWall')) {
488+
throw new Error('CorridorWall shader compilation failed');
489+
}
490+
491+
this.materials.set('corridorWall', corridorWallMaterial);
492+
console.log('CorridorWall shader material created successfully');
493+
494+
} catch (error) {
495+
console.warn('Failed to load corridor wall shaders, using fallback material:', error);
496+
this.materials.set('corridorWall', new THREE.MeshStandardMaterial({
497+
color: 0xe10600,
498+
roughness: 0.5,
499+
metalness: 0.2,
500+
side: THREE.DoubleSide
501+
}));
502+
}
577503
} catch (error) {
578-
console.error('Error creating shader materials:', error);
504+
console.error("Error creating shader materials:", error);
579505
throw error;
580506
}
581507
}

src/utils/assetPath.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Asset path utility for handling paths in both development and production (GitHub Pages)
3+
*
4+
* This resolves issues with file paths in GitHub Pages deployment where
5+
* the base URL includes the repository name: /3D-Portfolio/
6+
*/
7+
8+
/**
9+
* Get the correct asset path based on environment
10+
* @param {string} path - The relative path to the asset (should start with /)
11+
* @returns {string} The correct asset path for the current environment
12+
*/
13+
export function getAssetPath(path) {
14+
// Get the base URL from the current environment
15+
const baseUrl = import.meta.env?.BASE_URL || '/3D-Portfolio/';
16+
17+
// Remove any leading double slashes and ensure path starts with /
18+
let cleanPath = path.replace(/^\/+/, '/');
19+
20+
// For paths starting with /assets/, point to the right location
21+
if (cleanPath.startsWith('/assets/')) {
22+
cleanPath = cleanPath.replace('/assets/', '/');
23+
}
24+
25+
// For paths with src/shaders, use shaders directly
26+
if (cleanPath.includes('/src/shaders/')) {
27+
cleanPath = cleanPath.replace('/src/shaders/', '/shaders/');
28+
}
29+
30+
// For any paths with ./src/shaders, use shaders directly
31+
if (cleanPath.includes('./src/shaders/')) {
32+
cleanPath = cleanPath.replace('./src/shaders/', '/shaders/');
33+
}
34+
35+
// Remove leading slash to avoid double slashes when joining with baseUrl
36+
cleanPath = cleanPath.replace(/^\//, '');
37+
38+
// Join with base URL
39+
return baseUrl + cleanPath;
40+
}

0 commit comments

Comments
 (0)