Browse Source

自定义重试策略,怀疑babylon默认的重试策略有bug

dev
刘向辉 3 years ago
parent
commit
b8cf6d4764
  1. 20
      src/app/babylon/controller/scene-manager.ts
  2. 58
      src/app/babylon/game.ts
  3. 1
      src/app/babylon/tool/babylon-tool.ts

20
src/app/babylon/controller/scene-manager.ts

@ -12,6 +12,7 @@ import {
HemisphericLight,
HighlightLayer,
IParticleSystem,
ISceneLoaderProgressEvent,
Mesh,
MeshBuilder,
Observable,
@ -46,18 +47,18 @@ import { ModelInfo_mark } from '../model/info/mark/model-info-mark';
import { MarkData, MarkType } from '../model/data/mark/mark-data';
import { Event_KeyboardInput } from './event-manager/events/event-keyboard-input';
import { ModelInfo_mark_area } from '../model/info/mark/other/mark-plan-area-info';
import { classToClass, plainToClass } from 'class-transformer';
import { plainToClass } from 'class-transformer';
import { MarkData_Area } from '../model/data/mark/other/mark-data-area';
import { MarkData_Line } from '../model/data/mark/other/mark-data-line';
import { ModelInfo_mark_line } from '../model/info/mark/other/mark-plan-line-info';
import { MarkData_multiLine } from '../model/data/mark/other/mark-data-multi-line';
import { ModelInfo_mark_multiLine } from '../model/info/mark/other/mark-plan-multi-line-info';
import { MarkData_multiArrow_CT, MarkData_multiArrow_JG } from '../model/data/mark/other/mark-data-multi-arrow';
import { ModelInfo_mark_multiArrow } from '../model/info/mark/other/mark-plan-multi-arrow';
import { ModelInfo_mark_particle } from '../model/info/mark/other/mark-plan-particle-info';
import { FacilityPosType, ModelData_facility } from '../model/data/model-data/model-data-facility';
import { LoadTool } from '../tool/load-tool';
//场景管理器
export class SceneManager {
//----------------Camera-----------------\\
@ -595,7 +596,11 @@ export class SceneManager {
let box = SceneManager.importMeshSuccess(newMeshes, particleSystems, skeletons, animationGroups, modelInfo, needBox, modelData);
//console.log("加载模型完成", modelData.resName);
onSuccess(newMeshes, box, modelInfo);
}, null,
}, function (event: ISceneLoaderProgressEvent) {
//console.log(modelData.resName + "加载中", event, new Date().getTime());
},
function (scene: Scene, message: string, exception?: any) {
if (index < 5) {
@ -930,6 +935,8 @@ class ImportMeshSyncData {
onsuccessObservable: Observable<ImportMeshSyncCallBack>;
constructor(path: string,
name: string) {
this.isBreak = false;
@ -938,8 +945,13 @@ class ImportMeshSyncData {
this.onsuccessObservable = new Observable();
}
}
/**
*
*/

58
src/app/babylon/game.ts

@ -1,4 +1,4 @@
import { Database, Engine, RenderingManager, Scene } from "@babylonjs/core";
import { Database, Engine, FileTools, RenderingManager, Scene } from "@babylonjs/core";
import { SceneManager } from "./controller/scene-manager";
import { LoginSatus } from "./controller/status/login-status";
@ -18,8 +18,9 @@ export class Game {
//初始化引擎和画布
public init(canvas: HTMLCanvasElement) {
// FileTools.DefaultRetryStrategy = MyRetryStrategy.ExponentialBackoff(2, 1000);
// FileTools.DefaultRetryStrategy = RetryStrategy.ExponentialBackoff(2, 1000);
FileTools.DefaultRetryStrategy = MyRetryStrategy.ExponentialBackoff(2, 1000);
// FileTools.DefaultRetryStrategy = RetryStrategy.ExponentialBackoff(2, 1000);
if (Game.instance != null) {
// canvas.setAttribute("touch-action", "none");
// canvas.style.touchAction = "none";
@ -117,27 +118,30 @@ export class Game {
}
// /**
// * 重试策略
// */
// var MyRetryStrategy = /** @class */ (function () {
// function RetryStrategy() {
// }
// /**
// * Function used to defines an exponential back off strategy
// * @param maxRetries defines the maximum number of retries (3 by default)
// * @param baseInterval defines the interval between retries
// * @returns the strategy function to use
// */
// MyRetryStrategy.ExponentialBackoff = function (maxRetries, baseInterval) {
// if (maxRetries === void 0) { maxRetries = 3; }
// if (baseInterval === void 0) { baseInterval = 500; }
// return function (url, request, retryIndex) {
// if (request.status !== 0 || retryIndex >= maxRetries || url.indexOf("file:") !== -1) {
// return -1;
// }
// return Math.pow(2, retryIndex) * baseInterval;
// };
// };
// return MyRetryStrategy;
// }());
/**
*
*/
var MyRetryStrategy = /** @class */ (function () {
function MyRetryStrategy() {
}
/**
* Function used to defines an exponential back off strategy
* @param maxRetries defines the maximum number of retries (3 by default)
* @param baseInterval defines the interval between retries
* @returns the strategy function to use
*/
MyRetryStrategy.ExponentialBackoff = function (maxRetries, baseInterval) {
if (maxRetries === void 0) { maxRetries = 3; }
if (baseInterval === void 0) { baseInterval = 500; }
return function (url, request, retryIndex) {
if (request.status == 0 || retryIndex >= maxRetries || url.indexOf("file:") !== -1) {
console.log("不重试加载", request.status, retryIndex, url.indexOf("file:"));
return -1;
}
console.log("重试加载", request.status, retryIndex, url.indexOf("file:"));
return Math.pow(2, retryIndex) * baseInterval;
};
};
return MyRetryStrategy;
}());

1
src/app/babylon/tool/babylon-tool.ts

@ -134,6 +134,7 @@ export class BabylonTool {
let modelPath = path + sceneFilename;
LoadTool.add(modelPath, tag);
let isSuccess = false;
let plugin =
SceneLoader.ImportMeshAsync(

Loading…
Cancel
Save