Skip to content

Commit c41c642

Browse files
decided to split default old skybox behaviour from the new custom texture url variant
1 parent 4300757 commit c41c642

File tree

3 files changed

+79
-36
lines changed

3 files changed

+79
-36
lines changed

packages/dev/babylonjs/lib/api/bitbybit/babylon/scene.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,30 @@ export class BabylonScene {
336336

337337
let texture: BABYLON.CubeTexture | BABYLON.HDRCubeTexture;
338338

339-
if (inputs.skybox === "custom" && inputs.textureUrl) {
340-
// Handle custom HDR/EXR textures
339+
if (inputs.skybox === Inputs.Base.skyboxEnum.default) {
340+
texture = new BABYLON.CubeTexture("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/default_skybox/skybox", this.context.scene);
341+
} else if (inputs.skybox === Inputs.Base.skyboxEnum.greyGradient) {
342+
texture = new BABYLON.CubeTexture("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/grey_gradient/skybox", this.context.scene);
343+
} else if (inputs.skybox === Inputs.Base.skyboxEnum.clearSky) {
344+
texture = BABYLON.CubeTexture.CreateFromPrefilteredData("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/clear_sky/environment.env",
345+
this.context.scene, false, false);
346+
} else if (inputs.skybox === Inputs.Base.skyboxEnum.city) {
347+
texture = BABYLON.CubeTexture.CreateFromPrefilteredData("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/city/environmentSpecular.env",
348+
this.context.scene, false, false);
349+
}
350+
351+
this.createSkyboxMesh(texture, inputs.size, inputs.blur, inputs.hideSkybox, inputs.environmentIntensity);
352+
}
353+
354+
/**
355+
* Enables skybox with custom texture
356+
* @param inputs Skybox configuration
357+
* @group environment
358+
* @shortname skybox
359+
*/
360+
enableSkyboxCustomTexture(inputs: Inputs.BabylonScene.SkyboxCustomTextureDto): void {
361+
if (inputs.textureUrl) {
362+
let texture: BABYLON.CubeTexture | BABYLON.HDRCubeTexture;
341363
const textureUrl = inputs.textureUrl;
342364
const textureSize = inputs.textureSize || 512; // Default size
343365

@@ -346,37 +368,17 @@ export class BabylonScene {
346368

347369
if (urlPath.endsWith(".hdr")) {
348370
// Use HDRCubeTexture for .hdr files
349-
if (inputs.hdrTexture) {
350-
texture = new BABYLON.HDRCubeTexture(textureUrl, this.context.scene, textureSize, false, true, false, true);
351-
}
371+
texture = new BABYLON.HDRCubeTexture(textureUrl, this.context.scene, textureSize, false, true, false, true);
352372
} else if (urlPath.endsWith(".env")) {
353373
texture = BABYLON.CubeTexture.CreateFromPrefilteredData(inputs.textureUrl,
354374
this.context.scene, false, false);
355375
} else {
356376
// Fallback to CubeTexture for other formats
357377
texture = new BABYLON.CubeTexture(textureUrl, this.context.scene);
358378
}
359-
} else {
360-
if (inputs.skybox === Inputs.Base.skyboxEnum.default) {
361-
texture = new BABYLON.CubeTexture("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/default_skybox/skybox", this.context.scene);
362-
} else if (inputs.skybox === Inputs.Base.skyboxEnum.greyGradient) {
363-
texture = new BABYLON.CubeTexture("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/grey_gradient/skybox", this.context.scene);
364-
} else if (inputs.skybox === Inputs.Base.skyboxEnum.clearSky) {
365-
texture = BABYLON.CubeTexture.CreateFromPrefilteredData("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/clear_sky/environment.env",
366-
this.context.scene, false, false);
367-
} else if (inputs.skybox === Inputs.Base.skyboxEnum.city) {
368-
texture = BABYLON.CubeTexture.CreateFromPrefilteredData("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/city/environmentSpecular.env",
369-
this.context.scene, false, false);
370-
}
371-
}
372379

373-
this.context.scene.getMeshByName("bitbybit-hdrSkyBox")?.dispose(false, true);
374-
const skybox = this.context.scene.createDefaultSkybox(texture, true, inputs.size, inputs.blur, true);
375-
skybox.name = "bitbybit-hdrSkyBox";
376-
if (inputs.hideSkybox) {
377-
skybox.isVisible = false;
380+
this.createSkyboxMesh(texture, inputs.size, inputs.blur, inputs.hideSkybox, inputs.environmentIntensity);
378381
}
379-
this.context.scene.environmentIntensity = inputs.environmentIntensity;
380382
}
381383

382384
/**
@@ -452,4 +454,15 @@ export class BabylonScene {
452454
}
453455
return angle;
454456
}
457+
458+
private createSkyboxMesh(texture: BABYLON.BaseTexture, size: number, blur: number, hideSkybox: boolean, environmentIntensity: number) {
459+
this.context.scene.getMeshByName("bitbybit-hdrSkyBox")?.dispose(false, true);
460+
const skybox = this.context.scene.createDefaultSkybox(texture, true, size, blur, true);
461+
skybox.name = "bitbybit-hdrSkyBox";
462+
if (hideSkybox) {
463+
skybox.isVisible = false;
464+
}
465+
this.context.scene.environmentIntensity = environmentIntensity;
466+
}
467+
455468
}

packages/dev/babylonjs/lib/api/inputs/base-inputs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
export namespace Base {
33
export enum skyboxEnum {
44
default = "default",
5-
custom = "custom",
65
clearSky = "clearSky",
76
city = "city",
87
greyGradient = "greyGradient",

packages/dev/babylonjs/lib/api/inputs/scene-inputs.ts

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,12 @@ export namespace BabylonScene {
401401
wheelPrecision = 3;
402402
}
403403
export class SkyboxDto {
404-
constructor(skybox?: Base.skyboxEnum, size?: number, blur?: number, environmentIntensity?: number, hideSkybox?: boolean, textureUrl?: string, textureSize?: number, hdrTexture?: boolean,) {
404+
constructor(skybox?: Base.skyboxEnum, size?: number, blur?: number, environmentIntensity?: number, hideSkybox?: boolean) {
405405
if (skybox !== undefined) { this.skybox = skybox; }
406406
if (size !== undefined) { this.size = size; }
407407
if (blur !== undefined) { this.blur = blur; }
408408
if (environmentIntensity !== undefined) { this.environmentIntensity = environmentIntensity; }
409409
if (hideSkybox !== undefined) { this.hideSkybox = hideSkybox; }
410-
if (textureUrl !== undefined) { this.textureUrl = textureUrl; }
411-
if (textureSize !== undefined) { this.textureSize = textureSize; }
412-
if (hdrTexture !== undefined) { this.hdrTexture = hdrTexture; }
413410
}
414411
/**
415412
* Skybox type
@@ -445,24 +442,58 @@ export namespace BabylonScene {
445442
* @default false
446443
*/
447444
hideSkybox?: boolean = false;
445+
}
446+
447+
export class SkyboxCustomTextureDto {
448+
constructor(textureUrl?: string, textureSize?: number, size?: number, blur?: number, environmentIntensity?: number, hideSkybox?: boolean) {
449+
if (textureUrl !== undefined) { this.textureUrl = textureUrl; }
450+
if (textureSize !== undefined) { this.textureSize = textureSize; }
451+
if (size !== undefined) { this.size = size; }
452+
if (blur !== undefined) { this.blur = blur; }
453+
if (environmentIntensity !== undefined) { this.environmentIntensity = environmentIntensity; }
454+
if (hideSkybox !== undefined) { this.hideSkybox = hideSkybox; }
455+
}
448456
/**
449-
* Skybox texture URL - only needed if skybox type is set to custom
457+
* Skybox texture URL pointing to .hdr, .env or root of the cubemap images
450458
* @default undefined
451459
* @optional true
452460
*/
453461
textureUrl?: string;
454-
/**
455-
* Skybox HDR texture URL - only needed if skybox type is set to custom and the texture is in .hdr format
456-
* @default true
457-
* @optional true
458-
*/
459-
hdrTexture?: boolean = true;
460462
/**
461463
* Skybox texture size (only applies to custom URL texture)
462464
* @default 512
463465
* @optional true
464466
*/
465467
textureSize?: number = 512;
468+
/**
469+
* Skybox size
470+
* @default 1000
471+
* @minimum 0
472+
* @maximum Infinity
473+
* @step 10
474+
*/
475+
size = 1000;
476+
/**
477+
* Identifies if skybox texture should affect scene environment
478+
* @default 0.1
479+
* @minimum 0
480+
* @maximum Infinity
481+
* @step 0.1
482+
*/
483+
blur = 0.1;
484+
/**
485+
* Identifies if skybox texture should affect scene environment
486+
* @default 0.7
487+
* @minimum 0
488+
* @maximum Infinity
489+
* @step 0.1
490+
*/
491+
environmentIntensity = 0.7;
492+
/**
493+
* Hides the skybox mesh but keeps the environment texture
494+
* @default false
495+
*/
496+
hideSkybox?: boolean = false;
466497
}
467498

468499
export class PointerDto {

0 commit comments

Comments
 (0)