matrix-engine-wgpu 1.0.5 → 1.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.
Files changed (88) hide show
  1. package/.codesandbox/tasks.json +46 -0
  2. package/.devcontainer/devcontainer.json +22 -0
  3. package/.github/dependabot.yml +12 -0
  4. package/REFERENCE.md +5 -2
  5. package/dev.md +460 -0
  6. package/empty.js +7 -6
  7. package/examples/games/jamb/jamb.js +1127 -0
  8. package/examples/load-obj-file.js +67 -37
  9. package/examples/unlit-textures.js +26 -23
  10. package/examples.js +35 -3
  11. package/main.js +441 -43
  12. package/non-project-files/dev.txt +21 -0
  13. package/non-project-files/image1.png +0 -0
  14. package/non-project-files/image6.png +0 -0
  15. package/package.json +50 -41
  16. package/public/app.js +11409 -8893
  17. package/public/css/style.css +376 -112
  18. package/public/empty.html +1 -1
  19. package/public/empty.js +9890 -8885
  20. package/public/examples.html +10 -8
  21. package/public/examples.js +945 -203
  22. package/public/index.html +5 -7
  23. package/public/manifest copy.web +35 -0
  24. package/public/res/audios/block.mp3 +0 -0
  25. package/public/res/audios/dice1.mp3 +0 -0
  26. package/public/res/audios/dice2.mp3 +0 -0
  27. package/public/res/audios/start.mp3 +0 -0
  28. package/public/res/fonts/Accuratist.ttf +0 -0
  29. package/public/res/fonts/Closeness.ttf +0 -0
  30. package/public/res/fonts/WARGAMES.TTF +0 -0
  31. package/public/res/fonts/readme.txt +5 -0
  32. package/public/res/fonts/stormfaze.ttf +0 -0
  33. package/public/res/meshes/blender/cube.blend +0 -0
  34. package/public/res/meshes/blender/cube.blend1 +0 -0
  35. package/public/res/meshes/blender/cube.mtl +12 -0
  36. package/public/res/meshes/blender/cube.obj +46 -0
  37. package/public/res/meshes/blender/cube.png +0 -0
  38. package/public/res/meshes/blender/cubeSmartUV.blend +0 -0
  39. package/public/res/meshes/blender/cubeSmartUV.mtl +12 -0
  40. package/public/res/meshes/blender/cubeSmartUV.obj +46 -0
  41. package/public/res/meshes/blender/sphepe.blend +0 -0
  42. package/public/res/meshes/blender/sphepe.blend1 +0 -0
  43. package/public/res/meshes/blender/sphere.mtl +10 -0
  44. package/public/res/meshes/blender/sphere.obj +3402 -0
  45. package/public/res/meshes/jamb/bg.blend +0 -0
  46. package/public/res/meshes/jamb/bg.blend1 +0 -0
  47. package/public/res/meshes/jamb/bg.mtl +12 -0
  48. package/public/res/meshes/jamb/bg.obj +17 -0
  49. package/public/res/meshes/jamb/bg.png +0 -0
  50. package/public/res/meshes/jamb/dice-default.png +0 -0
  51. package/public/res/meshes/jamb/dice-mark.png +0 -0
  52. package/public/res/meshes/jamb/dice.mtl +12 -0
  53. package/public/res/meshes/jamb/dice.obj +40 -0
  54. package/public/res/meshes/jamb/dice.png +0 -0
  55. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  56. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  57. package/public/res/meshes/jamb/jamb.blend +0 -0
  58. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  59. package/public/res/meshes/jamb/logo.png +0 -0
  60. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  61. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  62. package/public/res/meshes/jamb/pile.blend +0 -0
  63. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  64. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  65. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  66. package/public/res/meshes/jamb/text.png +0 -0
  67. package/public/res/multilang/en.json +27 -0
  68. package/public/res/multilang/sr.json +27 -0
  69. package/public/test.html +636 -0
  70. package/public/three-test.js +165 -0
  71. package/public/worker.html +1 -1
  72. package/readme.md +232 -116
  73. package/src/engine/cube.js +10 -5
  74. package/src/engine/engine.js +3 -9
  75. package/src/engine/loader-obj.js +9 -6
  76. package/src/engine/matrix-class.js +240 -202
  77. package/src/engine/mesh-obj.js +605 -525
  78. package/src/engine/mesh.js +476 -0
  79. package/src/engine/raycast-test.js +93 -0
  80. package/src/engine/utils.js +129 -15
  81. package/src/multilang/lang.js +35 -0
  82. package/src/physics/matrix-ammo.js +204 -30
  83. package/src/shaders/fragment.wgsl.js +4 -2
  84. package/src/shaders/shaders.js +1 -1
  85. package/src/shaders/vertexShadow.wgsl.js +1 -1
  86. package/src/sounds/sounds.js +47 -0
  87. package/src/world.js +312 -236
  88. package/src/engine/matrix-mesh.js +0 -49
