Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 718eaa0

Browse files
committed
behave graph fixes, camera fade to black uses sphere
1 parent 9ad06de commit 718eaa0

File tree

4 files changed

+63
-102
lines changed

4 files changed

+63
-102
lines changed

packages/editor/src/components/graph/BehaveFlow.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import {
3333
setComponent
3434
} from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
3535
import { NO_PROXY, getMutableState, useHookstate } from '@etherealengine/hyperflux'
36-
import { isEqual } from 'lodash'
3736
import React, { useEffect } from 'react'
3837
import AutoSizer from 'react-virtualized-auto-sizer'
3938
import 'reactflow/dist/style.css'
4039
import { SelectionState } from '../../services/SelectionServices'
4140
import { PropertiesPanelButton } from '../inputs/Button'
41+
import { commitProperty } from '../properties/Util'
4242
import { Flow } from './ee-flow'
4343
import './ee-flow/styles.css'
4444

@@ -81,13 +81,10 @@ const BehaveFlow = () => {
8181
)}
8282
{validEntity && (
8383
<Flow
84-
initialGraph={graphComponent?.value?.graph}
84+
initialGraph={graphComponent?.get(NO_PROXY)?.graph}
8585
examples={{}}
8686
registry={behaveGraphState.registries.get(NO_PROXY)[graphComponent?.domain.value]}
87-
onChangeGraph={(newGraph) => {
88-
if (!graphComponent.graph || isEqual(graphComponent.graph.get(NO_PROXY), newGraph)) return
89-
graphComponent.graph.set(JSON.parse(JSON.stringify(newGraph)))
90-
}}
87+
onChangeGraph={commitProperty(BehaveGraphComponent, 'graph')}
9188
/>
9289
)}
9390
</div>

packages/editor/src/components/graph/ee-flow/components/Flow.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { Background, BackgroundVariant, ReactFlow } from 'reactflow'
2929
import { GraphJSON, IRegistry } from '@behave-graph/core'
3030

