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/math/Mat4.js DELETED
@@ -1,694 +0,0 @@
1
- import { NumericArray, PI, checkArray } from "./constants";
2
- import Vec from "./Vec";
3
- import Mat3 from "./Mat3";
4
- import { equals, isZero } from "./functions";
5
-
6
- export default class Mat4 extends NumericArray {
7
- constructor() {
8
- const inMatrix = [
9
- 0, 0, 0, 0,
10
- 0, 0, 0, 0,
11
- 0, 0, 0, 0,
12
- 0, 0, 0, 0
13
- ];
14
-
15
- // Create from matrix3
16
- if (arguments.length === 9) {
17
- inMatrix[0] = arguments[0];
18
- inMatrix[1] = arguments[1];
19
- inMatrix[2] = arguments[2];
20
-
21
- inMatrix[4] = arguments[3];
22
- inMatrix[5] = arguments[4];
23
- inMatrix[6] = arguments[5];
24
-
25
- inMatrix[8] = arguments[6];
26
- inMatrix[9] = arguments[7];
27
- inMatrix[10] = arguments[8];
28
-
29
- inMatrix[15] = 1;
30
- }
31
- else if (arguments.length === 1 && arguments[0].length === 9) {
32
- inMatrix[0] = arguments[0][0];
33
- inMatrix[1] = arguments[0][1];
34
- inMatrix[2] = arguments[0][2];
35
-
36
- inMatrix[4] = arguments[0][3];
37
- inMatrix[5] = arguments[0][4];
38
- inMatrix[6] = arguments[0][5];
39
-
40
- inMatrix[8] = arguments[0][6];
41
- inMatrix[9] = arguments[0][7];
42
- inMatrix[10] = arguments[0][8];
43
-
44
- inMatrix[15] = 1;
45
- }
46
- // Create from matrix4
47
- else if (arguments.length === 16) {
48
- inMatrix[0 ] = arguments[0];
49
- inMatrix[1 ] = arguments[1 ];
50
- inMatrix[2 ] = arguments[2 ];
51
- inMatrix[3 ] = arguments[3 ];
52
-
53
- inMatrix[4 ] = arguments[4 ];
54
- inMatrix[5 ] = arguments[5 ];
55
- inMatrix[6 ] = arguments[6 ];
56
- inMatrix[7 ] = arguments[7 ];
57
-
58
- inMatrix[8 ] = arguments[8 ];
59
- inMatrix[9 ] = arguments[9 ];
60
- inMatrix[10] = arguments[10];
61
- inMatrix[11] = arguments[11];
62
-
63
- inMatrix[12] = arguments[12];
64
- inMatrix[13] = arguments[13];
65
- inMatrix[14] = arguments[14];
66
- inMatrix[15] = arguments[15];
67
- }
68
- else if (arguments.length === 1 && arguments[0].length === 16) {
69
- inMatrix[0 ] = arguments[0][0];
70
- inMatrix[1 ] = arguments[0][1 ];
71
- inMatrix[2 ] = arguments[0][2 ];
72
- inMatrix[3 ] = arguments[0][3 ];
73
-
74
- inMatrix[4 ] = arguments[0][4 ];
75
- inMatrix[5 ] = arguments[0][5 ];
76
- inMatrix[6 ] = arguments[0][6 ];
77
- inMatrix[7 ] = arguments[0][7 ];
78
-
79
- inMatrix[8 ] = arguments[0][8 ];
80
- inMatrix[9 ] = arguments[0][9 ];
81
- inMatrix[10] = arguments[0][10];
82
- inMatrix[11] = arguments[0][11];
83
-
84
- inMatrix[12] = arguments[0][12];
85
- inMatrix[13] = arguments[0][13];
86
- inMatrix[14] = arguments[0][14];
87
- inMatrix[15] = arguments[0][15];
88
- }
89
- else if (arguments.length != 0) {
90
- throw new Error(`Invalid parameter size in Matrix3 constructor`);
91
- }
92
-
93
- super(inMatrix);
94
- }
95
-
96
- ////// Initializers
97
- identity() {
98
- this[0 ] = 1; this[1 ] = 0; this[2 ] = 0; this[3 ] = 0
99
- this[4 ] = 0; this[5 ] = 1; this[6 ] = 0; this[7 ] = 0
100
- this[8 ] = 0; this[9 ] = 0; this[10] = 1; this[11] = 0
101
- this[12] = 0; this[13] = 0; this[14] = 0; this[15] = 1
102
- return this;
103
- }
104
-
105
- zero() {
106
- this[ 0] = 0; this[ 1] = 0; this[ 2] = 0; this[ 3] = 0;
107
- this[ 4] = 0; this[ 5] = 0; this[ 6] = 0; this[ 7] = 0;
108
- this[ 8] = 0; this[ 9] = 0; this[10] = 0; this[11] = 0;
109
- this[12] = 0; this[13] = 0; this[14] = 0; this[15] = 0;
110
- return this;
111
- }
112
-
113
- perspective(fovy, aspect, nearPlane, farPlane) {
114
- let fovy2 = Math.tan(fovy * PI / 360.0) * nearPlane;
115
- let fovy2aspect = fovy2 * aspect;
116
- this.frustum(-fovy2aspect,fovy2aspect,-fovy2,fovy2,nearPlane,farPlane);
117
- return this;
118
- }
119
-
120
- frustum(left, right, bottom, top, nearPlane, farPlane) {
121
- let A = right - left;
122
- let B = top-bottom;
123
- let C = farPlane-nearPlane;
124
-
125
- this.setRow(0, new Vec(nearPlane*2.0/A, 0.0, 0.0, 0.0));
126
- this.setRow(1, new Vec(0.0, nearPlane*2.0/B, 0.0, 0.0));
127
- this.setRow(2, new Vec((right+left)/A, (top+bottom)/B, -(farPlane+nearPlane)/C, -1.0));
128
- this.setRow(3, new Vec(0.0, 0.0, -(farPlane*nearPlane*2.0)/C, 0.0));
129
-
130
- return this;
131
- }
132
-
133
- ortho(left, right, bottom, top, nearPlane, farPlane) {
134
- let m = right-left;
135
- let l = top-bottom;
136
- let k = farPlane-nearPlane;;
137
-
138
- this[0] = 2/m; this[1] = 0; this[2] = 0; this[3] = 0;
139
- this[4] = 0; this[5] = 2/l; this[6] = 0; this[7] = 0;
140
- this[8] = 0; this[9] = 0; this[10] = -2/k; this[11]= 0;
141
- this[12]=-(left+right)/m; this[13] = -(top+bottom)/l; this[14] = -(farPlane+nearPlane)/k; this[15]=1;
142
-
143
- return this;
144
- }
145
-
146
- lookAt(p_eye, p_center, p_up) {
147
- this.identity();
148
-
149
- const y = new Vec(p_up);
150
- const z = Vec.Sub(p_eye,p_center);
151
- z.normalize();
152
- const x = Vec.Cross(y,z);
153
- x.normalize();
154
- y.normalize();
155
-
156
- this.m00 = x.x;
157
- this.m10 = x.y;
158
- this.m20 = x.z;
159
- this.m30 = -Vec.Dot(x, p_eye);
160
- this.m01 = y.x;
161
- this.m11 = y.y;
162
- this.m21 = y.z;
163
- this.m31 = -Vec.Dot(y, p_eye);
164
- this.m02 = z.x;
165
- this.m12 = z.y;
166
- this.m22 = z.z;
167
- this.m32 = -Vec.Dot(z, p_eye);
168
- this.m03 = 0;
169
- this.m13 = 0;
170
- this.m23 = 0;
171
- this.m33 = 1;
172
-
173
- return this;
174
- }
175
-
176
-
177
-
178
-
179
- ///// Setters and getters
180
- get m00() { return this[0]; }
181
- get m01() { return this[1]; }
182
- get m02() { return this[2]; }
183
- get m03() { return this[3]; }
184
- get m10() { return this[4]; }
185
- get m11() { return this[5]; }
186
- get m12() { return this[6]; }
187
- get m13() { return this[7]; }
188
- get m20() { return this[8]; }
189
- get m21() { return this[9]; }
190
- get m22() { return this[10]; }
191
- get m23() { return this[11]; }
192
- get m30() { return this[12]; }
193
- get m31() { return this[13]; }
194
- get m32() { return this[14]; }
195
- get m33() { return this[15]; }
196
-
197
- set m00(v) { this[0] = v; }
198
- set m01(v) { this[1] = v; }
199
- set m02(v) { this[2] = v; }
200
- set m03(v) { this[3] = v; }
201
- set m10(v) { this[4] = v; }
202
- set m11(v) { this[5] = v; }
203
- set m12(v) { this[6] = v; }
204
- set m13(v) { this[7] = v; }
205
- set m20(v) { this[8] = v; }
206
- set m21(v) { this[9] = v; }
207
- set m22(v) { this[10] = v; }
208
- set m23(v) { this[11] = v; }
209
- set m30(v) { this[12] = v; }
210
- set m31(v) { this[13] = v; }
211
- set m32(v) { this[14] = v; }
212
- set m33(v) { this[15] = v; }
213
-
214
- get mat3() {
215
- return new Mat3(this[0], this[1], this[ 2],
216
- this[4], this[5], this[ 6],
217
- this[8], this[9], this[10]);
218
- }
219
-
220
- get forwardVector() {
221
- return Mat4.TransformDirection(this, new Vec(0.0, 0.0, 1.0));
222
- }
223
-
224
- get rightVector() {
225
- return Mat4.TransformDirection(this, new Vec(1.0, 0.0, 0.0));
226
- }
227
-
228
- get upVector() {
229
- return Mat4.TransformDirection(this, new Vec(0.0, 1.0, 0.0));
230
- }
231
-
232
- get backwardVector() {
233
- return Mat4.TransformDirection(this, new Vec(0.0, 0.0, -1.0));
234
- }
235
-
236
- get leftVector() {
237
- return Mat4.TransformDirection(this, new Vec(-1.0, 0.0, 0.0));
238
- }
239
-
240
- get downVector() {
241
- return Mat4.TransformDirection(this, new Vec(0.0, -1.0, 0.0));
242
- }
243
-
244
- row(i) {
245
- return new Vec(
246
- this[i * 4],
247
- this[i * 4 + 1],
248
- this[i * 4 + 2],
249
- this[i * 4 + 3]);
250
- }
251
-
252
- setRow(i, a, y = null, z = null, w = null) {
253
- if (a.length>=4) {
254
- this[i * 4] = a[0];
255
- this[i * 4 + 1] = a[1];
256
- this[i * 4 + 2] = a[2];
257
- this[i * 4 + 3] = a[3];
258
- }
259
- else if (a.length == 3) {
260
- this[i * 4] = a[0];
261
- this[i * 4 + 1] = a[1];
262
- this[i * 4 + 2] = a[2];
263
- }
264
- else if (typeof(a) === "number" &&
265
- typeof(y) === "number" &&
266
- typeof(z) === "number" &&
267
- typeof(w) === "number"
268
- ) {
269
- this[i * 4] = a;
270
- this[i * 4 + 1] = y;
271
- this[i * 4 + 2] = z;
272
- this[i * 4 + 3] = w;
273
- }
274
- else {
275
- throw new Error(`Invalid parameter setting matrix row`);
276
- }
277
- return this;
278
- }
279
-
280
- col(i) {
281
- return new Vec(
282
- this[i],
283
- this[i + 4],
284
- this[i + 4 * 2],
285
- this[i + 4 * 3]
286
- )
287
- }
288
-
289
- setCol(i, a, y = null, z = null, w = null) {
290
- if (a.length>=4) {
291
- this[i] = a[0];
292
- this[i + 4] = a[1];
293
- this[i + 4 * 2] = a[2];
294
- this[i + 4 * 3] = a[3];
295
- }
296
- else if (typeof(a) === "number" &&
297
- typeof(y) === "number" &&
298
- typeof(z) === "number" &&
299
- typeof(w) === "number"
300
- ) {
301
- this[i] = a;
302
- this[i + 4] = y;
303
- this[i + 4 * 2] = z;
304
- this[i + 4 * 3] = w;
305
- }
306
- else {
307
- throw new Error(`Invalid parameter setting matrix row`);
308
- }
309
- return this;
310
- }
311
-
312
- assign(a) {
313
- if (a.length==9) {
314
- this[0] = a[0]; this[1] = a[1]; this[2] = a[2]; this[3] = 0;
315
- this[4] = a[3]; this[5] = a[4]; this[6] = a[5]; this[7] = 0;
316
- this[8] = a[6]; this[9] = a[7]; this[10] = a[8]; this[11] = 0;
317
- this[12] = 0; this[13] = 0; this[14] = 0; this[15] = 1;
318
- }
319
- else if (a.length==16) {
320
- this[0] = a[0]; this[1] = a[1]; this[2] = a[2]; this[3] = a[3];
321
- this[4] = a[4]; this[5] = a[5]; this[6] = a[6]; this[7] = a[7];
322
- this[8] = a[8]; this[9] = a[9]; this[10] = a[10]; this[11] = a[11];
323
- this[12] = a[12]; this[13] = a[13]; this[14] = a[14]; this[15] = a[15];
324
- }
325
- return this;
326
- }
327
-
328
- translate(x, y, z) {
329
- if (checkArray(x,3)) {
330
- y = x[1];
331
- z = x[2];
332
- x = x[0];
333
- }
334
- this.mult(Mat4.MakeTranslation(x, y, z));
335
- return this;
336
- }
337
-
338
- rotate(alpha, x, y, z) {
339
- if (checkArray(x,3)) {
340
- y = x[1];
341
- z = x[2];
342
- x = x[0];
343
- }
344
- this.mult(Mat4.MakeRotation(alpha, x, y, z));
345
- return this;
346
- }
347
-
348
- scale(x, y, z) {
349
- if (checkArray(x,3)) {
350
- y = x[1];
351
- z = x[2];
352
- x = x[0];
353
- }
354
- this.mult(Mat4.MakeScale(x, y, z));
355
- return this;
356
- }
357
-
358
- toString() {
359
- return `[ ${this[ 0]}, ${this[ 1]}, ${this[ 2]}, ${this[ 3]}\n` +
360
- ` ${this[ 4]}, ${this[ 5]}, ${this[ 6]}, ${this[ 7]}\n` +
361
- ` ${this[ 8]}, ${this[ 9]}, ${this[10]}, ${this[11]}\n` +
362
- ` ${this[12]}, ${this[13]}, ${this[14]}, ${this[15]} ]`;
363
- }
364
-
365
- setScale(x,y,z) {
366
- const rx = new Vec(this[0], this[4], this[8]).normalize().scale(x);
367
- const ry = new Vec(this[1], this[5], this[9]).normalize().scale(y);
368
- const rz = new Vec(this[2], this[6], this[10]).normalize().scale(z);
369
- this[0] = rx.x; this[4] = rx.y; this[8] = rx.z;
370
- this[1] = ry.x; this[5] = ry.y; this[9] = ry.z;
371
- this[2] = rz.x; this[6] = rz.y; this[10] = rz.z;
372
- return this;
373
- }
374
-
375
- setPosition(pos,y,z) {
376
- if (typeof(pos)=="number") {
377
- this[12] = pos;
378
- this[13] = y;
379
- this[14] = z;
380
- }
381
- else {
382
- this[12] = pos.x;
383
- this[13] = pos.y;
384
- this[14] = pos.z;
385
- }
386
- return this;
387
- }
388
-
389
- setRotation(rotationMatrix) {
390
- if (rotationMatrix.length === 9) {
391
- this[0] = rotationMatrix[0]; this[1] = rotationMatrix[1]; this[2] = rotationMatrix[2];
392
- this[4] = rotationMatrix[3]; this[5] = rotationMatrix[4]; this[6] = rotationMatrix[5];
393
- this[8] = rotationMatrix[6]; this[9] = rotationMatrix[7]; this[10] = rotationMatrix[8];
394
- }
395
- else if (rotationMatrix.length === 16) {
396
- this[0] = rotationMatrix[0]; this[1] = rotationMatrix[1]; this[2] = rotationMatrix[2];
397
- this[4] = rotationMatrix[4]; this[5] = rotationMatrix[5]; this[6] = rotationMatrix[6];
398
- this[8] = rotationMatrix[8]; this[9] = rotationMatrix[9]; this[10] = rotationMatrix[10];
399
- }
400
- else {
401
- throw new Error("Invalid parameter setting rotation matrix");
402
- }
403
- }
404
-
405
- mult(a) {
406
- if (typeof(a)=='number') {
407
- this[ 0] *= a; this[ 1] *= a; this[ 2] *= a; this[ 3] *= a;
408
- this[ 4] *= a; this[ 5] *= a; this[ 6] *= a; this[ 7] *= a;
409
- this[ 8] *= a; this[ 9] *= a; this[10] *= a; this[11] *= a;
410
- this[12] *= a; this[13] *= a; this[14] *= a; this[15] *= a;
411
- return this;
412
- }
413
-
414
- const r0 = this.row(0);
415
- const r1 = this.row(1);
416
- const r2 = this.row(2);
417
- const r3 = this.row(3);
418
- const c0 = a.col(0);
419
- const c1 = a.col(1);
420
- const c2 = a.col(2);
421
- const c3 = a.col(3);
422
-
423
- this[0 ] = Vec.Dot(r0, c0); this[1 ] = Vec.Dot(r0, c1); this[2 ] = Vec.Dot(r0, c2); this[3 ] = Vec.Dot(r0, c3);
424
- this[4 ] = Vec.Dot(r1, c0); this[5 ] = Vec.Dot(r1, c1); this[6 ] = Vec.Dot(r1, c2); this[7 ] = Vec.Dot(r1, c3);
425
- this[8 ] = Vec.Dot(r2, c0); this[9 ] = Vec.Dot(r2, c1); this[10] = Vec.Dot(r2, c2); this[11] = Vec.Dot(r2, c3);
426
- this[12] = Vec.Dot(r3, c0); this[13] = Vec.Dot(r3, c1); this[14] = Vec.Dot(r3, c2); this[15] = Vec.Dot(r3, c3);
427
-
428
- return this;
429
- }
430
-
431
- multVector(vec) {
432
- if (vec.length<3) {
433
- throw new Error("Invalid parameter multiplying Mat4 by vector");
434
- }
435
-
436
- const x = vec[0];
437
- const y = vec[1];
438
- const z = vec[2];
439
- const w = vec.length >3 ? vec[3] : 1.0;
440
-
441
- return new Vec( this[0] * x + this[4] * y + this[ 8] * z + this[12] * w,
442
- this[1] * x + this[5] * y + this[ 9] * z + this[13] * w,
443
- this[2] * x + this[6] * y + this[10] * z + this[14] * w,
444
- this[3] * x + this[7] * y + this[11] * z + this[15] * w);
445
- }
446
-
447
- invert() {
448
- const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3],
449
- a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7],
450
- a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11],
451
- a30 = this[12], a31 = this[13], a32 = this[14], a33 = this[15];
452
-
453
- const b00 = a00 * a11 - a01 * a10,
454
- b01 = a00 * a12 - a02 * a10,
455
- b02 = a00 * a13 - a03 * a10,
456
- b03 = a01 * a12 - a02 * a11,
457
- b04 = a01 * a13 - a03 * a11,
458
- b05 = a02 * a13 - a03 * a12,
459
- b06 = a20 * a31 - a21 * a30,
460
- b07 = a20 * a32 - a22 * a30,
461
- b08 = a20 * a33 - a23 * a30,
462
- b09 = a21 * a32 - a22 * a31,
463
- b10 = a21 * a33 - a23 * a31,
464
- b11 = a22 * a33 - a23 * a32;
465
-
466
- let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
467
-
468
- if (!det) {
469
- this.zero();
470
- }
471
- else {
472
- det = 1.0 / det;
473
-
474
- this[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
475
- this[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
476
- this[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
477
- this[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
478
- this[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
479
- this[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
480
- this[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
481
- this[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
482
- this[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
483
- this[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
484
- this[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
485
- this[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
486
- this[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
487
- this[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
488
- this[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
489
- this[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
490
- }
491
-
492
- return this;
493
- }
494
-
495
- traspose() {
496
- const r0 = new Vec(this[0], this[4], this[ 8], this[12]);
497
- const r1 = new Vec(this[1], this[5], this[ 9], this[13]);
498
- const r2 = new Vec(this[2], this[6], this[10], this[14]);
499
- const r3 = new Vec(this[3], this[7], this[11], this[15]);
500
-
501
- this.setRow(0, r0);
502
- this.setRow(1, r1);
503
- this.setRow(2, r2);
504
- this.setRow(3, r3);
505
- return this;
506
- }
507
-
508
- ///////// Factory methods
509
- static MakeIdentity() {
510
- const m = new Mat4();
511
- return m.identity();
512
- }
513
-
514
- static MakeZero() {
515
- const m = new Mat4();
516
- return m.zero();
517
- }
518
-
519
- static MakeWithQuaternion(q) {
520
- const m = Mat4.MakeIdentity();
521
- m.setRotation(Mat3.MakeWithQuaternion(q));
522
- return m;
523
- }
524
-
525
- static MakeTranslation(x, y, z) {
526
- if (checkArray(x,3)) {
527
- y = x[1];
528
- z = x[2];
529
- x = x[0];
530
- }
531
- return new Mat4(
532
- 1.0, 0.0, 0.0, 0.0,
533
- 0.0, 1.0, 0.0, 0.0,
534
- 0.0, 0.0, 1.0, 0.0,
535
- x, y, z, 1.0
536
- );
537
- }
538
-
539
- static MakeRotation(alpha, x, y, z) {
540
- const axis = new Vec(x,y,z);
541
- axis.normalize();
542
-
543
- var cosAlpha = Math.cos(alpha);
544
- var acosAlpha = 1.0 - cosAlpha;
545
- var sinAlpha = Math.sin(alpha);
546
-
547
- return new Mat4(
548
- axis.x * axis.x * acosAlpha + cosAlpha, axis.x * axis.y * acosAlpha + axis.z * sinAlpha, axis.x * axis.z * acosAlpha - axis.y * sinAlpha, 0,
549
- axis.y * axis.x * acosAlpha - axis.z * sinAlpha, axis.y * axis.y * acosAlpha + cosAlpha, axis.y * axis.z * acosAlpha + axis.x * sinAlpha, 0,
550
- axis.z * axis.x * acosAlpha + axis.y * sinAlpha, axis.z * axis.y * acosAlpha - axis.x * sinAlpha, axis.z * axis.z * acosAlpha + cosAlpha, 0,
551
- 0,0,0,1
552
- );
553
- }
554
-
555
- static MakeRotationWithDirection(direction, up = new Vec(0,1,0)) {
556
- const trx = Mat4.MakeIdentity();
557
- trx.setRotation(Mat3.MakeRotationWithDirection(direction, up));
558
- return trx;
559
- }
560
-
561
- static MakeScale(x, y, z) {
562
- if (checkArray(x,3)) {
563
- y = x[1];
564
- z = x[2];
565
- x = x[0];
566
- }
567
- return new Mat4(
568
- x, 0, 0, 0,
569
- 0, y, 0, 0,
570
- 0, 0, z, 0,
571
- 0, 0, 0, 1
572
- )
573
- }
574
-
575
-
576
- static MakePerspective(fovy, aspect, nearPlane, farPlane) {
577
- return (new Mat4()).perspective(fovy, aspect, nearPlane, farPlane);
578
- }
579
-
580
- static MakeFrustum(left, right, bottom, top, nearPlane, farPlane) {
581
- return (new Mat4()).frustum(left, right, bottom, top, nearPlane, farPlane);
582
- }
583
-
584
- static MakeOrtho(left, right, bottom, top, nearPlane, farPlane) {
585
- return (new Mat4()).ortho(left, right, bottom, top, nearPlane, farPlane);
586
- }
587
-
588
- static MakeLookAt(origin, target, up) {
589
- return (new Mat4()).lookAt(origin,target,up);
590
- }
591
-
592
- // Other static methods. This function multyplies two B x A matrices. It works opposite than the non-static mult() function:
593
- // A.mult(B) is the same as Mat4.Mult(B,A)
594
- static Mult(A,B) {
595
- const result = new Mat4(B);
596
- return result.mult(A);
597
- }
598
-
599
- static Unproject(x, y, depth, mvMat, pMat, viewport) {
600
- let mvp = new Mat4(pMat);
601
- mvp.mult(mvMat);
602
- mvp.invert();
603
-
604
- const vin = new Vec(((x - viewport.y) / viewport.width) * 2.0 - 1.0,
605
- ((y - viewport.x) / viewport.height) * 2.0 - 1.0,
606
- depth * 2.0 - 1.0,
607
- 1.0);
608
-
609
- const result = new Vec4(mvp.multVector(vin));
610
- if (result.z==0) {
611
- result.set(0);
612
- }
613
- else {
614
- result.set( result.x/result.w,
615
- result.y/result.w,
616
- result.z/result.w,
617
- result.w/result.w);
618
- }
619
-
620
- return result;
621
- }
622
-
623
- static GetScale(m) {
624
- return new Vec(
625
- Vec.Magnitude([m[1], m[5], m[9]]),
626
- Vec.Magnitude([m[0], m[4], m[8]]),
627
- Vec.Magnitude([m[2], m[6], m[10]])
628
- );
629
- }
630
-
631
- static GetRotation(m) {
632
- const scale = Mat4.GetScale(m);
633
- return new Mat4(
634
- m[0] / scale.x, m[1] / scale.y, m[ 2] / scale.z, 0,
635
- m[4] / scale.x, m[5] / scale.y, m[ 6] / scale.z, 0,
636
- m[8] / scale.x, m[9] / scale.y, m[10] / scale.z, 0,
637
- 0, 0, 0, 1
638
- );
639
- }
640
-
641
- static GetPosition(m) {
642
- return new Vec(m[12], m[13], m[14]);
643
- }
644
-
645
- static GetInverted(m) {
646
- const inverted = new Mat4(m);
647
- inverted.invert();
648
- return inverted;
649
- }
650
-
651
- static GetNormalMatrix(m) {
652
- return new Mat4(m)
653
- .invert()
654
- .traspose()
655
- .mat3;
656
- }
657
-
658
- static Equals(m,n) {
659
- return m[ 0] == n[ 0] && m[ 1] == n[ 1] && m[ 2] == n[ 2] && m[ 3] == n[ 3] &&
660
- m[ 4] == n[ 4] && m[ 5] == n[ 5] && m[ 6] == n[ 6] && m[ 7] == n[ 7] &&
661
- m[ 8] == n[ 8] && m[ 9] == n[ 9] && m[10] == n[10] && m[11] == n[11] &&
662
- m[12] == n[12] && m[13] == n[13] && m[14] == n[14] && m[15] == n[15];
663
- }
664
-
665
- static TransformDirection(M, /* Vec */ dir) {
666
- const direction = new Vec(dir);
667
- const trx = new Mat4(M);
668
- trx.setRow(3, new Vec(0, 0, 0, 1));
669
- direction.assign(trx.multVector(direction).xyz);
670
- direction.normalize();
671
- return direction;
672
- }
673
-
674
- static IsNan() {
675
- return isNaN(this[ 0]) || isNaN(this[ 1]) || isNaN(this[ 2]) || isNaN(this[ 3]) ||
676
- isNaN(this[ 4]) || isNaN(this[ 5]) || isNaN(this[ 6]) || isNaN(this[ 7]) ||
677
- isNaN(this[ 8]) || isNaN(this[ 9]) || isNaN(this[10]) || isNaN(this[11]) ||
678
- isNaN(this[12]) || isNaN(this[13]) || isNaN(this[14]) || isNaN(this[15]);
679
- }
680
-
681
- static IsZero(m) {
682
- return isZero(m[ 0]) && isZero(m[ 1]) && isZero(m[ 2]) && isZero(m[ 3]) &&
683
- isZero(m[ 4]) && isZero(m[ 5]) && isZero(m[ 6]) && isZero(m[ 7]) &&
684
- isZero(m[ 8]) && isZero(m[ 9]) && isZero(m[10]) && isZero(m[11]) &&
685
- isZero(m[12]) && isZero(m[13]) && isZero(m[14]) && isZero(m[15]);
686
- }
687
-
688
- static IsIdentity(m) {
689
- return equals(m[ 0],1) && equals(m[ 1],0) && equals(m[ 2],0) && equals(m[ 3],0) &&
690
- equals(m[ 4],0) && equals(m[ 5],1) && equals(m[ 6],0) && equals(m[ 7],0) &&
691
- equals(m[ 8],0) && equals(m[ 9],0) && equals(m[10],1) && equals(m[11],0) &&
692
- equals(m[12],0) && equals(m[13],0) && equals(m[14],0) && equals(m[15],1);
693
- }
694
- }
@@ -1,23 +0,0 @@
1
- import Mat4 from "./Mat4";
2
-
3
-
4
- export default class MatrixStrategy {
5
- constructor(target) {
6
- if (!target instanceof Mat4) {
7
- throw Error("MatrixStrategy: invalid target object. Target object must be of type bg.math.Mat4");
8
- }
9
- this._target = target;
10
- }
11
-
12
- get target() {
13
- return this._target;
14
- }
15
-
16
- set target(t) {
17
- this._target = t;
18
- }
19
-
20
- apply() {
21
- throw Error("MatrixStrategy.apply(): method not implemented");
22
- }
23
- }