@dreamcomposer/engine-types 2.1.1 → 3.0.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.
@@ -0,0 +1,44 @@
1
+ import { CameraPosition } from "./Camera";
2
+
3
+ /**
4
+ * Which camera a screenshot is taken through.
5
+ *
6
+ * - `"current"` shoots what the viewer shows, from the camera the user moved.
7
+ * - `"initial"` shoots the view the project opens with: the engine's default
8
+ * viewing angle, the object's center as the target, and the distance that
9
+ * fits the object into the image.
10
+ * - An explicit position shoots that pose. Anything left out of it is framed
11
+ * the way `"initial"` would frame it, so an empty object is `"initial"`.
12
+ *
13
+ * Everything but `"current"` is rendered through a second camera, so the
14
+ * camera on screen keeps its position and the viewer shows the same frame
15
+ * before and after.
16
+ */
17
+ export type ScreenshotCamera = "current" | "initial" | Partial<CameraPosition>;
18
+
19
+ /**
20
+ * What every screenshot request shares, whatever is done with the image
21
+ * afterwards.
22
+ */
23
+ export interface ScreenshotPayloadBase {
24
+ /**
25
+ * The width of the screenshot. Defaults to the width of the canvas.
26
+ */
27
+ width?: number;
28
+ /**
29
+ * The height of the screenshot. Defaults to the height of the canvas.
30
+ */
31
+ height?: number;
32
+ /**
33
+ * Which camera to shoot through. Defaults to `"current"`.
34
+ */
35
+ camera?: ScreenshotCamera;
36
+ /**
37
+ * A PNG image that is overlaid on top of the screenshot.
38
+ *
39
+ * It is drawn at the screenshot's own size, so it belongs to the framing the
40
+ * shot is taken in - pair it with the default camera rather than with a
41
+ * position the overlay was not captured for.
42
+ */
43
+ overlayPNG?: ImageBitmap;
44
+ }
@@ -0,0 +1,11 @@
1
+ import { FromEngineMessage } from "../post-messages";
2
+
3
+ /**
4
+ * Sent as the very first thing when the engine page starts, before any of
5
+ * its scripts are loaded. It only tells the embedder that the engine is
6
+ * reachable; it is still not allowed to send commands until it receives the
7
+ * `engine-ready` message.
8
+ */
9
+ export interface EngineAliveMessage extends FromEngineMessage<"engine-alive"> {
10
+ payload: true;
11
+ }
@@ -0,0 +1,16 @@
1
+ import { FromEngineMessage } from "../post-messages";
2
+
3
+ /**
4
+ * Sent when the engine fails in a way it cannot recover from on its own.
5
+ *
6
+ * `startup` errors happen before `engine-ready` was sent, i.e. the engine will
7
+ * never become ready. `runtime` errors happen afterwards and leave the engine
8
+ * unusable, e.g. a lost WebGL context that is not restored.
9
+ */
10
+ export interface EngineErrorMessage extends FromEngineMessage<"engine-error"> {
11
+ payload: {
12
+ phase: "startup" | "runtime";
13
+ /** A technical description for logs, not meant to be shown to users. */
14
+ message: string;
15
+ };
16
+ }
@@ -0,0 +1,27 @@
1
+ import { FromEngineMessage } from "../post-messages";
2
+
3
+ /**
4
+ * The image of a `take-screenshot` message.
5
+ *
6
+ * It is sent before the ack of that message.
7
+ */
8
+ export interface ScreenshotImageMessage extends FromEngineMessage<"screenshot-image"> {
9
+ payload: {
10
+ /**
11
+ * The `requestId` of the `take-screenshot` message this image belongs to.
12
+ */
13
+ requestId: string;
14
+ /**
15
+ * The height of the image.
16
+ */
17
+ height: number;
18
+ /**
19
+ * The width of the image.
20
+ */
21
+ width: number;
22
+ /**
23
+ * The base64 encoded image in the PNG format, as a data URL.
24
+ */
25
+ data: string;
26
+ };
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamcomposer/engine-types",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "description": "The type definitions for messages from and to the engine",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -1,5 +1,6 @@
1
1
  import { AckMessage } from "./from-engine/AckMessage";
2
- import { CanvasImageUrlMessage } from "./from-engine/CanvasImageUrlMessage";
2
+ import { EngineAliveMessage } from "./from-engine/EngineAliveMessage";
3
+ import { EngineErrorMessage } from "./from-engine/EngineErrorMessage";
3
4
  import { EngineReadyMessage } from "./from-engine/EngineReadyMessage";
4
5
  import { KeyDownMessage } from "./from-engine/KeyDownMessage";
5
6
  import { SetLoadingProgressMessage } from "./from-engine/SetLoadingProgressMessage";
@@ -56,6 +57,8 @@ import { SetAnnotationTagsMessage } from "./to-engine/SetAnnotationTagsMessage";
56
57
  import { SetCustomRequestHeaders } from "./to-engine/SetCustomRequestHeaders";
57
58
  import { SetObjectForScaleMessage } from "./to-engine/SetObjectForScaleMessage";
58
59
  import { ExportSceneMessage } from "./to-engine/ExportSceneMessage";
60
+ import { ScreenshotImageMessage } from "./from-engine/ScreenshotImageMessage";
61
+ import { TakeScreenshotMessage } from "./to-engine/TakeScreenshotMessage";
59
62
 
60
63
  /**
61
64
  * A message sent from the engine to the embedder.
@@ -80,8 +83,9 @@ export interface ToEngineMessage<Channel> {
80
83
 
81
84
  export type FromEnginePostMessage =
82
85
  | AckMessage
83
- | CanvasImageUrlMessage
84
86
  | DisplayLoadingUiMessage
87
+ | EngineAliveMessage
88
+ | EngineErrorMessage
85
89
  | EngineReadyMessage
86
90
  | HideGuiMessage
87
91
  | HideLoadingUiMessage
@@ -93,10 +97,12 @@ export type FromEnginePostMessage =
93
97
  | CameraPositionChangeMessage
94
98
  | EnvironmentRotationChangedMessage
95
99
  | GeometryTransformChangeMessage
96
- | AnnotationTagPositionChangedMessage;
100
+ | AnnotationTagPositionChangedMessage
101
+ | ScreenshotImageMessage;
97
102
 
98
103
  export type ToEnginePostMessage =
99
104
  | DownloadScreenshotMessage
105
+ | TakeScreenshotMessage
100
106
  | HighlightLayerMessage
101
107
  | MouseEventMessage
102
108
  | ResetCameraPositionMessage
@@ -1,20 +1,18 @@
1
+ import { ScreenshotPayloadBase } from "../Screenshot";
1
2
  import { ToEngineMessage } from "../post-messages";
2
3
 
3
- export interface ScreenshotPayload {
4
+ export interface ScreenshotPayload extends ScreenshotPayloadBase {
5
+ /**
6
+ * The name of the file to download the screenshot as.
7
+ */
4
8
  fileName: string;
5
- overlayPNG?: ImageBitmap;
6
- width?: number;
7
- height?: number;
8
9
  }
