Commit b0da6575 authored by bp0002's avatar bp0002
Browse files

# fix: SpriteModel Load Check

parent a93492db
Showing with 16 additions and 10 deletions
+16 -10
......@@ -127,7 +127,7 @@ export interface IAtlasParam {
export class GlobalAtlasManager {
public static atlasMap: Map<string, Atlas> = new Map();
public static atlasSpriteLimit: Map<string, IAtlasParam> = new Map();
private static atlasLoadMap: Map<string, Promise<null>> = new Map();
private static atlasLoadMap: Map<string, Promise<Atlas[]>> = new Map();
private static readonly Default: [number, number, number, number] = [1, 1, 0, 0]
public static load(atlasConfigPath: string, spriteLimit?: number, samplerMode?: number, alphaMode?: number, noMipmap: boolean = true, renderMode: 0 | 1 | 2 = 0) {
let result = GlobalAtlasManager.atlasLoadMap.get(atlasConfigPath);
......@@ -138,9 +138,9 @@ export class GlobalAtlasManager {
result = ExtensionTools.LoadFile(res, atlasConfigPath).then((data) => {
let json = ExtensionTools.UTF8Decode((<ArrayBuffer>data));
let atlas = TexturePackAtlas.fromJson(JSON.parse(json));
GlobalAtlasManager.regist(atlas, spriteLimit, samplerMode, alphaMode, noMipmap, renderMode);
let result = GlobalAtlasManager.regist(atlas, spriteLimit, samplerMode, alphaMode, noMipmap, renderMode);
res.clear();
return null;
return result;
});
GlobalAtlasManager.atlasLoadMap.set(atlasConfigPath, result);
return result;
......@@ -257,7 +257,8 @@ export class GlobalAtlasManager {
GlobalAtlasManager.regist(result, spriteLimit, samplerMode, alphaMode, noMipmap, renderMode);
}
public static regist(atlas: ISpriteAtlas | ISpriteAtlas[], spriteLimit?: number, samplerMode?: number, alphaMode?: number, noMipmap: boolean = true, renderMode: 0 | 1 | 2 = 0) {
public static regist(atlas: ISpriteAtlas | ISpriteAtlas[], spriteLimit?: number, samplerMode?: number, alphaMode?: number, noMipmap: boolean = true, renderMode: 0 | 1 | 2 = 0): Atlas[] {
let result = [];
if (atlas instanceof Array) {
atlas.forEach((item) => {
spriteLimit = GlobalAtlasManager.atlasSpriteLimit.get(item.image)?.spriteLimit || spriteLimit;
......@@ -265,8 +266,10 @@ export class GlobalAtlasManager {
alphaMode = GlobalAtlasManager.atlasSpriteLimit.get(item.image)?.alphaMode || alphaMode || item.alphaMode;
noMipmap = GlobalAtlasManager.atlasSpriteLimit.get(item.image)?.noMipmap || noMipmap || item.noMipmap;
renderMode = GlobalAtlasManager.atlasSpriteLimit.get(item.image)?.renderMode || renderMode || item.renderMode;
GlobalAtlasManager.atlasMap.set(item.image, new Atlas(item, samplerMode, alphaMode, noMipmap, renderMode));
let atlas = new Atlas(item, samplerMode, alphaMode, noMipmap, renderMode);
GlobalAtlasManager.atlasMap.set(item.image, atlas);
GlobalAtlasManager.atlasSpriteLimit.set(item.image, { spriteLimit, samplerMode, alphaMode, noMipmap, renderMode });
result.push(atlas);
});
} else {
spriteLimit = GlobalAtlasManager.atlasSpriteLimit.get(atlas.image)?.spriteLimit || spriteLimit;
......@@ -274,9 +277,12 @@ export class GlobalAtlasManager {
alphaMode = GlobalAtlasManager.atlasSpriteLimit.get(atlas.image)?.alphaMode || alphaMode || atlas.alphaMode;
noMipmap = GlobalAtlasManager.atlasSpriteLimit.get(atlas.image)?.noMipmap || noMipmap || atlas.noMipmap;
renderMode = GlobalAtlasManager.atlasSpriteLimit.get(atlas.image)?.renderMode || renderMode || atlas.renderMode;
GlobalAtlasManager.atlasMap.set(atlas.image, new Atlas(atlas, samplerMode, alphaMode, noMipmap, renderMode));
let _atlas = new Atlas(atlas, samplerMode, alphaMode, noMipmap, renderMode)
GlobalAtlasManager.atlasMap.set(atlas.image, _atlas);
GlobalAtlasManager.atlasSpriteLimit.set(atlas.image, { spriteLimit, samplerMode, alphaMode, noMipmap, renderMode });
result.push(_atlas);
}
return result;
}
public static getAtlas(atlas: ISpriteAtlas | string): Atlas {
if ((<ISpriteAtlas>atlas).image) {
......
......@@ -33,11 +33,10 @@ export class SpriteModel extends ModelObj {
super(meshName, scene, opt);
opt.fileName = fileName;
let atlasName = opt.spriteAtlas || ((opt.path || "") + fileName);
let pureName = atlasName.replace(".png", "").replace(".atlas", "");
this._loadPromise = new Promise((resolve, reject) => {
let atlas = GlobalAtlasManager.getAtlas(`${pureName}.png`);
let atlas = GlobalAtlasManager.getAtlas(atlasName);
if (atlas) {
this.atlas = <ITexturePackAtlas>atlas.atlas;
// if (this.atlas.animations) {
......@@ -61,8 +60,9 @@ export class SpriteModel extends ModelObj {
// reject(`SpriteModel Atlas Not Found Animation! ${pureName}`);
// }
} else {
GlobalAtlasManager.load(`${pureName}.atlas`).then(() => {
let atlas = GlobalAtlasManager.getAtlas(`${pureName}.png`);
let pureName = atlasName.replace(".png", "").replace(".jpg", "").replace(".atlas", "");
GlobalAtlasManager.load(`${pureName}.atlas`).then((atlasList) => {
let atlas = atlasList[0];
if (atlas) {
this.atlas = <ITexturePackAtlas>atlas.atlas;
// if (this.atlas.animations) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment