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.
- 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 +1133 -0
- package/examples/load-obj-file.js +65 -28
- package/examples/unlit-textures.js +26 -23
- package/examples.js +35 -3
- package/index.js +8 -2
- package/main.js +454 -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 +31 -13
- package/public/app.js +2234 -114
- 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 +2035 -247
- 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 +193 -115
- package/src/engine/ball.js +477 -468
- package/src/engine/cube.js +486 -468
- package/src/engine/engine.js +4 -6
- package/src/engine/loader-obj.js +9 -6
- package/src/engine/matrix-class.js +237 -204
- package/src/engine/mesh-obj.js +603 -515
- package/src/engine/raycast.js +101 -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
package/main.js
CHANGED
|
@@ -1,57 +1,463 @@
|
|
|
1
1
|
import MatrixEngineWGPU from "./src/world.js";
|
|
2
2
|
import {downloadMeshes} from './src/engine/loader-obj.js';
|
|
3
|
-
import {LOG_FUNNY, LOG_INFO, LOG_MATRIX} from "./src/engine/utils.js";
|
|
3
|
+
import {LOG_FUNNY, LOG_INFO, LOG_MATRIX, randomFloatFromTo, randomIntFromTo} from "./src/engine/utils.js";
|
|
4
|
+
import {dices, myDom} from "./examples/games/jamb/jamb.js";
|
|
5
|
+
import {MatrixSounds} from "./src/sounds/sounds.js";
|
|
6
|
+
import {addRaycastListener, touchCoordinate, rayIntersectsSphere, getRayFromMouse} from "./src/engine/raycast.js";
|
|
4
7
|
|
|
5
8
|
export let application = new MatrixEngineWGPU({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
useSingleRenderPass: true,
|
|
10
|
+
canvasSize: 'fullscreen',
|
|
11
|
+
mainCameraParams: {
|
|
12
|
+
type: 'WASD',
|
|
13
|
+
responseCoef: 1000
|
|
14
|
+
}
|
|
12
15
|
}, () => {
|
|
16
|
+
// Dom operations
|
|
17
|
+
application.myDom = myDom;
|
|
18
|
+
myDom.createJamb();
|
|
19
|
+
myDom.createBlocker();
|
|
13
20
|
|
|
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
|
-
|
|
21
|
+
application.dices = dices;
|
|
22
|
+
|
|
23
|
+
// this code must be on top
|
|
24
|
+
application.matrixAmmo.detectCollision = function() {
|
|
25
|
+
this.lastRoll = '';
|
|
26
|
+
this.presentScore = '';
|
|
27
|
+
let dispatcher = this.dynamicsWorld.getDispatcher();
|
|
28
|
+
let numManifolds = dispatcher.getNumManifolds();
|
|
29
|
+
for(let i = 0;i < numManifolds;i++) {
|
|
30
|
+
let contactManifold = dispatcher.getManifoldByIndexInternal(i);
|
|
31
|
+
// let numContacts = contactManifold.getNumContacts();
|
|
32
|
+
if(this.ground.kB == contactManifold.getBody0().kB ||
|
|
33
|
+
this.ground.kB == contactManifold.getBody1().kB) {
|
|
34
|
+
// console.log(this.ground ,'GROUND IS IN CONTACT WHO IS BODY1 ', contactManifold.getBody1())
|
|
35
|
+
// CHECK ROTATION BEST WAY - VISAL PART IS NOT INTEREST NOW
|
|
36
|
+
if(this.ground.kB == contactManifold.getBody0().kB) {
|
|
37
|
+
var MY_DICE_NAME = this.getNameByBody(contactManifold.getBody1());
|
|
38
|
+
var testR = contactManifold.getBody1().getWorldTransform().getRotation();
|
|
39
|
+
}
|
|
40
|
+
if(this.ground.kB == contactManifold.getBody1().kB) {
|
|
41
|
+
var MY_DICE_NAME = this.getNameByBody(contactManifold.getBody0());
|
|
42
|
+
var testR = contactManifold.getBody0().getWorldTransform().getRotation();
|
|
43
|
+
}
|
|
44
|
+
var passed = false;
|
|
45
|
+
if(Math.abs(testR.y()) < 0.00001) {
|
|
46
|
+
this.lastRoll = "3";
|
|
47
|
+
this.presentScore += 4;
|
|
48
|
+
passed = true;
|
|
49
|
+
}
|
|
50
|
+
if(Math.abs(testR.x()) < 0.00001) {
|
|
51
|
+
this.lastRoll = "5";
|
|
52
|
+
this.presentScore += 3;
|
|
53
|
+
passed = true;
|
|
54
|
+
}
|
|
55
|
+
if(testR.x().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
|
|
56
|
+
this.lastRoll = "6";
|
|
57
|
+
this.presentScore += 2;
|
|
58
|
+
passed = true;
|
|
59
|
+
}
|
|
60
|
+
if(testR.x().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
|
|
61
|
+
this.lastRoll = "2";
|
|
62
|
+
this.presentScore += 1;
|
|
63
|
+
passed = true;
|
|
64
|
+
}
|
|
65
|
+
if(testR.z().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
|
|
66
|
+
this.lastRoll = "4";
|
|
67
|
+
this.presentScore += 6;
|
|
68
|
+
passed = true;
|
|
69
|
+
}
|
|
70
|
+
if(testR.z().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
|
|
71
|
+
this.lastRoll = "1";
|
|
72
|
+
this.presentScore += 5;
|
|
73
|
+
passed = true;
|
|
74
|
+
}
|
|
75
|
+
if(passed == true) dispatchEvent(new CustomEvent(`dice-${this.lastRoll}`, {
|
|
76
|
+
detail: {
|
|
77
|
+
result: `dice-${this.lastRoll}`,
|
|
78
|
+
cubeId: MY_DICE_NAME
|
|
79
|
+
}
|
|
80
|
+
}))
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
addRaycastListener();
|
|
86
|
+
|
|
87
|
+
addEventListener("ray.hit.event", (e) => {
|
|
88
|
+
|
|
89
|
+
console.log("hit cube ", e.detail.hitObject.name)
|
|
90
|
+
|
|
91
|
+
if(application.dices.STATUS == "FREE_TO_PLAY") {
|
|
92
|
+
console.log("hit cube status free to play prevent pick. ", e.detail.hitObject.name)
|
|
93
|
+
} else if(application.dices.STATUS == "SELECT_DICES_1") {
|
|
94
|
+
console.log("hit cube status SELECT1 pick.", e.detail.hitObject.name)
|
|
95
|
+
application.dices.pickDice(e.detail.hitObject.name)
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
// OR add manual see readme
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
addEventListener('mousemove', (e) => {
|
|
102
|
+
// console.log('only on click')
|
|
103
|
+
touchCoordinate.enabled = true;
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// Sounds
|
|
107
|
+
application.matrixSounds.createAudio('start', 'res/audios/start.mp3', 1)
|
|
108
|
+
application.matrixSounds.createAudio('block', 'res/audios/block.mp3', 6)
|
|
109
|
+
application.matrixSounds.createAudio('dice1', 'res/audios/dice1.mp3', 6)
|
|
110
|
+
application.matrixSounds.createAudio('dice2', 'res/audios/dice2.mp3', 6)
|
|
111
|
+
|
|
112
|
+
addEventListener('AmmoReady', () => {
|
|
113
|
+
downloadMeshes({
|
|
114
|
+
cube: "./res/meshes/jamb/dice.obj",
|
|
115
|
+
}, onLoadObj, {scale: [1, 1, 1], swap: [null]})
|
|
116
|
+
|
|
117
|
+
downloadMeshes({
|
|
118
|
+
bg: "./res/meshes/jamb/bg.obj",
|
|
119
|
+
}, onLoadObjFloor, {scale: [3, 1, 3], swap: [null]})
|
|
120
|
+
|
|
121
|
+
downloadMeshes({
|
|
122
|
+
mainTitle: "./res/meshes/jamb/jamb-title.obj",
|
|
123
|
+
}, onLoadObjOther, {scale: [3, 2, 3], swap: [null]})
|
|
124
|
+
|
|
125
|
+
downloadMeshes({
|
|
126
|
+
cube: "./res/meshes/jamb/dice.obj",
|
|
127
|
+
}, onLoadObjWallCenter, {scale: [50, 10, 10], swap: [null]})
|
|
128
|
+
|
|
129
|
+
downloadMeshes({
|
|
130
|
+
cube: "./res/meshes/jamb/dice.obj",
|
|
131
|
+
}, (m) => {
|
|
132
|
+
for(var key in m) {
|
|
133
|
+
// console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
|
|
134
|
+
}
|
|
135
|
+
// right
|
|
136
|
+
application.addMeshObj({
|
|
137
|
+
position: {x: 25, y: 5.5, z: -25},
|
|
138
|
+
rotation: {x: 0, y: -22, z: 0},
|
|
139
|
+
scale: [25, 10, 4],
|
|
140
|
+
texturesPaths: ['./res/meshes/jamb/text.png'],
|
|
141
|
+
name: 'wallRight',
|
|
142
|
+
mesh: m.cube,
|
|
143
|
+
physics: {
|
|
144
|
+
mass: 0,
|
|
145
|
+
enabled: true,
|
|
146
|
+
geometry: "Cube"
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
application.addMeshObj({
|
|
151
|
+
position: {x: -25, y: 5.5, z: -25},
|
|
152
|
+
rotation: {x: 0, y: 22, z: 0},
|
|
153
|
+
scale: [25, 10, 4],
|
|
154
|
+
texturesPaths: ['./res/meshes/jamb/text.png'],
|
|
155
|
+
name: 'wallLeft',
|
|
156
|
+
mesh: m.cube,
|
|
157
|
+
physics: {
|
|
158
|
+
mass: 0,
|
|
159
|
+
enabled: true,
|
|
160
|
+
geometry: "Cube"
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
}, {scale: [25, 10, 4], swap: [null]})
|
|
164
|
+
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
function onLoadObjWallCenter(m) {
|
|
168
|
+
application.myLoadedMeshesWalls = m;
|
|
169
|
+
for(var key in m) {
|
|
170
|
+
// console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// WALLS Center
|
|
174
|
+
application.addMeshObj({
|
|
175
|
+
position: {x: 0, y: 5, z: -45},
|
|
176
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
177
|
+
scale: [50, 10, 10],
|
|
178
|
+
texturesPaths: ['./res/meshes/jamb/text.png'],
|
|
179
|
+
name: 'wallCenter',
|
|
180
|
+
mesh: m.cube,
|
|
181
|
+
physics: {
|
|
182
|
+
mass: 0,
|
|
183
|
+
enabled: true,
|
|
184
|
+
geometry: "Cube"
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function onLoadObjOther(m) {
|
|
190
|
+
application.myLoadedMeshes = m;
|
|
191
|
+
for(var key in m) {
|
|
192
|
+
// console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
|
|
193
|
+
}
|
|
194
|
+
// Add logo text top
|
|
195
|
+
application.addMeshObj({
|
|
196
|
+
position: {x: 0, y: 6, z: -15},
|
|
197
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
198
|
+
texturesPaths: ['./res/meshes/jamb/text.png'],
|
|
199
|
+
name: 'mainTitle',
|
|
200
|
+
mesh: m.mainTitle,
|
|
201
|
+
physics: {
|
|
202
|
+
mass: 0,
|
|
203
|
+
enabled: true,
|
|
204
|
+
geometry: "Cube"
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
// console.log('camera set')
|
|
208
|
+
// application.cameras.WASD.pitch = 0.2
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
app.cameras.WASD.velocity[1] = 18
|
|
211
|
+
// BODY , x, y, z, rotX, rotY, RotZ
|
|
212
|
+
app.matrixAmmo.setKinematicTransform(
|
|
213
|
+
app.matrixAmmo.getBodyByName('mainTitle'), 0, 0, 0, 1)
|
|
214
|
+
app.matrixAmmo.setKinematicTransform(
|
|
215
|
+
app.matrixAmmo.getBodyByName('bg'), 0, -10, 0, 0, 0, 0)
|
|
216
|
+
// Better access getBodyByName
|
|
217
|
+
console.log(' app.matrixAmmo. ', app.matrixAmmo.getBodyByName('CubePhysics1'))
|
|
218
|
+
}, 1225)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function onLoadObjFloor(m) {
|
|
222
|
+
application.myLoadedMeshes = m;
|
|
223
|
+
for(var key in m) {
|
|
224
|
+
// console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
application.addMeshObj({
|
|
228
|
+
scale: [10, 0.1, 0.1],
|
|
229
|
+
position: {x: 0, y: 6, z: -10},
|
|
230
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
231
|
+
// rotationSpeed: {x: 0, y: 0, z: 0},
|
|
232
|
+
texturesPaths: ['./res/meshes/jamb/bg.png'],
|
|
233
|
+
name: 'bg',
|
|
234
|
+
mesh: m.bg,
|
|
235
|
+
physics: {
|
|
236
|
+
collide: false,
|
|
237
|
+
mass: 0,
|
|
238
|
+
enabled: true,
|
|
239
|
+
geometry: "Cube"
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function onLoadObj(m) {
|
|
245
|
+
application.myLoadedMeshes = m;
|
|
246
|
+
for(var key in m) {
|
|
247
|
+
// console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Add dices
|
|
251
|
+
application.addMeshObj({
|
|
252
|
+
position: {x: 0, y: 6, z: -10},
|
|
253
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
254
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
255
|
+
texturesPaths: ['./res/meshes/jamb/dice.png'],
|
|
256
|
+
useUVShema4x2: true,
|
|
257
|
+
name: 'CubePhysics1',
|
|
258
|
+
mesh: m.cube,
|
|
259
|
+
raycast: {enabled: true, radius: 2},
|
|
260
|
+
physics: {
|
|
261
|
+
enabled: true,
|
|
262
|
+
geometry: "Cube"
|
|
263
|
+
}
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
application.addMeshObj({
|
|
267
|
+
position: {x: -5, y: 4, z: -14},
|
|
268
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
269
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
270
|
+
texturesPaths: ['./res/meshes/jamb/dice.png'],
|
|
271
|
+
useUVShema4x2: true,
|
|
272
|
+
name: 'CubePhysics2',
|
|
273
|
+
mesh: m.cube,
|
|
274
|
+
raycast: {enabled: true, radius: 2},
|
|
275
|
+
physics: {
|
|
276
|
+
enabled: true,
|
|
277
|
+
geometry: "Cube"
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
application.addMeshObj({
|
|
282
|
+
position: {x: 4, y: 8, z: -10},
|
|
283
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
284
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
285
|
+
texturesPaths: ['./res/meshes/jamb/dice.png'],
|
|
286
|
+
useUVShema4x2: true,
|
|
287
|
+
name: 'CubePhysics3',
|
|
288
|
+
mesh: m.cube,
|
|
289
|
+
raycast: {enabled: true, radius: 2},
|
|
290
|
+
physics: {
|
|
291
|
+
enabled: true,
|
|
292
|
+
geometry: "Cube"
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
application.addMeshObj({
|
|
297
|
+
position: {x: 3, y: 4, z: -10},
|
|
298
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
299
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
300
|
+
texturesPaths: ['./res/meshes/jamb/dice.png'],
|
|
301
|
+
useUVShema4x2: true,
|
|
302
|
+
name: 'CubePhysics4',
|
|
303
|
+
mesh: m.cube,
|
|
304
|
+
raycast: {enabled: true, radius: 2},
|
|
305
|
+
physics: {
|
|
306
|
+
enabled: true,
|
|
307
|
+
geometry: "Cube"
|
|
308
|
+
}
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
application.addMeshObj({
|
|
312
|
+
position: {x: -2, y: 4, z: -13},
|
|
313
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
314
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
315
|
+
texturesPaths: ['./res/meshes/jamb/dice.png'],
|
|
316
|
+
useUVShema4x2: true,
|
|
317
|
+
name: 'CubePhysics5',
|
|
318
|
+
mesh: m.cube,
|
|
319
|
+
raycast: {enabled: true,radius: 2},
|
|
320
|
+
physics: {
|
|
321
|
+
enabled: true,
|
|
322
|
+
geometry: "Cube"
|
|
323
|
+
}
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
application.addMeshObj({
|
|
327
|
+
position: {x: -4, y: 6, z: -9},
|
|
328
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
329
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
330
|
+
texturesPaths: ['./res/meshes/jamb/dice.png'],
|
|
331
|
+
useUVShema4x2: true,
|
|
332
|
+
name: 'CubePhysics6',
|
|
333
|
+
mesh: m.cube,
|
|
334
|
+
raycast: {enabled: true, radius: 2},
|
|
335
|
+
physics: {
|
|
336
|
+
enabled: true,
|
|
337
|
+
geometry: "Cube"
|
|
338
|
+
}
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
application.TOLERANCE = 0;
|
|
343
|
+
let allDiceDoneProcedure = () => {
|
|
344
|
+
console.log("ALL DONE")
|
|
345
|
+
application.TOLERANCE++;
|
|
346
|
+
if(application.TOLERANCE >= 1) {
|
|
347
|
+
removeEventListener('dice-1', dice1Click)
|
|
348
|
+
removeEventListener('dice-2', dice2Click)
|
|
349
|
+
removeEventListener('dice-3', dice3Click)
|
|
350
|
+
removeEventListener('dice-4', dice4Click)
|
|
351
|
+
removeEventListener('dice-5', dice5Click)
|
|
352
|
+
removeEventListener('dice-6', dice6Click)
|
|
353
|
+
console.log('FINAL >>>> ', dices.R)
|
|
354
|
+
application.TOLERANCE = 0;
|
|
355
|
+
|
|
356
|
+
app.cameras.WASD.yaw = 0.01;
|
|
357
|
+
app.cameras.WASD.pitch = -1.26;
|
|
358
|
+
app.cameras.WASD.position[2] = -18;
|
|
359
|
+
app.cameras.WASD.position[1] = 19;
|
|
360
|
+
|
|
361
|
+
// dices.STATUS = "PLACE_RESULT";
|
|
362
|
+
dices.STATUS = "SELECT_DICES_1";
|
|
363
|
+
// application.dices.STATUS = "FREE_TO_PLAY";
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
addEventListener('all-done', allDiceDoneProcedure)
|
|
368
|
+
|
|
369
|
+
addEventListener('FREE_TO_PLAY', () => {
|
|
370
|
+
// setup againt 3d space loc
|
|
371
|
+
console.info(' setup againt 3d space loc make some logic for pos ...')
|
|
372
|
+
app.matrixAmmo.getBodyByName('CubePhysics1').setLinearVelocity(new Ammo.btVector3(2, 2, 12))
|
|
373
|
+
app.matrixAmmo.getBodyByName('CubePhysics2').setLinearVelocity(new Ammo.btVector3(2, 2, 12))
|
|
374
|
+
app.matrixAmmo.getBodyByName('CubePhysics3').setLinearVelocity(new Ammo.btVector3(2, 2, 12))
|
|
375
|
+
app.matrixAmmo.getBodyByName('CubePhysics4').setLinearVelocity(new Ammo.btVector3(2, 2, 12))
|
|
376
|
+
app.matrixAmmo.getBodyByName('CubePhysics5').setLinearVelocity(new Ammo.btVector3(2, 2, 12))
|
|
377
|
+
app.matrixAmmo.getBodyByName('CubePhysics6').setLinearVelocity(new Ammo.btVector3(2, 2, 12))
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
// ACTIONS
|
|
381
|
+
let dice1Click = (e) => {
|
|
382
|
+
// console.info('DICE 1', e.detail)
|
|
383
|
+
dices.R[e.detail.cubeId] = '1';
|
|
384
|
+
dices.checkAll()
|
|
385
|
+
};
|
|
386
|
+
// addEventListener('dice-1', dice1Click)
|
|
387
|
+
|
|
388
|
+
let dice2Click = (e) => {
|
|
389
|
+
// console.info('DICE 2', e.detail)
|
|
390
|
+
dices.R[e.detail.cubeId] = '2';
|
|
391
|
+
dices.checkAll()
|
|
392
|
+
};
|
|
393
|
+
// addEventListener('dice-2', dice2Click)
|
|
394
|
+
|
|
395
|
+
let dice3Click = (e) => {
|
|
396
|
+
// console.info('DICE 3', e.detail)
|
|
397
|
+
dices.R[e.detail.cubeId] = '3';
|
|
398
|
+
dices.checkAll()
|
|
399
|
+
};
|
|
400
|
+
// addEventListener('dice-3', dice3Click)
|
|
401
|
+
|
|
402
|
+
let dice4Click = (e) => {
|
|
403
|
+
// console.info('DICE 4', e.detail)
|
|
404
|
+
dices.R[e.detail.cubeId] = '4';
|
|
405
|
+
dices.checkAll()
|
|
406
|
+
}
|
|
407
|
+
// addEventListener('dice-4', dice4Click)
|
|
408
|
+
|
|
409
|
+
let dice5Click = (e) => {
|
|
410
|
+
// console.info('DICE 5', e.detail)
|
|
411
|
+
dices.R[e.detail.cubeId] = '5';
|
|
412
|
+
dices.checkAll()
|
|
413
|
+
}
|
|
414
|
+
// addEventListener('dice-5', dice5Click)
|
|
415
|
+
|
|
416
|
+
let dice6Click = (e) => {
|
|
417
|
+
// console.info('DICE 6', e.detail)
|
|
418
|
+
dices.R[e.detail.cubeId] = '6';
|
|
419
|
+
dices.checkAll()
|
|
420
|
+
}
|
|
421
|
+
// addEventListener('dice-6', dice6Click)
|
|
422
|
+
|
|
423
|
+
let rollProcedure = () => {
|
|
424
|
+
if(dices.STATUS == "FREE_TO_PLAY") {
|
|
425
|
+
|
|
426
|
+
app.matrixSounds.play('start')
|
|
427
|
+
|
|
428
|
+
dices.STATUS = "IN_PLAY";
|
|
429
|
+
addEventListener('dice-1', dice1Click)
|
|
430
|
+
addEventListener('dice-2', dice2Click)
|
|
431
|
+
addEventListener('dice-3', dice3Click)
|
|
432
|
+
addEventListener('dice-4', dice4Click)
|
|
433
|
+
addEventListener('dice-5', dice5Click)
|
|
434
|
+
addEventListener('dice-6', dice6Click)
|
|
435
|
+
|
|
436
|
+
function shootDice(x) {
|
|
437
|
+
setTimeout(() => {
|
|
438
|
+
app.matrixAmmo.getBodyByName(`CubePhysics${x}`).setAngularVelocity(new Ammo.btVector3(
|
|
439
|
+
randomFloatFromTo(3, 12), 9, 9
|
|
440
|
+
))
|
|
441
|
+
app.matrixAmmo.getBodyByName(`CubePhysics${x}`).setLinearVelocity(new Ammo.btVector3(
|
|
442
|
+
randomFloatFromTo(-5, 5), 15, -20
|
|
443
|
+
))
|
|
444
|
+
}, 200 * x)
|
|
445
|
+
}
|
|
446
|
+
for(var x = 1;x < 7;x++) {
|
|
447
|
+
shootDice(x)
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
addEventListener('DICE.ROLL', rollProcedure)
|
|
455
|
+
|
|
456
|
+
app.ROLL = () => {
|
|
457
|
+
dispatchEvent(new CustomEvent('DICE.ROLL', {}))
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
}
|
|
55
461
|
})
|
|
56
462
|
|
|
57
463
|
window.app = application
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
app.matrixAmmo.rigidBodies[0].setAngularVelocity(new Ammo.btVector3(5,6,0))
|
|
3
|
+
app.matrixAmmo.rigidBodies[0].setLinearVelocity(new Ammo.btVector3(-0,16,1))
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
dice shema for now
|
|
7
|
+
====================
|
|
8
|
+
FOR 4 gives 1
|
|
9
|
+
2 6
|
|
10
|
+
6 5
|
|
11
|
+
1 2
|
|
12
|
+
3 4
|
|
13
|
+
5 3
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
https://phaser.discourse.group/t/disable-all-collision-impacts-matter-js/13715/2
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
https://stackoverflow.com/questions/17755848/is-it-possible-to-disable-x-z-rotation-in-ammo-js
|
|
21
|
+
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matrix-engine-wgpu",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "webGPU powered pwa application. Crazy fast rendering with AmmoJS physics support.",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "+HOTFIX raycast, webGPU powered pwa application. Crazy fast rendering with AmmoJS physics support. Simple raycaster hit object added.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"main-worker": "watchify app-worker.js -p [esmify --noImplicitAny] -o public/app-worker.js",
|
|
8
8
|
"examples": "watchify examples.js -p [esmify --noImplicitAny] -o public/examples.js",
|
|
9
9
|
"main": "watchify main.js -p [esmify --noImplicitAny] -o public/app.js",
|
|
10
|
-
"
|
|
11
|
-
"build-all": "npm run main-worker | npm run examples | npm run main | npm run
|
|
10
|
+
"empty": "watchify empty.js -p [esmify --noImplicitAny] -o public/empty.js",
|
|
11
|
+
"build-all": "npm run main-worker | npm run examples | npm run main | npm run empty",
|
|
12
|
+
"hosts": "http-server ./public/ -p 3000",
|
|
13
|
+
"build.demo1": "browserify main.js -p esmify > public/app.js"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
|
-
"3dScene",
|
|
15
|
-
"webGPU
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
16
|
+
"3dScene",
|
|
17
|
+
"webGPU",
|
|
18
|
+
"webGPU-hit-detect",
|
|
19
|
+
"webGPU-raycaster",
|
|
20
|
+
"webGPU-click-on-object",
|
|
21
|
+
"webGPU-scene",
|
|
22
|
+
"webGPU-engine",
|
|
23
|
+
"matrix",
|
|
24
|
+
"matrix-engine",
|
|
25
|
+
"matrix-engine-webGPU",
|
|
26
|
+
"matrix-calculation",
|
|
27
|
+
"modelView",
|
|
28
|
+
"modelViewProjectionMatrix",
|
|
29
|
+
"ProjectionMatrix",
|
|
30
|
+
"render",
|
|
31
|
+
"wgpu",
|
|
32
|
+
"zlatnaspirala",
|
|
33
|
+
"maximumroulette.com",
|
|
34
|
+
"GLSL",
|
|
35
|
+
"raycast",
|
|
36
|
+
"hit-3d-object",
|
|
37
|
+
"hit-object",
|
|
38
|
+
"webgpu-obj-loader",
|
|
39
|
+
"webgpu-fps"
|
|
23
40
|
],
|
|
24
41
|
"author": "Nikola Lukic",
|
|
25
42
|
"license": "MIT",
|
|
@@ -30,6 +47,7 @@
|
|
|
30
47
|
"watchify": "^4.0.0"
|
|
31
48
|
},
|
|
32
49
|
"dependencies": {
|
|
50
|
+
"http-server": "^14.1.1",
|
|
33
51
|
"wgpu-matrix": "^2.5.1"
|
|
34
52
|
}
|
|
35
53
|
}
|