bg2e-js 2.0.0 → 2.0.2

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.
Files changed (132) hide show
  1. package/dist/bg2e-js.js +11001 -0
  2. package/dist/bg2e-js.js.map +1 -0
  3. package/package.json +17 -6
  4. package/app/AppController.js +0 -32
  5. package/app/Canvas.js +0 -98
  6. package/app/EventBase.js +0 -8
  7. package/app/KeyboardEvent.js +0 -51
  8. package/app/MainLoop.js +0 -251
  9. package/app/MouseEvent.js +0 -77
  10. package/app/TouchEvent.js +0 -15
  11. package/base/Color.js +0 -131
  12. package/base/Environment.js +0 -78
  13. package/base/Light.js +0 -176
  14. package/base/Material.js +0 -619
  15. package/base/PolyList.js +0 -336
  16. package/base/Texture.js +0 -545
  17. package/db/Bg2LoaderPlugin.js +0 -113
  18. package/db/DBPluginApi.js +0 -40
  19. package/db/Loader.js +0 -91
  20. package/db/LoaderPlugin.js +0 -26
  21. package/db/MtlParser.js +0 -7
  22. package/db/ObjLoaderPlugin.js +0 -51
  23. package/db/ObjParser.js +0 -233
  24. package/db/ObjWriterPlugin.js +0 -18
  25. package/db/VitscnjLoaderPlugin.js +0 -87
  26. package/db/Writer.js +0 -49
  27. package/db/WriterPlugin.js +0 -20
  28. package/debug/DebugRenderer.js +0 -138
  29. package/debug/WebGLTextureViewer.js +0 -67
  30. package/manipulation/SelectionBuffer.js +0 -65
  31. package/manipulation/SelectionHighlight.js +0 -69
  32. package/manipulation/SelectionIdAssignVisitor.js +0 -86
  33. package/manipulation/SelectionManager.js +0 -134
  34. package/manipulation/SelectionMode.js +0 -6
  35. package/math/Mat3.js +0 -248
  36. package/math/Mat4.js +0 -694
  37. package/math/MatrixStrategy.js +0 -23
  38. package/math/Quat.js +0 -60
  39. package/math/Vec.js +0 -728
  40. package/math/constants.js +0 -44
  41. package/math/functions.js +0 -104
  42. package/math/index.js +0 -74
  43. package/phsics/joint.js +0 -124
  44. package/primitives/arrow.js +0 -58
  45. package/primitives/cone.js +0 -137
  46. package/primitives/cube.js +0 -59
  47. package/primitives/cylinder.js +0 -215
  48. package/primitives/index.js +0 -13
  49. package/primitives/plane.js +0 -31
  50. package/primitives/sphere.js +0 -808
  51. package/render/BRDFIntegrationMap.js +0 -4
  52. package/render/Environment.js +0 -105
  53. package/render/EnvironmentRenderer.js +0 -12
  54. package/render/FrameBuffer.js +0 -26
  55. package/render/MaterialRenderer.js +0 -28
  56. package/render/Pipeline.js +0 -83
  57. package/render/PolyListRenderer.js +0 -42
  58. package/render/RenderBuffer.js +0 -189
  59. package/render/RenderQueue.js +0 -162
  60. package/render/RenderState.js +0 -82
  61. package/render/Renderer.js +0 -202
  62. package/render/SceneAppController.js +0 -208
  63. package/render/SceneRenderer.js +0 -310
  64. package/render/Shader.js +0 -21
  65. package/render/ShadowRenderer.js +0 -159
  66. package/render/SkyCube.js +0 -77
  67. package/render/SkySphere.js +0 -94
  68. package/render/TextureMergerRenderer.js +0 -58
  69. package/render/TextureRenderer.js +0 -29
  70. package/render/webgl/FrameBuffer.js +0 -9
  71. package/render/webgl/MaterialRenderer.js +0 -99
  72. package/render/webgl/Pipeline.js +0 -82
  73. package/render/webgl/PolyListRenderer.js +0 -224
  74. package/render/webgl/RenderBuffer.js +0 -244
  75. package/render/webgl/Renderer.js +0 -239
  76. package/render/webgl/SceneRenderer.js +0 -43
  77. package/render/webgl/ShaderProgram.js +0 -348
  78. package/render/webgl/ShadowRenderer.js +0 -6
  79. package/render/webgl/SkyCube.js +0 -15
  80. package/render/webgl/SkySphere.js +0 -14
  81. package/render/webgl/State.js +0 -149
  82. package/render/webgl/TextureRenderer.js +0 -167
  83. package/render/webgl/VertexBuffer.js +0 -128
  84. package/scene/Camera.js +0 -378
  85. package/scene/Chain.js +0 -43
  86. package/scene/ChainJoint.js +0 -55
  87. package/scene/Component.js +0 -146
  88. package/scene/ComponentMap.js +0 -99
  89. package/scene/Drawable.js +0 -130
  90. package/scene/EnvironmentComponent.js +0 -123
  91. package/scene/FindNodeVisitor.js +0 -55
  92. package/scene/LightComponent.js +0 -146
  93. package/scene/MatrixState.js +0 -39
  94. package/scene/Node.js +0 -300
  95. package/scene/NodeVisitor.js +0 -12
  96. package/scene/OrbitCameraController.js +0 -407
  97. package/scene/SmoothOrbitCameraController.js +0 -92
  98. package/scene/Transform.js +0 -74
  99. package/scene/index.js +0 -24
  100. package/shaders/BasicDiffuseColorShader.js +0 -91
  101. package/shaders/BasicPBRLightShader.js +0 -238
  102. package/shaders/DebugRenderShader.js +0 -79
  103. package/shaders/DepthRenderShader.js +0 -69
  104. package/shaders/IrradianceMapCubeShader.js +0 -99
  105. package/shaders/PBRLightIBLShader.js +0 -380
  106. package/shaders/PickSelectionShader.js +0 -75
  107. package/shaders/PresentDebugFramebufferShader.js +0 -90
  108. package/shaders/PresentTextureShader.js +0 -73
  109. package/shaders/SelectionHighlightShader.js +0 -98
  110. package/shaders/ShaderFunction.js +0 -72
  111. package/shaders/SkyCubeShader.js +0 -78
  112. package/shaders/SkySphereShader.js +0 -77
  113. package/shaders/SpecularMapCubeShader.js +0 -145
  114. package/shaders/TextureMergerShader.js +0 -127
  115. package/shaders/webgl_shader_lib.js +0 -187
  116. package/tools/BinaryResourceProvider.js +0 -15
  117. package/tools/ImageResourceProvider.js +0 -65
  118. package/tools/MaterialModifier.js +0 -228
  119. package/tools/Resource.js +0 -177
  120. package/tools/ResourceProvider.js +0 -56
  121. package/tools/TextResourceProvider.js +0 -24
  122. package/tools/TextureCache.js +0 -44
  123. package/tools/TextureResourceDatabase.js +0 -87
  124. package/tools/UserAgent.js +0 -294
  125. package/tools/VideoResourceProvider.js +0 -51
  126. package/tools/WriteStrategy.js +0 -22
  127. package/tools/base64.js +0 -15
  128. package/tools/crypto.js +0 -15
  129. package/tools/endiantess.js +0 -15
  130. package/tools/image.js +0 -15
  131. package/tools/index.js +0 -33
  132. 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.0",
