mirror of
https://github.com/galacean/engine.git
synced 2026-06-01 08:14:10 +08:00
Support dependency map in resource config (#2476)
* feat: support dependency map in `resource config`
This commit is contained in:
@@ -184,7 +184,7 @@ export class ResourceManager {
|
||||
* @internal
|
||||
*/
|
||||
_getRemoteUrl(url: string): string {
|
||||
return this._virtualPathMap[url] ?? url;
|
||||
return this._virtualPathResourceMap[url]?.path ?? url;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +206,7 @@ export class ResourceManager {
|
||||
* @internal
|
||||
*/
|
||||
_onSubAssetSuccess<T>(assetBaseURL: string, assetSubPath: string, value: T): void {
|
||||
const remoteAssetBaseURL = this._virtualPathMap[assetBaseURL] ?? assetBaseURL;
|
||||
const remoteAssetBaseURL = this._virtualPathResourceMap[assetBaseURL]?.path ?? assetBaseURL;
|
||||
|
||||
const subPromiseCallback = this._subAssetPromiseCallbacks[remoteAssetBaseURL]?.[assetSubPath];
|
||||
if (subPromiseCallback) {
|
||||
@@ -361,7 +361,7 @@ export class ResourceManager {
|
||||
const paths = queryPath ? this._parseQueryPath(queryPath) : [];
|
||||
|
||||
// Get remote asset base url
|
||||
const remoteAssetBaseURL = this._virtualPathMap[assetBaseURL] ?? assetBaseURL;
|
||||
const remoteAssetBaseURL = this._virtualPathResourceMap[assetBaseURL]?.path ?? assetBaseURL;
|
||||
|
||||
// Check cache
|
||||
const cacheObject = this._assetUrlPool[remoteAssetBaseURL];
|
||||
@@ -553,9 +553,9 @@ export class ResourceManager {
|
||||
/** @internal */
|
||||
_objectPool: { [key: string]: any } = Object.create(null);
|
||||
/** @internal */
|
||||
_editorResourceConfig: EditorResourceConfig = Object.create(null);
|
||||
_idResourceMap: Record<ResourceId, EditorResourceItem> = Object.create(null);
|
||||
/** @internal */
|
||||
_virtualPathMap: Record<string, string> = Object.create(null);
|
||||
_virtualPathResourceMap: Record<VirtualPath, EditorResourceItem> = Object.create(null);
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -568,9 +568,9 @@ export class ResourceManager {
|
||||
if (obj) {
|
||||
promise = Promise.resolve(obj);
|
||||
} else {
|
||||
const resourceConfig = this._editorResourceConfig[refId];
|
||||
const resourceConfig = this._idResourceMap[refId];
|
||||
if (!resourceConfig) {
|
||||
Logger.warn(`refId:${refId} is not find in this._editorResourceConfig.`);
|
||||
Logger.warn(`refId:${refId} is not find in this._idResourceMap.`);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
let url = resourceConfig.virtualPath;
|
||||
@@ -592,8 +592,11 @@ export class ResourceManager {
|
||||
*/
|
||||
initVirtualResources(config: EditorResourceItem[]): void {
|
||||
config.forEach((element) => {
|
||||
this._virtualPathMap[element.virtualPath] = element.path;
|
||||
this._editorResourceConfig[element.id] = element;
|
||||
this._virtualPathResourceMap[element.virtualPath] = element;
|
||||
this._idResourceMap[element.id] = element;
|
||||
if (element.dependentAssetMap) {
|
||||
this._virtualPathResourceMap[element.virtualPath].dependentAssetMap = element.dependentAssetMap;
|
||||
}
|
||||
});
|
||||
}
|
||||
//-----------------Editor temp solution-----------------
|
||||
@@ -631,8 +634,15 @@ const rePropName = RegExp(
|
||||
"g"
|
||||
);
|
||||
|
||||
type EditorResourceItem = { virtualPath: string; path: string; type: string; id: string };
|
||||
type EditorResourceConfig = Record<string, EditorResourceItem>;
|
||||
type ResourceId = string;
|
||||
type VirtualPath = string;
|
||||
type EditorResourceItem = {
|
||||
virtualPath: string;
|
||||
path: string;
|
||||
type: string;
|
||||
id: string;
|
||||
dependentAssetMap?: { [key: string]: string };
|
||||
};
|
||||
type SubAssetPromiseCallbacks<T> = Record<
|
||||
// main asset url, ie. "https://***.glb"
|
||||
string,
|
||||
|
||||
Reference in New Issue
Block a user