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

Commit

Permalink
Update apis
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelEstes committed May 30, 2024
1 parent 7692452 commit 76d45fe
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
78 changes: 51 additions & 27 deletions engine/benchmarks/AvatarBenchmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
UUIDComponent,
createEntity,
getComponent,
removeEntity,
setComponent,
useComponent,
useOptionalComponent
Expand All @@ -22,13 +21,16 @@ import { AvatarColliderComponent } from '@etherealengine/engine/src/avatar/compo
import { LoopAnimationComponent } from '@etherealengine/engine/src/avatar/components/LoopAnimationComponent'
import { AvatarNetworkAction } from '@etherealengine/engine/src/avatar/state/AvatarNetworkActions'
import { ModelComponent } from '@etherealengine/engine/src/scene/components/ModelComponent'
import { dispatchAction, useHookstate } from '@etherealengine/hyperflux'
import { applyIncomingActions, dispatchAction, useHookstate } from '@etherealengine/hyperflux'
import { NetworkObjectComponent } from '@etherealengine/network'
import { TransformComponent } from '@etherealengine/spatial'
import { RigidBodyComponent } from '@etherealengine/spatial/src/physics/components/RigidBodyComponent'
import { Object3DComponent } from '@etherealengine/spatial/src/renderer/components/Object3DComponent'
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent'
import { EntityTreeComponent, destroyEntityTree } from '@etherealengine/spatial/src/transform/components/EntityTree'
import {
EntityTreeComponent,
removeEntityNodeRecursively
} from '@etherealengine/spatial/src/transform/components/EntityTree'
import React, { useEffect } from 'react'
import { Group, MathUtils, Quaternion, Vector3 } from 'three'
import { useAvatars } from '../TestUtils'
Expand Down Expand Up @@ -118,8 +120,7 @@ const AvatarSetupReactor = (props: {
})

return () => {
removeEntity(entity)
destroyEntityTree(entity)
removeEntityNodeRecursively(entity)
}
}, [])

Expand Down Expand Up @@ -160,35 +161,60 @@ const spawnAvatar = (
)
}

