Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tech
pi_babylon
Commits
b0da6575
Commit
b0da6575
authored
9 months ago
by
bp0002
Browse files
Options
Download
Email Patches
Plain Diff
# fix: SpriteModel Load Check
parent
a93492db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/sprite/sprite_atlas.ts
+12
-6
src/sprite/sprite_atlas.ts
src/sprite/sprite_model.ts
+4
-4
src/sprite/sprite_model.ts
with
16 additions
and
10 deletions
+16
-10
src/sprite/sprite_atlas.ts
+
12
-
6
View file @
b0da6575
...
...
@@ -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
n
ul
l
;
return
res
ul
t
;
});
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
)
{
...
...
This diff is collapsed.
Click to expand it.
src/sprite/sprite_model.ts
+
4
-
4
View file @
b0da6575
...
...
@@ -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) {
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help