Skip to content

Commit 4300757

Browse files
expanding skybox capabilities
1 parent a6d70d1 commit 4300757

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

examples/angular/threejs/simple/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LaptopHolder
1+
# Simple
22

33
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.5.
44

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,49 @@ export class BabylonScene {
333333
* @shortname skybox
334334
*/
335335
enableSkybox(inputs: Inputs.BabylonScene.SkyboxDto): void {
336-
let texture: BABYLON.CubeTexture;
337-
if (inputs.skybox === Inputs.Base.skyboxEnum.default) {
338-
texture = new BABYLON.CubeTexture("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/default_skybox/skybox", this.context.scene);
339-
} else if (inputs.skybox === Inputs.Base.skyboxEnum.greyGradient) {
340-
texture = new BABYLON.CubeTexture("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/grey_gradient/skybox", this.context.scene);
341-
} else if (inputs.skybox === Inputs.Base.skyboxEnum.clearSky) {
342-
texture = BABYLON.CubeTexture.CreateFromPrefilteredData("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/clear_sky/environment.env",
343-
this.context.scene, false, false);
344-
} else if (inputs.skybox === Inputs.Base.skyboxEnum.city) {
345-
texture = BABYLON.CubeTexture.CreateFromPrefilteredData("https://cdn.jsdelivr.net/gh/bitbybit-dev/bitbybit-assets@0.20.5/textures/skybox/city/environmentSpecular.env",
346-
this.context.scene, false, false);
336+
337+
let texture: BABYLON.CubeTexture | BABYLON.HDRCubeTexture;
338+
339+
if (inputs.skybox === "custom" && inputs.textureUrl) {
340+
// Handle custom HDR/EXR textures
341+
const textureUrl = inputs.textureUrl;
342+
const textureSize = inputs.textureSize || 512; // Default size
343+
344+
// Better URL parsing to handle query strings
345+
const urlPath = textureUrl.split("?")[0].toLowerCase();
346+
347+
if (urlPath.endsWith(".hdr")) {
348+
// Use HDRCubeTexture for .hdr files
349+
if (inputs.hdrTexture) {
350+
texture = new BABYLON.HDRCubeTexture(textureUrl, this.context.scene, textureSize, false, true, false, true);
351+
}
352+
} else if (urlPath.endsWith(".env")) {
353+
texture = BABYLON.CubeTexture.CreateFromPrefilteredData(inputs.textureUrl,
354+
this.context.scene, false, false);
355+
} else {
356+
// Fallback to CubeTexture for other formats
357+
texture = new BABYLON.CubeTexture(textureUrl, this.context.scene);
358+
}
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+
}
347371
}
348372

349373
this.context.scene.getMeshByName("bitbybit-hdrSkyBox")?.dispose(false, true);
350374
const skybox = this.context.scene.createDefaultSkybox(texture, true, inputs.size, inputs.blur, true);
351375
skybox.name = "bitbybit-hdrSkyBox";
376+
if (inputs.hideSkybox) {
377+
skybox.isVisible = false;
378+
}
352379
this.context.scene.environmentIntensity = inputs.environmentIntensity;
353380
}
354381

packages/dev/babylonjs/lib/api/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class Context extends ContextBase {
88
scene: BABYLON.Scene;
99
engine: BABYLON.Engine | BABYLON.WebGPUEngine;
1010
havokPlugin: BABYLON.HavokPlugin;
11-
11+
1212
getSamplingMode(samplingMode: Inputs.BabylonTexture.samplingModeEnum): number {
1313
switch (samplingMode) {
1414
case Inputs.BabylonTexture.samplingModeEnum.nearest:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export namespace Base {
33
export enum skyboxEnum {
44
default = "default",
5+
custom = "custom",
56
clearSky = "clearSky",
67
city = "city",
78
greyGradient = "greyGradient",

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,15 @@ export namespace BabylonScene {
401401
wheelPrecision = 3;
402402
}
403403
export class SkyboxDto {
404-
constructor(skybox?: Base.skyboxEnum, size?: number, blur?: number, environmentIntensity?: number) {
404+
constructor(skybox?: Base.skyboxEnum, size?: number, blur?: number, environmentIntensity?: number, hideSkybox?: boolean, textureUrl?: string, textureSize?: number, hdrTexture?: 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; }
409+
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; }
409413
}
410414
/**
411415
* Skybox type
@@ -436,6 +440,29 @@ export namespace BabylonScene {
436440
* @step 0.1
437441
*/
438442
environmentIntensity = 0.7;
443+
/**
444+
* Hides the skybox mesh but keeps the environment texture
445+
* @default false
446+
*/
447+
hideSkybox?: boolean = false;
448+
/**
449+
* Skybox texture URL - only needed if skybox type is set to custom
450+
* @default undefined
451+
* @optional true
452+
*/
453+
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;
460+
/**
461+
* Skybox texture size (only applies to custom URL texture)
462+
* @default 512
463+
* @optional true
464+
*/
465+
textureSize?: number = 512;
439466
}
440467

441468
export class PointerDto {

0 commit comments

Comments
 (0)