const createIkTargetsForAvatar = (parentUUID: EntityUUID, userID: string): Entity[] => {
const createIkTargetsForAvatar = (parentUUID: EntityUUID, userID: string): EntityUUID[] => {
const headUUID = (userID + ikTargets.head) as EntityUUID
const leftHandUUID = (userID + ikTargets.leftHand) as EntityUUID
const rightHandUUID = (userID + ikTargets.rightHand) as EntityUUID
const leftFootUUID = (userID + ikTargets.leftFoot) as EntityUUID
const rightFootUUID = (userID + ikTargets.rightFoot) as EntityUUID

const entities = [] as Entity[]
;[headUUID, leftHandUUID, rightHandUUID, leftFootUUID, rightFootUUID].forEach((uuid) => {
const entity = UUIDComponent.getOrCreateEntityByUUID(uuid)
setComponent(entity, TransformComponent, { position: randomVec3(), rotation: randomQuaternion() })
entities.push(entity)
})
const targetUUIDs = [headUUID, leftHandUUID, rightHandUUID, leftFootUUID, rightFootUUID]

const posRot = targetUUIDs.map(() => ({ position: randomVec3(), rotation: randomQuaternion() }))

dispatchAction(AvatarNetworkAction.spawnIKTarget({ parentUUID, entityUUID: headUUID, name: 'head', blendWeight: 1 }))
dispatchAction(
AvatarNetworkAction.spawnIKTarget({ parentUUID, entityUUID: leftHandUUID, name: 'leftHand', blendWeight: 1 })
AvatarNetworkAction.spawnIKTarget({ parentUUID, entityUUID: headUUID, name: 'head', blendWeight: 1, ...posRot[0] })
)
dispatchAction(
AvatarNetworkAction.spawnIKTarget({
parentUUID,
entityUUID: leftHandUUID,
name: 'leftHand',
blendWeight: 1,
...posRot[1]
})
)
dispatchAction(
AvatarNetworkAction.spawnIKTarget({ parentUUID, entityUUID: rightHandUUID, name: 'rightHand', blendWeight: 1 })
AvatarNetworkAction.spawnIKTarget({
parentUUID,
entityUUID: rightHandUUID,
name: 'rightHand',
blendWeight: 1,
...posRot[2]
})
)
dispatchAction(
AvatarNetworkAction.spawnIKTarget({ parentUUID, entityUUID: leftFootUUID, name: 'leftFoot', blendWeight: 1 })
AvatarNetworkAction.spawnIKTarget({
parentUUID,
entityUUID: leftFootUUID,
name: 'leftFoot',
blendWeight: 1,
...posRot[3]
})
)
dispatchAction(
AvatarNetworkAction.spawnIKTarget({ parentUUID, entityUUID: rightFootUUID, name: 'rightFoot', blendWeight: 1 })
AvatarNetworkAction.spawnIKTarget({
parentUUID,
entityUUID: rightFootUUID,
name: 'rightFoot',
blendWeight: 1,
...posRot[4]
})
)

return entities
applyIncomingActions()

return targetUUIDs
}

export const AvatarIKBenchmark = (props: { rootEntity: Entity; onComplete: () => void }) => {
Expand All @@ -211,7 +237,7 @@ export const AvatarIKBenchmark = (props: { rootEntity: Entity; onComplete: () =>
props.push({
src: avatarSrc,
position: position,
animIndex: validAnimations[Math.floor(Math.random() * validAnimations.length)],
animIndex: 0,
rootEntity: rootEntity
})
}
Expand Down Expand Up @@ -241,11 +267,10 @@ export const AvatarIKBenchmark = (props: { rootEntity: Entity; onComplete: () =>
const AvatarIKSetupReactor = (props: {
src: string
position: Vector3
animIndex: number
rootEntity: Entity
onComplete: () => void
}) => {
const { src, position, animIndex, rootEntity, onComplete } = props
const { src, position, rootEntity, onComplete } = props
const rootUUID = useComponent(rootEntity, UUIDComponent)
const entity = useHookstate(createEntity).value
const model = useOptionalComponent(entity, ModelComponent)
Expand All @@ -271,15 +296,14 @@ const AvatarIKSetupReactor = (props: {
setComponent(entity, AvatarRigComponent)

spawnAvatar(rootUUID.value, uuid, src, { position, rotation: new Quaternion() })
const targetEntities = createIkTargetsForAvatar(rootUUID.value, uuid)
const targetUUIDs = createIkTargetsForAvatar(rootUUID.value, uuid)

return () => {
for (const targetEntity of targetEntities) {
removeEntity(targetEntity)
destroyEntityTree(targetEntity)
for (const targetUUID of targetUUIDs) {
const targetEntity = UUIDComponent.getEntityByUUID(targetUUID)
removeEntityNodeRecursively(targetEntity)
}
removeEntity(entity)
destroyEntityTree(entity)
removeEntityNodeRecursively(entity)
}
}, [])

Expand Down
8 changes: 4 additions & 4 deletions engine/benchmarks/BenchmarkOrchestration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const benchmarkOrder = [
BenchmarkStage.Physics,
BenchmarkStage.Particles,
BenchmarkStage.Avatar,
BenchmarkStage.IK,
BenchmarkStage.Animation,
BenchmarkStage.Rendering
BenchmarkStage.Rendering,
BenchmarkStage.IK
]

const benchmarks: { [key in BenchmarkStage]: Benchmark | null } = {
[BenchmarkStage.Avatar]: {
benchmark: AvatarBenchmark,
systemUUIDs: [SkinnedMeshTransformSystem]
systemUUIDs: [SkinnedMeshTransformSystem, AvatarAnimationSystem]
},
[BenchmarkStage.Physics]: {
benchmark: PhysicsBenchmark,
Expand All @@ -51,7 +51,7 @@ const benchmarks: { [key in BenchmarkStage]: Benchmark | null } = {
},
[BenchmarkStage.IK]: {
benchmark: AvatarIKBenchmark,
systemUUIDs: [SkinnedMeshTransformSystem, AvatarAnimationSystem]
systemUUIDs: [SkinnedMeshTransformSystem]
},
[BenchmarkStage.Animation]: null,
[BenchmarkStage.Rendering]: null
Expand Down
2 changes: 2 additions & 0 deletions engine/examples/ExamplesComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ModelComponent } from '@etherealengine/engine/src/scene/components/Mode
import { ParticleSystemComponent } from '@etherealengine/engine/src/scene/components/ParticleSystemComponent'
import { PrimitiveGeometryComponent } from '@etherealengine/engine/src/scene/components/PrimitiveGeometryComponent'
import { SDFComponent } from '@etherealengine/engine/src/scene/components/SDFComponent'
import { ShadowComponent } from '@etherealengine/engine/src/scene/components/ShadowComponent'
import { SourceComponent } from '@etherealengine/engine/src/scene/components/SourceComponent'
import { SplineComponent } from '@etherealengine/engine/src/scene/components/SplineComponent'
import { SplineTrackComponent } from '@etherealengine/engine/src/scene/components/SplineTrackComponent'
Expand Down Expand Up @@ -93,6 +94,7 @@ export const examples: Example[] = [
config.client.fileServer +
'/projects/ee-development-test-suite/assets/GLTF/Flight%20Helmet/FlightHelmet.gltf'
})
setComponent(entity, ShadowComponent, { receive: false })
setVisibleComponent(entity, true)
getComponent(entity, TransformComponent).scale.set(3, 3, 3)
}, [])
Expand Down

0 comments on commit 76d45fe

Please sign in to comment.