Skip to content

Commit

Permalink
fix synced onLoad event process
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0310 committed Aug 8, 2023
1 parent c4778aa commit ad9f451
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Loader/mmdAsyncTextureLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AssetContainer } from "@babylonjs/core/assetContainer";
import { Texture } from "@babylonjs/core/Materials/Textures/texture";
import { Observable } from "@babylonjs/core/Misc/observable";
import { TimingTools } from "@babylonjs/core/Misc/timingTools";
import type { Scene } from "@babylonjs/core/scene";
import type { Nullable } from "@babylonjs/core/types";

Expand Down Expand Up @@ -36,7 +37,7 @@ class MmdTextureData {
public readonly cacheKey: string;
private readonly _scene: Scene;
private readonly _assetContainer: Nullable<AssetContainer>;
private readonly _onLoad?: Nullable<() => void>;
private readonly _onLoad: Nullable<() => void>;
private readonly _onError?: Nullable<(message?: string, exception?: any) => void>;

private _arrayBuffer: Nullable<ArrayBuffer>;
Expand All @@ -49,7 +50,7 @@ class MmdTextureData {
assetContainer: Nullable<AssetContainer>,
urlOrTextureName: string,
useLazyLoadWithBuffer: boolean,
onLoad?: Nullable<() => void>,
onLoad: Nullable<() => void>,
onError?: Nullable<(message?: string, exception?: any) => void>
) {
this.cacheKey = cacheKey;
Expand Down Expand Up @@ -108,7 +109,7 @@ class MmdTextureData {
assetContainer: Nullable<AssetContainer>,
textureName: string,
arrayBuffer: ArrayBuffer,
onLoad?: Nullable<() => void>,
onLoad: Nullable<() => void>,
onError?: Nullable<(message?: string, exception?: any) => void>
): void {
scene._blockEntityCollection = !!assetContainer;
Expand All @@ -118,7 +119,13 @@ class MmdTextureData {
undefined,
undefined,
undefined,
onLoad,
() => {
if (this._texture === null) {
if (onLoad !== null) TimingTools.SetImmediate(onLoad);
} else {
onLoad?.();
}
},
onError,
arrayBuffer,
true
Expand Down

0 comments on commit ad9f451

Please sign in to comment.