Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 36x 23x 23x 23x 5x 5x 18x 18x 36x 36x 36x 36x 36x 36x 36x 36x 36x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 36x 36x 36x 36x 36x 36x 34x 1x 1x 33x 33x 36x 36x 36x 36x 36x 36x 2x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 1x 1x 1x 2x 36x 36x 36x 36x 36x 36x 36x 11x 11x 11x 11x 36x 1x 1x | import { getUUID } from '../../utils/get-uuid';
import { illusionService } from '../illusion-service';
export interface ViewTarget {
canvasId: string;
canvas?: HTMLCanvasElement | OffscreenCanvas;
cTarget: CViewTarget;
needTransform: boolean;
}
/**
* 视图目标工具类
*/
export class ViewTargetHandler {
map: Map<string, ViewTarget>;
constructor() {
this.map = new Map();
}
private getTargetElement(canvasId: string): HTMLCanvasElement | OffscreenCanvas {
const { module } = illusionService;
canvasId = canvasId.substring(1);
if(module.GL.offscreenCanvases[canvasId]) {
return module.GL.offscreenCanvases[canvasId];
}
return document.getElementById(canvasId) as HTMLCanvasElement;
}
/**
* 创建视图目标实例
* @param canvasId - 视图的 Id
* @param width - 画布宽度
* @param height - 画布高度
* @returns 视图目标 id
*/
create(canvasId: string, width: number, height: number) {
const id = getUUID();
const cTarget = new illusionService.module.ViewTarget(canvasId);
cTarget.setTargetSize(width, height);
this.map.set(id, {
cTarget,
canvasId,
canvas: this.getTargetElement(canvasId),
needTransform: false
});
return { id };
}
/**
* 获取视图目标实例
* @param id - 视图目标 id
*/
getViewTarget(id: string): ViewTarget {
if(!this.map.has(id)) {
throw new Error(`viewTarget: ${id} is not exist`);
}
return this.map.get(id)!;
}
/**
* 销毁视图目标实例
* @param id - 视图目标 id
*/
destory(id: string) {
const { cTarget } = this.getViewTarget(id);
cTarget.delete();
this.map.delete(id);
}
/**
* 设置渲染目标尺寸
* @param id - 视图目标 id
* @param width - 宽度
* @param height - 高度
*/
setTargetSize(id: string, width: number, height: number): void {
const { cTarget, canvas } = this.getViewTarget(id);
cTarget.setTargetSize(width, height);
if(canvas) {
canvas.width = width;
canvas.height = height;
}
}
/**
* 设置是否为离屏 canvas
* @param offscreen - 是否离屏
* @param needTransform - 是否需要传输离屏 ImageBitmap
*/
setOffscreen(id: string, offscreen: boolean, needTransform: boolean = true) {
const target = this.getViewTarget(id);
target.cTarget.setOffscreen(offscreen);
target.needTransform = needTransform;
}
}
export const viewTargetHandler = new ViewTargetHandler(); |