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

Resource State #9632

Merged
merged 88 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
ef60ca0
Start of Resource State
MichaelEstes Jan 16, 2024
1054824
licenses
MichaelEstes Jan 16, 2024
b49b8b5
Start of resource manager hooks
MichaelEstes Jan 17, 2024
4226e4e
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 17, 2024
5e301f7
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 17, 2024
3c8243c
Resource hook refactoring
MichaelEstes Jan 17, 2024
4c47a5a
useTexture for SkyboxComponent
MichaelEstes Jan 17, 2024
2655b3f
Start of unloading logic
MichaelEstes Jan 17, 2024
2be8cdd
Include entity in useTexture
MichaelEstes Jan 17, 2024
2d9f5ed
Seperate logic by resource type
MichaelEstes Jan 18, 2024
e5ff4d2
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 18, 2024
3cd761b
Update Three cache
MichaelEstes Jan 18, 2024
284203c
Avatar loading system to resource manager
MichaelEstes Jan 18, 2024
9cf9fd3
Particle system to resource manager
MichaelEstes Jan 18, 2024
a23ea3e
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 18, 2024
7bc8a6d
Per type metadata
MichaelEstes Jan 18, 2024
531fb95
Include entity
MichaelEstes Jan 18, 2024
038331d
Unload assets when changed in editor, onUnload callback
MichaelEstes Jan 19, 2024
d2820de
Image component resource manager hooks
MichaelEstes Jan 19, 2024
dba2b8d
Don't use unloaded callback when the component is being unmounted
MichaelEstes Jan 19, 2024
ec4036c
Batch loader, loopAnimationComponent, AvatarAnimationSystem resource …
MichaelEstes Jan 19, 2024
df76a2c
Spawn point component to resource hooks, make sure unload only is cal…
MichaelEstes Jan 19, 2024
3c38a6a
Better typing
MichaelEstes Jan 20, 2024
ab41c92
onStart callback for setting initial metadata per type
MichaelEstes Jan 20, 2024
4b9351c
Update loaders to use abort controller signal
MichaelEstes Jan 22, 2024
dc2a8d2
license
MichaelEstes Jan 22, 2024
a8c2b3f
loader typings
MichaelEstes Jan 22, 2024
83f5b44
Portal texture resource hook
MichaelEstes Jan 22, 2024
781f43e
Media component resource hooks, potential on gpu callback
MichaelEstes Jan 22, 2024
3a9d192
EnvmapComponent resource hooks
MichaelEstes Jan 22, 2024
018cab7
rename abort controller function
MichaelEstes Jan 22, 2024
64358ed
fix ordering
MichaelEstes Jan 23, 2024
fc2ccf8
Envmap and Hyperspace to resource hooks
MichaelEstes Jan 23, 2024
4edc20b
seperate resources by type, start of tests
MichaelEstes Jan 23, 2024
ed96d01
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 23, 2024
e77f7f5
Update typing
MichaelEstes Jan 23, 2024
db6c2b5
Remove references to three FileLoader, Loader
MichaelEstes Jan 23, 2024
33f30af
Replace three loader reference
MichaelEstes Jan 23, 2024
3a6ec21
Parse function is optional
MichaelEstes Jan 23, 2024
eeed674
Custom loading manager with more hooks, tests
MichaelEstes Jan 24, 2024
53aa851
license
MichaelEstes Jan 24, 2024
fd19ef5
cleanup
MichaelEstes Jan 24, 2024
c5e60db
tests
MichaelEstes Jan 24, 2024
7f78ef8
tests
MichaelEstes Jan 24, 2024
a2a57db
tests
MichaelEstes Jan 24, 2024
a63b58c
Remove materials on model unload
MichaelEstes Jan 24, 2024
6d725a4
Model component fix wip
MichaelEstes Jan 25, 2024
48fdabe
Track textures loaded by the GLTFLoader
MichaelEstes Jan 26, 2024
3bca691
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 26, 2024
c1ac967
Update imports
MichaelEstes Jan 26, 2024
760f720
Resource manager track and manage materials, geometry
MichaelEstes Jan 26, 2024
e4d376c
Cleanup, no need to set asset to null when resources are disposed
MichaelEstes Jan 26, 2024
fd0355c
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 26, 2024
093893b
Track resources used by avatar preview, preliminary fixes for unloadi…
MichaelEstes Jan 27, 2024
b9656d0
unload correctly in avatar preview, envmapcomponent, model component
MichaelEstes Jan 29, 2024
92e0c56
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 29, 2024
16a304b
Update imports
MichaelEstes Jan 29, 2024
7aea3ba
Start of variant resource manager
MichaelEstes Jan 30, 2024
de97c1a
Resource manager loads variants if exists
MichaelEstes Jan 31, 2024
abb90a8
Merge branch 'dev' into ResourceManager
MichaelEstes Jan 31, 2024
588cbe2
hookstate fix
MichaelEstes Jan 31, 2024
30e3985
Component typing
MichaelEstes Jan 31, 2024
7779358
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 1, 2024
fa66e8f
Merge branch 'dev' into ResourceManager
HexaField Feb 5, 2024
3478a38
Merge branch 'dev' into ResourceManager
HexaField Feb 6, 2024
208c4b6
Avatar preview animation fixes
MichaelEstes Feb 6, 2024
e2ec75b
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 6, 2024
2892502
Mesh bvh hookstate and race condition fix, shadow system unmount fix
MichaelEstes Feb 6, 2024
f68e097
Mesh bvh fixes, object layer component fixes
MichaelEstes Feb 6, 2024
9c3fdcd
Preliminary fix for avatar switching
MichaelEstes Feb 7, 2024
7714d55
Fix errors when selecting a new avatar
MichaelEstes Feb 7, 2024
182d437
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 7, 2024
2a02c32
track textures by source uuid, remove dispose calls, mesh bvh hooksta…
MichaelEstes Feb 8, 2024
2f3b46b
debug change
MichaelEstes Feb 8, 2024
b1330e1
Update mesh bvh
MichaelEstes Feb 8, 2024
0c5fade
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 8, 2024
ba0aeb4
remove property
MichaelEstes Feb 8, 2024
d4a4906
test fix
MichaelEstes Feb 8, 2024
07f3d2a
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 9, 2024
df00fb8
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 12, 2024
1d5d89f
Fix for multiple avtars shown in avatar selection panel
MichaelEstes Feb 12, 2024
65874fe
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 12, 2024
dae6e74
Avatar selection working
MichaelEstes Feb 13, 2024
91afb0b
Merge branch 'dev' into ResourceManager
MichaelEstes Feb 13, 2024
cc5cc1f
Merge branch 'dev' into ResourceManager
DanielBelmes Feb 14, 2024
04d1dc0
bug fixes
HexaField Feb 14, 2024
746388b
src ref
HexaField Feb 14, 2024
1d5b96d
Merge branch 'dev' into ResourceManager
HexaField Feb 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { SxProps, Theme } from '@mui/material/styles'
import styles from './index.module.scss'

