@mml-io/mml-web-playcanvas-standalone 0.0.0-experimental-edf5cd7-20250120

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2023 Improbable MV Limited
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MML Web PlayCanvas Standalone
2
+ #### `@mml-io/mml-web-playcanvas-standalone`
3
+
4
+ [![npm version](https://img.shields.io/npm/v/@mml-io/mml-web-playcanvas-standalone.svg?style=flat)](https://www.npmjs.com/package/@mml-io/mml-web-playcanvas-standalone)
5
+
6
+ This package contains a class, `StandalonePlayCanvasAdapter`, that is a PlayCanvas-backed Graphics Adapter implementation for `@mml-io/mml-web` that creates:
7
+ * A PlayCanvas App instance
8
+ * with embedded DRACO, Ammo, glglang, and twgsl WASM bundles as base64 encoded strings (to avoid external dependencies at runtime)
9
+ * Orbit and drag-fly controls
10
+ * A factory for MML element graphics instances from the `@mml-io/mml-web-playcanvas` package.
11
+
12
+ It is intended to be used with the following packages:
13
+ * `@mml-io/mml-web`
14
+ * provides the MML element handling and parsing and can use this package as a Graphics Adapter.
15
+
16
+
17
+ ## Example Usage
18
+
19
+ ```typescript
20
+ import { FullScreenMMLScene } from "@mml-io/mml-web";
21
+ import {
22
+ StandalonePlayCanvasAdapter, StandalonePlayCanvasAdapterControlsType,
23
+ } from "@mml-io/mml-web-playcanvas-standalone";
24
+
25
+ // ** This code is not a complete example. See @mml-io/mml-web for more info on how to use an MMLScene **
26
+
27
+ // Create an MML Scene that will act as the container for MML content
28
+ const fullScreenMMLScene = new FullScreenMMLScene<StandalonePlayCanvasAdapter>();
29
+ // Append the element of the MML scene to the page
30
+ document.body.append(fullScreenMMLScene.element);
31
+
32
+ // Provide the element for the renderer to the adapter to attach controls to
33
+ const graphicsAdapter = await StandalonePlayCanvasAdapter.create(fullScreenMMLScene.element, {
34
+ controlsType: StandalonePlayCanvasAdapterControlsType.DragFly,
35
+ });
36
+
37
+ // Provide the Graphics Adapter to the MML Scene to use to render elements
38
+ fullScreenMMLScene.init(graphicsAdapter);
39
+ ```
@@ -0,0 +1,54 @@
1
+ import { Interaction, MMLGraphicsInterface } from "@mml-io/mml-web";
2
+ import { PlayCanvasGraphicsAdapter } from "@mml-io/mml-web-playcanvas";
3
+ import * as playcanvas from "playcanvas";
4
+ import { PlayCanvasControls } from "./controls/PlayCanvasControls";
5
+ export declare enum StandalonePlayCanvasAdapterControlsType {
6
+ None = 0,
7
+ DragFly = 1,
8
+ Orbit = 2
9
+ }
10
+ export type StandalonePlayCanvasAdapterOptions = {
11
+ controlsType?: StandalonePlayCanvasAdapterControlsType;
12
+ };
13
+ export declare class StandalonePlayCanvasAdapter implements PlayCanvasGraphicsAdapter {
14
+ private element;
15
+ private options;
16
+ containerType: playcanvas.Entity;
17
+ collisionType: playcanvas.Entity;
18
+ private playcanvasApp;
19
+ controls: PlayCanvasControls | null;
20
+ private camera;
21
+ private canvas;
22
+ private clickTrigger;
23
+ private constructor();
24
+ getPlayCanvasApp(): playcanvas.AppBase;
25
+ getCamera(): playcanvas.Entity;
26
+ getGraphicsAdapterFactory(): MMLGraphicsInterface<this>;
27
+ static create(element: HTMLElement, options: StandalonePlayCanvasAdapterOptions): Promise<StandalonePlayCanvasAdapter>;
28
+ interactionShouldShowDistance(interaction: Interaction<this>): number | null;
29
+ init(): Promise<void>;
30
+ setControlsType(type?: StandalonePlayCanvasAdapterControlsType): void;
31
+ setCameraFOV(fov: number): null | undefined;
32
+ start(): void;
33
+ getUserPositionAndRotation(): {
34
+ position: {
35
+ x: number;
36
+ y: number;
37
+ z: number;
38
+ };
39
+ rotation: {
40
+ x: number;
41
+ y: number;
42
+ z: number;
43
+ };
44
+ };
45
+ resize(width: number, height: number): void;
46
+ dispose(): void;
47
+ getRootContainer(): playcanvas.Entity;
48
+ getBoundingBoxForElement(element: HTMLElement): {
49
+ x: number;
50
+ y: number;
51
+ width: number;
52
+ height: number;
53
+ } | null;
54
+ }
@@ -0,0 +1,12 @@
1
+ import { IVect3 } from "@mml-io/mml-web";
2
+ export interface PlayCanvasControls {
3
+ type: string;
4
+ enable: () => void;
5
+ disable: () => void;
6
+ fitContent: (boundingBox: {
7
+ min: IVect3;
8
+ max: IVect3;
9
+ }) => void;
10
+ update: (dt: number) => void;
11
+ dispose: () => void;
12
+ }
@@ -0,0 +1,42 @@
1
+ import { IVect3 } from "@mml-io/mml-web";
2
+ import * as playcanvas from "playcanvas";
3
+ export declare class PlayCanvasDragFlyCameraControls {
4
+ readonly type = "drag-fly";
5
+ private enabled;
6
+ private camera;
7
+ private domElement;
8
+ private speed;
9
+ private yaw;
10
+ private pitch;
11
+ private forward;
12
+ private backward;
13
+ private left;
14
+ private right;
15
+ private up;
16
+ private down;
17
+ private minPolarAngle;
18
+ private maxPolarAngle;
19
+ private invertedMouseY;
20
+ private eventHandlerCollection;
21
+ private mouseDown;
22
+ constructor(camera: playcanvas.Entity, domElement: HTMLElement, speed?: number);
23
+ fitContent(boundingBox: {
24
+ min: IVect3;
25
+ max: IVect3;
26
+ }): void;
27
+ enable(): void;
28
+ disable(): void;
29
+ setInvert(invert: boolean): void;
30
+ dispose(): void;
31
+ setCameraPosition(x: number, y: number, z: number): void;
32
+ setLookAt(x: number, y: number, z: number): void;
33
+ update(dt: number): void;
34
+ private onKeyDown;
35
+ private onKeyUp;
36
+ private onBlur;
37
+ private onMouseDown;
38
+ private onMouseMove;
39
+ private updateCameraFromYawAndPitch;
40
+ private onMouseUp;
41
+ private onMouseWheel;
42
+ }
@@ -0,0 +1,39 @@
1
+ import { IVect3 } from "@mml-io/mml-web";
2
+ import * as playcanvas from "playcanvas";
3
+ import { PlayCanvasControls } from "./PlayCanvasControls";
4
+ export declare class PlayCanvasOrbitCameraControls implements PlayCanvasControls {
5
+ private camera;
6
+ private domElement;
7
+ private distance;
8
+ readonly type = "orbit";
9
+ private enabled;
10
+ private degreesPerSecond;
11
+ private yaw;
12
+ private pitch;
13
+ private minPolarAngle;
14
+ private maxPolarAngle;
15
+ private invertedMouseY;
16
+ private eventHandlerCollection;
17
+ private mouseDown;
18
+ private cameraLookAt;
19
+ constructor(camera: playcanvas.Entity, domElement: HTMLElement, distance?: number);
20
+ fitContent(boundingBox: {
21
+ min: IVect3;
22
+ max: IVect3;
23
+ }): void;
24
+ enable(): void;
25
+ disable(): void;
26
+ setInvert(invert: boolean): void;
27
+ dispose(): void;
28
+ private getBaseYaw;
29
+ update(): void;
30
+ private onBlur;
31
+ private onMouseDown;
32
+ setDegreesPerSecond(degreesPerSecond: number): void;
33
+ setLookAt(x: number, y: number, z: number): void;
34
+ setDistance(distance: number): void;
35
+ setPitchDegrees(pitch: number): void;
36
+ private onMouseMove;
37
+ private onMouseUp;
38
+ private onMouseWheel;
39
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./PlayCanvasControls";
2
+ export * from "./PlayCanvasDragFlyCameraControls";
3
+ export * from "./PlayCanvasOrbitCameraControls";
@@ -0,0 +1,2 @@
1
+ export * from "./controls/";
2
+ export * from "./StandalonePlayCanvasAdapter";