3131
import { useGraphRunner } from '@etherealengine/engine/src/behave-graph/functions/useGraphRunner.js'
32-
import _ from 'lodash'
32+
import { useHookstate } from '@hookstate/core'
3333
import { useBehaveGraphFlow } from '../hooks/useBehaveGraphFlow.js'
3434
import { useFlowHandlers } from '../hooks/useFlowHandlers.js'
3535
import { useNodeSpecGenerator } from '../hooks/useNodeSpecGenerator.js'
@@ -49,6 +49,9 @@ export const Flow: React.FC<FlowProps> = ({ initialGraph: graph, examples, regis
4949

5050
const flowRef = useRef(null)
5151

52+
const dragging = useHookstate(false)
53+
const mouseOver = useHookstate(false)
54+
5255
const { nodes, edges, onNodesChange, onEdgesChange, graphJson, setGraphJson, nodeTypes } = useBehaveGraphFlow({
5356
initialGraphJson: graph,
5457
specGenerator
@@ -77,30 +80,28 @@ export const Flow: React.FC<FlowProps> = ({ initialGraph: graph, examples, regis
7780
registry
7881
})
7982

80-
const debouncedOnChangeGraph = _.debounce(() => {
81-
onChangeGraph(graphJson ?? graph)
82-
}, 2000)
83-
8483
useEffect(() => {
85-
debouncedOnChangeGraph()
86-
return () => {
87-
debouncedOnChangeGraph.cancel()
88-
}
89-
}, [graphJson])
84+
if (dragging.value || !mouseOver.value) return
85+
onChangeGraph(graphJson ?? graph)
86+
}, [dragging, graphJson])
9087

9188
return (
9289
<ReactFlow
9390
ref={flowRef}
9491
nodeTypes={nodeTypes}
9592
nodes={nodes}
9693
edges={edges}
94+
onNodeDragStart={() => dragging.set(true)}
95+
onNodeDragStop={() => dragging.set(false)}
9796
onNodesChange={onNodesChange}
9897
onEdgesChange={onEdgesChange}
9998
onConnect={onConnect}
10099
// @ts-ignore
101100
onConnectStart={handleStartConnect}
102101
// @ts-ignore
103102
onConnectEnd={handleStopConnect}
103+
onPaneMouseEnter={() => mouseOver.set(true)}
104+
onPaneMouseLeave={() => mouseOver.set(false)}
104105
fitView
105106
fitViewOptions={{ maxZoom: 1 }}
106107
onPaneClick={handlePaneClick}

packages/editor/src/components/graph/ee-flow/transformers/flowToBehave.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Ethereal Engine. All Rights Reserved.
2525

2626
import { Edge, Node } from 'reactflow'
2727

28-
import { GraphJSON, NodeJSON, ValueJSON } from '@behave-graph/core'
28+
import { GraphJSON, NodeJSON } from '@behave-graph/core'
2929
import { NodeSpecGenerator } from '../hooks/useNodeSpecGenerator'
3030

3131
const isNullish = (value: any): value is null | undefined => value === undefined || value === null
@@ -47,22 +47,29 @@ export const flowToBehave = (nodes: Node[], edges: Edge[], specGenerator: NodeSp
4747
positionY: String(node.position.y)
4848
}
4949
}
50-
if (node.data.configuration) {
51-
Object.entries(node.data.configuration).forEach(([key, value]) => {
52-
if (behaveNode.configuration === undefined) {
53-
behaveNode.configuration = {}
54-
}
55-
behaveNode.configuration[key] = value as ValueJSON
56-
})
57-
}
58-
if (node.data.values) {
59-
Object.entries(node.data.values).forEach(([key, value]) => {
60-
if (behaveNode.parameters === undefined) {
61-
behaveNode.parameters = {}
62-
}
63-
behaveNode.parameters[key] = { value: value as string }
64-
})
65-
}
50+
// if (node.data.configuration) {
51+
// Object.entries(node.data.configuration).forEach(([key, value]) => {
52+
// if (behaveNode.configuration === undefined) {
53+
// behaveNode.configuration = {}
54+
// }
55+
// behaveNode.configuration[key] = value as ValueJSON
56+
// })
57+
// }
58+
// if (node.data.values) {
59+
// Object.entries(node.data.values).forEach(([key, value]) => {
60+
// if (behaveNode.parameters === undefined) {
61+
// behaveNode.parameters = {}
62+
// }
63+
// behaveNode.parameters[key] = { value: value as string }
64+
// })
65+
// }
66+
67+
Object.entries(node.data).forEach(([key, value]) => {
68+
if (behaveNode.parameters === undefined) {
69+
behaveNode.parameters = {}
70+
}
71+
behaveNode.parameters[key] = { value: value as string }
72+
})
6673

6774
edges
6875
.filter((edge) => edge.target === node.id)

packages/engine/src/camera/systems/CameraFadeBlackEffectSystem.ts

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,44 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
2323
Ethereal Engine. All Rights Reserved.
2424
*/
2525

26-
import { Color, Mesh, PlaneGeometry, ShaderMaterial, Texture, Uniform, Vector2, Vector3 } from 'three'
26+
import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry, Texture } from 'three'
2727

28-
import { defineActionQueue, defineState, getMutableState, getState, useHookstate } from '@etherealengine/hyperflux'
28+
import { defineActionQueue, defineState, getState } from '@etherealengine/hyperflux'
2929

30-
import { useEffect } from 'react'
3130
import { AssetLoader } from '../../assets/classes/AssetLoader'
3231
import { Engine } from '../../ecs/classes/Engine'
3332
import { EngineState } from '../../ecs/classes/EngineState'
34-
import { removeComponent, setComponent } from '../../ecs/functions/ComponentFunctions'
33+
import { getComponent, removeComponent } from '../../ecs/functions/ComponentFunctions'
3534
import { createEntity } from '../../ecs/functions/EntityFunctions'
36-
import { EntityTreeComponent } from '../../ecs/functions/EntityTree'
3735
import { defineSystem } from '../../ecs/functions/SystemFunctions'
3836
import { addObjectToGroup } from '../../scene/components/GroupComponent'
3937
import { setVisibleComponent } from '../../scene/components/VisibleComponent'
4038
import { ObjectLayers } from '../../scene/constants/ObjectLayers'
4139
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'
4345
import { createTransitionState } from '../../xrui/functions/createTransitionState'
4446
import { CameraActions } from '../CameraState'
4547

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-
7748
const fadeToBlackQueue = defineActionQueue(CameraActions.fadeToBlack.matches)
7849

7950
const CameraFadeBlackEffectSystemState = defineState({
8051
name: 'CameraFadeBlackEffectSystemState',
8152
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({
8655
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
9359
})
9460

9561
const mesh = new Mesh(geometry, material)
62+
mesh.scale.set(-1, 1, -1)
63+
mesh.renderOrder = 1
9664
mesh.name = 'Camera Fade Transition'
9765
const entity = createEntity()
9866
addObjectToGroup(entity, mesh)
@@ -112,43 +80,31 @@ const execute = () => {
11280
for (const action of fadeToBlackQueue()) {
11381
transition.setState(action.in ? 'IN' : 'OUT')
11482
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+
)
11787
})
118-
setComponent(entity, EntityTreeComponent, { parentEntity: Engine.instance.cameraEntity })
119-
} else removeComponent(entity, LocalTransformComponent)
88+
} else removeComponent(entity, ComputedTransformComponent)
12089
if (action.graphicTexture) {
12190
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
12592
mesh.material.needsUpdate = true
12693
})
12794
} else {
128-
delete mesh.material.defines.USE_GRAPHIC
129-
mesh.material.uniforms.color = new Uniform(new Color('black'))
95+
mesh.material.map = null
13096
mesh.material.needsUpdate = true
13197
}
13298
}
99+
133100
const deltaSeconds = getState(EngineState).deltaSeconds
134101
transition.update(deltaSeconds, (alpha) => {
135-
mesh.material.uniforms.intensity.value = alpha
102+
mesh.material.opacity = alpha
136103
setVisibleComponent(entity, alpha > 0)
137104
})
138105
}
139106

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-
150107
export const CameraFadeBlackEffectSystem = defineSystem({
151108
uuid: 'ee.engine.CameraFadeBlackEffectSystem',
152-
execute,
153-
reactor
109+
execute
154110
})

0 commit comments

Comments
 (0)