9
10
 
10
11
  /**
11
- * Downloads a high-resolution screenshot of the current scene.
12
+ * Downloads a screenshot of the scene.
12
13
  *
13
14
  * The download starts automatically once the screenshot has been rendered.
14
15
  */
15
16
  export interface DownloadScreenshotMessage extends ToEngineMessage<"download-screenshot"> {
16
- /**
17
- * An empty object.
18
- */
19
17
  payload: ScreenshotPayload;
20
18
  }
@@ -0,0 +1,18 @@
1
+ import { ScreenshotPayloadBase } from "../Screenshot";
2
+ import { ToEngineMessage } from "../post-messages";
3
+
4
+ export interface TakeScreenshotPayload extends ScreenshotPayloadBase {
5
+ /**
6
+ * An id that the engine echoes back in the `screenshot-image` message, so
7
+ * that an embedder with several screenshots in flight can tell them apart.
8
+ */
9
+ requestId: string;
10
+ }
11
+
12
+ /**
13
+ * Renders a screenshot of the scene and sends the image back
14
+ * in a `screenshot-image` message, which arrives before the ack of this one.
15
+ */
16
+ export interface TakeScreenshotMessage extends ToEngineMessage<"take-screenshot"> {
17
+ payload: TakeScreenshotPayload;
18
+ }
@@ -1,26 +0,0 @@
1
- import { FromEngineMessage, ToEngineMessage } from "../post-messages";
2
-
3
- /**
4
- * A screenshot of the canvas that is sent to the embedder when the heatmap
5
- * collection is stopped.
6
- *
7
- * The screenshot is used by the embedder to draw the heatmap over it.
8
- */
9
- // TODO: This should have another name to make it clear it's related to the
10
- // heat map collection.
11
- export interface CanvasImageUrlMessage extends FromEngineMessage<"canvas-image-url"> {
12
- payload: {
13
- /**
14
- * The height of the image.
15
- */
16
- height: number;
17
- /**
18
- * The width of the image.
19
- */
20
- width: number;
21
- /**
22
- * The base64 encoded image in the PNG format.
23
- */
24
- data: string;
25
- };
26
- }