@@ -1,214 +1,252 @@
1
- import {degToRad} from "./utils";
1
+ import {degToRad, radToDeg} from "./utils";
2
2
 
3
- // Sub classes for matrix-wgpu
4
3
  /**
5
- * @description Base class
4
+ * @description
5
+ * Sub classes for matrix-wgpu
6
+ * Base class
6
7
  * Position { x, y, z }
7
8
  */
8
9
 
9
10
  export class Position {
10
-
11
- constructor(x, y, z) {
12
-
13
- // Not in use for nwo this is from matrix-engine project [nameUniq]
14
- this.nameUniq = null;
15
-
16
- if(typeof x == 'undefined') x = 0;
17
- if(typeof y == 'undefined') y = 0;
18
- if(typeof z == 'undefined') z = 0;
19
-
20
- this.x = x;
21
- this.y = y;
22
- this.z = z;
23
-
24
- this.velY = 0;
25
- this.velX = 0;
26
- this.velZ = 0;
27
- this.inMove = false;
28
- this.targetX = x;
29
- this.targetY = y;
30
- this.targetZ = z;
31
- this.thrust = 0.01;
32
-
33
- return this;
34
- }
35
-
36
- setSpeed(n) {
37
- if(typeof n === 'number') {
38
- this.thrust = n;
39
- } else {
40
- console.log('Description: arguments (w, h) must be type of number.');
41
- }
42
- }
43
-
44
- translateByX(x) {
45
- this.inMove = true;
46
- this.targetX = x;
47
- };
48
-
49
- translateByY(y) {
50
- this.inMove = true;
51
- this.targetY = y;
52
- }
53
-
54
- translateByZ(z) {
55
- this.inMove = true;
56
- this.targetZ = z;
57
- }
58
-
59
- translateByXY(x, y) {
60
- this.inMove = true;
61
- this.targetX = x;
62
- this.targetY = y;
63
- }
64
-
65
- translateByXZ(x, z) {
66
- this.inMove = true;
67
- this.targetX = x;
68
- this.targetZ = z;
69
- }
70
-
71
- translateByYZ(y, z) {
72
- this.inMove = true;
73
- this.targetY = y;
74
- this.targetZ = z;
75
- }
76
-
77
- onTargetPositionReach() {}
78
-
79
- update() {
80
- var tx = this.targetX - this.x,
81
- ty = this.targetY - this.y,
82
- tz = this.targetZ - this.z,
83
- dist = Math.sqrt(tx * tx + ty * ty + tz * tz);
84
- this.velX = (tx / dist) * this.thrust;
85
- this.velY = (ty / dist) * this.thrust;
86
- this.velZ = (tz / dist) * this.thrust;
87
- if(this.inMove == true) {
88
- if(dist > this.thrust) {
89
- this.x += this.velX;
90
- this.y += this.velY;
91
- this.z += this.velZ;
92
-
93
- // // from me
94
- // if(net && net.connection && typeof em === 'undefined' && App.scene[this.nameUniq].net.enable == true) net.connection.send({
95
- // netPos: {x: this.x, y: this.y, z: this.z},
96
- // netObjId: this.nameUniq,
97
- // });
98
-
99
- } else {
100
- this.x = this.targetX;
101
- this.y = this.targetY;
102
- this.z = this.targetZ;
103
- this.inMove = false;
104
- this.onTargetPositionReach();
105
-
106
- // // from me
107
- // if(net && net.connection && typeof em === 'undefined' && App.scene[this.nameUniq].net.enable == true) net.connection.send({
108
- // netPos: {x: this.x, y: this.y, z: this.z},
109
- // netObjId: this.nameUniq,
110
- // });
111
- }
112
- }
113
- }
114
-
115
- get worldLocation() {
116
- return [this.x, this.y, this.z];
117
- }
118
-
119
- SetX(newx, em) {
120
- this.x = newx;
121
- this.targetX = newx;
122
- this.inMove = false;
123
-
124
- // if(net && net.connection && typeof em === 'undefined' &&
125
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) {
126
- // net.connection.send({
127
- // netPos: {x: this.x, y: this.y, z: this.z},
128
- // netObjId: this.nameUniq,
129
- // });
130
- // }
131
- }
132
-
133
- SetY(newy, em) {
134
- this.y = newy;
135
- this.targetY = newy;
136
- this.inMove = false;
137
- // if(net && net.connection && typeof em === 'undefined' &&
138
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
139
- // netPos: {x: this.x, y: this.y, z: this.z},
140
- // netObjId: this.nameUniq,
141
- // });
142
- }
143
-
144
- SetZ(newz, em) {
145
- this.z = newz;
146
- this.targetZ = newz;
147
- this.inMove = false;
148
- // if(net && net.connection && typeof em === 'undefined' &&
149
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
150
- // netPos: {x: this.x, y: this.y, z: this.z},
151
- // netObjId: this.nameUniq,
152
- // });
153
- }
154
-
155
- setPosition(newx, newy, newz) {
156
- this.x = newx;
157
- this.y = newy;
158
- this.z = newz;
159
- this.targetX = newx;
160
- this.targetY = newy;
161
- this.targetZ = newz;
162
- this.inMove = false;
163
-
164
- // from me
165
- // if(App.scene[this.nameUniq] && net && net.connection && typeof em === 'undefined' &&
166
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
167
- // netPos: {x: this.x, y: this.y, z: this.z},
168
- // netObjId: this.nameUniq,
169
- // });
170
- }
11
+ constructor(x, y, z) {
12
+ // console.log('TEST TYTPOF ', x)
13
+ // Not in use for nwo this is from matrix-engine project [nameUniq]
14
+ this.nameUniq = null;
15
+
16
+ if(typeof x == 'undefined') x = 0;
17
+ if(typeof y == 'undefined') y = 0;
18
+ if(typeof z == 'undefined') z = 0;
19
+
20
+ this.x = parseFloat(x);
21
+ this.y = parseFloat(y);
22
+ this.z = parseFloat(z);
23
+
24
+ this.velY = 0;
25
+ this.velX = 0;
26
+ this.velZ = 0;
27
+ this.inMove = false;
28
+ this.targetX = parseFloat(x);
29
+ this.targetY = parseFloat(y);
30
+ this.targetZ = parseFloat(z);
31
+ this.thrust = 0.01;
32
+
33
+ return this;
34
+ }
35
+
36
+ setSpeed(n) {
37
+ if(typeof n === 'number') {
38
+ this.thrust = n;
39
+ } else {
40
+ console.log('Description: arguments (w, h) must be type of number.');
41
+ }
42
+ }
43
+
44
+ translateByX(x) {
45
+ this.inMove = true;
46
+ this.targetX = parseFloat(x);
47
+ };
48
+
49
+ translateByY(y) {
50
+ this.inMove = true;
51
+ this.targetY = parseFloat(y);
52
+ }
53
+
54
+ translateByZ(z) {
55
+ this.inMove = true;
56
+ this.targetZ = parseFloat(z);
57
+ }
58
+
59
+ translateByXY(x, y) {
60
+ this.inMove = true;
61
+ this.targetX = parseFloat(x);
62
+ this.targetY = parseFloat(y);
63
+ }
64
+
65
+ translateByXZ(x, z) {
66
+ this.inMove = true;
67
+ this.targetX = parseFloat(x);
68
+ this.targetZ = parseFloat(z);
69
+ }
70
+
71
+ translateByYZ(y, z) {
72
+ this.inMove = true;
73
+ this.targetY = parseFloat(y);
74
+ this.targetZ = parseFloat(z);
75
+ }
76
+
77
+ onTargetPositionReach() {}
78
+
79
+ update() {
80
+ var tx = parseFloat(this.targetX) - parseFloat(this.x),
81
+ ty = parseFloat(this.targetY) - parseFloat(this.y),
82
+ tz = parseFloat(this.targetZ) - parseFloat(this.z),
83
+ dist = Math.sqrt(tx * tx + ty * ty + tz * tz);
84
+ this.velX = (tx / dist) * this.thrust;
85
+ this.velY = (ty / dist) * this.thrust;
86
+ this.velZ = (tz / dist) * this.thrust;
87
+ if(this.inMove == true) {
88
+ if(dist > this.thrust) {
89
+ this.x += this.velX;
90
+ this.y += this.velY;
91
+ this.z += this.velZ;
92
+
93
+ // // from me
94
+ // if(net && net.connection && typeof em === 'undefined' && App.scene[this.nameUniq].net.enable == true) net.connection.send({
95
+ // netPos: {x: this.x, y: this.y, z: this.z},
96
+ // netObjId: this.nameUniq,
97
+ // });
98
+
99
+ } else {
100
+ this.x = this.targetX;
101
+ this.y = this.targetY;
102
+ this.z = this.targetZ;
103
+ this.inMove = false;
104
+ this.onTargetPositionReach();
105
+
106
+ // // from me
107
+ // if(net && net.connection && typeof em === 'undefined' && App.scene[this.nameUniq].net.enable == true) net.connection.send({
108
+ // netPos: {x: this.x, y: this.y, z: this.z},
109
+ // netObjId: this.nameUniq,
110
+ // });
111
+ }
112
+ }
113
+ }
114
+
115
+ get worldLocation() {
116
+ return [parseFloat(this.x), parseFloat(this.y), parseFloat(this.z)];
117
+ }
118
+
119
+ SetX(newx, em) {
120
+ this.x = newx;
121
+ this.targetX = newx;
122
+ this.inMove = false;
123
+
124
+ // if(net && net.connection && typeof em === 'undefined' &&
125
+ // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) {
126
+ // net.connection.send({
127
+ // netPos: {x: this.x, y: this.y, z: this.z},
128
+ // netObjId: this.nameUniq,
129
+ // });
130
+ // }
131
+ }
132
+
133
+ SetY(newy, em) {
134
+ this.y = newy;
135
+ this.targetY = newy;
136
+ this.inMove = false;
137
+ // if(net && net.connection && typeof em === 'undefined' &&
138
+ // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
139
+ // netPos: {x: this.x, y: this.y, z: this.z},
140
+ // netObjId: this.nameUniq,
141
+ // });
142
+ }
143
+
144
+ SetZ(newz, em) {
145
+ this.z = newz;
146
+ this.targetZ = newz;
147
+ this.inMove = false;
148
+ // if(net && net.connection && typeof em === 'undefined' &&
149
+ // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
150
+ // netPos: {x: this.x, y: this.y, z: this.z},
151
+ // netObjId: this.nameUniq,
152
+ // });
153
+ }
154
+
155
+ get X() {
156
+ return parseFloat(this.x)
157
+ }
158
+
159
+ get Y() {
160
+ return parseFloat(this.y)
161
+ }
162
+
163
+ get Z() {
164
+ return parseFloat(this.z)
165
+ }
166
+
167
+ setPosition(newx, newy, newz) {
168
+ this.x = newx;
169
+ this.y = newy;
170
+ this.z = newz;
171
+ this.targetX = newx;
172
+ this.targetY = newy;
173
+ this.targetZ = newz;
174
+ this.inMove = false;
175
+
176
+ // from me
177
+ // if(App.scene[this.nameUniq] && net && net.connection && typeof em === 'undefined' &&
178
+ // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
179
+ // netPos: {x: this.x, y: this.y, z: this.z},
180
+ // netObjId: this.nameUniq,
181
+ // });
182
+ }
171
183
  }
