fozmo-3d-preview
Advanced tools
Comparing version 1.0.48 to 1.0.49
@@ -9,6 +9,10 @@ import { BaseLoop } from './BaseLoop'; | ||
private _clock; | ||
private _frames; | ||
private _prevTime; | ||
private _fps; | ||
private constructor(); | ||
setFPS(fps: number): void; | ||
getCurrentFPS(): number; | ||
setCurrentBaseLoop(scene: BaseLoop): void; | ||
private update; | ||
} |
@@ -17,2 +17,5 @@ import { BPGameConfig } from '../BPGameConfig'; | ||
_clock; | ||
_frames = 0; | ||
_prevTime = -1; | ||
_fps = 0; | ||
constructor() { | ||
@@ -26,2 +29,5 @@ Fozmo.init(); | ||
} | ||
getCurrentFPS() { | ||
return this._fps; | ||
} | ||
setCurrentBaseLoop(scene) { | ||
@@ -31,7 +37,8 @@ this._currentScene = scene; | ||
update() { | ||
const now = Date.now(); | ||
if (now >= this._delta) { | ||
const time = Date.now(); | ||
if (time >= this._delta) { | ||
this._frames++; | ||
this._delta += this._interval; | ||
if (now >= this._delta) { | ||
this._delta = now; | ||
if (time >= this._delta) { | ||
this._delta = time; | ||
} | ||
@@ -44,2 +51,10 @@ const delta = Math.min(0.05, this._clock.getDelta()); | ||
} | ||
if (this._prevTime === -1) { | ||
this._prevTime = time; | ||
} | ||
if (time >= this._prevTime + 1000) { | ||
this._fps = (this._frames * 1000) / (time - this._prevTime); | ||
this._prevTime = time; | ||
this._frames = 0; | ||
} | ||
} | ||
@@ -46,0 +61,0 @@ requestAnimationFrame(this.update.bind(this)); |
@@ -25,6 +25,11 @@ import * as THREE from 'three'; | ||
loadModel(url: string, ext: string, rootPath?: string): Promise<GLTF | THREE.Group | THREE.Mesh>; | ||
private loadGLB; | ||
private loadFBX; | ||
private loadUSDZ; | ||
loadHDR(url: string): Promise<THREE.DataTexture>; | ||
loadGLB(url: string, ext: string, rootPath?: string, times?: number): Promise<GLTF>; | ||
private _loadGLB; | ||
private _loadFBX; | ||
loadFBX(url: string, ext: string, rootPath?: string, times?: number): Promise<THREE.Group>; | ||
private _loadUSDZ; | ||
loadUSDZ(url: string, ext: string, rootPath?: string, times?: number): Promise<THREE.Mesh | THREE.Group>; | ||
_loadHDR(url: string): Promise<THREE.DataTexture>; | ||
private _retryTimes; | ||
loadHDR(url: string, times?: number): Promise<THREE.DataTexture>; | ||
} |
@@ -13,2 +13,3 @@ import * as THREE from 'three'; | ||
import { SpaceManager } from './SpaceManager'; | ||
import { Utils } from '../framework/Utils/Utils'; | ||
const FORMAT_LABELS = { | ||
@@ -84,3 +85,16 @@ [THREE.RGBAFormat]: 'RGBA', | ||
} | ||
async loadGLB(url, ext, rootPath) { | ||
async loadGLB(url, ext, rootPath = null, times = 0) { | ||
let gltf = await this._loadGLB(url, ext, rootPath); | ||
if (!gltf && times < this._retryTimes) { | ||
await Utils.delay(1000); | ||
const t = times + 1; | ||
gltf = await this.loadGLB(url, ext, rootPath, t); | ||
} | ||
if (!gltf) { | ||
HHConsole.error('加载glb失败 no en'); | ||
return null; | ||
} | ||
return gltf; | ||
} | ||
async _loadGLB(url, ext, rootPath) { | ||
if (!this._glbLoader) { | ||
@@ -120,3 +134,3 @@ this._glbLoader = new GLTFLoader(); | ||
} | ||
async loadFBX(url, ext, rootPath) { | ||
async _loadFBX(url, ext, rootPath) { | ||
if (!this._fbxLoader) { | ||
@@ -146,3 +160,16 @@ this._fbxLoader = new FBXLoader(); | ||
} | ||
async loadUSDZ(url, ext, rootPath) { | ||
async loadFBX(url, ext, rootPath = null, times = 0) { | ||
let gltf = await this._loadFBX(url, ext, rootPath); | ||
if (!gltf && times < this._retryTimes) { | ||
await Utils.delay(1000); | ||
const t = times + 1; | ||
gltf = await this.loadFBX(url, ext, rootPath, t); | ||
} | ||
if (!gltf) { | ||
HHConsole.error('加载glb失败 no en'); | ||
return null; | ||
} | ||
return gltf; | ||
} | ||
async _loadUSDZ(url, ext, rootPath) { | ||
if (!this._usdzLoader) { | ||
@@ -172,3 +199,16 @@ this._usdzLoader = new USDZLoader(); | ||
} | ||
async loadHDR(url) { | ||
async loadUSDZ(url, ext, rootPath = null, times = 0) { | ||
let gltf = await this._loadUSDZ(url, ext, rootPath); | ||
if (!gltf && times < this._retryTimes) { | ||
await Utils.delay(1000); | ||
const t = times + 1; | ||
gltf = await this.loadUSDZ(url, ext, rootPath, t); | ||
} | ||
if (!gltf) { | ||
HHConsole.error('加载glb失败 no en'); | ||
return null; | ||
} | ||
return gltf; | ||
} | ||
async _loadHDR(url) { | ||
if (!this._rgbeLoader) { | ||
@@ -180,2 +220,12 @@ this._rgbeLoader = new RGBELoader(); | ||
} | ||
_retryTimes = 5; | ||
async loadHDR(url, times = 0) { | ||
let tex = await this._loadHDR(url); | ||
if (tex == null && times < this._retryTimes) { | ||
await Utils.delay(1000); | ||
const t = times + 1; | ||
tex = await this.loadHDR(url, t); | ||
} | ||
return tex; | ||
} | ||
} |
@@ -26,2 +26,4 @@ import { BaseScene, BaseSceneConfig } from '../Base/BaseScene'; | ||
private _saveCallback; | ||
private _timeOutId; | ||
private _checkFPS; | ||
private _ccaoParameters; | ||
@@ -56,2 +58,3 @@ private _ccpdParameters; | ||
private loadModel; | ||
private delayCheck; | ||
private loadHDR; | ||
@@ -58,0 +61,0 @@ private setBGColor; |
@@ -22,2 +22,3 @@ import { EEncryptExt, ENormalExt, ResLoaderManager } from './../manager/ResLoaderManager'; | ||
import TextureUtils from '../Env/TextureUtils'; | ||
import { LoopManager } from '../Base/LoopManager'; | ||
CameraControls.install({ THREE }); | ||
@@ -183,2 +184,4 @@ const padding = 0.0; | ||
_saveCallback = undefined; | ||
_timeOutId = 0; | ||
_checkFPS = false; | ||
_ccaoParameters = { | ||
@@ -324,2 +327,3 @@ radius: 0.25, | ||
this.onResize(); | ||
this.delayCheck(); | ||
return true; | ||
@@ -976,2 +980,3 @@ } | ||
} | ||
this.delayCheck(); | ||
} | ||
@@ -1021,2 +1026,9 @@ async loadModel(url, rootPath = '') { | ||
} | ||
delayCheck() { | ||
this._checkFPS = false; | ||
clearTimeout(this._timeOutId); | ||
this._timeOutId = setTimeout(() => { | ||
this._checkFPS = true; | ||
}, 1000); | ||
} | ||
async loadHDR(url) { | ||
@@ -1189,2 +1201,18 @@ if (this.scene.background) { | ||
} | ||
if (this._checkFPS) { | ||
if (LoopManager.inst.getCurrentFPS() < 25) { | ||
window.console.warn('>>>>>>>>>>>> 帧率过低,启动应急方案 <<<<<<<<<<<<'); | ||
if (this._lutPass && this._lutPass.enabled) { | ||
this._lutPass.enabled = false; | ||
} | ||
if (this._gtaoPass && this._gtaoPass.enabled) { | ||
this._gtaoPass.enabled = false; | ||
} | ||
if (this._ssaaPass && this._ssaaPass.enabled) { | ||
this._ssaaPass.enabled = false; | ||
this._smaaPass.enabled = true; | ||
} | ||
} | ||
this._checkFPS = false; | ||
} | ||
} | ||
@@ -1209,2 +1237,3 @@ onResize() { | ||
clear() { | ||
clearTimeout(this._timeOutId); | ||
if (this._model) { | ||
@@ -1211,0 +1240,0 @@ this.scene.remove(this._model); |
{ | ||
"name": "fozmo-3d-preview", | ||
"version": "1.0.48", | ||
"version": "1.0.49", | ||
"description": "风之末 作品预览", | ||
@@ -5,0 +5,0 @@ "main": "lib/Fozmo3DPreview.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205709
6080