@@ -23,6 +23,36 @@ const defaultConstructorOptions: CubemapLayerConstructorOptions = {
2323 preset : "universe-dark" ,
2424} ;
2525
26+ function configureOptions ( inputOptions : CubemapLayerConstructorOptions | true , defaults : CubemapLayerConstructorOptions ) {
27+ if ( inputOptions === true ) {
28+ return defaults ;
29+ }
30+
31+ const outputOptions = {
32+ ...defaults ,
33+ ...inputOptions ,
34+ } ;
35+
36+ // if input has faces defined, this takes precendence
37+ if ( inputOptions . faces ) {
38+ delete outputOptions . preset ;
39+ return outputOptions as CubemapLayerConstructorOptions ;
40+ }
41+
42+ // - Use path if defined.
43+ // - Path takes precendence over preset.
44+ // - Because we would have returned faces if it was defined
45+ // we don't need to delete it
46+ if ( inputOptions . path ) {
47+ delete outputOptions . preset ;
48+ return outputOptions as CubemapLayerConstructorOptions ;
49+ }
50+
51+ // path / faces will not be defined at this point
52+ // so we don't need to delete them
53+ return outputOptions as CubemapLayerConstructorOptions ;
54+ }
55+
2656class CubemapLayer implements CustomLayerInterface {
2757 public id : string = "Cubemap Layer" ;
2858 public type : CustomLayerInterface [ "type" ] = "custom" ;
@@ -39,14 +69,8 @@ class CubemapLayer implements CustomLayerInterface {
3969 private cubemap ?: Object3D < ( typeof ATTRIBUTES_KEYS ) [ number ] , ( typeof UNIFORMS_KEYS ) [ number ] > ;
4070 private texture ?: WebGLTexture ;
4171
42- constructor ( cubemapConfig : CubemapLayerConstructorOptions | boolean ) {
43- const options =
44- typeof cubemapConfig === "boolean"
45- ? defaultConstructorOptions
46- : {
47- ...defaultConstructorOptions ,
48- ...cubemapConfig ,
49- } ;
72+ constructor ( cubemapConfig : CubemapLayerConstructorOptions | true ) {
73+ const options = configureOptions ( cubemapConfig , defaultConstructorOptions ) ;
5074
5175 this . bgColor = parseColorStringToVec4 ( options . color ) ;
5276 this . faces = getCubemapFaces ( options as CubemapDefinition ) ;
0 commit comments