Skip to content

Commit dc46538

Browse files
author
Les Moffat
committed
fix(spacebox): add defaults for halo and cubemap layer
1 parent a3261e2 commit dc46538

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

demos/07-spacebox.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
color: "#111122",
4545
path: {
4646
baseUrl: "spacebox/transparent",
47-
// format: "png", defaults to png
47+
format: "png", //defaults to png
4848
},
4949
// OR
5050
// faces: {
@@ -60,11 +60,11 @@
6060
},
6161
halo: {
6262
scale: 1,
63-
stops: [
64-
[0.0, "transparent"],
65-
[0.2, "skyblue"],
66-
[0.3, "transparent"]
67-
],
63+
// stops: [
64+
// [0.0, "transparent"],
65+
// [0.2, "skyblue"],
66+
// [0.3, "transparent"]
67+
// ],
6868
}
6969
});
7070

src/custom-layers/CubemapLayer/CubemapLayer.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const UNIFORMS_KEYS = ["projectionMatrix", "modelViewMatrix", "cubeSampler", "bg
1818
const GL_USE_TEXTURE_MACRO_MARKER = "%USE_TEXTURE_MACRO_MARKER%";
1919
const GL_USE_TEXTURE_MACRO = "#define USE_TEXTURE";
2020

21+
const defaultConstructorOptions: CubemapLayerConstructorOptions = {
22+
color: "black",
23+
preset: "universe-dark",
24+
};
25+
2126
class CubemapLayer implements CustomLayerInterface {
2227
public id: string = "Cubemap Layer";
2328
public type: CustomLayerInterface["type"] = "custom";
@@ -34,9 +39,17 @@ class CubemapLayer implements CustomLayerInterface {
3439
private cubemap?: Object3D<(typeof ATTRIBUTES_KEYS)[number], (typeof UNIFORMS_KEYS)[number]>;
3540
private texture?: WebGLTexture;
3641

37-
constructor(cubemapConfig: CubemapLayerConstructorOptions) {
38-
this.bgColor = parseColorStringToVec4(cubemapConfig.color);
39-
this.faces = getCubemapFaces(cubemapConfig);
42+
constructor(cubemapConfig: CubemapLayerConstructorOptions | boolean) {
43+
const options =
44+
typeof cubemapConfig === "boolean"
45+
? defaultConstructorOptions
46+
: {
47+
...defaultConstructorOptions,
48+
...cubemapConfig,
49+
};
50+
51+
this.bgColor = parseColorStringToVec4(options.color);
52+
this.faces = getCubemapFaces(options as CubemapDefinition);
4053
this.useCubemapTexture = this.faces !== null;
4154
}
4255

src/custom-layers/RadialGradientLayer/RadialGradientLayer.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ const VERTICES = [
2828
0,
2929
];
3030

31+
const defaultConstructorOptions: RadialGradientLayerOptions = {
32+
scale: 1,
33+
stops: [
34+
[0.0, "rgba(176, 208, 240, 1)"],
35+
[0.2, "rgba(98, 168, 229, 0.8)"],
36+
[0.4, "rgba(32, 112, 208, 0.6)"],
37+
[0.6, "rgba(16, 42, 85, 0.4)"],
38+
[0.8, "rgba(10, 15, 37, 0.2)"],
39+
[1.0, "rgba(0, 0, 0, 0)"],
40+
],
41+
}
42+
3143
export class RadialGradientLayer implements CustomLayerInterface {
3244
public id: string = "Halo Layer";
3345
public type: CustomLayerInterface["type"] = "custom";
@@ -39,8 +51,16 @@ export class RadialGradientLayer implements CustomLayerInterface {
3951
private map!: MapSDK;
4052
private plane?: Object3D<(typeof ATTRIBUTES_KEYS)[number], (typeof UNIFORMS_KEYS)[number]>;
4153

42-
constructor(gradient: RadialGradientLayerOptions) {
43-
this.gradient = gradient;
54+
constructor(gradient: RadialGradientLayerOptions | boolean) {
55+
if (typeof gradient === "boolean") {
56+
this.gradient = defaultConstructorOptions;
57+
return;
58+
}
59+
60+
this.gradient = {
61+
...defaultConstructorOptions,
62+
...gradient,
63+
};
4464
}
4565

4666
public onAdd(map: MapSDK, gl: WebGLRenderingContext | WebGL2RenderingContext): void {

0 commit comments

Comments
 (0)