matrix-engine-wgpu 1.0.6 → 1.1.1

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 (71) 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 +1133 -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/index.js +8 -2
  12. package/main.js +454 -48
  13. package/non-project-files/dev.txt +21 -0
  14. package/non-project-files/image1.png +0 -0
  15. package/non-project-files/image6.png +0 -0
  16. package/package.json +31 -13
  17. package/public/app.js +2234 -114
  18. package/public/css/style.css +371 -110
  19. package/public/empty.html +1 -1
  20. package/public/empty.js +9887 -9264
  21. package/public/examples.html +10 -8
  22. package/public/examples.js +2035 -247
  23. package/public/index.html +3 -5
  24. package/public/manifest copy.web +35 -0
  25. package/public/res/audios/block.mp3 +0 -0
  26. package/public/res/audios/dice1.mp3 +0 -0
  27. package/public/res/audios/dice2.mp3 +0 -0
  28. package/public/res/audios/start.mp3 +0 -0
  29. package/public/res/meshes/jamb/bg.blend +0 -0
  30. package/public/res/meshes/jamb/bg.blend1 +0 -0
  31. package/public/res/meshes/jamb/bg.mtl +12 -0
  32. package/public/res/meshes/jamb/bg.obj +17 -0
  33. package/public/res/meshes/jamb/bg.png +0 -0
  34. package/public/res/meshes/jamb/dice-default.png +0 -0
  35. package/public/res/meshes/jamb/dice-mark.png +0 -0
  36. package/public/res/meshes/jamb/dice.mtl +12 -0
  37. package/public/res/meshes/jamb/dice.obj +40 -0
  38. package/public/res/meshes/jamb/dice.png +0 -0
  39. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  40. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  41. package/public/res/meshes/jamb/jamb.blend +0 -0
  42. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  43. package/public/res/meshes/jamb/logo.png +0 -0
  44. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  45. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  46. package/public/res/meshes/jamb/pile.blend +0 -0
  47. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  48. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  49. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  50. package/public/res/meshes/jamb/text.png +0 -0
  51. package/public/res/multilang/en.json +27 -0
  52. package/public/res/multilang/sr.json +27 -0
  53. package/public/test.html +636 -0
  54. package/public/three-test.js +165 -0
  55. package/public/worker.html +1 -1
  56. package/readme.md +193 -115
  57. package/src/engine/ball.js +477 -468
  58. package/src/engine/cube.js +486 -468
  59. package/src/engine/engine.js +4 -6
  60. package/src/engine/loader-obj.js +9 -6
  61. package/src/engine/matrix-class.js +237 -204
  62. package/src/engine/mesh-obj.js +603 -515
  63. package/src/engine/raycast.js +101 -0
  64. package/src/engine/utils.js +69 -3
  65. package/src/multilang/lang.js +35 -0
  66. package/src/physics/matrix-ammo.js +168 -15
  67. package/src/shaders/fragment.wgsl.js +4 -2
  68. package/src/shaders/shaders.js +1 -1
  69. package/src/shaders/vertexShadow.wgsl.js +1 -1
  70. package/src/sounds/sounds.js +47 -0
  71. package/src/world.js +311 -248
@@ -164,7 +164,9 @@ export class WASDCamera extends CameraBase {
164
164
  const position = vec3.copy(this.position);
165
165
 
166
166
  // Reconstruct the camera's rotation, and store into the camera matrix.
167
- super.matrix = mat4.rotateX(mat4.rotationY(this.yaw), this.pitch);
167
+ super.matrix = mat4.rotateX(mat4.rotationY(this.yaw), this.pitch);
168
+ // super.matrix = mat4.rotateX(mat4.rotationY(this.yaw), -this.pitch);
169
+ // super.matrix = mat4.rotateY(mat4.rotateX(this.pitch), this.yaw);
168
170
 
169
171
  // Calculate the new target velocity
170
172
  const digital = input.digital;
@@ -337,9 +339,7 @@ function lerp(a, b, s) {
337
339
  return vec3.addScaled(a, vec3.sub(b, a), s);
338
340
  }
339
341
 
340
- // IMPUT
341
-
342
- // // Input holds as snapshot of input state
342
+ // Input holds as snapshot of input state
343
343
  // export default interface Input {
344
344
  // // Digital input (e.g keyboard state)
345
345
  // readonly digital: {
@@ -358,10 +358,8 @@ function lerp(a, b, s) {
358
358
  // readonly touching: boolean;
359
359
  // };
360
360
  // }
361
-
362
361
  // InputHandler is a function that when called, returns the current Input state.
363
362
  // export type InputHandler = () => Input;
364
-
365
363
  // createInputHandler returns an InputHandler by attaching event handlers to the window and canvas.
366
364
  export function createInputHandler(window, canvas) {
367
365
  let digital = {
@@ -4,6 +4,9 @@
4
4
  * information can then be used later on when creating your VBOs. See
5
5
  * OBJ.initMeshBuffers for an example of how to use the newly created Mesh
6
6
  *
7
+ * Nidza Note:
8
+ * There is difference from me source obj loader and me-wgpu obj loader
9
+ * Here we need scele in comp x,y,z because we use also primitive [cube, sphere etc...]
7
10
  * @class Mesh
8
11
  * @constructor
9
12
  *
@@ -21,7 +24,7 @@ export class constructMesh {
21
24
  this.create(this.objectData, this.inputArg)
22
25
  };
23
26
  this.updateBuffers = () => {
24
- this.inputArg.scale = 1;
27
+ this.inputArg.scale = [0.1,0.1,0.1];
25
28
  this.create(this.objectData, this.inputArg);
26
29
  };
27
30
  }
@@ -184,9 +187,9 @@ export class constructMesh {
184
187
  This same process is repeated for verts and textures.
185
188
  */
186
189
  // vertex position
187
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[0]] * inputArg.scale);
188
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[1]] * inputArg.scale);
189
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[2]] * inputArg.scale);
190
+ unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[0]] * inputArg.scale[0]);
191
+ unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[1]] * inputArg.scale[1]);
192
+ unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[2]] * inputArg.scale[2]);
190
193
 
191
194
  // vertex textures
192
195
  if (textures.length) {
@@ -263,11 +266,11 @@ export var downloadMeshes = function (nameAndURLs, completionCallback, inputArg)
263
266
  // a new object is created. this will be passed into the completionCallback
264
267
  if (typeof inputArg === 'undefined') {
265
268
  var inputArg = {
266
- scale: 1,
269
+ scale: [0.1,0.1,0.1],
267
270
  swap: [null]
268
271
  };
269
272
  }
270
- if (typeof inputArg.scale === 'undefined') inputArg.scale = 0.1;
273
+ if (typeof inputArg.scale === 'undefined') inputArg.scale = [0.1,0.1,0.1];
271
274
  if (typeof inputArg.swap === 'undefined') inputArg.swap = [null];
272
275
 
273
276
  var meshes = {};
@@ -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
  }