matrix-engine-wgpu 1.0.6 → 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 (69) 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 +3 -5
  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 +65 -28
  9. package/examples/unlit-textures.js +26 -23
  10. package/examples.js +35 -3
  11. package/main.js +442 -48
  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 +28 -13
  16. package/public/app.js +11405 -9375
  17. package/public/css/style.css +371 -110
  18. package/public/empty.html +1 -1
  19. package/public/empty.js +9887 -9264
  20. package/public/examples.html +10 -8
  21. package/public/examples.js +553 -193
  22. package/public/index.html +3 -5
  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/meshes/jamb/bg.blend +0 -0
  29. package/public/res/meshes/jamb/bg.blend1 +0 -0
  30. package/public/res/meshes/jamb/bg.mtl +12 -0
  31. package/public/res/meshes/jamb/bg.obj +17 -0
  32. package/public/res/meshes/jamb/bg.png +0 -0
  33. package/public/res/meshes/jamb/dice-default.png +0 -0
  34. package/public/res/meshes/jamb/dice-mark.png +0 -0
  35. package/public/res/meshes/jamb/dice.mtl +12 -0
  36. package/public/res/meshes/jamb/dice.obj +40 -0
  37. package/public/res/meshes/jamb/dice.png +0 -0
  38. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  39. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  40. package/public/res/meshes/jamb/jamb.blend +0 -0
  41. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  42. package/public/res/meshes/jamb/logo.png +0 -0
  43. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  44. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  45. package/public/res/meshes/jamb/pile.blend +0 -0
  46. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  47. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  48. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  49. package/public/res/meshes/jamb/text.png +0 -0
  50. package/public/res/multilang/en.json +27 -0
  51. package/public/res/multilang/sr.json +27 -0
  52. package/public/test.html +636 -0
  53. package/public/three-test.js +165 -0
  54. package/public/worker.html +1 -1
  55. package/readme.md +189 -115
  56. package/src/engine/cube.js +10 -1
  57. package/src/engine/engine.js +1 -5
  58. package/src/engine/loader-obj.js +9 -6
  59. package/src/engine/matrix-class.js +237 -204
  60. package/src/engine/mesh-obj.js +605 -515
  61. package/src/engine/raycast-test.js +93 -0
  62. package/src/engine/utils.js +69 -3
  63. package/src/multilang/lang.js +35 -0
  64. package/src/physics/matrix-ammo.js +168 -15
  65. package/src/shaders/fragment.wgsl.js +4 -2
  66. package/src/shaders/shaders.js +1 -1
  67. package/src/shaders/vertexShadow.wgsl.js +1 -1
  68. package/src/sounds/sounds.js +47 -0
  69. package/src/world.js +311 -248
@@ -1,4 +1,4 @@
1
- import {degToRad} from "./utils";
1
+ import {degToRad, radToDeg} from "./utils";
2
2
 
3
3
  /**
4
4
  * @description
@@ -8,212 +8,245 @@ import {degToRad} from "./utils";
8
8
  */
9
9
 
