Skip to content

Commit ee43748

Browse files
committed
refactor: update UUIDComponent usage to include entitySourceID and entityID
1 parent ccc57a3 commit ee43748

File tree

14 files changed

+175
-98
lines changed

14 files changed

+175
-98
lines changed

src/engine/benchmarks/AvatarBenchmark.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Engine,
55
Entity,
66
EntityTreeComponent,
7-
EntityUUID,
87
UUIDComponent,
98
createEntity,
109
getComponent,
@@ -25,10 +24,9 @@ import { useHookstate } from '@ir-engine/hyperflux'
2524
import { NetworkObjectComponent } from '@ir-engine/network'
2625
import { TransformComponent } from '@ir-engine/spatial'
2726
import { RigidBodyComponent } from '@ir-engine/spatial/src/physics/components/RigidBodyComponent'
28-
import { ObjectComponent } from '@ir-engine/spatial/src/renderer/components/ObjectComponent'
2927
import { VisibleComponent, setVisibleComponent } from '@ir-engine/spatial/src/renderer/components/VisibleComponent'
3028
import React, { useEffect } from 'react'
31-
import { Group, MathUtils, Quaternion, Vector3 } from 'three'
29+
import { MathUtils, Quaternion, Vector3 } from 'three'
3230
import {
3331
createIkTargetsForAvatar,
3432
randomQuaternion,
@@ -186,26 +184,21 @@ const AvatarIKSetupReactor = (props: {
186184
const model = useOptionalComponent(entity, GLTFComponent)
187185

188186
useEffect(() => {
189-
const obj3d = new Group()
190-
obj3d.entity = entity
191-
const uuid = MathUtils.generateUUID()
192-
setComponent(entity, UUIDComponent, uuid as EntityUUID)
187+
const entityID = UUIDComponent.generate()
188+
setComponent(entity, UUIDComponent, { entitySourceID: rootUUID.entitySourceID.value, entityID: entityID })
193189
setComponent(entity, EntityTreeComponent, { parentEntity: rootEntity })
194-
setComponent(entity, ObjectComponent, obj3d)
195190
setComponent(entity, TransformComponent, { position })
196191
setComponent(entity, VisibleComponent, true)
197192
setComponent(entity, RigidBodyComponent, { type: 'kinematic' })
198-
setComponent(entity, NetworkObjectComponent, { ownerId: uuid as UserID })
193+
setComponent(entity, NetworkObjectComponent, { ownerId: getComponent(entity, UUIDComponent) as any as UserID })
199194
setComponent(entity, GLTFComponent, { src: src })
200195
setComponent(entity, AvatarColliderComponent)
201196
setComponent(entity, AvatarComponent)
202-
setComponent(entity, AvatarAnimationComponent, {
203-
locomotion: new Vector3()
204-
})
197+
setComponent(entity, AvatarAnimationComponent)
205198
setComponent(entity, AvatarRigComponent)
206199

207-
spawnAvatar(rootUUID.value, uuid, src, { position, rotation: new Quaternion() })
208-
const targetUUIDs = createIkTargetsForAvatar(rootUUID.value, uuid, randomVec3(), randomQuaternion())
200+
spawnAvatar(UUIDComponent.concatenateUUID(rootUUID.value), entityID, src, { position, rotation: new Quaternion() })
201+
const targetUUIDs = createIkTargetsForAvatar(rootUUID.value, randomVec3(), randomQuaternion())
209202

210203
return () => {
211204
for (const targetUUID of targetUUIDs) {

src/examples/GLTFs.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useEffect } from 'react'
33
import { ComponentType, getComponent, setComponent, useOptionalComponent } from '@ir-engine/ecs/src/ComponentFunctions'
44
import { State, getMutableState, useImmediateEffect } from '@ir-engine/hyperflux'
55

6-
import { Entity, EntityUUID, UUIDComponent, createEntity, removeEntity } from '@ir-engine/ecs'
6+
import { Entity, EntityID, UUIDComponent, createEntity, removeEntity } from '@ir-engine/ecs'
77

88
import config from '@ir-engine/common/src/config'
99
import { EntityTreeComponent } from '@ir-engine/ecs'
@@ -648,7 +648,12 @@ const GLTF = (props: {
648648

649649
const imageEntity = createEntity()
650650

651-
setComponent(imageEntity, UUIDComponent, UUIDComponent.generateUUID())
651+
const rootSourceID = getComponent(root, UUIDComponent).entitySourceID
652+
653+
setComponent(imageEntity, UUIDComponent, {
654+
entitySourceID: rootSourceID,
655+
entityID: 'screenshot' as EntityID
656+
})
652657
setComponent(imageEntity, NameComponent, 'Screenshot')
653658
setComponent(imageEntity, TransformComponent)
654659
setComponent(imageEntity, EntityTreeComponent, { parentEntity: root })
@@ -718,7 +723,11 @@ export default function GLTFViewer(props: {
718723
if (!props.light || !sceneEntity) return
719724

720725
const entity = createEntity()
721-
setComponent(entity, UUIDComponent, 'ambient light' as EntityUUID)
726+
const sourceID = getComponent(sceneEntity, UUIDComponent).entitySourceID
727+
setComponent(entity, UUIDComponent, {
728+
entitySourceID: sourceID,
729+
entityID: 'ambient light' as EntityID
730+
})
722731
setComponent(entity, NameComponent, 'Ambient Light')
723732
setComponent(entity, TransformComponent, { rotation: new Quaternion().setFromEuler(new Euler(2, 5, 3)) })
724733
setComponent(entity, EntityTreeComponent, { parentEntity: sceneEntity })

src/examples/MultipleCanvasCameras.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import config from '@ir-engine/common/src/config'
22
import {
3+
EntityID,
34
EntityTreeComponent,
45
EntityUUID,
56
UUIDComponent,
67
UndefinedEntity,
78
createEntity,
8-
generateEntityUUID,
99
getMutableComponent,
1010
hasComponent,
1111
removeEntityNodeRecursively,
@@ -58,7 +58,10 @@ const useScene = (canvas: React.MutableRefObject<HTMLCanvasElement>) => {
5858
const { cameraEntity } = panelState.value
5959

6060
setComponent(cameraEntity, NameComponent, '3D Preview Camera for ' + count)
61-
setComponent(cameraEntity, UUIDComponent, ('3D Preview Camera for ' + count) as EntityUUID)
61+
setComponent(cameraEntity, UUIDComponent, {
62+
entitySourceID: 'engine' as EntityUUID,
63+
entityID: ('camera' + count) as EntityID
64+
})
6265

6366
count++
6467

@@ -76,8 +79,10 @@ const useScene = (canvas: React.MutableRefObject<HTMLCanvasElement>) => {
7679
export default function MultipleCanvasCameras() {
7780
const sceneEntity = useHookstate(() => {
7881
const sceneEntity = createEntity()
79-
const uuid = generateEntityUUID()
80-
setComponent(sceneEntity, UUIDComponent, (uuid + '-scene') as EntityUUID)
82+
setComponent(sceneEntity, UUIDComponent, {
83+
entitySourceID: 'engine' as EntityUUID,
84+
entityID: 'scene' as EntityID
85+
})
8186
setComponent(sceneEntity, TransformComponent)
8287
setComponent(sceneEntity, VisibleComponent)
8388
setComponent(sceneEntity, EntityTreeComponent, { parentEntity: UndefinedEntity })
@@ -103,7 +108,10 @@ export default function MultipleCanvasCameras() {
103108
const camera1Entity = panel1State.cameraEntity
104109
const camera2Entity = panel2State.cameraEntity
105110
const modelEntity = createEntity()
106-
setComponent(modelEntity, UUIDComponent, generateEntityUUID())
111+
setComponent(modelEntity, UUIDComponent, {
112+
entitySourceID: 'engine' as EntityUUID,
113+
entityID: 'model' as EntityID
114+
})
107115
setComponent(modelEntity, TransformComponent)
108116
setComponent(modelEntity, VisibleComponent)
109117
setComponent(modelEntity, NameComponent, 'Model Entity 1')

src/examples/MultipleCanvasScenes.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import config from '@ir-engine/common/src/config'
22
import {
3+
EntityID,
34
EntityTreeComponent,
45
EntityUUID,
56
UUIDComponent,
67
UndefinedEntity,
78
createEntity,
8-
generateEntityUUID,
99
hasComponent,
1010
removeEntityNodeRecursively,
1111
setComponent
@@ -28,15 +28,20 @@ const useScene = (canvas: React.MutableRefObject<HTMLCanvasElement>) => {
2828

2929
const panelState = useHookstate(() => {
3030
const sceneEntity = createEntity()
31-
const uuid = generateEntityUUID()
32-
setComponent(sceneEntity, UUIDComponent, (uuid + '-scene') as EntityUUID)
31+
setComponent(sceneEntity, UUIDComponent, {
32+
entitySourceID: 'engine' as EntityUUID,
33+
entityID: 'scene' as EntityID
34+
})
3335
setComponent(sceneEntity, TransformComponent)
3436
setComponent(sceneEntity, VisibleComponent)
3537
setComponent(sceneEntity, EntityTreeComponent, { parentEntity: UndefinedEntity })
3638
setComponent(sceneEntity, SceneComponent)
3739

3840
const cameraEntity = createEntity()
39-
setComponent(cameraEntity, UUIDComponent, (uuid + '-camera') as EntityUUID)
41+
setComponent(cameraEntity, UUIDComponent, {
42+
entitySourceID: 'engine' as EntityUUID,
43+
entityID: 'camera' as EntityID
44+
})
4045
setComponent(cameraEntity, CameraComponent)
4146
setComponent(cameraEntity, TransformComponent)
4247
setComponent(cameraEntity, VisibleComponent)
@@ -95,7 +100,10 @@ export default function MultipleCanvasScenes() {
95100
useEffect(() => {
96101
const { cameraEntity, sceneEntity } = panel1State
97102
const modelEntity = createEntity()
98-
setComponent(modelEntity, UUIDComponent, generateEntityUUID())
103+
setComponent(modelEntity, UUIDComponent, {
104+
entitySourceID: 'engine' as EntityUUID,
105+
entityID: 'model 1' as EntityID
106+
})
99107
setComponent(modelEntity, TransformComponent)
100108
setComponent(modelEntity, VisibleComponent)
101109
setComponent(modelEntity, NameComponent, 'Model Entity 1')
@@ -109,7 +117,10 @@ export default function MultipleCanvasScenes() {
109117
useEffect(() => {
110118
const { cameraEntity, sceneEntity } = panel2State
111119
const modelEntity = createEntity()
112-
setComponent(modelEntity, UUIDComponent, generateEntityUUID())
120+
setComponent(modelEntity, UUIDComponent, {
121+
entitySourceID: 'engine' as EntityUUID,
122+
entityID: 'model 2' as EntityID
123+
})
113124
setComponent(modelEntity, TransformComponent)
114125
setComponent(modelEntity, VisibleComponent)
115126
setComponent(modelEntity, NameComponent, 'Model Entity 2')

src/examples/PostProcessing.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React, { useEffect } from 'react'
22

3-
import { getMutableState, useHookstate } from '@ir-engine/hyperflux'
3+
import { useHookstate } from '@ir-engine/hyperflux'
44

5-
import { UUIDComponent, useQuery } from '@ir-engine/ecs'
6-
import { getComponent } from '@ir-engine/ecs/src/ComponentFunctions'
5+
import { useQuery } from '@ir-engine/ecs'
76
import { Entity } from '@ir-engine/ecs/src/Entity'
8-
import { SelectionState } from '@ir-engine/editor/src/services/SelectionServices'
97
import { PostProcessingComponent } from '@ir-engine/spatial/src/renderer/components/PostProcessingComponent'
108
import PostProcessingSettingsEditor from '@ir-engine/ui/src/components/editor/properties/postProcessing'
119
import { useSearchParams } from 'react-router-dom'
@@ -24,7 +22,7 @@ export default function PostProcessing() {
2422
// EditorControlFunctions.modifyProperty = (entities, component, properties) => {
2523
// setComponent(entity.value!, PostProcessingComponent, properties)
2624
// }
27-
getMutableState(SelectionState).selectedEntities.set([getComponent(entity.value!, UUIDComponent)])
25+
// getMutableState(SelectionState).selectedEntities.set([getComponent(entity.value!, UUIDComponent)])
2826
}, [postProEnt])
2927

3028
return (

src/examples/avatarMocap.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useWorldNetwork } from '@ir-engine/client-core/src/common/services/LocationInstanceConnectionService'
2-
import { Entity, EntityUUID, UUIDComponent, generateEntityUUID, removeEntityNodeRecursively } from '@ir-engine/ecs'
2+
import { Entity, EntityID, EntityUUID, UUIDComponent, removeEntityNodeRecursively } from '@ir-engine/ecs'
33
import { setComponent, useComponent, useOptionalComponent } from '@ir-engine/ecs/src/ComponentFunctions'
44
import { AvatarRigComponent } from '@ir-engine/engine/src/avatar/components/AvatarAnimationComponent'
55
import { MotionCaptureResults, mocapDataChannelType } from '@ir-engine/engine/src/mocap/MotionCaptureSystem'
@@ -170,12 +170,14 @@ function AvatarMocap(props: { sceneEntity: Entity }) {
170170
useEffect(() => {
171171
if (!selectedAvatar.value || !network?.ready.value) return
172172

173-
const uuid = generateEntityUUID()
174173
const entity = setupEntity(props.sceneEntity)
175-
setComponent(entity, UUIDComponent, uuid)
174+
setComponent(entity, UUIDComponent, {
175+
entitySourceID: rootUUID.value.entitySourceID,
176+
entityID: 'avatar' as EntityID
177+
})
176178
setComponent(entity, VisibleComponent, true)
177179

178-
const id = spawnAvatar(rootUUID.value, uuid, selectedAvatar.value, {
180+
const id = spawnAvatar(rootUUID.value.entitySourceID, rootUUID.value.entityID, selectedAvatar.value, {
179181
position: new Vector3(),
180182
rotation: new Quaternion()
181183
})

src/examples/avatarSimple.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useFind } from '@ir-engine/common'
1717
import { avatarPath } from '@ir-engine/common/src/schema.type.module'
1818
import {
1919
createEntity,
20+
EntityID,
2021
EntityTreeComponent,
2122
EntityUUID,
2223
getComponent,
@@ -72,8 +73,14 @@ export default function AvatarSimpleEntry() {
7273
useEffect(() => {
7374
if (!renderer?.value) return
7475

76+
const originEntity = getState(ReferenceSpaceState).originEntity
77+
const originUUID = getComponent(originEntity, UUIDComponent)
78+
7579
const lightEntity = createEntity()
76-
setComponent(lightEntity, UUIDComponent, 'directional light' as EntityUUID)
80+
setComponent(lightEntity, UUIDComponent, {
81+
entitySourceID: originUUID.entitySourceID,
82+
entityID: 'directional light' as EntityID
83+
})
7784
setComponent(lightEntity, NameComponent, 'Directional Light')
7885
setComponent(lightEntity, TransformComponent, { rotation: new Quaternion().setFromEuler(new Euler(2, 5, 3)) })
7986
setComponent(lightEntity, EntityTreeComponent, { parentEntity: getState(ReferenceSpaceState).originEntity })
@@ -89,7 +96,7 @@ export default function AvatarSimpleEntry() {
8996
const blob = new Blob([JSON.stringify(gltf)], { type: 'application/json' })
9097
const blobURL = URL.createObjectURL(blob)
9198

92-
const gltfEntity = AssetState.load(blobURL, blobURL as EntityUUID)
99+
const gltfEntity = AssetState.load(blobURL, 'scene' as EntityID)
93100
renderer.scenes.merge([gltfEntity])
94101
setComponent(gltfEntity, SceneComponent)
95102
getMutableState(SceneState)[sceneURL].set(gltfEntity)
@@ -122,13 +129,14 @@ export default function AvatarSimpleEntry() {
122129
})
123130
)
124131
peerIndexesCreated.push(i)
125-
const parentUUID = getComponent(entity.value, UUIDComponent)
132+
const parentUUID = UUIDComponent.concatenateUUID(getComponent(entity.value, UUIDComponent))
126133
dispatchAction(
127134
AvatarNetworkAction.spawn({
128135
position: new Vector3((Math.random() - 0.5) * spread, 0, (Math.random() - 0.5) * spread),
129-
parentUUID,
136+
parentUUID: parentUUID,
130137
avatarURL: randomAvatar.modelResource!.url,
131-
entityUUID: ('test user ' + i + '_avatar') as EntityUUID,
138+
entitySourceID: parentUUID,
139+
entityID: 'avatar' as EntityID,
132140
name: 'test user ' + i,
133141
$peer: ('test peer ' + i) as PeerID
134142
})

src/examples/componentExamples/componentExamples.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
UUIDComponent,
77
UndefinedEntity,
88
createEntity,
9-
generateEntityUUID,
109
getComponent,
1110
removeEntity,
1211
setComponent,
@@ -226,16 +225,14 @@ export const subComponentExamples = [
226225
const { parent, onLoad } = props
227226
const entity = useExampleEntity(parent)
228227
const particles = useOptionalComponent(entity, ParticleSystemComponent)
229-
const source = GLTFComponent.useInstanceID(parent)
230228

231229
useEffect(() => {
232-
if (!source) return
233230
setComponent(entity, NameComponent, 'Particle-Example')
234231
setComponent(entity, ParticleSystemComponent)
235-
setComponent(entity, SourceComponent, source)
232+
setComponent(entity, SourceComponent, parent)
236233
setVisibleComponent(entity, true)
237234
getComponent(entity, TransformComponent).position.set(0, 2, 0)
238-
}, [source])
235+
}, [])
239236

240237
useEffect(() => {
241238
if (particles?.system.value) onLoad(entity)
@@ -351,7 +348,7 @@ export const subComponentExamples = [
351348
geometryParams: { radius: 0.2, segments: 10 }
352349
})
353350
setVisibleComponent(childEntity, true)
354-
setComponent(childEntity, SplineTrackComponent, { splineEntityUUID: getComponent(entity, NodeIDComponent) })
351+
setComponent(childEntity, SplineTrackComponent, { splineEntityUUID: UUIDComponent.getUUID(entity) })
355352
onLoad(entity)
356353
}, [])
357354

@@ -495,7 +492,11 @@ export const ComponentExamples = (props: {
495492

496493
useEffect(() => {
497494
const componentNamesUIEntity = createEntity()
498-
setComponent(componentNamesUIEntity, UUIDComponent, generateEntityUUID())
495+
const sceneSourceID = getComponent(sceneEntity, UUIDComponent).entitySourceID
496+
setComponent(componentNamesUIEntity, UUIDComponent, {
497+
entitySourceID: sceneSourceID,
498+
entityID: UUIDComponent.generate()
499+
})
499500
setComponent(componentNamesUIEntity, EntityTreeComponent, { parentEntity: sceneEntity })
500501
setComponent(componentNamesUIEntity, NameComponent, 'componentNamesUI')
501502
const componentNamesUI = createXRUI(ComponentNamesUI, xrui, { interactable: false }, componentNamesUIEntity)

src/examples/gltfViewer.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getComponent, removeComponent, setComponent } from '@ir-engine/ecs/src/
55
import { DndWrapper } from '@ir-engine/editor/src/components/dnd/DndWrapper'
66
import { getMutableState, getState, useHookstate, useMutableState } from '@ir-engine/hyperflux'
77

8-
import { Entity, EntityUUID, UUIDComponent, createEntity, removeEntity } from '@ir-engine/ecs'
8+
import { Entity, EntityID, UUIDComponent, createEntity, removeEntity } from '@ir-engine/ecs'
99

1010
import config from '@ir-engine/common/src/config'
1111
import { EntityTreeComponent } from '@ir-engine/ecs'
@@ -45,7 +45,12 @@ const GLTF = () => {
4545
let modelEntity: Entity | undefined
4646
if (loadOldModel) {
4747
modelEntity = createEntity()
48-
setComponent(modelEntity, UUIDComponent, 'gltf viewer' as EntityUUID)
48+
const originEntity = getState(ReferenceSpaceState).originEntity
49+
const originUUID = getComponent(originEntity, UUIDComponent)
50+
setComponent(modelEntity, UUIDComponent, {
51+
entitySourceID: originUUID.entitySourceID,
52+
entityID: '3D Preview Entity' as EntityID
53+
})
4954
setComponent(modelEntity, NameComponent, '3D Preview Entity')
5055
setComponent(modelEntity, TransformComponent, { position: new Vector3(3, 0, 0) })
5156
setComponent(modelEntity, EntityTreeComponent, { parentEntity: getState(ReferenceSpaceState).originEntity })
@@ -55,7 +60,12 @@ const GLTF = () => {
5560
}
5661

5762
const entity = createEntity()
58-
setComponent(entity, UUIDComponent, 'directional light' as EntityUUID)
63+
const originEntity = getState(ReferenceSpaceState).originEntity
64+
const originUUID = getComponent(originEntity, UUIDComponent)
65+
setComponent(entity, UUIDComponent, {
66+
entitySourceID: originUUID.entitySourceID,
67+
entityID: 'directional light' as EntityID
68+
})
5969
setComponent(entity, NameComponent, 'Directional Light')
6070
setComponent(entity, TransformComponent, { rotation: new Quaternion().setFromEuler(new Euler(2, 5, 3)) })
6171
setComponent(entity, EntityTreeComponent, { parentEntity: getState(ReferenceSpaceState).originEntity })

0 commit comments

Comments
 (0)