@@ -23,76 +23,44 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
23
23
Ethereal Engine. All Rights Reserved.
24
24
*/
25
25
26
- import { Color , Mesh , PlaneGeometry , ShaderMaterial , Texture , Uniform , Vector2 , Vector3 } from 'three'
26
+ import { DoubleSide , Mesh , MeshBasicMaterial , SphereGeometry , Texture } from 'three'
27
27
28
- import { defineActionQueue , defineState , getMutableState , getState , useHookstate } from '@etherealengine/hyperflux'
28
+ import { defineActionQueue , defineState , getState } from '@etherealengine/hyperflux'
29
29
30
- import { useEffect } from 'react'
31
30
import { AssetLoader } from '../../assets/classes/AssetLoader'
32
31
import { Engine } from '../../ecs/classes/Engine'
33
32
import { EngineState } from '../../ecs/classes/EngineState'
34
- import { removeComponent , setComponent } from '../../ecs/functions/ComponentFunctions'
33
+ import { getComponent , removeComponent } from '../../ecs/functions/ComponentFunctions'
35
34
import { createEntity } from '../../ecs/functions/EntityFunctions'
36
- import { EntityTreeComponent } from '../../ecs/functions/EntityTree'
37
35
import { defineSystem } from '../../ecs/functions/SystemFunctions'
38
36
import { addObjectToGroup } from '../../scene/components/GroupComponent'
39
37
import { setVisibleComponent } from '../../scene/components/VisibleComponent'
40
38
import { ObjectLayers } from '../../scene/constants/ObjectLayers'
41
39
import { setObjectLayers } from '../../scene/functions/setObjectLayers'
42
- import { LocalTransformComponent } from '../../transform/components/TransformComponent'
40
+ import {
41
+ ComputedTransformComponent ,
42
+ setComputedTransformComponent
43
+ } from '../../transform/components/ComputedTransformComponent'
44
+ import { TransformComponent } from '../../transform/components/TransformComponent'
43
45
import { createTransitionState } from '../../xrui/functions/createTransitionState'
44
46
import { CameraActions } from '../CameraState'
45
47
46
- const VERTEX_SHADER = `
47
- precision highp float;
48
-
49
- void main() {
50
- vec3 newPosition = position * 2.0;
51
- gl_Position = vec4(newPosition, 1.0);
52
- }`
53
-
54
- const FRAGMENT_SHADER = `
55
- precision highp float;
56
-
57
- uniform vec2 resolution;
58
- uniform vec3 color;
59
- uniform float intensity;
60
- #ifdef USE_GRAPHIC
61
- uniform sampler2D graphicTexture;
62
- #endif
63
- void main() {
64
- vec2 uv = gl_FragCoord.xy / resolution.xy;
65
- vec4 baseColor = vec4(color, intensity);
66
- #ifdef USE_GRAPHIC
67
- if (uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0) {
68
- vec4 graphicColor = texture2D(graphicTexture, uv);
69
- baseColor = graphicColor * baseColor;
70
- } else {
71
- baseColor = vec4(0.0, 0.0, 0.0, 1.0);
72
- }
73
- #endif
74
- gl_FragColor = baseColor;
75
- }`
76
-
77
48
const fadeToBlackQueue = defineActionQueue ( CameraActions . fadeToBlack . matches )
78
49
79
50
const CameraFadeBlackEffectSystemState = defineState ( {
80
51
name : 'CameraFadeBlackEffectSystemState' ,
81
52
initial : ( ) => {
82
- const geometry = new PlaneGeometry ( 1 , 1 )
83
- const material = new ShaderMaterial ( {
84
- vertexShader : VERTEX_SHADER ,
85
- fragmentShader : FRAGMENT_SHADER ,
53
+ const geometry = new SphereGeometry ( 10 )
54
+ const material = new MeshBasicMaterial ( {
86
55
transparent : true ,
87
- depthTest : false ,
88
- uniforms : {
89
- color : { value : new Color ( 'black' ) } ,
90
- intensity : { value : 0 } ,
91
- resolution : { value : new Vector2 ( window . outerWidth , window . outerHeight ) }
92
- }
56
+ side : DoubleSide ,
57
+ depthWrite : true ,
58
+ depthTest : false
93
59
} )
94
60
95
61
const mesh = new Mesh ( geometry , material )
62
+ mesh . scale . set ( - 1 , 1 , - 1 )
63
+ mesh . renderOrder = 1
96
64
mesh . name = 'Camera Fade Transition'
97
65
const entity = createEntity ( )
98
66
addObjectToGroup ( entity , mesh )
@@ -112,43 +80,31 @@ const execute = () => {
112
80
for ( const action of fadeToBlackQueue ( ) ) {
113
81
transition . setState ( action . in ? 'IN' : 'OUT' )
114
82
if ( action . in ) {
115
- setComponent ( entity , LocalTransformComponent , {
116
- position : new Vector3 ( 0 , 0 , - 0.1 )
83
+ setComputedTransformComponent ( entity , Engine . instance . cameraEntity , ( ) => {
84
+ getComponent ( entity , TransformComponent ) . position . copy (
85
+ getComponent ( Engine . instance . cameraEntity , TransformComponent ) . position
86
+ )
117
87
} )
118
- setComponent ( entity , EntityTreeComponent , { parentEntity : Engine . instance . cameraEntity } )
119
- } else removeComponent ( entity , LocalTransformComponent )
88
+ } else removeComponent ( entity , ComputedTransformComponent )
120
89
if ( action . graphicTexture ) {
121
90
AssetLoader . load ( action . graphicTexture , { } , ( texture : Texture ) => {
122
- mesh . material . uniforms . graphicTexture = new Uniform ( texture )
123
- mesh . material . uniforms . color = new Uniform ( new Color ( 'white' ) )
124
- mesh . material . defines . USE_GRAPHIC = true
91
+ mesh . material . map = texture
125
92
mesh . material . needsUpdate = true
126
93
} )
127
94
} else {
128
- delete mesh . material . defines . USE_GRAPHIC
129
- mesh . material . uniforms . color = new Uniform ( new Color ( 'black' ) )
95
+ mesh . material . map = null
130
96
mesh . material . needsUpdate = true
131
97
}
132
98
}
99
+
133
100
const deltaSeconds = getState ( EngineState ) . deltaSeconds
134
101
transition . update ( deltaSeconds , ( alpha ) => {
135
- mesh . material . uniforms . intensity . value = alpha
102
+ mesh . material . opacity = alpha
136
103
setVisibleComponent ( entity , alpha > 0 )
137
104
} )
138
105
}
139
106
140
- const reactor = ( ) => {
141
- const outerWidth = useHookstate ( window . outerWidth )
142
- const outerHeight = useHookstate ( window . outerHeight )
143
- const { mesh } = useHookstate ( getMutableState ( CameraFadeBlackEffectSystemState ) )
144
- useEffect ( ( ) => {
145
- mesh . material . uniforms . resolution . nested ( 'value' ) . set ( [ outerWidth . value , outerHeight . value ] )
146
- } , [ outerWidth , outerHeight ] )
147
- return null
148
- }
149
-
150
107
export const CameraFadeBlackEffectSystem = defineSystem ( {
151
108
uuid : 'ee.engine.CameraFadeBlackEffectSystem' ,
152
- execute,
153
- reactor
109
+ execute
154
110
} )
0 commit comments