feat(3d): 优化3D场景性能并添加纹理缓存
refactor(DeviceModel): 使用相机Z坐标阈值减少背板渲染状态更新 refactor(LODManager): 基于距离变化率优化LOD切换逻辑 feat(TextureCache): 新增纹理缓存类用于U位标签纹理管理 refactor(RackModel): 使用纹理缓存重构U位标签生成逻辑 feat(backend): 添加端口兼容性检查功能 feat(cables): 实现端口类型和速率兼容性验证API feat(frontend): 新增设备筛选组件FilterableDeviceSelect refactor(PortPanel): 优化端口占用状态显示和交互 feat(CableWizardModal): 集成端口兼容性检查并优化UI
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import * as THREE from 'three';
|
||||
|
||||
class TextureCache {
|
||||
constructor() {
|
||||
this.cache = new Map();
|
||||
}
|
||||
|
||||
getOrCreate(key, creator) {
|
||||
if (!this.cache.has(key)) {
|
||||
this.cache.set(key, creator());
|
||||
}
|
||||
return this.cache.get(key);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.cache.forEach(texture => {
|
||||
if (texture instanceof THREE.CanvasTexture) {
|
||||
texture.dispose();
|
||||
}
|
||||
});
|
||||
this.cache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
const uLabelTextureCache = new TextureCache();
|
||||
|
||||
export const getULabelTexture = num => {
|
||||
return uLabelTextureCache.getOrCreate(num, () => {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 32;
|
||||
canvas.height = 32;
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
ctx.clearRect(0, 0, 32, 32);
|
||||
|
||||
ctx.fillStyle = '#ffffff';
|
||||
ctx.font = 'bold 20px Arial';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(num.toString(), 16, 16);
|
||||
|
||||
return new THREE.CanvasTexture(canvas);
|
||||
});
|
||||
};
|
||||
|
||||
export const disposeULabelTextures = () => {
|
||||
uLabelTextureCache.dispose();
|
||||
};
|
||||
|
||||
export default TextureCache;
|
||||
Reference in New Issue
Block a user