10
10
  export class Position {
11
-
12
- constructor(x, y, z) {
13
-
14
- // Not in use for nwo this is from matrix-engine project [nameUniq]
15
- this.nameUniq = null;
16
-
17
- if(typeof x == 'undefined') x = 0;
18
- if(typeof y == 'undefined') y = 0;
19
- if(typeof z == 'undefined') z = 0;
20
-
21
- this.x = x;
22
- this.y = y;
23
- this.z = z;
24
-
25
- this.velY = 0;
26
- this.velX = 0;
27
- this.velZ = 0;
28
- this.inMove = false;
29
- this.targetX = x;
30
- this.targetY = y;
31
- this.targetZ = z;
32
- this.thrust = 0.01;
33
-
34
- return this;
35
- }
36
-
37
- setSpeed(n) {
38
- if(typeof n === 'number') {
39
- this.thrust = n;
40
- } else {
41
- console.log('Description: arguments (w, h) must be type of number.');
42
- }
43
- }
44
-
45
- translateByX(x) {
46
- this.inMove = true;
47
- this.targetX = x;
48
- };
49
-
50
- translateByY(y) {
51
- this.inMove = true;
52
- this.targetY = y;
53
- }
54
-
55
- translateByZ(z) {
56
- this.inMove = true;
57
- this.targetZ = z;
58
- }
59
-
60
- translateByXY(x, y) {
61
- this.inMove = true;
62
- this.targetX = x;
63
- this.targetY = y;
64
- }
65
-
66
- translateByXZ(x, z) {
67
- this.inMove = true;
68
- this.targetX = x;
69
- this.targetZ = z;
70
- }
71
-
72
- translateByYZ(y, z) {
73
- this.inMove = true;
74
- this.targetY = y;
75
- this.targetZ = z;
76
- }
77
-
78
- onTargetPositionReach() {}
79
-
80
- update() {
81
- var tx = this.targetX - this.x,
82
- ty = this.targetY - this.y,
83
- tz = this.targetZ - this.z,
84
- dist = Math.sqrt(tx * tx + ty * ty + tz * tz);
85
- this.velX = (tx / dist) * this.thrust;
86
- this.velY = (ty / dist) * this.thrust;
87
- this.velZ = (tz / dist) * this.thrust;
88
- if(this.inMove == true) {
89
- if(dist > this.thrust) {
90
- this.x += this.velX;
91
- this.y += this.velY;
92
- this.z += this.velZ;
93
-
94
- // // from me
95
- // if(net && net.connection && typeof em === 'undefined' && App.scene[this.nameUniq].net.enable == true) net.connection.send({
96
- // netPos: {x: this.x, y: this.y, z: this.z},
97
- // netObjId: this.nameUniq,
98
- // });
99
-
100
- } else {
101
- this.x = this.targetX;
102
- this.y = this.targetY;
103
- this.z = this.targetZ;
104
- this.inMove = false;
105
- this.onTargetPositionReach();
106
-
107
- // // from me
108
- // if(net && net.connection && typeof em === 'undefined' && App.scene[this.nameUniq].net.enable == true) net.connection.send({
109
- // netPos: {x: this.x, y: this.y, z: this.z},
110
- // netObjId: this.nameUniq,
111
- // });
112
- }
113
- }
114
- }
115
-
116
- get worldLocation() {
117
- return [this.x, this.y, this.z];
118
- }
119
-
120
- SetX(newx, em) {
121
- this.x = newx;
122
- this.targetX = newx;
123
- this.inMove = false;
124
-
125
- // if(net && net.connection && typeof em === 'undefined' &&
126
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) {
127
- // net.connection.send({
128
- // netPos: {x: this.x, y: this.y, z: this.z},
129
- // netObjId: this.nameUniq,
130
- // });
131
- // }
132
- }
133
-
134
- SetY(newy, em) {
135
- this.y = newy;
136
- this.targetY = newy;
137
- this.inMove = false;
138
- // if(net && net.connection && typeof em === 'undefined' &&
139
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
140
- // netPos: {x: this.x, y: this.y, z: this.z},
141
- // netObjId: this.nameUniq,
142
- // });
143
- }
144
-
145
- SetZ(newz, em) {
146
- this.z = newz;
147
- this.targetZ = newz;
148
- this.inMove = false;
149
- // if(net && net.connection && typeof em === 'undefined' &&
150
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
151
- // netPos: {x: this.x, y: this.y, z: this.z},
152
- // netObjId: this.nameUniq,
153
- // });
154
- }
155
-
156
- setPosition(newx, newy, newz) {
157
- this.x = newx;
158
- this.y = newy;
159
- this.z = newz;
160
- this.targetX = newx;
161
- this.targetY = newy;
162
- this.targetZ = newz;
163
- this.inMove = false;
164
-
165
- // from me
166
- // if(App.scene[this.nameUniq] && net && net.connection && typeof em === 'undefined' &&
167
- // App.scene[this.nameUniq].net && App.scene[this.nameUniq].net.enable == true) net.connection.send({
168
- // netPos: {x: this.x, y: this.y, z: this.z},
169
- // netObjId: this.nameUniq,
170
- // });
171
- }
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
+ }
172
183
  }
173
184
 
174
185
  export class Rotation {
175
186
 
176
- constructor(x, y, z) {
177
- // Not in use for nwo this is from matrix-engine project [nameUniq]
178
- this.nameUniq = null;
179
- if(typeof x == 'undefined') x = 0;
180
- if(typeof y == 'undefined') y = 0;
181
- if(typeof z == 'undefined') z = 0;
182
- this.x = x;
183
- this.y = y;
184
- this.z = z;
185
- this.rotationSpeed = {x: 0, y: 0, z: 0};
186
- this.angle = 0;
187
- this.axis = {x:0, y:0 , z:0};
188
- // not in use good for exstend logic
189
- this.matrixRotation = null;
190
- }
191
-
192
- getRotX () {
193
- if (this.rotationSpeed.x == 0) {
194
- return degToRad(this.x);
195
- } else {
196
- this.x = this.x + this.rotationSpeed.x* 0.001;
197
- return degToRad(this.x);
198
- }
199
- }
200
-
201
- getRotY () {
202
- if (this.rotationSpeed.y == 0) {
203
- return degToRad(this.y);
204
- } else {
205
- this.y = this.y + this.rotationSpeed.y * 0.001;
206
- return degToRad(this.y);
207
- }
208
- }
209
-
210
- getRotZ () {
211
- if (this.rotationSpeed.z == 0) {
212
- return degToRad(this.z);
213
- } else {
214
- this.z = this.z + this.rotationSpeed.z* 0.001;
215
- return degToRad(this.z);
216
- }
217
- }
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
+ }
218
251
 
219
252
  }