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.
- package/.codesandbox/tasks.json +46 -0
- package/.devcontainer/devcontainer.json +22 -0
- package/.github/dependabot.yml +12 -0
- package/REFERENCE.md +3 -5
- package/dev.md +460 -0
- package/empty.js +7 -6
- package/examples/games/jamb/jamb.js +1127 -0
- package/examples/load-obj-file.js +65 -28
- package/examples/unlit-textures.js +26 -23
- package/examples.js +35 -3
- package/main.js +442 -48
- package/non-project-files/dev.txt +21 -0
- package/non-project-files/image1.png +0 -0
- package/non-project-files/image6.png +0 -0
- package/package.json +28 -13
- package/public/app.js +11405 -9375
- package/public/css/style.css +371 -110
- package/public/empty.html +1 -1
- package/public/empty.js +9887 -9264
- package/public/examples.html +10 -8
- package/public/examples.js +553 -193
- package/public/index.html +3 -5
- package/public/manifest copy.web +35 -0
- package/public/res/audios/block.mp3 +0 -0
- package/public/res/audios/dice1.mp3 +0 -0
- package/public/res/audios/dice2.mp3 +0 -0
- package/public/res/audios/start.mp3 +0 -0
- package/public/res/meshes/jamb/bg.blend +0 -0
- package/public/res/meshes/jamb/bg.blend1 +0 -0
- package/public/res/meshes/jamb/bg.mtl +12 -0
- package/public/res/meshes/jamb/bg.obj +17 -0
- package/public/res/meshes/jamb/bg.png +0 -0
- package/public/res/meshes/jamb/dice-default.png +0 -0
- package/public/res/meshes/jamb/dice-mark.png +0 -0
- package/public/res/meshes/jamb/dice.mtl +12 -0
- package/public/res/meshes/jamb/dice.obj +40 -0
- package/public/res/meshes/jamb/dice.png +0 -0
- package/public/res/meshes/jamb/jamb-title.mtl +12 -0
- package/public/res/meshes/jamb/jamb-title.obj +26008 -0
- package/public/res/meshes/jamb/jamb.blend +0 -0
- package/public/res/meshes/jamb/jamb.blend1 +0 -0
- package/public/res/meshes/jamb/logo.png +0 -0
- package/public/res/meshes/jamb/nidzaDice.blend +0 -0
- package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
- package/public/res/meshes/jamb/pile.blend +0 -0
- package/public/res/meshes/jamb/simpleCube.blend +0 -0
- package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
- package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
- package/public/res/meshes/jamb/text.png +0 -0
- package/public/res/multilang/en.json +27 -0
- package/public/res/multilang/sr.json +27 -0
- package/public/test.html +636 -0
- package/public/three-test.js +165 -0
- package/public/worker.html +1 -1
- package/readme.md +189 -115
- package/src/engine/cube.js +10 -1
- package/src/engine/engine.js +1 -5
- package/src/engine/loader-obj.js +9 -6
- package/src/engine/matrix-class.js +237 -204
- package/src/engine/mesh-obj.js +605 -515
- package/src/engine/raycast-test.js +93 -0
- package/src/engine/utils.js +69 -3
- package/src/multilang/lang.js +35 -0
- package/src/physics/matrix-ammo.js +168 -15
- package/src/shaders/fragment.wgsl.js +4 -2
- package/src/shaders/shaders.js +1 -1
- package/src/shaders/vertexShadow.wgsl.js +1 -1
- package/src/sounds/sounds.js +47 -0
- 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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
}
|