@umicat/three-sdk 1.13.1 → 1.15.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/dist/DualScreen3D.d.ts +60 -2
- package/dist/DualScreen3D.js +55 -14
- package/package.json +1 -1
package/dist/DualScreen3D.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { ThreeUmicat } from './ThreeUmicat.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The size a game should render at: the upper panel when folded, else the
|
|
4
|
+
* window.
|
|
5
|
+
*
|
|
6
|
+
* Only needed by a game that wants to keep driving its own canvas — hand
|
|
7
|
+
* `installDualScreen` the renderer instead and none of this is your problem.
|
|
8
|
+
* Kept because a game with several views, or one that renders at a fraction of
|
|
9
|
+
* the panel, has a real reason to do the sizing itself.
|
|
10
|
+
*/
|
|
3
11
|
export declare function viewportSize(umicat: ThreeUmicat): {
|
|
4
12
|
width: number;
|
|
5
13
|
height: number;
|
|
@@ -16,4 +24,54 @@ export declare function viewportSize(umicat: ThreeUmicat): {
|
|
|
16
24
|
* All in CSS pixels; all `0` when there is no fold, so a stylesheet that uses
|
|
17
25
|
* them is correct on a flat screen too.
|
|
18
26
|
*/
|
|
19
|
-
|
|
27
|
+
/** What the SDK will resize for you. Everything is optional. */
|
|
28
|
+
export interface DualScreenTargets {
|
|
29
|
+
/** The game's renderer. Hand it over and the SDK owns the upper panel
|
|
30
|
+
* completely — buffer, CSS box and all. Leave it out and the canvas is not
|
|
31
|
+
* touched at all (see below). */
|
|
32
|
+
renderer?: {
|
|
33
|
+
setSize(width: number, height: number, updateStyle?: boolean): void;
|
|
34
|
+
domElement: HTMLCanvasElement;
|
|
35
|
+
};
|
|
36
|
+
/** Kept in step with the panel's aspect. Without it the picture is correctly
|
|
37
|
+
* sized and wrongly shaped. */
|
|
38
|
+
camera?: {
|
|
39
|
+
aspect: number;
|
|
40
|
+
updateProjectionMatrix(): void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* For a game that sizes its own buffer (via `viewportSize`) but still wants
|
|
44
|
+
* its canvas put in the right place. The SDK sets the CSS BOX and nothing
|
|
45
|
+
* else — no `setSize`, no aspect.
|
|
46
|
+
*
|
|
47
|
+
* This exists because a game with its own camera framing cannot hand over
|
|
48
|
+
* the renderer, and a buffer sized to the upper panel inside a canvas still
|
|
49
|
+
* stretched across the window is a picture stretched to twice its height.
|
|
50
|
+
* Found exactly that way, on Gomoku: the rig frames the board itself and
|
|
51
|
+
* offsets the view for its chat column, so it asks for the viewport — and
|
|
52
|
+
* then had nowhere correct to draw it.
|
|
53
|
+
*
|
|
54
|
+
* Ignored when `renderer` is given, which already covers the box.
|
|
55
|
+
*/
|
|
56
|
+
canvas?: HTMLCanvasElement;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Starts keeping the page laid out for the fold. Call once, after `init`.
|
|
60
|
+
*
|
|
61
|
+
* **Hand over `renderer` and `camera` and the game needs no other change.** The
|
|
62
|
+
* SDK then re-applies the panel size after every resize — its listener is
|
|
63
|
+
* registered after the game's, so the game's own
|
|
64
|
+
* `setSize(innerWidth, innerHeight)` runs first and is corrected, and a frame
|
|
65
|
+
* is re-applied on the next rAF in case a game registers its listener later.
|
|
66
|
+
*
|
|
67
|
+
* **Leave them out and the canvas is left ALONE.** That is deliberate, and it
|
|
68
|
+
* is a correction: an earlier version moved the canvas's CSS box into the
|
|
69
|
+
* upper panel without owning the buffer, so a game whose resize still asked
|
|
70
|
+
* the window rendered a 669x951 buffer at aspect 0.70 squeezed into a
|
|
71
|
+
* 669x455.5 box — visibly squashed. Half-owning a canvas is worse than not
|
|
72
|
+
* touching it, so now it is one or the other.
|
|
73
|
+
*
|
|
74
|
+
* The control layer moves either way: the SDK built it, so it is always the
|
|
75
|
+
* SDK's to place.
|
|
76
|
+
*/
|
|
77
|
+
export declare function installDualScreen(umicat: ThreeUmicat, targets?: DualScreenTargets): () => void;
|
package/dist/DualScreen3D.js
CHANGED
|
@@ -26,7 +26,15 @@
|
|
|
26
26
|
// crease. That is a worse picture, not a broken one, and it degrades without
|
|
27
27
|
// anybody having to ship anything.
|
|
28
28
|
const TOUCH_ROOT = '[data-umicat-touch]';
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The size a game should render at: the upper panel when folded, else the
|
|
31
|
+
* window.
|
|
32
|
+
*
|
|
33
|
+
* Only needed by a game that wants to keep driving its own canvas — hand
|
|
34
|
+
* `installDualScreen` the renderer instead and none of this is your problem.
|
|
35
|
+
* Kept because a game with several views, or one that renders at a fraction of
|
|
36
|
+
* the panel, has a real reason to do the sizing itself.
|
|
37
|
+
*/
|
|
30
38
|
export function viewportSize(umicat) {
|
|
31
39
|
const { dualScreen, top } = umicat.fold.layout;
|
|
32
40
|
if (dualScreen && top)
|
|
@@ -36,25 +44,58 @@ export function viewportSize(umicat) {
|
|
|
36
44
|
/**
|
|
37
45
|
* Starts keeping the page laid out for the fold. Call once, after `init`.
|
|
38
46
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
47
|
+
* **Hand over `renderer` and `camera` and the game needs no other change.** The
|
|
48
|
+
* SDK then re-applies the panel size after every resize — its listener is
|
|
49
|
+
* registered after the game's, so the game's own
|
|
50
|
+
* `setSize(innerWidth, innerHeight)` runs first and is corrected, and a frame
|
|
51
|
+
* is re-applied on the next rAF in case a game registers its listener later.
|
|
41
52
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
53
|
+
* **Leave them out and the canvas is left ALONE.** That is deliberate, and it
|
|
54
|
+
* is a correction: an earlier version moved the canvas's CSS box into the
|
|
55
|
+
* upper panel without owning the buffer, so a game whose resize still asked
|
|
56
|
+
* the window rendered a 669x951 buffer at aspect 0.70 squeezed into a
|
|
57
|
+
* 669x455.5 box — visibly squashed. Half-owning a canvas is worse than not
|
|
58
|
+
* touching it, so now it is one or the other.
|
|
44
59
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
60
|
+
* The control layer moves either way: the SDK built it, so it is always the
|
|
61
|
+
* SDK's to place.
|
|
47
62
|
*/
|
|
48
|
-
export function installDualScreen(umicat,
|
|
49
|
-
|
|
63
|
+
export function installDualScreen(umicat, targets = {}) {
|
|
64
|
+
let current = null;
|
|
65
|
+
const applyCanvas = () => {
|
|
66
|
+
if (!current)
|
|
67
|
+
return;
|
|
68
|
+
if (!targets.renderer) {
|
|
69
|
+
// Box only — the game sizes its own buffer.
|
|
70
|
+
if (targets.canvas)
|
|
71
|
+
placeCanvas(current, targets.canvas);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const size = current.dualScreen && current.top
|
|
75
|
+
? { width: current.top.width, height: current.top.height }
|
|
76
|
+
: { width: window.innerWidth, height: window.innerHeight };
|
|
77
|
+
targets.renderer.setSize(size.width, size.height, false);
|
|
78
|
+
if (targets.camera) {
|
|
79
|
+
targets.camera.aspect = size.width / size.height;
|
|
80
|
+
targets.camera.updateProjectionMatrix();
|
|
81
|
+
}
|
|
82
|
+
placeCanvas(current, targets.renderer.domElement);
|
|
83
|
+
};
|
|
84
|
+
const onResize = () => { applyCanvas(); requestAnimationFrame(applyCanvas); };
|
|
85
|
+
window.addEventListener('resize', onResize);
|
|
86
|
+
const off = umicat.fold.subscribe((layout) => {
|
|
87
|
+
current = layout;
|
|
50
88
|
publishVariables(layout);
|
|
51
|
-
placeCanvas(layout, canvas);
|
|
52
89
|
placeControls(layout);
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
window
|
|
90
|
+
applyCanvas();
|
|
91
|
+
// A game that drives its own canvas still needs to hear about it. Folding
|
|
92
|
+
// is a size change as far as it is concerned, but no window resize
|
|
93
|
+
// accompanies it — the window is exactly as big as it was, the usable part
|
|
94
|
+
// of it is not.
|
|
95
|
+
if (!targets.renderer)
|
|
96
|
+
window.dispatchEvent(new Event('resize'));
|
|
57
97
|
});
|
|
98
|
+
return () => { window.removeEventListener('resize', onResize); off(); };
|
|
58
99
|
}
|
|
59
100
|
function publishVariables(layout) {
|
|
60
101
|
const root = document.documentElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umicat/three-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "Three.js runtime for Umicat games: the scene3d design format, its loader with physics, a kinematic character controller, and the Umicat platform via @umicat/platform-sdk.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|