import { EntityUUID } from '@etherealengine/common/src/interfaces/EntityUUID'
import { hasComponent, removeComponent, setComponent } from '@etherealengine/ecs'
import { setComponent, UndefinedEntity } from '@etherealengine/ecs'
import { defaultAnimationPath, preloadedAnimations } from '@etherealengine/engine/src/avatar/animation/Util'
import { LoopAnimationComponent } from '@etherealengine/engine/src/avatar/components/LoopAnimationComponent'
import { AssetPreviewCameraComponent } from '@etherealengine/engine/src/camera/components/AssetPreviewCameraComponent'
Expand All @@ -55,6 +55,7 @@ import { UUIDComponent } from '@etherealengine/spatial/src/common/UUIDComponent'
import { ObjectLayerMaskComponent } from '@etherealengine/spatial/src/renderer/components/ObjectLayerComponent'
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent'
import { ObjectLayers } from '@etherealengine/spatial/src/renderer/constants/ObjectLayers'
import { EntityTreeComponent } from '@etherealengine/spatial/src/transform/components/EntityTree'
import { MathUtils } from 'three'

interface Props {
Expand All @@ -68,16 +69,10 @@ interface Props {
const AvatarPreview = ({ fill, avatarUrl, sx, onAvatarError, onAvatarLoaded }: Props) => {
const { t } = useTranslation()
const panelRef = useRef() as React.MutableRefObject<HTMLDivElement>

useRender3DPanelSystem(panelRef)

useEffect(() => {
loadAvatarPreview()
}, [avatarUrl])

const renderPanelState = getMutableState(PreviewPanelRendererState)

const loadAvatarPreview = () => {
useEffect(() => {
if (!avatarUrl) return

const renderPanelEntities = renderPanelState.entities[panelRef.current.id]
Expand All @@ -86,20 +81,19 @@ const AvatarPreview = ({ fill, avatarUrl, sx, onAvatarError, onAvatarLoaded }: P
setComponent(entity, UUIDComponent, uuid)
setComponent(entity, NameComponent, '3D Preview Entity')

if (hasComponent(entity, LoopAnimationComponent)) removeComponent(entity, LoopAnimationComponent)
if (hasComponent(entity, ModelComponent)) removeComponent(entity, ModelComponent)

setComponent(entity, VisibleComponent, true)
ObjectLayerMaskComponent.setLayer(entity, ObjectLayers.AssetPreview)
setComponent(entity, ModelComponent, { src: avatarUrl, convertToVRM: true })
setComponent(entity, LoopAnimationComponent, {
animationPack: defaultAnimationPath + preloadedAnimations.locomotion + '.glb',
activeClipIndex: 5
})
setComponent(entity, ModelComponent, { src: avatarUrl, convertToVRM: true })
setComponent(entity, EntityTreeComponent, { parentEntity: UndefinedEntity })

setComponent(entity, VisibleComponent, true)
ObjectLayerMaskComponent.setLayer(entity, ObjectLayers.AssetPreview)
setComponent(entity, EnvmapComponent, { type: EnvMapSourceType.Skybox })
const cameraEntity = renderPanelEntities[PanelEntities.camera].value
setComponent(cameraEntity, AssetPreviewCameraComponent, { targetModelEntity: entity })
}
}, [avatarUrl])

return (
<Box className={`${commonStyles.preview} ${fill ? styles.fill : ''}`} sx={sx}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ import React, { useEffect } from 'react'
import { Euler, Quaternion, Vector3, WebGLRenderer } from 'three'

import {
Engine,
Entity,
PresentationSystemGroup,
UndefinedEntity,
createEntity,
defineQuery,
defineSystem,
getComponent,
getOptionalComponent,
removeComponent,
removeEntity,
setComponent
} from '@etherealengine/ecs'
import { defineState, getMutableState, none } from '@etherealengine/hyperflux'
import { NO_PROXY, defineState, getMutableState, none } from '@etherealengine/hyperflux'
import { DirectionalLightComponent, TransformComponent } from '@etherealengine/spatial'
import { CameraComponent } from '@etherealengine/spatial/src/camera/components/CameraComponent'
import {
Expand All @@ -49,6 +49,7 @@ import {
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
import { InputSourceComponent } from '@etherealengine/spatial/src/input/components/InputSourceComponent'
import { addClientInputListeners } from '@etherealengine/spatial/src/input/systems/ClientInputSystem'
import { GroupComponent } from '@etherealengine/spatial/src/renderer/components/GroupComponent'
import {
ObjectLayerComponents,
ObjectLayerMaskComponent
Expand Down Expand Up @@ -158,6 +159,7 @@ export function useRender3DPanelSystem(panel: React.MutableRefObject<HTMLDivElem
getMutableState(ActiveOrbitCamera).set(UndefinedEntity)
const thisIdIndex = rendererState.ids.value.findIndex((value) => value === id)
rendererState.entities[id].set(none)
rendererState.renderers[id].get(NO_PROXY).dispose()
rendererState.renderers[id].set(none)
rendererState.ids[thisIdIndex].set(none)
}
Expand Down Expand Up @@ -193,21 +195,20 @@ export const render3DPanelSystem = defineSystem({
iterateEntityNode(previewEntity, (entity) => {
setComponent(entity, ObjectLayerComponents[ObjectLayers.AssetPreview])
})
const cameraComponent = getComponent(cameraEntity, CameraComponent)
// sync with view camera
const viewCamera = cameraComponent.cameras[0]
viewCamera.projectionMatrix.copy(cameraComponent.projectionMatrix)
viewCamera.quaternion.copy(cameraComponent.quaternion)
viewCamera.position.copy(cameraComponent.position)
viewCamera.layers.mask = getComponent(cameraEntity, ObjectLayerMaskComponent)
// hack to make the background transparent for the preview
const lastBackground = Engine.instance.scene.background
Engine.instance.scene.background = null
rendererState.renderers[id].value.render(Engine.instance.scene, viewCamera)
Engine.instance.scene.background = lastBackground
iterateEntityNode(previewEntity, (entity) => {
removeComponent(entity, ObjectLayerComponents[ObjectLayers.AssetPreview])
})
const group = getOptionalComponent(previewEntity, GroupComponent)
if (group && group[0]) {
const cameraComponent = getComponent(cameraEntity, CameraComponent)
// sync with view camera
const viewCamera = cameraComponent.cameras[0]
viewCamera.projectionMatrix.copy(cameraComponent.projectionMatrix)
viewCamera.quaternion.copy(cameraComponent.quaternion)
viewCamera.position.copy(cameraComponent.position)
viewCamera.layers.mask = getComponent(cameraEntity, ObjectLayerMaskComponent)
rendererState.renderers[id].value.render(group[0], viewCamera)
iterateEntityNode(previewEntity, (entity) => {
removeComponent(entity, ObjectLayerComponents[ObjectLayers.AssetPreview])
})
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"sift": "^17.0.1",
"simplex-noise": "^4.0.1",
"three": "0.158.0",
"three-mesh-bvh": "^0.6.8",
"three-mesh-bvh": "^0.7.1",
"three.quarks": "0.11.1",
"troika-three-text": "^0.49.0",
"ts-matches": "5.3.0",
Expand Down
21 changes: 6 additions & 15 deletions packages/engine/src/assets/classes/AssetLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
AudioLoader,
BufferAttribute,
BufferGeometry,
FileLoader,
Group,
LOD,
Material,
Expand All @@ -44,6 +43,8 @@ import {
TextureLoader
} from 'three'

import { FileLoader } from '../loaders/base/FileLoader'

import { getState } from '@etherealengine/hyperflux'

import { isClient } from '@etherealengine/common/src/utils/getEnvironment'
Expand Down Expand Up @@ -87,14 +88,6 @@ const onUploadDropBuffer = () =>
this.array = new this.array.constructor(1)
}

const onTextureUploadDropSource = () =>
function (this: Texture) {
// source.data can't be null because the WebGLRenderer checks for it
this.source.data = { width: this.source.data.width, height: this.source.data.height, __deleted: true }
this.mipmaps.map((b) => delete b.data)
this.mipmaps = []
}

export const cleanupAllMeshData = (child: Mesh, args: LoadingArgs) => {
if (getState(EngineState).isEditor || !child.isMesh) return
const geo = child.geometry as BufferGeometry
Expand All @@ -104,9 +97,6 @@ export const cleanupAllMeshData = (child: Mesh, args: LoadingArgs) => {
for (const name in attributes) (attributes[name] as BufferAttribute).onUploadCallback = onUploadDropBuffer()
if (geo.index) geo.index.onUploadCallback = onUploadDropBuffer()
}
Object.entries(mat)
.filter(([k, v]: [keyof typeof mat, Texture]) => v?.isTexture)
.map(([_, v]) => (v.onUpdate = onTextureUploadDropSource()))
}

const processModelAsset = (asset: Mesh, args: LoadingArgs): void => {
Expand Down Expand Up @@ -368,7 +358,7 @@ const assetLoadCallback =

const getAbsolutePath = (url) => (isAbsolutePath(url) ? url : getState(EngineState).publicPath + url)

type LoadingArgs = {
export type LoadingArgs = {
ignoreDisposeGeometry?: boolean
forceAssetType?: AssetType
assetRoot?: Entity
Expand All @@ -379,7 +369,8 @@ const load = async (
args: LoadingArgs,
onLoad = (response: any) => {},
onProgress = (request: ProgressEvent) => {},
onError = (event: ErrorEvent | Error) => {}
onError = (event: ErrorEvent | Error) => {},
signal?: AbortSignal
) => {
if (!_url) {
onError(new Error('URL is empty'))
Expand Down Expand Up @@ -430,7 +421,7 @@ const load = async (
const callback = assetLoadCallback(url, args, assetType, onLoad)

try {
return loader.load(url, callback, onProgress, onError)
return loader.load(url, callback, onProgress, onError, signal)
} catch (error) {
onError(error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
import fetch from 'cross-fetch'
import draco3d from 'draco3dgltf'
import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer'
import { FileLoader } from 'three'
import { FileLoader } from '../loaders/base/FileLoader'

import { EEMaterialExtension } from './extensions/EE_MaterialTransformer'
import { EEResourceIDExtension } from './extensions/EE_ResourceIDTransformer'
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/src/assets/font/FontLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { FileLoader, Loader, LoadingManager, ShapePath } from 'three'
import { LoadingManager, ShapePath } from 'three'

import { FileLoader } from '../loaders/base/FileLoader'
import { Loader } from '../loaders/base/Loader'
export class FontLoader extends Loader {
constructor(manager?: LoadingManager) {
super(manager)
Expand Down
Loading
Loading