1
- import { EnvLighting , Quat , Scene , Sky , SKYTYPE_DOME , Texture } from "playcanvas" ;
1
+ import { EnvLighting , Quat , Scene , Sky , SKYTYPE_DOME , SKYTYPE_INFINITE , Texture } from "playcanvas" ;
2
2
import { useEffect , useRef } from "react" ;
3
3
import { useApp } from "../hooks/use-app.tsx" ;
4
4
import { createComponentDefinition , getStaticNullApplication , Schema , validatePropsWithDefaults , warnOnce } from "../utils/validation.ts" ;
@@ -66,10 +66,11 @@ function Environment(props: EnvironmentProps) {
66
66
if ( appHasEnvironment . current ) return ;
67
67
68
68
const skyBoxAsset = safeSceneProps . skybox as Asset ;
69
+
69
70
const isCubeMap = Array . isArray ( skyBoxAsset . resources ) && skyBoxAsset . resources . length === 6 ;
70
71
let skybox : Texture = skyBoxAsset . resource as Texture ;
71
72
72
- // If the skybox is a HDRI, generate a cube map
73
+ // If the skybox is not a cube map, try to generate a cube map from it.
73
74
if ( ! isCubeMap ) {
74
75
skybox = EnvLighting . generateSkyboxCubemap ( skyBoxAsset . resource as Texture ) ;
75
76
}
@@ -121,7 +122,6 @@ function Environment(props: EnvironmentProps) {
121
122
app . scene . sky . center . set ( ...safeSkyProps . center ) ;
122
123
}
123
124
124
- console . log ( 'safeSkyProps.type' , safeSkyProps . type ) ;
125
125
app . scene . sky . type = safeSkyProps . type ?? SKYTYPE_DOME ;
126
126
app . scene . sky . depthWrite = safeSkyProps . depthWrite ?? true ;
127
127
@@ -132,34 +132,42 @@ function Environment(props: EnvironmentProps) {
132
132
app . scene . skyboxHighlightMultiplier = safeSceneProps . skyboxHighlightMultiplier ?? 1 ;
133
133
134
134
return ( ) => {
135
- // Reset the scene and sky to their default values
136
- // app.scene.exposure = 1;
137
- // app.scene.envAtlas = null;
138
- // app.scene.skybox = null;
139
- // app.scene.skyboxRotation = new Quat().setFromEulerAngles(0, 0, 0);
140
- // app.scene.sky.node.setLocalScale(100, 100, 100);
141
- // app.scene.sky.node.setLocalPosition(0, 0, 0);
142
- // app.scene.sky.center.set(0, 0.05, 0);
143
- // app.scene.sky.type = SKYTYPE_DOME;
144
- // app.scene.sky.depthWrite = true;
145
- // app.scene.skyboxMip = 0;
146
- // app.scene.skyboxLuminance = 1;
147
- // app.scene.skyboxIntensity = 1;
148
- // app.scene.skyboxHighlightMultiplier = 1;
135
+
136
+ /**
137
+ * We have hardcoded the default values for the scene and sky in order to reset them
138
+ *
139
+ * This isn't perfect as any changes the the engine defaults will break this.
140
+ * TODO: Find a better way to reset the scene and sky.
141
+ */
142
+
143
+ app . scene . exposure = 1 ;
144
+ app . scene . skyboxRotation = new Quat ( ) . setFromEulerAngles ( 0 , 0 , 0 ) ;
145
+ app . scene . sky . node . setLocalScale ( 1 , 1 , 1 ) ;
146
+ app . scene . sky . node . setLocalPosition ( 0 , 0 , 0 ) ;
147
+ app . scene . sky . center . set ( 0 , 0.05 , 0 ) ;
148
+ app . scene . sky . type = SKYTYPE_INFINITE ;
149
+ app . scene . sky . depthWrite = false ;
150
+ app . scene . skyboxMip = 0 ;
151
+ app . scene . skyboxLuminance = 0 ;
152
+ app . scene . skyboxIntensity = 1 ;
153
+ app . scene . skyboxHighlightMultiplier = 1 ;
149
154
} ;
150
155
151
156
} , [
152
157
appHasEnvironment . current ,
153
- safeSkyProps . scale ,
154
- safeSkyProps . center ,
155
158
safeSceneProps . exposure ,
156
- safeSkyProps . rotation ,
159
+ safeSkyProps . type ,
160
+ safeSkyProps . depthWrite ,
157
161
safeSceneProps . skyboxMip ,
158
162
safeSceneProps . skyboxLuminance ,
159
163
safeSceneProps . skyboxIntensity ,
160
164
safeSceneProps . skyboxHighlightMultiplier ,
161
- safeSkyProps . type ,
162
- safeSkyProps . depthWrite ,
165
+
166
+ // compute keys for scale, rotation, and center
167
+ `scale-${ safeSkyProps . scale ?. join ( '-' ) } ` ,
168
+ `rotation-${ safeSkyProps . rotation ?. join ( '-' ) } ` ,
169
+ `center-${ safeSkyProps . center ?. join ( '-' ) } ` ,
170
+
163
171
] ) ;
164
172
165
173
return null
0 commit comments