172
184
 
173
185
  export class Rotation {
174
186
 
175
- constructor(x, y, z) {
176
- // Not in use for nwo this is from matrix-engine project [nameUniq]
177
- this.nameUniq = null;
178
- if(typeof x == 'undefined') x = 0;
179
- if(typeof y == 'undefined') y = 0;
180
- if(typeof z == 'undefined') z = 0;
181
- this.x = x;
182
- this.y = y;
183
- this.z = z;
184
- this.rotationSpeed = {x: 0, y: 0, z: 0}
185
- }
186
-
187
- getRotX () {
188
- if (this.rotationSpeed.x == 0) {
189
- return degToRad(this.x);
190
- } else {
191
- this.x = this.x + this.rotationSpeed.x* 0.001;
192
- return this.x;
193
- }
194
- }
195
-
196
- getRotY () {
197
- if (this.rotationSpeed.y == 0) {
198
- return degToRad(this.y);
199
- } else {
200
- this.y = this.y + this.rotationSpeed.y * 0.001;
201
- return this.y;
202
- }
203
- }
204
-
205
- getRotZ () {
206
- if (this.rotationSpeed.z == 0) {
207
- return degToRad(this.z);
208
- } else {
209
- this.z = this.z + this.rotationSpeed.z* 0.001;
210
- return this.z;
211
- }
212
- }
187
+ constructor(x, y, z) {
188
+ // Not in use for nwo this is from matrix-engine project [nameUniq]
189
+ this.nameUniq = null;
190
+ if(typeof x == 'undefined') x = 0;
191
+ if(typeof y == 'undefined') y = 0;
192
+ if(typeof z == 'undefined') z = 0;
193
+ this.x = x;
194
+ this.y = y;
195
+ this.z = z;
196
+ this.rotationSpeed = {x: 0, y: 0, z: 0};
197
+ this.angle = 0;
198
+ this.axis = {x: 0, y: 0, z: 0};
199
+ // not in use good for exstend logic
200
+ this.matrixRotation = null;
201
+ }
202
+
203
+ toDegree() {
204
+
205
+ /*
206
+ heading = atan2(y * sin(angle)- x * z * (1 - cos(angle)) , 1 - (y2 + z2 ) * (1 - cos(angle)))
207
+ attitude = asin(x * y * (1 - cos(angle)) + z * sin(angle))
208
+ bank = atan2(x * sin(angle)-y * z * (1 - cos(angle)) , 1 - (x2 + z2) * (1 - cos(angle)))
209
+ */
210
+ return [radToDeg(this.axis.x), radToDeg(this.axis.y), radToDeg(this.axis.z)];
211
+ }
212
+
213
+ toDegreeX() {
214
+ return Math.cos(radToDeg(this.axis.x) / 2)
215
+ }
216
+
217
+ toDegreeY() {
218
+ return Math.cos(radToDeg(this.axis.z) / 2)
219
+ }
220
+
221
+ toDegreeZ() {
222
+ return Math.cos(radToDeg(this.axis.y) / 2)
223
+ }
224
+
225
+ getRotX() {
226
+ if(this.rotationSpeed.x == 0) {
227
+ return degToRad(this.x);
228
+ } else {
229
+ this.x = this.x + this.rotationSpeed.x * 0.001;
230
+ return degToRad(this.x);
231
+ }
232
+ }
233
+
234
+ getRotY() {
235
+ if(this.rotationSpeed.y == 0) {
236
+ return degToRad(this.y);
237
+ } else {
238
+ this.y = this.y + this.rotationSpeed.y * 0.001;
239
+ return degToRad(this.y);
240
+ }
241
+ }
242
+
243
+ getRotZ() {
244
+ if(this.rotationSpeed.z == 0) {
245
+ return degToRad(this.z);
246
+ } else {
247
+ this.z = this.z + this.rotationSpeed.z * 0.001;
248
+ return degToRad(this.z);
249
+ }
250
+ }
213
251
 
214
252
  }