@illgrenoble/webx-client 1.10.5 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/WebXClient.js +1 -11
- package/dist/WebXClient.js.map +1 -1
- package/dist/display/WebXDisplay.d.ts +16 -4
- package/dist/display/WebXDisplay.js +93 -17
- package/dist/display/WebXDisplay.js.map +1 -1
- package/dist/display/WebXWindow.d.ts +7 -2
- package/dist/display/WebXWindow.js +9 -1
- package/dist/display/WebXWindow.js.map +1 -1
- package/dist/renderer/WebXAlphaStencilBlender.d.ts +30 -0
- package/dist/renderer/WebXAlphaStencilBlender.js +136 -0
- package/dist/renderer/WebXAlphaStencilBlender.js.map +1 -0
- package/dist/renderer/WebXBlenderWorker.d.ts +1 -0
- package/dist/renderer/WebXBlenderWorker.js +33 -0
- package/dist/renderer/WebXBlenderWorker.js.map +1 -0
- package/dist/renderer/WebXCanvasRenderer.d.ts +91 -0
- package/dist/renderer/WebXCanvasRenderer.js +190 -0
- package/dist/renderer/WebXCanvasRenderer.js.map +1 -0
- package/dist/renderer/WebXWindowBlender.d.ts +11 -0
- package/dist/renderer/WebXWindowBlender.js +27 -0
- package/dist/renderer/WebXWindowBlender.js.map +1 -0
- package/dist/renderer/WebXWindowCanvas.d.ts +114 -0
- package/dist/renderer/WebXWindowCanvas.js +306 -0
- package/dist/renderer/WebXWindowCanvas.js.map +1 -0
- package/dist/renderer/blender.d.ts +5 -0
- package/dist/renderer/blender.js +201 -0
- package/dist/renderer/blender.js.map +1 -0
- package/dist/renderer/index.d.ts +3 -0
- package/dist/renderer/index.js +20 -0
- package/dist/renderer/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WebXAlphaStencilBlender = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* The Alpha and stencil buffer blending function. The alpha buffer contains alpha data in the
|
|
15
|
+
* green channel. The stencil buffer is a black and white image: only pixels with a stencil value > 127 are to be rendered
|
|
16
|
+
* @param colorData the color data array
|
|
17
|
+
* @param alphaData the alpha data array
|
|
18
|
+
* @param stencilData the stencil data array
|
|
19
|
+
*/
|
|
20
|
+
function alphaAndStencilBlend(colorData, alphaData, stencilData) {
|
|
21
|
+
if (alphaData && stencilData) {
|
|
22
|
+
for (let i = 0; i < colorData.length; i += 4) {
|
|
23
|
+
if (stencilData[i] < 128) {
|
|
24
|
+
colorData[i + 3] = 0;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
colorData[i + 3] = alphaData[i + 1];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (alphaData) {
|
|
32
|
+
for (let i = 0; i < colorData.length; i += 4) {
|
|
33
|
+
colorData[i + 3] = alphaData[i + 1];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (stencilData) {
|
|
37
|
+
for (let i = 0; i < colorData.length; i += 4) {
|
|
38
|
+
colorData[i + 3] = stencilData[i] < 128 ? 0 : 255;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The entry point for the web worker. Receives messages with data for color, alpha and stencil data and calls the blending
|
|
44
|
+
* function.
|
|
45
|
+
*/
|
|
46
|
+
function alphaWorkerFunc() {
|
|
47
|
+
self.onmessage = (e) => {
|
|
48
|
+
const { id, colorBuffer, alphaBuffer, stencilBuffer, width, height } = e.data;
|
|
49
|
+
const colorData = new Uint8ClampedArray(colorBuffer);
|
|
50
|
+
const alphaData = alphaBuffer ? new Uint8ClampedArray(alphaBuffer) : null;
|
|
51
|
+
const stencilData = stencilBuffer ? new Uint8ClampedArray(stencilBuffer) : null;
|
|
52
|
+
alphaAndStencilBlend(colorData, alphaData, stencilData);
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
self.postMessage({ id, colorBuffer: colorData.buffer, width, height }, [colorData.buffer]);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The `WebXAlphaStencilBlender` class handles blending of alpha and stencil data
|
|
59
|
+
* for rendering purposes. It uses a Web Worker for asynchronous processing.
|
|
60
|
+
*/
|
|
61
|
+
class WebXAlphaStencilBlender {
|
|
62
|
+
/**
|
|
63
|
+
* Initializes the `WebXAlphaStencilBlender` and sets up the Web Worker (if web-workers present on the client).
|
|
64
|
+
* The web worker is initialised from the worker/blending functions above. Each blending request is assigned an id.
|
|
65
|
+
* The data is passed to the web worker along with the Id. The web worker returns the Id with blended data so that the
|
|
66
|
+
* calling promise can be resolved.
|
|
67
|
+
*/
|
|
68
|
+
constructor() {
|
|
69
|
+
this._pending = new Map();
|
|
70
|
+
this._nextId = 1;
|
|
71
|
+
if (typeof Worker !== 'undefined') {
|
|
72
|
+
const blob = new Blob([alphaAndStencilBlend.toString(), '(', alphaWorkerFunc.toString(), ')()'], { type: 'application/javascript' });
|
|
73
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
74
|
+
this._worker = new Worker(blobUrl);
|
|
75
|
+
URL.revokeObjectURL(blobUrl);
|
|
76
|
+
this._worker.onmessage = (e) => {
|
|
77
|
+
const { id, colorBuffer, width, height } = e.data;
|
|
78
|
+
const callback = this._pending.get(id);
|
|
79
|
+
if (!callback)
|
|
80
|
+
return;
|
|
81
|
+
this._pending.delete(id);
|
|
82
|
+
// Recreate ImageData from transferred buffer
|
|
83
|
+
const blendedData = new Uint8ClampedArray(colorBuffer);
|
|
84
|
+
const blendedImageData = new ImageData(blendedData, width, height);
|
|
85
|
+
callback(blendedImageData);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Blends alpha and stencil data asynchronously.
|
|
91
|
+
* Main entry point to blend the different buffers. If a web-worker is available on the client then the data is prepared to transfer
|
|
92
|
+
* to the worker. Otherwise the standard blending function is called immediately.
|
|
93
|
+
* @param colorImageData - The color image data.
|
|
94
|
+
* @param alphaImageData - The alpha image data.
|
|
95
|
+
* @param stencilImageData - The stencil image data.
|
|
96
|
+
* @returns A promise that resolves to the blended `ImageData`.
|
|
97
|
+
*/
|
|
98
|
+
blendAlphaAndStencil(colorImageData, alphaImageData, stencilImageData) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return new Promise((resolve) => {
|
|
101
|
+
if (this._worker) {
|
|
102
|
+
const id = this._nextId++;
|
|
103
|
+
this._pending.set(id, resolve);
|
|
104
|
+
const width = colorImageData.width;
|
|
105
|
+
const height = colorImageData.height;
|
|
106
|
+
const colorBuffer = colorImageData.data.buffer;
|
|
107
|
+
let alphaBuffer = null;
|
|
108
|
+
let stencilBuffer = null;
|
|
109
|
+
const transfers = [colorBuffer];
|
|
110
|
+
if (alphaImageData) {
|
|
111
|
+
alphaBuffer = alphaImageData.data.buffer;
|
|
112
|
+
transfers.push(alphaBuffer);
|
|
113
|
+
}
|
|
114
|
+
if (stencilImageData) {
|
|
115
|
+
stencilBuffer = stencilImageData.data.buffer;
|
|
116
|
+
transfers.push(stencilBuffer);
|
|
117
|
+
}
|
|
118
|
+
this._worker.postMessage({ id, colorBuffer, alphaBuffer, stencilBuffer, width, height }, transfers);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
alphaAndStencilBlend(colorImageData.data, alphaImageData === null || alphaImageData === void 0 ? void 0 : alphaImageData.data, stencilImageData === null || stencilImageData === void 0 ? void 0 : stencilImageData.data);
|
|
122
|
+
resolve(colorImageData);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Terminates the Web Worker and clears pending tasks.
|
|
129
|
+
*/
|
|
130
|
+
terminate() {
|
|
131
|
+
this._worker.terminate();
|
|
132
|
+
this._pending.clear();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.WebXAlphaStencilBlender = WebXAlphaStencilBlender;
|
|
136
|
+
//# sourceMappingURL=WebXAlphaStencilBlender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebXAlphaStencilBlender.js","sourceRoot":"","sources":["../../src/renderer/WebXAlphaStencilBlender.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,SAAS,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW;IAC7D,IAAI,SAAS,IAAI,WAAW,EAAE,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC;gBACzB,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YAEvB,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;IAEH,CAAC;SAAM,IAAI,SAAS,EAAE,CAAC;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI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QACd,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AArFD,0DAqFC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare function alphaAndStencilBlend(colorData: any, alphaData: any, stencilData: any): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function alphaAndStencilBlend(colorData, alphaData, stencilData) {
|
|
2
|
+
// Blend alpha (green channel -> alpha)
|
|
3
|
+
if (alphaData && stencilData) {
|
|
4
|
+
for (let i = 0; i < colorData.length; i += 4) {
|
|
5
|
+
if (stencilData[i] < 128) {
|
|
6
|
+
colorData[i + 3] = 0;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
colorData[i + 3] = alphaData[i + 1];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
else if (alphaData) {
|
|
14
|
+
for (let i = 0; i < colorData.length; i += 4) {
|
|
15
|
+
colorData[i + 3] = alphaData[i + 1];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else if (stencilData) {
|
|
19
|
+
for (let i = 0; i < colorData.length; i += 4) {
|
|
20
|
+
colorData[i + 3] = stencilData[i] < 128 ? 0 : 255;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
onmessage = (e) => {
|
|
25
|
+
const { id, colorBuffer, alphaBuffer, stencilBuffer, width, height } = e.data;
|
|
26
|
+
const colorData = new Uint8ClampedArray(colorBuffer);
|
|
27
|
+
const alphaData = alphaBuffer ? new Uint8ClampedArray(alphaBuffer) : null;
|
|
28
|
+
const stencilData = stencilBuffer ? new Uint8ClampedArray(stencilBuffer) : null;
|
|
29
|
+
alphaAndStencilBlend(colorData, alphaData, stencilData);
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
self.postMessage({ id, colorBuffer: colorData.buffer, width, height }, [colorData.buffer]);
|
|
32
|
+
};
|
|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,GAAG,CAAC,CAAC,EAAE,EAAE;IAChB,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;IAE9E,MAAM,SAAS,GAAG,IAAI,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1E,MAAM,WAAW,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEhF,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IAExD,aAAa;IACb,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7F,CAAC,CAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Camera, ColorRepresentation, Object3D, Texture, Vector2 } from 'three';
|
|
2
|
+
import { Blob } from "buffer";
|
|
3
|
+
/**
|
|
4
|
+
* The `WebXCanvasRenderer` class is responsible for rendering a desktop-like environment
|
|
5
|
+
* using HTML elements. It integrates with the Three.js library using 3D objects (meshes, materials, textures)
|
|
6
|
+
* to hold the graphical data used to render the windows.
|
|
7
|
+
*/
|
|
8
|
+
export declare class WebXCanvasRenderer {
|
|
9
|
+
private _width;
|
|
10
|
+
private _height;
|
|
11
|
+
private _desktopContainer;
|
|
12
|
+
private _desktop;
|
|
13
|
+
private _clearColor;
|
|
14
|
+
private readonly _alphaStencilBlender;
|
|
15
|
+
private _windowCanvases;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the root DOM element of the renderer.
|
|
18
|
+
* @returns The root DOM element.
|
|
19
|
+
*/
|
|
20
|
+
get domElement(): HTMLElement;
|
|
21
|
+
/**
|
|
22
|
+
* Initializes the `WebXCanvasRenderer` by creating the main desktop container
|
|
23
|
+
* and initializing the alpha stencil blender.
|
|
24
|
+
*/
|
|
25
|
+
constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Sets the size of the desktop container.
|
|
28
|
+
* @param width - The width of the desktop in pixels.
|
|
29
|
+
* @param height - The height of the desktop in pixels.
|
|
30
|
+
* @param unused - An optional unused parameter.
|
|
31
|
+
*/
|
|
32
|
+
setSize(width: number, height: number, unused?: boolean): void;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the background color of the desktop.
|
|
35
|
+
* @param color - The color to set, represented as a `ColorRepresentation`.
|
|
36
|
+
*/
|
|
37
|
+
setClearColor(color: ColorRepresentation): void;
|
|
38
|
+
/**
|
|
39
|
+
* Renders the scene: updates the window element positions, sizes and z-orders and updates
|
|
40
|
+
* the graphical content of the windows. Any windows that are no longer in the scene have their
|
|
41
|
+
* graphical elements removed from the dom.
|
|
42
|
+
* @param scene - The root `Object3D` containing the scene to render.
|
|
43
|
+
* @param camera - The `Camera` used for rendering (currently unused).
|
|
44
|
+
*/
|
|
45
|
+
render(scene: Object3D, camera: Camera): void;
|
|
46
|
+
/**
|
|
47
|
+
* Generates a screenshot of the current windows. Each window canvas is rendered onto a global
|
|
48
|
+
* desktop canvas. The main canvas is then converted into a blob with the specified image type and quality
|
|
49
|
+
* @param type The type of the screenshot (e.g., 'image/png').
|
|
50
|
+
* @param quality The quality of the screenshot (0 to 1).
|
|
51
|
+
*/
|
|
52
|
+
createScreenshot(type: string, quality: number): Promise<Blob>;
|
|
53
|
+
/**
|
|
54
|
+
* Disposes of the renderer by removing all window canvases and terminating
|
|
55
|
+
* the alpha stencil blender (and its web worker if present).
|
|
56
|
+
*/
|
|
57
|
+
dispose(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Updates a specific region of a window canvas from the color and alpha data sent from the server. The updates are stored in the window
|
|
60
|
+
* and handled at the next render request.
|
|
61
|
+
* @param meshId - The ID of the mesh associated with the window canvas.
|
|
62
|
+
* @param srcColorMap - The source color texture.
|
|
63
|
+
* @param dstColorMap - The destination color texture.
|
|
64
|
+
* @param srcAlphaMap - The source alpha texture.
|
|
65
|
+
* @param dstAlphaMap - The destination alpha texture.
|
|
66
|
+
* @param width - The width of the region to update.
|
|
67
|
+
* @param height - The height of the region to update.
|
|
68
|
+
* @param dstPosition - The destination position of the region.
|
|
69
|
+
*/
|
|
70
|
+
updateWindowRegion(meshId: number, srcColorMap: Texture, dstColorMap: Texture, srcAlphaMap: Texture, dstAlphaMap: Texture, width: number, height: number, dstPosition: Vector2): void;
|
|
71
|
+
/**
|
|
72
|
+
* Creates the main desktop container element and initializes its styles.
|
|
73
|
+
*/
|
|
74
|
+
private createMainElement;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new window canvas for the given mesh and adds it to the desktop.
|
|
77
|
+
* @param mesh - The `Mesh` object representing the window.
|
|
78
|
+
*/
|
|
79
|
+
private createWindowCanvas;
|
|
80
|
+
/**
|
|
81
|
+
* Removes a window canvas from the desktop and cleans up its resources.
|
|
82
|
+
* @param windowCanvas - The `WebXWindowCanvas` to remove.
|
|
83
|
+
*/
|
|
84
|
+
private removeWindowCanvas;
|
|
85
|
+
/**
|
|
86
|
+
* Creates an HTML element with the specified namespace.
|
|
87
|
+
* @param name - The name of the element to create.
|
|
88
|
+
* @returns The created `HTMLElement`.
|
|
89
|
+
*/
|
|
90
|
+
private createElementNS;
|
|
91
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebXCanvasRenderer = void 0;
|
|
4
|
+
const three_1 = require("three");
|
|
5
|
+
const WebXWindowCanvas_1 = require("./WebXWindowCanvas");
|
|
6
|
+
const WebXAlphaStencilBlender_1 = require("./WebXAlphaStencilBlender");
|
|
7
|
+
/**
|
|
8
|
+
* The `WebXCanvasRenderer` class is responsible for rendering a desktop-like environment
|
|
9
|
+
* using HTML elements. It integrates with the Three.js library using 3D objects (meshes, materials, textures)
|
|
10
|
+
* to hold the graphical data used to render the windows.
|
|
11
|
+
*/
|
|
12
|
+
class WebXCanvasRenderer {
|
|
13
|
+
/**
|
|
14
|
+
* Gets the root DOM element of the renderer.
|
|
15
|
+
* @returns The root DOM element.
|
|
16
|
+
*/
|
|
17
|
+
get domElement() {
|
|
18
|
+
return this._desktopContainer;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the `WebXCanvasRenderer` by creating the main desktop container
|
|
22
|
+
* and initializing the alpha stencil blender.
|
|
23
|
+
*/
|
|
24
|
+
constructor() {
|
|
25
|
+
this._clearColor = new three_1.Color(0, 0, 0);
|
|
26
|
+
this._windowCanvases = new Map();
|
|
27
|
+
this.createMainElement();
|
|
28
|
+
this._alphaStencilBlender = new WebXAlphaStencilBlender_1.WebXAlphaStencilBlender();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sets the size of the desktop container.
|
|
32
|
+
* @param width - The width of the desktop in pixels.
|
|
33
|
+
* @param height - The height of the desktop in pixels.
|
|
34
|
+
* @param unused - An optional unused parameter.
|
|
35
|
+
*/
|
|
36
|
+
setSize(width, height, unused) {
|
|
37
|
+
this._width = width;
|
|
38
|
+
this._height = height;
|
|
39
|
+
this._desktop.style.width = `${width}px`;
|
|
40
|
+
this._desktop.style.height = `${height}px`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets the background color of the desktop.
|
|
44
|
+
* @param color - The color to set, represented as a `ColorRepresentation`.
|
|
45
|
+
*/
|
|
46
|
+
setClearColor(color) {
|
|
47
|
+
this._clearColor.set(color);
|
|
48
|
+
this._desktop.style.backgroundColor = `#${this._clearColor.getHexString()}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Renders the scene: updates the window element positions, sizes and z-orders and updates
|
|
52
|
+
* the graphical content of the windows. Any windows that are no longer in the scene have their
|
|
53
|
+
* graphical elements removed from the dom.
|
|
54
|
+
* @param scene - The root `Object3D` containing the scene to render.
|
|
55
|
+
* @param camera - The `Camera` used for rendering (currently unused).
|
|
56
|
+
*/
|
|
57
|
+
render(scene, camera) {
|
|
58
|
+
if (scene.children.length > 0) {
|
|
59
|
+
const screen = scene.children[0];
|
|
60
|
+
const activeWindowIds = new Set();
|
|
61
|
+
for (const object of screen.children) {
|
|
62
|
+
if (object instanceof three_1.Mesh && object.visible) {
|
|
63
|
+
if (!this._windowCanvases.has(object.id)) {
|
|
64
|
+
this.createWindowCanvas(object);
|
|
65
|
+
}
|
|
66
|
+
const windowCanvas = this._windowCanvases.get(object.id);
|
|
67
|
+
windowCanvas.updateGeometry();
|
|
68
|
+
windowCanvas.updateCanvas();
|
|
69
|
+
activeWindowIds.add(object.id);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Remove defunct windows
|
|
73
|
+
for (const [windowId, windowCanvas] of this._windowCanvases.entries()) {
|
|
74
|
+
if (!activeWindowIds.has(windowId)) {
|
|
75
|
+
this.removeWindowCanvas(windowCanvas);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (this._windowCanvases.size > 0) {
|
|
80
|
+
// Remove all windows
|
|
81
|
+
for (const [_, windowCanvas] of this._windowCanvases.entries()) {
|
|
82
|
+
this.removeWindowCanvas(windowCanvas);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Generates a screenshot of the current windows. Each window canvas is rendered onto a global
|
|
88
|
+
* desktop canvas. The main canvas is then converted into a blob with the specified image type and quality
|
|
89
|
+
* @param type The type of the screenshot (e.g., 'image/png').
|
|
90
|
+
* @param quality The quality of the screenshot (0 to 1).
|
|
91
|
+
*/
|
|
92
|
+
createScreenshot(type, quality) {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
try {
|
|
95
|
+
const screenshotCanvas = this.createElementNS('canvas');
|
|
96
|
+
screenshotCanvas.width = this._width;
|
|
97
|
+
screenshotCanvas.height = this._height;
|
|
98
|
+
const context = screenshotCanvas.getContext('2d');
|
|
99
|
+
// Ensure that the background is set correctly
|
|
100
|
+
context.fillStyle = `#${this._clearColor.getHexString()}`;
|
|
101
|
+
context.fillRect(0, 0, this._width, this._height);
|
|
102
|
+
// Painters algorithm: Order the windows from back to front and draw the window canvas into the screenshot
|
|
103
|
+
Array.from(this._windowCanvases.values()).sort((a, b) => a.zIndex - b.zIndex).forEach(window => {
|
|
104
|
+
context.drawImage(window.canvas, window.x, window.y);
|
|
105
|
+
});
|
|
106
|
+
// Convert to specified image type and return the blob
|
|
107
|
+
screenshotCanvas.toBlob((blob) => {
|
|
108
|
+
resolve(blob);
|
|
109
|
+
}, type, quality);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
reject(error);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Disposes of the renderer by removing all window canvases and terminating
|
|
118
|
+
* the alpha stencil blender (and its web worker if present).
|
|
119
|
+
*/
|
|
120
|
+
dispose() {
|
|
121
|
+
// Remove all windows
|
|
122
|
+
for (const [_, windowCanvas] of this._windowCanvases.entries()) {
|
|
123
|
+
this.removeWindowCanvas(windowCanvas);
|
|
124
|
+
}
|
|
125
|
+
// Terminate the blended web worker if present
|
|
126
|
+
this._alphaStencilBlender.terminate();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Updates a specific region of a window canvas from the color and alpha data sent from the server. The updates are stored in the window
|
|
130
|
+
* and handled at the next render request.
|
|
131
|
+
* @param meshId - The ID of the mesh associated with the window canvas.
|
|
132
|
+
* @param srcColorMap - The source color texture.
|
|
133
|
+
* @param dstColorMap - The destination color texture.
|
|
134
|
+
* @param srcAlphaMap - The source alpha texture.
|
|
135
|
+
* @param dstAlphaMap - The destination alpha texture.
|
|
136
|
+
* @param width - The width of the region to update.
|
|
137
|
+
* @param height - The height of the region to update.
|
|
138
|
+
* @param dstPosition - The destination position of the region.
|
|
139
|
+
*/
|
|
140
|
+
updateWindowRegion(meshId, srcColorMap, dstColorMap, srcAlphaMap, dstAlphaMap, width, height, dstPosition) {
|
|
141
|
+
const windowCanvas = this._windowCanvases.get(meshId);
|
|
142
|
+
if (windowCanvas) {
|
|
143
|
+
windowCanvas.addRegionUpdate(srcColorMap, dstColorMap, srcAlphaMap, dstAlphaMap, width, height, dstPosition);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates the main desktop container element and initializes its styles.
|
|
148
|
+
*/
|
|
149
|
+
createMainElement() {
|
|
150
|
+
const desktopContainer = this.createElementNS('div');
|
|
151
|
+
desktopContainer.id = 'webx-desktop-container';
|
|
152
|
+
desktopContainer.style.display = 'block';
|
|
153
|
+
desktopContainer.style.position = 'relative';
|
|
154
|
+
desktopContainer.style.overflow = 'hidden';
|
|
155
|
+
const desktop = document.createElement('div');
|
|
156
|
+
desktop.id = 'webx-desktop';
|
|
157
|
+
desktopContainer.style.position = 'absolute';
|
|
158
|
+
desktopContainer.style.transformOrigin = 'top left';
|
|
159
|
+
desktopContainer.appendChild(desktop);
|
|
160
|
+
this._desktopContainer = desktopContainer;
|
|
161
|
+
this._desktop = desktop;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates a new window canvas for the given mesh and adds it to the desktop.
|
|
165
|
+
* @param mesh - The `Mesh` object representing the window.
|
|
166
|
+
*/
|
|
167
|
+
createWindowCanvas(mesh) {
|
|
168
|
+
const windowCanvas = new WebXWindowCanvas_1.WebXWindowCanvas(mesh, this._alphaStencilBlender);
|
|
169
|
+
this._desktop.appendChild(windowCanvas.canvas);
|
|
170
|
+
this._windowCanvases.set(mesh.id, windowCanvas);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Removes a window canvas from the desktop and cleans up its resources.
|
|
174
|
+
* @param windowCanvas - The `WebXWindowCanvas` to remove.
|
|
175
|
+
*/
|
|
176
|
+
removeWindowCanvas(windowCanvas) {
|
|
177
|
+
this._desktop.removeChild(windowCanvas.canvas);
|
|
178
|
+
this._windowCanvases.delete(windowCanvas.id);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Creates an HTML element with the specified namespace.
|
|
182
|
+
* @param name - The name of the element to create.
|
|
183
|
+
* @returns The created `HTMLElement`.
|
|
184
|
+
*/
|
|
185
|
+
createElementNS(name) {
|
|
186
|
+
return document.createElementNS('http://www.w3.org/1999/xhtml', name);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.WebXCanvasRenderer = WebXCanvasRenderer;
|
|
190
|
+
//# sourceMappingURL=WebXCanvasRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebXCanvasRenderer.js","sourceRoot":"","sources":["../../src/renderer/WebXCanvasRenderer.ts"],"names":[],"mappings":";;;AAAA,iCAA2F;AAC3F,yDAAoD;AACpD,uEAAkE;AAGlE;;;;GAIG;AACH,MAAa,kBAAkB;IAW7B;;;OAGG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH;QAjBQ,gBAAW,GAAU,IAAI,aAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAGxC,oBAAe,GAAkC,IAAI,GAAG,EAAE,CAAC;QAejE,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,oBAAoB,GAAG,IAAI,iDAAuB,EAAE,CAAC;IAC5D,CAAC;IAED;;;;;OAKG;IACI,OAAO,CAAC,KAAa,EAAE,MAAc,EAAE,MAAgB;QAC5D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,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CAAC;IACxE,CAAC;CACF;AA5MD,gDA4MC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BlenderModule } from './blender';
|
|
2
|
+
export declare class WebXWindowBlender {
|
|
3
|
+
private _blenderModule;
|
|
4
|
+
private _byteSize;
|
|
5
|
+
private _stencilPtr;
|
|
6
|
+
private _stencilView;
|
|
7
|
+
constructor(_blenderModule: BlenderModule);
|
|
8
|
+
setByteSize(size: number): void;
|
|
9
|
+
setStencilData(stencilData: ImageData): void;
|
|
10
|
+
private _freeStencilData;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebXWindowBlender = void 0;
|
|
4
|
+
class WebXWindowBlender {
|
|
5
|
+
constructor(_blenderModule) {
|
|
6
|
+
this._blenderModule = _blenderModule;
|
|
7
|
+
}
|
|
8
|
+
setByteSize(size) {
|
|
9
|
+
this._byteSize = size;
|
|
10
|
+
this._freeStencilData();
|
|
11
|
+
}
|
|
12
|
+
setStencilData(stencilData) {
|
|
13
|
+
this._freeStencilData();
|
|
14
|
+
const byteLength = stencilData.data.length;
|
|
15
|
+
this._stencilPtr = this._blenderModule._malloc(byteLength);
|
|
16
|
+
this._stencilView = new Uint8ClampedArray(this._blenderModule.HEAPU8.buffer, this._stencilPtr, byteLength);
|
|
17
|
+
this._stencilView.set(stencilData.data);
|
|
18
|
+
}
|
|
19
|
+
_freeStencilData() {
|
|
20
|
+
if (this._stencilPtr) {
|
|
21
|
+
this._blenderModule._free(this._stencilPtr);
|
|
22
|
+
this._stencilView = null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.WebXWindowBlender = WebXWindowBlender;
|
|
27
|
+
//# sourceMappingURL=WebXWindowBlender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebXWindowBlender.js","sourceRoot":"","sources":["../../src/renderer/WebXWindowBlender.ts"],"names":[],"mappings":";;;AAEA,MAAa,iBAAiB;IAM5B,YAAoB,cAA6B;QAA7B,mBAAc,GAAd,cAAc,CAAe;IACjD,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,cAAc,CAAC,WAAsB;QACnC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAExB,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,YAAY,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QAC1G,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAGO,gBAAgB;QACtB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC5C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;IACH,CAAC;CAGF;AAjCD,8CAiCC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Mesh, Texture, Vector2 } from "three";
|
|
2
|
+
import { WebXAlphaStencilBlender } from "./WebXAlphaStencilBlender";
|
|
3
|
+
/**
|
|
4
|
+
* The `WebXWindowCanvas` class holds the graphical elements necessary for rendering
|
|
5
|
+
* a specific window in the desktop environment. HTML Canvases are used for rendering image data. Window image data
|
|
6
|
+
* is received in the form of color, alpha and stencil buffers. These are blended to produce the final window image.
|
|
7
|
+
*/
|
|
8
|
+
export declare class WebXWindowCanvas {
|
|
9
|
+
private readonly _mesh;
|
|
10
|
+
private readonly _alphaStencilBlender;
|
|
11
|
+
private readonly _canvas;
|
|
12
|
+
private _context;
|
|
13
|
+
private _stencilCanvas;
|
|
14
|
+
private _stencilContext;
|
|
15
|
+
private _x;
|
|
16
|
+
private _y;
|
|
17
|
+
private _zIndex;
|
|
18
|
+
private _width;
|
|
19
|
+
private _height;
|
|
20
|
+
private _colorMap;
|
|
21
|
+
private _alphaMap;
|
|
22
|
+
private _stencilMap;
|
|
23
|
+
private _regionUpdates;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the unique ID of the associated mesh.
|
|
26
|
+
*/
|
|
27
|
+
get id(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the window canvas
|
|
30
|
+
*/
|
|
31
|
+
get canvas(): HTMLCanvasElement;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the left-hand x coordinate of the window
|
|
34
|
+
*/
|
|
35
|
+
get x(): number;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the top y coordinate of the window
|
|
38
|
+
*/
|
|
39
|
+
get y(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the zIndex of the window
|
|
42
|
+
*/
|
|
43
|
+
get zIndex(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the width of the window
|
|
46
|
+
*/
|
|
47
|
+
get width(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the height of the window
|
|
50
|
+
*/
|
|
51
|
+
get height(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Initializes a new `WebXWindowCanvas` for the given window Mesh and Material. The Mesh and Material contains all graphical information
|
|
54
|
+
* necessary to render a window (namely window position, size and z-order), the Mesh Material contains the graphical information (color, alpha and stencil data).
|
|
55
|
+
* @param _mesh - The `Mesh` object representing the window.
|
|
56
|
+
* @param _alphaStencilBlender - The alpha stencil blender instance.
|
|
57
|
+
*/
|
|
58
|
+
constructor(_mesh: Mesh, _alphaStencilBlender: WebXAlphaStencilBlender);
|
|
59
|
+
/**
|
|
60
|
+
* Updates the geometry of the window canvas based on the mesh's properties if any changes are needed.
|
|
61
|
+
*/
|
|
62
|
+
updateGeometry(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Updates the canvas content using the material textures (color, alpha and stencil buffers)
|
|
65
|
+
* if any changes have occurred.
|
|
66
|
+
*/
|
|
67
|
+
updateCanvas(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Adds a region update to the canvas taking into account the color, alpha and stencil buffers. Here we store a simple
|
|
70
|
+
* array of all the updates necessary for this frame. The updates are taken into account in the next rendering request of the window
|
|
71
|
+
* (and are only applied if the destination buffers have not been replaced).
|
|
72
|
+
* @param srcColorMap - The source color texture.
|
|
73
|
+
* @param dstColorMap - The destination color texture.
|
|
74
|
+
* @param srcAlphaMap - The source alpha texture.
|
|
75
|
+
* @param dstAlphaMap - The destination alpha texture.
|
|
76
|
+
* @param width - The width of the region to update.
|
|
77
|
+
* @param height - The height of the region to update.
|
|
78
|
+
* @param dstPosition - The destination position of the region.
|
|
79
|
+
*/
|
|
80
|
+
addRegionUpdate(srcColorMap: Texture, dstColorMap: Texture, srcAlphaMap: Texture, dstAlphaMap: Texture, width: number, height: number, dstPosition: Vector2): void;
|
|
81
|
+
/**
|
|
82
|
+
* Handles all pending region updates for the canvas. The different buffers (color, alpha and stencil) are blended (in a web
|
|
83
|
+
* worker if available) and then re-rendered into the main canvas of the window. If the window has only a color buffer then this
|
|
84
|
+
* is rendered immediately into the main canvas.
|
|
85
|
+
*/
|
|
86
|
+
private handleRegionUpdates;
|
|
87
|
+
/**
|
|
88
|
+
* Checks if the provided alpha map is valid for the canvas (dimensions are equal).
|
|
89
|
+
* @param alphaMap - The alpha texture to validate.
|
|
90
|
+
* @returns `true` if the alpha map is valid, otherwise `false`.
|
|
91
|
+
*/
|
|
92
|
+
private isValidAlphaMap;
|
|
93
|
+
/**
|
|
94
|
+
* Updates the stencil map for the window if it exists in the material and has changed.
|
|
95
|
+
* @param material - The material of the associated mesh.
|
|
96
|
+
*/
|
|
97
|
+
private updateStencilMap;
|
|
98
|
+
/**
|
|
99
|
+
* Prepares temporary canvases to renderer the image data (jpeg format) into raw pixmaps. The pixmap data for the different
|
|
100
|
+
* images is sent to the blender for processing.
|
|
101
|
+
* @param colorImage - The color image.
|
|
102
|
+
* @param alphaImage - The alpha image.
|
|
103
|
+
* @param dstX - The destination X position.
|
|
104
|
+
* @param dstY - The destination Y position.
|
|
105
|
+
* @returns A promise that resolves to the blended `ImageData`.
|
|
106
|
+
*/
|
|
107
|
+
private blendAlphaAndStencil;
|
|
108
|
+
/**
|
|
109
|
+
* Creates an HTML element with the specified namespace.
|
|
110
|
+
* @param name - The name of the element to create.
|
|
111
|
+
* @returns The created `HTMLElement`.
|
|
112
|
+
*/
|
|
113
|
+
private createElementNS;
|
|
114
|
+
}
|