bg2e-js 2.0.1 → 2.1.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/bg2e-js.js +11005 -0
- package/dist/bg2e-js.js.map +1 -0
- package/package.json +17 -6
- package/app/AppController.d.ts +0 -37
- package/app/AppController.js +0 -32
- package/app/Canvas.d.ts +0 -42
- package/app/Canvas.js +0 -98
- package/app/EventBase.js +0 -8
- package/app/KeyboardEvent.js +0 -51
- package/app/MainLoop.d.ts +0 -245
- package/app/MainLoop.js +0 -251
- package/app/MouseEvent.js +0 -77
- package/app/TouchEvent.js +0 -15
- package/base/Color.js +0 -131
- package/base/Environment.js +0 -78
- package/base/Light.js +0 -176
- package/base/Material.js +0 -619
- package/base/PolyList.js +0 -336
- package/base/Texture.js +0 -545
- package/db/Bg2LoaderPlugin.js +0 -113
- package/db/DBPluginApi.js +0 -40
- package/db/Loader.js +0 -91
- package/db/LoaderPlugin.js +0 -26
- package/db/MtlParser.js +0 -7
- package/db/ObjLoaderPlugin.js +0 -51
- package/db/ObjParser.js +0 -233
- package/db/ObjWriterPlugin.js +0 -18
- package/db/VitscnjLoaderPlugin.js +0 -87
- package/db/Writer.js +0 -49
- package/db/WriterPlugin.js +0 -20
- package/debug/DebugRenderer.js +0 -138
- package/debug/WebGLTextureViewer.js +0 -67
- package/manipulation/SelectionBuffer.js +0 -65
- package/manipulation/SelectionHighlight.js +0 -69
- package/manipulation/SelectionIdAssignVisitor.js +0 -86
- package/manipulation/SelectionManager.js +0 -134
- package/manipulation/SelectionMode.js +0 -6
- package/math/Mat3.js +0 -248
- package/math/Mat4.js +0 -694
- package/math/MatrixStrategy.js +0 -23
- package/math/Quat.js +0 -60
- package/math/Vec.js +0 -728
- package/math/constants.js +0 -44
- package/math/functions.js +0 -104
- package/math/index.js +0 -74
- package/phsics/joint.js +0 -124
- package/primitives/arrow.js +0 -58
- package/primitives/cone.js +0 -137
- package/primitives/cube.js +0 -59
- package/primitives/cylinder.js +0 -215
- package/primitives/index.js +0 -13
- package/primitives/plane.js +0 -31
- package/primitives/sphere.js +0 -808
- package/render/BRDFIntegrationMap.js +0 -4
- package/render/Environment.js +0 -105
- package/render/EnvironmentRenderer.js +0 -12
- package/render/FrameBuffer.js +0 -26
- package/render/MaterialRenderer.js +0 -28
- package/render/Pipeline.js +0 -83
- package/render/PolyListRenderer.js +0 -42
- package/render/RenderBuffer.js +0 -189
- package/render/RenderQueue.js +0 -162
- package/render/RenderState.js +0 -82
- package/render/Renderer.js +0 -202
- package/render/SceneAppController.js +0 -208
- package/render/SceneRenderer.js +0 -310
- package/render/Shader.js +0 -21
- package/render/ShadowRenderer.js +0 -159
- package/render/SkyCube.js +0 -77
- package/render/SkySphere.js +0 -94
- package/render/TextureMergerRenderer.js +0 -58
- package/render/TextureRenderer.js +0 -29
- package/render/webgl/FrameBuffer.js +0 -9
- package/render/webgl/MaterialRenderer.js +0 -99
- package/render/webgl/Pipeline.js +0 -82
- package/render/webgl/PolyListRenderer.js +0 -224
- package/render/webgl/RenderBuffer.js +0 -244
- package/render/webgl/Renderer.js +0 -239
- package/render/webgl/SceneRenderer.js +0 -43
- package/render/webgl/ShaderProgram.js +0 -350
- package/render/webgl/ShadowRenderer.js +0 -6
- package/render/webgl/SkyCube.js +0 -15
- package/render/webgl/SkySphere.js +0 -14
- package/render/webgl/State.js +0 -149
- package/render/webgl/TextureRenderer.js +0 -167
- package/render/webgl/VertexBuffer.js +0 -128
- package/scene/Camera.js +0 -378
- package/scene/Chain.js +0 -43
- package/scene/ChainJoint.js +0 -55
- package/scene/Component.js +0 -146
- package/scene/ComponentMap.js +0 -99
- package/scene/Drawable.js +0 -130
- package/scene/EnvironmentComponent.js +0 -123
- package/scene/FindNodeVisitor.js +0 -55
- package/scene/LightComponent.js +0 -146
- package/scene/MatrixState.js +0 -39
- package/scene/Node.js +0 -300
- package/scene/NodeVisitor.js +0 -12
- package/scene/OrbitCameraController.js +0 -407
- package/scene/SmoothOrbitCameraController.js +0 -92
- package/scene/Transform.js +0 -74
- package/scene/index.js +0 -24
- package/shaders/BasicDiffuseColorShader.js +0 -91
- package/shaders/BasicPBRLightShader.js +0 -238
- package/shaders/DebugRenderShader.js +0 -79
- package/shaders/DepthRenderShader.js +0 -69
- package/shaders/IrradianceMapCubeShader.js +0 -99
- package/shaders/PBRLightIBLShader.js +0 -380
- package/shaders/PickSelectionShader.js +0 -75
- package/shaders/PresentDebugFramebufferShader.js +0 -90
- package/shaders/PresentTextureShader.js +0 -73
- package/shaders/SelectionHighlightShader.js +0 -98
- package/shaders/ShaderFunction.js +0 -72
- package/shaders/SkyCubeShader.js +0 -78
- package/shaders/SkySphereShader.js +0 -77
- package/shaders/SpecularMapCubeShader.js +0 -145
- package/shaders/TextureMergerShader.js +0 -127
- package/shaders/webgl_shader_lib.js +0 -187
- package/tools/BinaryResourceProvider.js +0 -15
- package/tools/ImageResourceProvider.js +0 -65
- package/tools/MaterialModifier.js +0 -228
- package/tools/Resource.js +0 -177
- package/tools/ResourceProvider.js +0 -56
- package/tools/TextResourceProvider.js +0 -24
- package/tools/TextureCache.js +0 -44
- package/tools/TextureResourceDatabase.js +0 -87
- package/tools/UserAgent.js +0 -294
- package/tools/VideoResourceProvider.js +0 -51
- package/tools/WriteStrategy.js +0 -22
- package/tools/base64.js +0 -15
- package/tools/crypto.js +0 -15
- package/tools/endiantess.js +0 -15
- package/tools/image.js +0 -15
- package/tools/index.js +0 -33
- package/tools/processType.js +0 -56
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bg2e-js",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "a graphics engine for productivity applications",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "./dist/bg2e-js.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/bg2e-js.js",
|
|
8
|
+
"dist/bg2e-js.js.map"
|
|
9
|
+
],
|
|
10
|
+
"module": "./dist/bg2e-js.js",
|
|
6
11
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "vite build --watch --emptyOutDir",
|
|
14
|
+
"build": "vite build --emptyOutDir"
|
|
9
15
|
},
|
|
10
|
-
"scripts": {},
|
|
11
16
|
"repository": {
|
|
12
17
|
"type": "git",
|
|
13
18
|
"url": "git+https://github.com/ferserc1/bg2e-js.git"
|
|
@@ -23,5 +28,11 @@
|
|
|
23
28
|
"bugs": {
|
|
24
29
|
"url": "https://github.com/ferserc1/bg2e-js/issues"
|
|
25
30
|
},
|
|
26
|
-
"homepage": "https://github.com/ferserc1/bg2e-js#readme"
|
|
31
|
+
"homepage": "https://github.com/ferserc1/bg2e-js#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"bg2io": "^1.0.7"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"vite": "^7.1.5"
|
|
37
|
+
}
|
|
27
38
|
}
|
package/app/AppController.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import MainLoop from './MainLoop';
|
|
3
|
-
import Canvas from './Canvas';
|
|
4
|
-
import MouseEvent from './MouseEvent';
|
|
5
|
-
import TouchEvent from './TouchEvent';
|
|
6
|
-
import KeyboardEvent from './KeyboardEvent';
|
|
7
|
-
import Renderer from '../render/Renderer';
|
|
8
|
-
|
|
9
|
-
export default class AppController {
|
|
10
|
-
constructor();
|
|
11
|
-
|
|
12
|
-
get mainLoop() ; MainLoop;
|
|
13
|
-
set mainLoop(ml: MainLoop);
|
|
14
|
-
|
|
15
|
-
get canvas() : Canvas;
|
|
16
|
-
|
|
17
|
-
get renderer() : Renderer;
|
|
18
|
-
|
|
19
|
-
get viewport() : { width: number, height: number, aspectRatio: number };
|
|
20
|
-
|
|
21
|
-
async init();
|
|
22
|
-
reshape(width: number, height: number);
|
|
23
|
-
async frame(delta: number);
|
|
24
|
-
display();
|
|
25
|
-
destroy();
|
|
26
|
-
keyDown(evt: KeyboardEvent);
|
|
27
|
-
keyUp(evt: KeyboardEvent);
|
|
28
|
-
mouseUp(evt: MouseEvent);
|
|
29
|
-
mouseDown(evt: MouseEvent);
|
|
30
|
-
mouseMove(evt: MouseEvent);
|
|
31
|
-
mouseOut(evt: MouseEvent);
|
|
32
|
-
mouseDrag(evt: MouseEvent);
|
|
33
|
-
mouseWheel(evt: MouseEvent);
|
|
34
|
-
touchStart(evt: TouchEvent);
|
|
35
|
-
touchMove(evt: TouchEvent);
|
|
36
|
-
touchEnd(evt: TouchEvent);
|
|
37
|
-
}
|
package/app/AppController.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default class AppController {
|
|
3
|
-
constructor() {
|
|
4
|
-
this._mainLoop = null;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
get mainLoop() { return this._mainLoop; }
|
|
8
|
-
set mainLoop(ml) { this._mainLoop = ml; }
|
|
9
|
-
|
|
10
|
-
get canvas() { return this._mainLoop?.canvas; }
|
|
11
|
-
|
|
12
|
-
get renderer() { return this._mainLoop?.canvas?.renderer; }
|
|
13
|
-
|
|
14
|
-
get viewport() { return this.canvas?.viewport || { width: 0, height: 0, aspectRatio: 0 }; }
|
|
15
|
-
|
|
16
|
-
async init() {}
|
|
17
|
-
reshape(width,height) {}
|
|
18
|
-
async frame(delta) {}
|
|
19
|
-
display() {}
|
|
20
|
-
destroy() {}
|
|
21
|
-
keyDown(evt) {}
|
|
22
|
-
keyUp(evt) {}
|
|
23
|
-
mouseUp(evt) {}
|
|
24
|
-
mouseDown(evt) {}
|
|
25
|
-
mouseMove(evt) {}
|
|
26
|
-
mouseOut(evt) {}
|
|
27
|
-
mouseDrag(evt) {}
|
|
28
|
-
mouseWheel(evt) {}
|
|
29
|
-
touchStart(evt) {}
|
|
30
|
-
touchMove(evt) {}
|
|
31
|
-
touchEnd(evt) {}
|
|
32
|
-
}
|
package/app/Canvas.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { MainLoop } from './MainLoop';
|
|
3
|
-
|
|
4
|
-
export type Touch = {
|
|
5
|
-
identifier: number
|
|
6
|
-
x: number
|
|
7
|
-
y: number
|
|
8
|
-
force: number
|
|
9
|
-
rotationAngle: number
|
|
10
|
-
radiusX: number
|
|
11
|
-
radiusY: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export declare function getMouseEventOffset(evt: any, canvas: Canvas) : { x: number, y: number };
|
|
15
|
-
|
|
16
|
-
export declare function getEventTouches(evt: any, canvas: Canvas) : Touch[];
|
|
17
|
-
|
|
18
|
-
export default class Canvas {
|
|
19
|
-
static FirstCanvas() : Canvas;
|
|
20
|
-
|
|
21
|
-
constructor(domElement: HTMLElement, renderer: any);
|
|
22
|
-
|
|
23
|
-
get id() : string;
|
|
24
|
-
|
|
25
|
-
async init() : Promise<void>;
|
|
26
|
-
|
|
27
|
-
get mainLoop() : MainLoop;
|
|
28
|
-
|
|
29
|
-
get renderer() { return this._renderer; }
|
|
30
|
-
|
|
31
|
-
get domElement() { return this._domElement; }
|
|
32
|
-
|
|
33
|
-
get width() { return this._domElement.clientWidth; }
|
|
34
|
-
|
|
35
|
-
get height() { return this._domElement.clientHeight; }
|
|
36
|
-
|
|
37
|
-
get viewport() { return { width: this.width, height: this.height, aspectRatio: this.width / this.height }; }
|
|
38
|
-
|
|
39
|
-
updateViewportSize() : void;
|
|
40
|
-
|
|
41
|
-
screenshot(format: string, width: number, height: number);
|
|
42
|
-
}
|
package/app/Canvas.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { generateUUID } from "../tools/crypto";
|
|
2
|
-
|
|
3
|
-
export const getMouseEventOffset = (evt,canvas) => {
|
|
4
|
-
const offset = canvas.domElement.getBoundingClientRect();
|
|
5
|
-
return {
|
|
6
|
-
x: evt.clientX - offset.left,
|
|
7
|
-
y: evt.clientY - offset.top
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const getEventTouches = (evt,canvas) => {
|
|
12
|
-
const offset = canvas.domElement.getBoundingClientRect();
|
|
13
|
-
const touches = Array.from(evt.touches).map(touch => {
|
|
14
|
-
return {
|
|
15
|
-
identifier: touch.identifier,
|
|
16
|
-
x: touch.clientX - offset.left,
|
|
17
|
-
y: touch.clientY - offset.top,
|
|
18
|
-
force: touch.force,
|
|
19
|
-
rotationAngle: touch.rotationAngle,
|
|
20
|
-
radiusX: touch.radiusX,
|
|
21
|
-
radiusY: touch.radiusY
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
return touches;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let g_firstCanvas = null;
|
|
28
|
-
|
|
29
|
-
export default class Canvas {
|
|
30
|
-
static FirstCanvas() {
|
|
31
|
-
return g_firstCanvas;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
constructor(domElement,renderer) {
|
|
35
|
-
this._renderer = renderer;
|
|
36
|
-
this._domElement = domElement;
|
|
37
|
-
this._domElement._bg2e_id = generateUUID();
|
|
38
|
-
|
|
39
|
-
g_firstCanvas = g_firstCanvas || this;
|
|
40
|
-
|
|
41
|
-
// Initialized in mainLoop constructor
|
|
42
|
-
this._mainLoop = null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get id() {
|
|
46
|
-
return this._domElement._bg2e_id;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async init() {
|
|
50
|
-
await this._renderer.init(this);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get mainLoop() { return this._mainLoop; }
|
|
54
|
-
|
|
55
|
-
get renderer() { return this._renderer; }
|
|
56
|
-
|
|
57
|
-
get domElement() { return this._domElement; }
|
|
58
|
-
|
|
59
|
-
get width() { return this._domElement.clientWidth; }
|
|
60
|
-
|
|
61
|
-
get height() { return this._domElement.clientHeight; }
|
|
62
|
-
|
|
63
|
-
get viewport() { return { width: this.width, height: this.height, aspectRatio: this.width / this.height }; }
|
|
64
|
-
|
|
65
|
-
updateViewportSize() {
|
|
66
|
-
const sizeInPx = { w: this.domElement.clientWidth, h: this.domElement.clientHeight };
|
|
67
|
-
this.domElement.width = sizeInPx.w * window.devicePixelRatio;
|
|
68
|
-
this.domElement.height = sizeInPx.h * window.devicePixelRatio;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
screenshot(format, width, height) {
|
|
72
|
-
let canvasStyle = "";
|
|
73
|
-
const prevSize = {};
|
|
74
|
-
|
|
75
|
-
if (width) {
|
|
76
|
-
height = height ? height : width;
|
|
77
|
-
canvasStyle = this.domElement.style.cssText;
|
|
78
|
-
prevSize.width = this.domElement.width;
|
|
79
|
-
prevSize.height = this.domElement.height;
|
|
80
|
-
|
|
81
|
-
this.domElement.style.cssText = `top:auto;left:auto;bottom:auto;right:auto;width:${width}px;height:${height}px;`;
|
|
82
|
-
this.domElement.width = width;
|
|
83
|
-
this.domElement.height = height;
|
|
84
|
-
this.mainLoop.appController.reshape(width,height);
|
|
85
|
-
this.mainLoop.appController.display();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const data = this.domElement.toDataURL(format);
|
|
89
|
-
if (width) {
|
|
90
|
-
this.domElement.cssText = canvasStyle;
|
|
91
|
-
this.domElement.width = prevSize.width;
|
|
92
|
-
this.domElement.height = prevSize.height;
|
|
93
|
-
this.mainLoop.appController.reshape(prevSize.width, prevSize.heigth);
|
|
94
|
-
this.mainLoop.appController.display();
|
|
95
|
-
}
|
|
96
|
-
return data;
|
|
97
|
-
}
|
|
98
|
-
}
|
package/app/EventBase.js
DELETED
package/app/KeyboardEvent.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import EventBase from "./EventBase";
|
|
2
|
-
|
|
3
|
-
export const SpecialKey = {
|
|
4
|
-
BACKSPACE: "Backspace",
|
|
5
|
-
TAB: "Tab",
|
|
6
|
-
ENTER: "Enter",
|
|
7
|
-
SHIFT: "Shift",
|
|
8
|
-
SHIFT_LEFT: "ShiftLeft",
|
|
9
|
-
SHIFT_RIGHT: "ShiftRight",
|
|
10
|
-
CTRL: "Control",
|
|
11
|
-
CTRL_LEFT: "ControlLeft",
|
|
12
|
-
CTRL_LEFT: "ControlRight",
|
|
13
|
-
ALT: "Alt",
|
|
14
|
-
ALT_LEFT: "AltLeft",
|
|
15
|
-
ALT_RIGHT: "AltRight",
|
|
16
|
-
PAUSE: "Pause",
|
|
17
|
-
CAPS_LOCK: "CapsLock",
|
|
18
|
-
ESCAPE: "Escape",
|
|
19
|
-
PAGE_UP: "PageUp",
|
|
20
|
-
PAGEDOWN: "PageDown",
|
|
21
|
-
END: "End",
|
|
22
|
-
HOME: "Home",
|
|
23
|
-
LEFT_ARROW: "ArrowLeft",
|
|
24
|
-
UP_ARROW: "ArrowUp",
|
|
25
|
-
RIGHT_ARROW: "ArrowRight",
|
|
26
|
-
DOWN_ARROW: "ArrowDown",
|
|
27
|
-
INSERT: "Insert",
|
|
28
|
-
DELETE: "Delete",
|
|
29
|
-
SPACE: "Space"
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const createKeyboardEvent = (evt) => {
|
|
33
|
-
const code = SpecialKey[evt.code] != null ? evt.keyCode : evt.code;
|
|
34
|
-
return new KeyboardEvent(code, evt);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default class KeyboardEvent extends EventBase {
|
|
38
|
-
static IsSpecialKey(event) {
|
|
39
|
-
return SpecialKey[event.code]!=null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
constructor(key,event) {
|
|
43
|
-
super();
|
|
44
|
-
this.key = key;
|
|
45
|
-
this.event = event;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get isSpecialKey() {
|
|
49
|
-
return KeyboardEvent.IsSpecialKey(this.event);
|
|
50
|
-
}
|
|
51
|
-
}
|
package/app/MainLoop.d.ts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Canvas } from "./Canvas";
|
|
3
|
-
import { AppController } from "./AppController";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
MouseButtonEventType,
|
|
7
|
-
createMouseEvent,
|
|
8
|
-
leftMouseButton,
|
|
9
|
-
middleMouseButton,
|
|
10
|
-
clearMouseButtons,
|
|
11
|
-
setMouseButton
|
|
12
|
-
} from "./MouseEvent";
|
|
13
|
-
import { createTouchEvent } from "./TouchEvent";
|
|
14
|
-
import { createKeyboardEvent } from "./KeyboardEvent";
|
|
15
|
-
|
|
16
|
-
export const FrameUpdate = {
|
|
17
|
-
AUTO: 0,
|
|
18
|
-
MANUAL: 1
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const g_animationLoop = {
|
|
22
|
-
lastTime: 0,
|
|
23
|
-
mainLoop: []
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
async function animationLoop(totalTime) {
|
|
27
|
-
totalTime = totalTime || 0;
|
|
28
|
-
requestAnimationFrame(animationLoop);
|
|
29
|
-
const elapsed = totalTime - g_animationLoop.lastTime;
|
|
30
|
-
g_animationLoop.lastTime = totalTime;
|
|
31
|
-
for (const ml of g_animationLoop.mainLoop) {
|
|
32
|
-
await onUpdate(ml, elapsed);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
class MouseStatus {
|
|
37
|
-
constructor() {
|
|
38
|
-
this.pos = {x: 0, y: 0};
|
|
39
|
-
this.leftButton = false;
|
|
40
|
-
this.middleButton = false;
|
|
41
|
-
this.rightButton = false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get anyButton() { return this.leftButton || this.middleButton || this.rightButton; }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default class MainLoop {
|
|
48
|
-
constructor(canvas: Canvas, appController: AppController);
|
|
49
|
-
|
|
50
|
-
get canvas() : Canvas;
|
|
51
|
-
get appController() : AppController;
|
|
52
|
-
get renderer() { return this._canvas?.renderer; }
|
|
53
|
-
|
|
54
|
-
get updateMode() { return this._updateMode; }
|
|
55
|
-
set updateMode(um) { this._updateMode = um; }
|
|
56
|
-
|
|
57
|
-
get mouseStatus() { return this._mouseStatus; }
|
|
58
|
-
|
|
59
|
-
get redisplay() { return this._redisplayFrames>0; }
|
|
60
|
-
|
|
61
|
-
async run() {
|
|
62
|
-
await this.canvas.init();
|
|
63
|
-
await this.appController.init();
|
|
64
|
-
initEvents(this);
|
|
65
|
-
g_animationLoop.mainLoop.push(this);
|
|
66
|
-
animationLoop();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exit() {
|
|
70
|
-
this.appController.destroy();
|
|
71
|
-
const i = g_animationLoop.mainLoop.indexOf(this);
|
|
72
|
-
if (i!==-1) {
|
|
73
|
-
g_animationLoop.mainLoop.splice(i,1);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
postReshape() {
|
|
78
|
-
onResize(this);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
postRedisplay({ frames=2,timeout=10 } = {}) {
|
|
82
|
-
if (timeout <= 0) {
|
|
83
|
-
this._redisplayFrames = frames;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
setTimeout(() => this._redisplayFrames = frames, timeout);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
function initEvents(mainLoop) {
|
|
93
|
-
onResize(mainLoop);
|
|
94
|
-
|
|
95
|
-
const handlePropagation = (bgEvt,evt) => {
|
|
96
|
-
if (bgEvt.isEventPropagationStopped) {
|
|
97
|
-
evt.stopPropagation();
|
|
98
|
-
evt.preventDefault();
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const c = mainLoop.canvas.domElement;
|
|
105
|
-
c.__mainLoop = mainLoop;
|
|
106
|
-
c.addEventListener("mousedown", evt => {
|
|
107
|
-
return handlePropagation(onMouseDown(evt, evt.target.__mainLoop), evt);
|
|
108
|
-
});
|
|
109
|
-
c.addEventListener("mousemove", evt => {
|
|
110
|
-
return handlePropagation(onMouseMove(evt, evt.target.__mainLoop), evt);
|
|
111
|
-
});
|
|
112
|
-
c.addEventListener("mouseout", evt => {
|
|
113
|
-
return handlePropagation(onMouseOut(evt, evt.target.__mainLoop), evt);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
c.addEventListener("mouseover", evt => {
|
|
117
|
-
return handlePropagation(onMouseOver(evt, evt.target.__mainLoop), evt);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
c.addEventListener("mouseup", evt => {
|
|
121
|
-
return handlePropagation(onMouseUp(evt, evt.target.__mainLoop), evt);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
c.addEventListener("touchstart", evt => {
|
|
125
|
-
return handlePropagation(onTouchStart(evt, evt.target.__mainLoop), evt);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
c.addEventListener("touchmove", evt => {
|
|
129
|
-
return handlePropagation(onTouchMove(evt, evt.target.__mainLoop), evt);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
c.addEventListener("touchend", evt => {
|
|
133
|
-
return handlePropagation(onTouchEnd(evt, evt.target.__mainLoop), evt);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const mouseWheelEvt = (/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel";
|
|
137
|
-
c.addEventListener(mouseWheelEvt, evt => {
|
|
138
|
-
return handlePropagation(onMouseWheel(evt, evt.target.__mainLoop), evt);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
window.addEventListener("keydown", evt => {
|
|
142
|
-
g_animationLoop.mainLoop.forEach(ml => onKeyDown(evt, ml));
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
window.addEventListener("keyup", evt => {
|
|
146
|
-
g_animationLoop.mainLoop.forEach(ml => onKeyUp(evt, ml));
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
window.addEventListener("resize", evt => {
|
|
150
|
-
onResize(mainLoop);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
c.oncontextmenu = evt => false;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function onResize(mainLoop) {
|
|
157
|
-
const dpi = window.devicePixelRatio;
|
|
158
|
-
mainLoop.appController.reshape(mainLoop.canvas.width * dpi, mainLoop.canvas.height * dpi);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async function onUpdate(mainLoop, elapsed) {
|
|
162
|
-
if (mainLoop.redisplay) {
|
|
163
|
-
if (mainLoop.updateMode === FrameUpdate.AUTO) {
|
|
164
|
-
mainLoop._redisplayFrames = 1;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
mainLoop._redisplayFrames--;
|
|
168
|
-
}
|
|
169
|
-
if (mainLoop._redisplayFrames > 0) {
|
|
170
|
-
await mainLoop.appController.frame(elapsed);
|
|
171
|
-
mainLoop.appController.display();
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function onMouseDown(evt,mainLoop) {
|
|
177
|
-
const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.DOWN);
|
|
178
|
-
setMouseButton(bg2Event, true);
|
|
179
|
-
mainLoop.appController.mouseDown(bg2Event);
|
|
180
|
-
return bg2Event;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function onMouseMove(evt,mainLoop) {
|
|
184
|
-
const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.NONE);
|
|
185
|
-
mainLoop.appController.mouseMove(bg2Event);
|
|
186
|
-
if (mainLoop.mouseStatus.anyButton) {
|
|
187
|
-
mainLoop.appController.mouseDrag(bg2Event);
|
|
188
|
-
}
|
|
189
|
-
return bg2Event;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function onMouseOut(evt,mainLoop) {
|
|
193
|
-
const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.NONE);
|
|
194
|
-
clearMouseButtons();
|
|
195
|
-
mainLoop.appController.mouseOut(bg2Event);
|
|
196
|
-
return bg2Event;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function onMouseOver(evt,mainLoop) {
|
|
200
|
-
return onMouseMove(evt,mainLoop)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function onMouseUp(evt,mainLoop) {
|
|
204
|
-
const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.UP);
|
|
205
|
-
setMouseButton(bg2Event, false);
|
|
206
|
-
mainLoop.appController.mouseUp(bg2Event);
|
|
207
|
-
return bg2Event;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function onMouseWheel(evt,mainLoop) {
|
|
211
|
-
const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.NONE);
|
|
212
|
-
bg2Event.delta = evt.wheelDelta ? evt.wheelDelta * -1 : evt.detail * 10;
|
|
213
|
-
mainLoop.appController.mouseWheel(bg2Event);
|
|
214
|
-
return bg2Event;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function onTouchStart(evt,mainLoop) {
|
|
218
|
-
const bgEvent = createTouchEvent(evt,mainLoop);
|
|
219
|
-
mainLoop.appController.touchStart(bgEvent);
|
|
220
|
-
return bgEvent;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function onTouchMove(evt,mainLoop) {
|
|
224
|
-
const bgEvent = createTouchEvent(evt,mainLoop);
|
|
225
|
-
mainLoop.appController.touchMove(bgEvent);
|
|
226
|
-
return bgEvent;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function onTouchEnd(evt,mainLoop) {
|
|
230
|
-
const bgEvent = createTouchEvent(evt,mainLoop);
|
|
231
|
-
mainLoop.appController.touchEnd(bgEvent);
|
|
232
|
-
return bgEvent;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function onKeyDown(evt,mainLoop) {
|
|
236
|
-
const bgEvent = createKeyboardEvent(evt);
|
|
237
|
-
mainLoop.appController.keyDown(bgEvent);
|
|
238
|
-
return bgEvent;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function onKeyUp(evt,mainLoop) {
|
|
242
|
-
const bgEvent = createKeyboardEvent(evt);
|
|
243
|
-
mainLoop.appController.keyUp(bgEvent);
|
|
244
|
-
return bgEvent;
|
|
245
|
-
}
|