3
+ "version": "2.0.2",
4
4
  "description": "a graphics engine for productivity applications",
5
- "main": "index.js",
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
- "dependencies": {
8
- "bg2io": "^1.0.7"
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
  }
@@ -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.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
@@ -1,8 +0,0 @@
1
-
2
- export default class EventBase {
3
- stopPropagation() {
4
- this._stopPropagation = true;
5
- }
6
-
7
- get isEventPropagationStopped() { return this._stopPropagation; }
8
- }
@@ -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.js DELETED
@@ -1,251 +0,0 @@
1
-
2
- import {
3
- MouseButtonEventType,
4
- createMouseEvent,
5
- leftMouseButton,
6
- middleMouseButton,
7
- clearMouseButtons,
8
- setMouseButton
9
- } from "./MouseEvent";
10
- import { createTouchEvent } from "./TouchEvent";
11
- import { createKeyboardEvent } from "./KeyboardEvent";
12
-
13
- export const FrameUpdate = {
14
- AUTO: 0,
15
- MANUAL: 1
16
- };
17
-
18
- const g_animationLoop = {
19
- lastTime: 0,
20
- mainLoop: []
21
- };
22
-
23
- async function animationLoop(totalTime) {
24
- totalTime = totalTime || 0;
25
- requestAnimationFrame(animationLoop);
26
- const elapsed = totalTime - g_animationLoop.lastTime;
27
- g_animationLoop.lastTime = totalTime;
28
- for (const ml of g_animationLoop.mainLoop) {
29
- await onUpdate(ml, elapsed);
30
- }
31
- }
32
-
33
- class MouseStatus {
34
- constructor() {
35
- this.pos = {x: 0, y: 0};
36
- this.leftButton = false;
37
- this.middleButton = false;
38
- this.rightButton = false;
39
- }
40
-
41
- get anyButton() { return this.leftButton || this.middleButton || this.rightButton; }
42
- }
43
-
44
- export default class MainLoop {
45
- constructor(canvas, appController) {
46
- this._canvas = canvas;
47
- this._canvas._mainLoop = this;
48
- this._appController = appController;
49
- this._appController._mainLoop = this;
50
- this._updateMode = FrameUpdate.AUTO;
51
- this._redisplayFrames = 1;
52
-
53
- this._mouseStatus = new MouseStatus();
54
- }
55
-
56
- get canvas() { return this._canvas; }
57
- get appController() { return this._appController; }
58
- get renderer() { return this._canvas?.renderer; }
59
-
60
- get updateMode() { return this._updateMode; }
61
- set updateMode(um) { this._updateMode = um; }
62
-
63
- get mouseStatus() { return this._mouseStatus; }
64
-
65
- get redisplay() { return this._redisplayFrames>0; }
66
-
67
- async run() {
68
- await this.canvas.init();
69
- await this.appController.init();
70
- initEvents(this);
71
- g_animationLoop.mainLoop.push(this);
72
- animationLoop();
73
- }
74
-
75
- exit() {
76
- this.appController.destroy();
77
- const i = g_animationLoop.mainLoop.indexOf(this);
78
- if (i!==-1) {
79
- g_animationLoop.mainLoop.splice(i,1);
80
- }
81
- }
82
-
83
- postReshape() {
84
- onResize(this);
85
- }
86
-
87
- postRedisplay({ frames=2,timeout=10 } = {}) {
88
- if (timeout <= 0) {
89
- this._redisplayFrames = frames;
90
- }
91
- else {
92
- setTimeout(() => this._redisplayFrames = frames, timeout);
93
- }
94
- }
95
- }
96
-
97
-
98
- function initEvents(mainLoop) {
99
- onResize(mainLoop);
100
-
101
- const handlePropagation = (bgEvt,evt) => {
102
- if (bgEvt.isEventPropagationStopped) {
103
- evt.stopPropagation();
104
- evt.preventDefault();
105
- return false;
106
- }
107
- return true;
108
- }
109
-
110
- const c = mainLoop.canvas.domElement;
111
- c.__mainLoop = mainLoop;
112
- c.addEventListener("mousedown", evt => {
113
- return handlePropagation(onMouseDown(evt, evt.target.__mainLoop), evt);
114
- });
115
- c.addEventListener("mousemove", evt => {
116
- return handlePropagation(onMouseMove(evt, evt.target.__mainLoop), evt);
117
- });
118
- c.addEventListener("mouseout", evt => {
119
- return handlePropagation(onMouseOut(evt, evt.target.__mainLoop), evt);
120
- });
121
-
122
- c.addEventListener("mouseover", evt => {
123
- return handlePropagation(onMouseOver(evt, evt.target.__mainLoop), evt);
124
- });
125
-
126
- c.addEventListener("mouseup", evt => {
127
- return handlePropagation(onMouseUp(evt, evt.target.__mainLoop), evt);
128
- });
129
-
130
- c.addEventListener("touchstart", evt => {
131
- return handlePropagation(onTouchStart(evt, evt.target.__mainLoop), evt);
132
- });
133
-
134
- c.addEventListener("touchmove", evt => {
135
- return handlePropagation(onTouchMove(evt, evt.target.__mainLoop), evt);
136
- });
137
-
138
- c.addEventListener("touchend", evt => {
139
- return handlePropagation(onTouchEnd(evt, evt.target.__mainLoop), evt);
140
- });
141
-
142
- const mouseWheelEvt = (/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel";
143
- c.addEventListener(mouseWheelEvt, evt => {
144
- return handlePropagation(onMouseWheel(evt, evt.target.__mainLoop), evt);
145
- });
146
-
147
- window.addEventListener("keydown", evt => {
148
- g_animationLoop.mainLoop.forEach(ml => onKeyDown(evt, ml));
149
- });
150
-
151
- window.addEventListener("keyup", evt => {
152
- g_animationLoop.mainLoop.forEach(ml => onKeyUp(evt, ml));
153
- });
154
-
155
- window.addEventListener("resize", evt => {
156
- onResize(mainLoop);
157
- });
158
-
159
- c.oncontextmenu = evt => false;
160
- }
161
-
162
- function onResize(mainLoop) {
163
- const dpi = window.devicePixelRatio;
164
- mainLoop.appController.reshape(mainLoop.canvas.width * dpi, mainLoop.canvas.height * dpi);
165
- }
166
-
167
- async function onUpdate(mainLoop, elapsed) {
168
- if (mainLoop.redisplay) {
169
- if (mainLoop.updateMode === FrameUpdate.AUTO) {
170
- mainLoop._redisplayFrames = 1;
171
- }
172
- else {
173
- mainLoop._redisplayFrames--;
174
- }
175
- if (mainLoop._redisplayFrames > 0) {
176
- await mainLoop.appController.frame(elapsed);
177
- mainLoop.appController.display();
178
- }
179
- }
180
- }
181
-
182
- function onMouseDown(evt,mainLoop) {
183
- const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.DOWN);
184
- setMouseButton(bg2Event, true);
185
- mainLoop.appController.mouseDown(bg2Event);
186
- return bg2Event;
187
- }
188
-
189
- function onMouseMove(evt,mainLoop) {
190
- const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.NONE);
191
- mainLoop.appController.mouseMove(bg2Event);
192
- if (mainLoop.mouseStatus.anyButton) {
193
- mainLoop.appController.mouseDrag(bg2Event);
194
- }
195
- return bg2Event;
196
- }
197
-
198
- function onMouseOut(evt,mainLoop) {
199
- const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.NONE);
200
- clearMouseButtons();
201
- mainLoop.appController.mouseOut(bg2Event);
202
- return bg2Event;
203
- }
204
-
205
- function onMouseOver(evt,mainLoop) {
206
- return onMouseMove(evt,mainLoop)
207
- }
208
-
209
- function onMouseUp(evt,mainLoop) {
210
- const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.UP);
211
- setMouseButton(bg2Event, false);
212
- mainLoop.appController.mouseUp(bg2Event);
213
- return bg2Event;
214
- }
215
-
216
- function onMouseWheel(evt,mainLoop) {
217
- const bg2Event = createMouseEvent(evt, mainLoop, MouseButtonEventType.NONE);
218
- bg2Event.delta = evt.wheelDelta ? evt.wheelDelta * -1 : evt.detail * 10;
219
- mainLoop.appController.mouseWheel(bg2Event);
220
- return bg2Event;
221
- }
222
-
223
- function onTouchStart(evt,mainLoop) {
224
- const bgEvent = createTouchEvent(evt,mainLoop);
225
- mainLoop.appController.touchStart(bgEvent);
226
- return bgEvent;
227
- }
228
-
229
- function onTouchMove(evt,mainLoop) {
230
- const bgEvent = createTouchEvent(evt,mainLoop);
231
- mainLoop.appController.touchMove(bgEvent);
232
- return bgEvent;
233
- }
234
-
235
- function onTouchEnd(evt,mainLoop) {
236
- const bgEvent = createTouchEvent(evt,mainLoop);
237
- mainLoop.appController.touchEnd(bgEvent);
238
- return bgEvent;
239
- }
240
-
241
- function onKeyDown(evt,mainLoop) {
242
- const bgEvent = createKeyboardEvent(evt);
243
- mainLoop.appController.keyDown(bgEvent);
244
- return bgEvent;
245
- }
246
-
247
- function onKeyUp(evt,mainLoop) {
248
- const bgEvent = createKeyboardEvent(evt);
249
- mainLoop.appController.keyUp(bgEvent);
250
- return bgEvent;
251
- }
package/app/MouseEvent.js DELETED
@@ -1,77 +0,0 @@
1
- import { getMouseEventOffset } from "./Canvas";
2
- import EventBase from "./EventBase";
3
-
4
- export const MouseButton = {
5
- LEFT: 0,
6
- MIDDLE: 1,
7
- RIGHT: 2,
8
- NONE: -1
9
- };
10
-
11
- export const MouseButtonEventType = {
12
- NONE: 0,
13
- UP: 1,
14
- DOWN: 2
15
- };
16
-
17
- export const createMouseEvent = (evt,mainLoop,buttonType) => {
18
- mainLoop.mouseStatus.pos = getMouseEventOffset(evt, mainLoop.canvas);
19
- if (buttonType !== MouseButtonEventType.NONE) {
20
- const buttonStatus = buttonType === MouseButtonEventType.DOWN;
21
- if (evt.button === MouseButton.LEFT) {
22
- mainLoop.mouseStatus.leftButton = buttonStatus;
23
- }
24
- else if (evt.button === MouseButton.MIDDLE) {
25
- mainLoop.mouseStatus.middleButton = buttonStatus;
26
- }
27
- else if (evt.button === MouseButton.RIGHT) {
28
- mainLoop.mouseStatus.rightButton = buttonStatus;
29
- }
30
- }
31
-
32
- return new MouseEvent(evt.button, mainLoop.mouseStatus.pos.x, mainLoop.mouseStatus.pos.y, 0, evt);
33
- }
34
-
35
- const g_mouseButtons = [false,false,false];
36
- export const leftMouseButton = () => {
37
- return g_mouseButtons[0];
38
- }
39
-
40
- export const middleMouseButton = () => {
41
- return g_mouseButtons[1];
42
- }
43
-
44
- export const rightMouseButton = () => {
45
- return g_mouseButtons[2];
46
- }
47
-
48
- export const clearMouseButtons = () => {
49
- g_mouseButtons[0] = false;
50
- g_mouseButtons[1] = false;
51
- g_mouseButtons[2] = false;
52
- }
53
-
54
- export const setMouseButton = (event, status) => {
55
- switch (event.button) {
56
- case MouseButton.LEFT:
57
- g_mouseButtons[0] = status;
58
- break;
59
- case MouseButton.MIDDLE:
60
- g_mouseButtons[1] = status;
61
- break;
62
- case MouseButton.RIGHT:
63
- g_mouseButtons[2] = status;
64
- break;
65
- }
66
- }
67
- export default class MouseEvent extends EventBase {
68
-
69
- constructor(button = MouseButton.NONE, x=-1, y=-1, delta=0,event=null) {
70
- super();
71
- this.button = button;
72
- this.x = x;
73
- this.y = y;
74
- this.delta = delta;
75
- this.event = event;
76
- }
77
- }
package/app/TouchEvent.js DELETED
@@ -1,15 +0,0 @@
1
- import { getEventTouches } from "./Canvas";
2
- import EventBase from "./EventBase";
3
-
4
- export const createTouchEvent = (evt,mainLoop) => {
5
- const touches = getEventTouches(evt,mainLoop.canvas);
6
- return new TouchEvent(touches, evt);
7
- }
8
-
9
- export default class TouchEvent extends EventBase {
10
- constructor(touches,event) {
11
- super();
12
- this.touches = touches;
13
- this.event = event;
14
- }
15
- }
package/base/Color.js DELETED
@@ -1,131 +0,0 @@
1
- import Vec from '../math/Vec';
2
-
3
- const checkLength = (v1,v2 = null) => {
4
- if (v1.length < 4 || (v2 !== null && v2.length < 4)) {
5
- throw new Error(`Invalid color component length`);
6
- }
7
- }
8
-
9
- export default class Color extends Vec {
10
- constructor() {
11
- if (arguments.length === 1 && arguments[0].length === 4) {
12
- // 4 elements array
13
- super(arguments[0]);
14
- }
15
- else if (arguments.length === 1 && arguments[0].length === 3) {
16
- super(arguments[0][0], arguments[0][1], arguments[0][2], 1);
17
- }
18
- else if (typeof(arguments) === "object" &&
19
- arguments[0].rgb !== undefined ||
20
- arguments[0].r !== undefined ||
21
- arguments[0].g !== undefined ||
22
- arguments[0].b !== undefined ||
23
- arguments[0].a !== undefined
24
- ) {
25
- const r = arguments[0].r || arguments[0].rgb || 0;
26
- const g = arguments[0].g || arguments[0].rgb || 0;
27
- const b = arguments[0].b || arguments[0].rgb || 0;
28
- const a = arguments[0].a || arguments[0].a || 1;
29
- super(r, g, b, a);
30
- }
31
- else if (arguments.length === 0) {
32
- super([0, 0, 0, 1]);
33
- }
34
- else {
35
- throw new Error('Invalid initialization parameters in Color constructor');
36
- }
37
- }
38
-
39
- static Yellow() { return new Color([1.0,1.0,0.0,1.0]); }
40
- static Orange() { return new Color([1.0,0.5,0.0,1.0]); }
41
- static Red() { return new Color([1.0,0.0,0.0,1.0]); }
42
- static Violet() { return new Color([0.5,0.0,1.0,1.0]); }
43
- static Blue() { return new Color([0.0,0.0,1.0,1.0]); }
44
- static Green() { return new Color([0.0,1.0,0.0,1.0]); }
45
- static White() { return new Color([1.0,1.0,1.0,1.0]); }
46
- static LightGray() { return new Color([0.8,0.8,0.8,1.0]); }
47
- static Gray() { return new Color([0.5,0.5,0.5,1.0]); }
48
- static DarkGray() { return new Color([0.2,0.2,0.2,1.0]); }
49
- static Black() { return new Color([0.0,0.0,0.0,1.0]); }
50
- static Brown() { return new Color([0.4,0.2,0.0,1.0]); }
51
- static Transparent() { return new Color([0,0,0,0]); }
52
-
53
- get r() { return this[0]; }
54
- set r(v) { this[0] = v; }
55
- get g() { return this[1]; }
56
- set g(v) { this[1] = v; }
57
- get b() { return this[2]; }
58
- set b(v) { this[2] = v; }
59
- get a() { return this[3]; }
60
- set a(v) { this[3] = v; }
61
-
62
- get rgb() { return new Vec(this[0], this[1], this[2]); }
63
- set rgb(rgb) {
64
- if (rgb.length === 3) {
65
- this[0] = rgb[0];
66
- this[1] = rgb[1];
67
- this[2] = rgb[2];
68
- }
69
- else {
70
- throw new Error("Invalid parameter settings rgb values in Color");
71
- }
72
- }
73
-
74
- static Max(v1,v2) {
75
- checkLength(v1, v2);
76
- return new Color([
77
- v1[0]>v2[0] ? v1[0] : v2[0],
78
- v1[1]>v2[1] ? v1[1] : v2[1],
79
- v1[2]>v2[2] ? v1[2] : v2[2],
80
- v1[3]>v2[3] ? v1[3] : v2[3]
81
- ]);
82
- }
83
-
84
- static Min(v1,v2) {
85
- checkLength(v1, v2);
86
- return new Color([
87
- v1[0]<v2[0] ? v1[0] : v2[0],
88
- v1[1]<v2[1] ? v1[1] : v2[1],
89
- v1[2]<v2[2] ? v1[2] : v2[2],
90
- v1[3]<v2[3] ? v1[3] : v2[3]
91
- ]);
92
- }
93
-
94
- static Add(v1,v2) {
95
- checkLength(v1, v2);
96
- return new Color([
97
- v1[0] + v2[0],
98
- v1[1] + v2[1],
99
- v1[2] + v2[2],
100
- v1[3] + v2[3]
101
- ]);
102
- }
103
-
104
- static Sub(v1,v2) {
105
- checkLength(v1, v2);
106
- return new Color([
107
- v1[0] - v2[0],
108
- v1[1] - v2[1],
109
- v1[2] - v2[2],
110
- v1[3] - v2[3]
111
- ]);
112
- }
113
-
114
- static Mult(v,s) {
115
- checkLength(v);
116
- new Color([ v[0] * s, v[1] * s, v[2] * s, v[3] * s ]);
117
- }
118
-
119
- static Div(v,s) {
120
- switch (v.length) {
121
- case 2:
122
- return new Vec([ v[0] / s, v[1] / s ]);
123
- case 3:
124
- return new Vec([ v[0] / s, v[1] / s, v[2] / s ]);
125
- case 4:
126
- return new Vec([ v[0] / s, v[1] / s, v[2] / s, v[3] / s ]);
127
- default:
128
- throw new Error(`Invalid vector size: ${ v.length }`);
129
- }
130
- }
131
- }