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

Commit

Permalink
IR-1775-Changes-for-examples (#10387)
Browse files Browse the repository at this point in the history
* Overrideable asset loader for blob files, reparent canvas to previous parent, update mocap data structure

* Remove test pose data

* Fix for resource loading manager not being loaded anymore

* Don't undo default tier if getGPUTier fails

* wip

* Revert "wip"

This reverts commit 5306032.
  • Loading branch information
MichaelEstes authored Jun 18, 2024
1 parent 2d7bbe3 commit ba9c614
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 2,433 deletions.
6 changes: 3 additions & 3 deletions packages/client-core/src/hooks/useRemoveEngineCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { useEffect } from 'react'
export const useRemoveEngineCanvas = () => {
useEffect(() => {
const canvas = document.getElementById('engine-renderer-canvas')!
canvas.parentElement?.removeChild(canvas)
const parent = canvas.parentElement
parent?.removeChild(canvas)

return () => {
const body = document.body
body.appendChild(canvas)
parent?.appendChild(canvas)
}
}, [])

Expand Down
10 changes: 7 additions & 3 deletions packages/engine/src/assets/classes/AssetLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,19 @@ const loadAsset = async <T>(
onLoad: (response: T) => void = () => {},
onProgress: (request: ProgressEvent) => void = () => {},
onError: (event: ErrorEvent | Error) => void = () => {},
signal?: AbortSignal
signal?: AbortSignal,
loader?: ReturnType<typeof getLoader>
) => {
if (!url) {
onError(new Error('URL is empty'))
return
}
url = getAbsolutePath(url)
const assetExt = AssetLoader.getAssetType(url)
const loader = getLoader(assetExt)

if (!loader) {
const assetExt = AssetLoader.getAssetType(url)
loader = getLoader(assetExt)
}

try {
return loader.load(url, onLoad, onProgress, onError, signal)
Expand Down
16 changes: 14 additions & 2 deletions packages/engine/src/assets/functions/resourceLoaderFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ import {
ResourceType
} from '@etherealengine/spatial/src/resources/ResourceState'

import { AssetLoader } from '../classes/AssetLoader'
import { AssetExt } from '@etherealengine/common/src/constants/AssetType'
import { AssetLoader, getLoader } from '../classes/AssetLoader'

const getLoaderForResourceType = (resourceType: ResourceType) => {
switch (resourceType) {
case ResourceType.GLTF:
return getLoader(AssetExt.GLTF)
default:
break
}
return undefined
}

export const loadResource = <T extends ResourceAssetType>(
url: string,
Expand Down Expand Up @@ -96,7 +107,8 @@ export const loadResource = <T extends ResourceAssetType>(
onError(error)
ResourceManager.unload(url, entity, uuid)
},
signal
signal,
getLoaderForResourceType(resourceType)
)
}

Expand Down
3 changes: 3 additions & 0 deletions packages/engine/src/assets/loaders/base/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Ethereal Engine. All Rights Reserved.
*/

import { DefaultLoadingManager, LoadingManager } from 'three'
import { ResourceLoadingManagerState } from '../../state/ResourceLoadingManagerState'

interface Load<TData, TUrl> {
load: (
Expand Down Expand Up @@ -53,6 +54,8 @@ class Loader<TData = unknown, TUrl = string> implements Load<TData, TUrl> {
this.path = ''
this.resourcePath = ''
this.requestHeader = {}

ResourceLoadingManagerState.initialize()
}

load(
Expand Down
28 changes: 16 additions & 12 deletions packages/engine/src/assets/state/ResourceLoadingManagerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ import { ResourceManager, ResourceState, ResourceStatus } from '@etherealengine/

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

export const ResourceLoadingManagerState = defineState({
name: 'ResourceLoadingManagerState',
initial: () => new ResourceLoadingManager(onItemStart, onStart, onLoad, onProgress, onError),
reactor: () => {
const resourceLoadingManager = useMutableState(ResourceLoadingManagerState)

useEffect(() => {
setDefaultLoadingManager(resourceLoadingManager.value as LoadingManager)
}, [resourceLoadingManager])
}
})

export const setDefaultLoadingManager = (
loadingManager: LoadingManager = new ResourceLoadingManager(
onItemStart,
Expand Down Expand Up @@ -91,3 +79,19 @@ const onLoad = () => {

const onProgress = (url: string, loaded: number, total: number) => {}
const onError = (url: string) => {}

export const ResourceLoadingManagerState = defineState({
name: 'ResourceLoadingManagerState',
initial: () => new ResourceLoadingManager(onItemStart, onStart, onLoad, onProgress, onError),
reactor: () => {
const resourceLoadingManager = useMutableState(ResourceLoadingManagerState)

useEffect(() => {
setDefaultLoadingManager(resourceLoadingManager.value as LoadingManager)
}, [resourceLoadingManager])
},
initialize: () => {
// This is for getting around this file being removed during tree shaking
getState(ResourceLoadingManagerState)
}
})
Loading

0 comments on commit ba9c614

Please sign in to comment.