matrix-engine-wgpu 1.4.4 → 1.4.6
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/examples/video-texture.js +6 -1
- package/main.js +57 -43
- package/non-project-files/3d-jamb.png +0 -0
- package/non-project-files/performance.png +0 -0
- package/package.json +1 -1
- package/public/app.js +12835 -12497
- package/public/examples.js +71 -33
- package/public/res/meshes/jamb/dice - Copy.png +0 -0
- package/public/res/meshes/jamb/dice.obj +40 -40
- package/readme.md +12 -1
- package/src/engine/engine.js +3 -1
- package/src/engine/materials.js +1 -1
- package/src/engine/raycast.js +68 -38
- package/public/res/meshes/jamb/dice-default.png +0 -0
- package/public/res/meshes/jamb/dice-mark.png +0 -0
package/public/examples.js
CHANGED
|
@@ -473,6 +473,10 @@ var loadVideoTexture = function () {
|
|
|
473
473
|
// if you dont wanna light just use intesity = 0
|
|
474
474
|
// videoTexture is app main instance
|
|
475
475
|
videoTexture.addLight();
|
|
476
|
+
(0, _raycast.addRaycastsAABBListener)();
|
|
477
|
+
videoTexture.canvas.addEventListener("ray.hit.event", e => {
|
|
478
|
+
console.log('test ray after shadows merge');
|
|
479
|
+
});
|
|
476
480
|
addEventListener('AmmoReady', () => {
|
|
477
481
|
(0, _loaderObj.downloadMeshes)({
|
|
478
482
|
welcomeText: "./res/meshes/blender/piramyd.obj",
|
|
@@ -510,8 +514,11 @@ var loadVideoTexture = function () {
|
|
|
510
514
|
physics: {
|
|
511
515
|
enabled: true,
|
|
512
516
|
geometry: "Cube"
|
|
517
|
+
},
|
|
518
|
+
raycast: {
|
|
519
|
+
enabled: true,
|
|
520
|
+
radius: 12
|
|
513
521
|
}
|
|
514
|
-
// raycast: { enabled: true , radius: 2 }
|
|
515
522
|
});
|
|
516
523
|
var TEST = videoTexture.getSceneObjectByName('MyVideoTex');
|
|
517
524
|
console.log(`%c Test video-texture...`, _utils.LOG_MATRIX);
|
|
@@ -8049,7 +8056,7 @@ class Materials {
|
|
|
8049
8056
|
return;
|
|
8050
8057
|
} else {}
|
|
8051
8058
|
if (this.isVideo == true) {
|
|
8052
|
-
console.info("✅ video sceneBindGroupForRender ");
|
|
8059
|
+
// console.info("✅ video sceneBindGroupForRender ");
|
|
8053
8060
|
this.sceneBindGroupForRender = this.device.createBindGroup({
|
|
8054
8061
|
layout: this.bglForRender,
|
|
8055
8062
|
entries: [{
|
|
@@ -8912,34 +8919,64 @@ function getRayFromMouse(event, canvas, camera) {
|
|
|
8912
8919
|
const rect = canvas.getBoundingClientRect();
|
|
8913
8920
|
let x = (event.clientX - rect.left) / rect.width * 2 - 1;
|
|
8914
8921
|
let y = (event.clientY - rect.top) / rect.height * 2 - 1;
|
|
8915
|
-
//
|
|
8916
|
-
|
|
8917
|
-
y = -y;
|
|
8918
|
-
const fov = Math.PI / 4;
|
|
8922
|
+
y = -y; // flip Y only (WebGPU NDC)
|
|
8923
|
+
|
|
8919
8924
|
const aspect = canvas.width / canvas.height;
|
|
8920
|
-
|
|
8921
|
-
const far = 1000;
|
|
8922
|
-
camera.projectionMatrix = _wgpuMatrix.mat4.perspective(2 * Math.PI / 5, aspect, 1, 1000.0);
|
|
8925
|
+
camera.projectionMatrix = _wgpuMatrix.mat4.perspective(2 * Math.PI / 5, aspect, 0.1, 1000);
|
|
8923
8926
|
const invProjection = _wgpuMatrix.mat4.inverse(camera.projectionMatrix);
|
|
8924
8927
|
const invView = _wgpuMatrix.mat4.inverse(camera.view);
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
let
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
}
|
|
8935
|
-
const rayOrigin = [camera.position[0], camera.position[1], camera.position[2]];
|
|
8936
|
-
const rayDirection = _wgpuMatrix.vec3.normalize(_wgpuMatrix.vec3.subtract(world, rayOrigin));
|
|
8937
|
-
rayDirection[2] = -rayDirection[2];
|
|
8928
|
+
|
|
8929
|
+
// NDC -> clip -> eye -> world
|
|
8930
|
+
let clip = [x, y, 1, 1];
|
|
8931
|
+
let eye = _wgpuMatrix.vec4.transformMat4(clip, invProjection);
|
|
8932
|
+
eye = [eye[0], eye[1], -1, 0]; // direction in view space
|
|
8933
|
+
|
|
8934
|
+
let worldDir = _wgpuMatrix.vec4.transformMat4(eye, invView);
|
|
8935
|
+
const rayDirection = _wgpuMatrix.vec3.normalize([worldDir[0], worldDir[1], worldDir[2]]);
|
|
8936
|
+
const rayOrigin = [...camera.position];
|
|
8938
8937
|
return {
|
|
8939
8938
|
rayOrigin,
|
|
8940
8939
|
rayDirection
|
|
8941
8940
|
};
|
|
8942
8941
|
}
|
|
8942
|
+
// export function getRayFromMouse(event, canvas, camera) {
|
|
8943
|
+
// const rect = canvas.getBoundingClientRect();
|
|
8944
|
+
// let x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
|
8945
|
+
// let y = ((event.clientY - rect.top) / rect.height) * 2 - 1;
|
|
8946
|
+
// // simple invert
|
|
8947
|
+
// x = -x;
|
|
8948
|
+
// y = -y;
|
|
8949
|
+
// const fov = Math.PI / 4;
|
|
8950
|
+
// const aspect = canvas.width / canvas.height;
|
|
8951
|
+
// const near = 0.1;
|
|
8952
|
+
// const far = 1000;
|
|
8953
|
+
// camera.projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 1000.0);
|
|
8954
|
+
// const invProjection = mat4.inverse(camera.projectionMatrix);
|
|
8955
|
+
// const invView = mat4.inverse(camera.view);
|
|
8956
|
+
// const ndc = [x, y, 1, 1];
|
|
8957
|
+
// let worldPos = multiplyMatrixVector(invProjection, ndc);
|
|
8958
|
+
// worldPos = multiplyMatrixVector(invView, worldPos);
|
|
8959
|
+
// let world;
|
|
8960
|
+
// if(worldPos[3] !== 0) {
|
|
8961
|
+
// world = [
|
|
8962
|
+
// worldPos[0] / worldPos[3],
|
|
8963
|
+
// worldPos[2] / worldPos[3],
|
|
8964
|
+
// worldPos[1] / worldPos[3]
|
|
8965
|
+
// ];
|
|
8966
|
+
// } else {
|
|
8967
|
+
// console.log("[raycaster]special case 0.");
|
|
8968
|
+
// world = [
|
|
8969
|
+
// worldPos[0],
|
|
8970
|
+
// worldPos[1],
|
|
8971
|
+
// worldPos[2]
|
|
8972
|
+
// ];
|
|
8973
|
+
// }
|
|
8974
|
+
// const rayOrigin = [camera.position[0], camera.position[1], camera.position[2]];
|
|
8975
|
+
// const rayDirection = vec3.normalize(vec3.subtract(world, rayOrigin));
|
|
8976
|
+
// rayDirection[2] = -rayDirection[2];
|
|
8977
|
+
// return {rayOrigin, rayDirection};
|
|
8978
|
+
// }
|
|
8979
|
+
|
|
8943
8980
|
function getRayFromMouse2(event, canvas, camera) {
|
|
8944
8981
|
const rect = canvas.getBoundingClientRect();
|
|
8945
8982
|
let x = (event.clientX - rect.left) / rect.width * 2 - 1;
|
|
@@ -8988,17 +9025,17 @@ function addRaycastListener(canvasId = "canvas1") {
|
|
|
8988
9025
|
rayDirection
|
|
8989
9026
|
} = getRayFromMouse(event, canvasDom, camera);
|
|
8990
9027
|
for (const object of app.mainRenderBundle) {
|
|
8991
|
-
if (object.raycast.enabled ==
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
|
|
8995
|
-
|
|
8996
|
-
|
|
8997
|
-
|
|
8998
|
-
|
|
8999
|
-
|
|
9000
|
-
}
|
|
9001
|
-
}
|
|
9028
|
+
if (object.raycast.enabled == true) {
|
|
9029
|
+
if (rayIntersectsSphere(rayOrigin, rayDirection, object.position, object.raycast.radius)) {
|
|
9030
|
+
// Just like in matrix-engine webGL version "ray.hit.event"
|
|
9031
|
+
canvasDom.dispatchEvent(new CustomEvent('ray.hit.event', {
|
|
9032
|
+
detail: {
|
|
9033
|
+
hitObject: object,
|
|
9034
|
+
rayOrigin: rayOrigin,
|
|
9035
|
+
rayDirection: rayDirection
|
|
9036
|
+
}
|
|
9037
|
+
}));
|
|
9038
|
+
}
|
|
9002
9039
|
}
|
|
9003
9040
|
}
|
|
9004
9041
|
});
|
|
@@ -9059,6 +9096,7 @@ function addRaycastsAABBListener(canvasId = "canvas1") {
|
|
|
9059
9096
|
return;
|
|
9060
9097
|
}
|
|
9061
9098
|
canvasDom.addEventListener('click', event => {
|
|
9099
|
+
console.warn(`Canvas click ${event} `);
|
|
9062
9100
|
const camera = app.cameras.WASD;
|
|
9063
9101
|
const {
|
|
9064
9102
|
rayOrigin,
|
|
Binary file
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# Blender 4.1.1
|
|
2
|
-
# www.blender.org
|
|
3
|
-
mtllib dice.mtl
|
|
4
|
-
o Cube
|
|
5
|
-
v 1.000000 1.000000 -1.000000
|
|
6
|
-
v 1.000000 -1.000000 -1.000000
|
|
7
|
-
v 1.000000 1.000000 1.000000
|
|
8
|
-
v 1.000000 -1.000000 1.000000
|
|
9
|
-
v -1.000000 1.000000 -1.000000
|
|
10
|
-
v -1.000000 -1.000000 -1.000000
|
|
11
|
-
v -1.000000 1.000000 1.000000
|
|
12
|
-
v -1.000000 -1.000000 1.000000
|
|
13
|
-
vn -0.0000 1.0000 -0.0000
|
|
14
|
-
vn -0.0000 -0.0000 1.0000
|
|
15
|
-
vn -1.0000 -0.0000 -0.0000
|
|
16
|
-
vn -0.0000 -1.0000 -0.0000
|
|
17
|
-
vn 1.0000 -0.0000 -0.0000
|
|
18
|
-
vn -0.0000 -0.0000 -1.0000
|
|
19
|
-
vt 0.625000 0.500000
|
|
20
|
-
vt 0.875000 0.500000
|
|
21
|
-
vt 0.875000 0.750000
|
|
22
|
-
vt 0.625000 0.750000
|
|
23
|
-
vt 0.375000 0.750000
|
|
24
|
-
vt 0.625000 1.000000
|
|
25
|
-
vt 0.375000 1.000000
|
|
26
|
-
vt 0.375000 0.000000
|
|
27
|
-
vt 0.625000 0.000000
|
|
28
|
-
vt 0.625000 0.250000
|
|
29
|
-
vt 0.375000 0.250000
|
|
30
|
-
vt 0.125000 0.500000
|
|
31
|
-
vt 0.375000 0.500000
|
|
32
|
-
vt 0.125000 0.750000
|
|
33
|
-
s 0
|
|
34
|
-
usemtl Material
|
|
35
|
-
f 1/1/1 5/2/1 7/3/1 3/4/1
|
|
36
|
-
f 4/5/2 3/4/2 7/6/2 8/7/2
|
|
37
|
-
f 8/8/3 7/9/3 5/10/3 6/11/3
|
|
38
|
-
f 6/12/4 2/13/4 4/5/4 8/14/4
|
|
39
|
-
f 2/13/5 1/1/5 3/4/5 4/5/5
|
|
40
|
-
f 6/11/6 5/10/6 1/1/6 2/13/6
|
|
1
|
+
# Blender 4.1.1
|
|
2
|
+
# www.blender.org
|
|
3
|
+
mtllib dice.mtl
|
|
4
|
+
o Cube
|
|
5
|
+
v 1.000000 1.000000 -1.000000
|
|
6
|
+
v 1.000000 -1.000000 -1.000000
|
|
7
|
+
v 1.000000 1.000000 1.000000
|
|
8
|
+
v 1.000000 -1.000000 1.000000
|
|
9
|
+
v -1.000000 1.000000 -1.000000
|
|
10
|
+
v -1.000000 -1.000000 -1.000000
|
|
11
|
+
v -1.000000 1.000000 1.000000
|
|
12
|
+
v -1.000000 -1.000000 1.000000
|
|
13
|
+
vn -0.0000 1.0000 -0.0000
|
|
14
|
+
vn -0.0000 -0.0000 1.0000
|
|
15
|
+
vn -1.0000 -0.0000 -0.0000
|
|
16
|
+
vn -0.0000 -1.0000 -0.0000
|
|
17
|
+
vn 1.0000 -0.0000 -0.0000
|
|
18
|
+
vn -0.0000 -0.0000 -1.0000
|
|
19
|
+
vt 0.625000 0.500000
|
|
20
|
+
vt 0.875000 0.500000
|
|
21
|
+
vt 0.875000 0.750000
|
|
22
|
+
vt 0.625000 0.750000
|
|
23
|
+
vt 0.375000 0.750000
|
|
24
|
+
vt 0.625000 1.000000
|
|
25
|
+
vt 0.375000 1.000000
|
|
26
|
+
vt 0.375000 0.000000
|
|
27
|
+
vt 0.625000 0.000000
|
|
28
|
+
vt 0.625000 0.250000
|
|
29
|
+
vt 0.375000 0.250000
|
|
30
|
+
vt 0.125000 0.500000
|
|
31
|
+
vt 0.375000 0.500000
|
|
32
|
+
vt 0.125000 0.750000
|
|
33
|
+
s 0
|
|
34
|
+
usemtl Material
|
|
35
|
+
f 1/1/1 5/2/1 7/3/1 3/4/1
|
|
36
|
+
f 4/5/2 3/4/2 7/6/2 8/7/2
|
|
37
|
+
f 8/8/3 7/9/3 5/10/3 6/11/3
|
|
38
|
+
f 6/12/4 2/13/4 4/5/4 8/14/4
|
|
39
|
+
f 2/13/5 1/1/5 3/4/5 4/5/5
|
|
40
|
+
f 6/11/6 5/10/6 1/1/6 2/13/6
|
package/readme.md
CHANGED
|
@@ -227,7 +227,8 @@ Automatic raycast listener:
|
|
|
227
227
|
```js
|
|
228
228
|
addRaycastListener();
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
// Must be app.canvas or [Program name].canvas
|
|
231
|
+
app.canvas.addEventListener("ray.hit.event", event => {
|
|
231
232
|
console.log("Ray hit:", event.detail.hitObject);
|
|
232
233
|
});
|
|
233
234
|
```
|
|
@@ -438,9 +439,14 @@ urlQuery.lang;
|
|
|
438
439
|
`main.js` is the main instance for the Ultimate Yahtzee game template.
|
|
439
440
|
It contains the game context, e.g., `dices`.
|
|
440
441
|
|
|
442
|
+
What ever you find here onder main.js is open source part.
|
|
443
|
+
Next level of upgrade is commercial part.
|
|
444
|
+
|
|
441
445
|
For a clean startup without extra logic, use `empty.js`.
|
|
442
446
|
This minimal build is ideal for online editors like CodePen or StackOverflow snippets.
|
|
443
447
|
|
|
448
|
+
<img width="860" height="640" src="https://github.com/zlatnaspirala/matrix-engine-wgpu/blob/main/non-project-files/3d-jamb.png?raw=true" />
|
|
449
|
+
|
|
444
450
|
---
|
|
445
451
|
|
|
446
452
|
## NPM Scripts
|
|
@@ -481,6 +487,11 @@ This is static file storage.
|
|
|
481
487
|
|
|
482
488
|
---
|
|
483
489
|
|
|
490
|
+
Performance for Jamb game:
|
|
491
|
+
|
|
492
|
+
<img width="860" height="640" src="https://github.com/zlatnaspirala/matrix-engine-wgpu/blob/main/non-project-files/performance.png?raw=true" />
|
|
493
|
+
|
|
494
|
+
|
|
484
495
|
## License
|
|
485
496
|
|
|
486
497
|
### Usage Note
|
package/src/engine/engine.js
CHANGED
|
@@ -356,7 +356,9 @@ export function createInputHandler(window, canvas) {
|
|
|
356
356
|
case 'ControlLeft':
|
|
357
357
|
case 'KeyC': digital.down = value; break;
|
|
358
358
|
}
|
|
359
|
-
|
|
359
|
+
// if you wanna dosavle all keyboard input for some reason...
|
|
360
|
+
// add later like new option feature...
|
|
361
|
+
// e.preventDefault();
|
|
360
362
|
e.stopPropagation();
|
|
361
363
|
};
|
|
362
364
|
|
package/src/engine/materials.js
CHANGED
|
@@ -200,7 +200,7 @@ export default class Materials {
|
|
|
200
200
|
|
|
201
201
|
}
|
|
202
202
|
if(this.isVideo == true) {
|
|
203
|
-
console.info("✅ video sceneBindGroupForRender ");
|
|
203
|
+
// console.info("✅ video sceneBindGroupForRender ");
|
|
204
204
|
this.sceneBindGroupForRender = this.device.createBindGroup({
|
|
205
205
|
layout: this.bglForRender,
|
|
206
206
|
entries: [
|
package/src/engine/raycast.js
CHANGED
|
@@ -28,39 +28,62 @@ export function getRayFromMouse(event, canvas, camera) {
|
|
|
28
28
|
const rect = canvas.getBoundingClientRect();
|
|
29
29
|
let x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
|
30
30
|
let y = ((event.clientY - rect.top) / rect.height) * 2 - 1;
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
y = -y;
|
|
34
|
-
const fov = Math.PI / 4;
|
|
31
|
+
y = -y; // flip Y only (WebGPU NDC)
|
|
32
|
+
|
|
35
33
|
const aspect = canvas.width / canvas.height;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
camera.projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 1000.0);
|
|
34
|
+
camera.projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 0.1, 1000);
|
|
35
|
+
|
|
39
36
|
const invProjection = mat4.inverse(camera.projectionMatrix);
|
|
40
37
|
const invView = mat4.inverse(camera.view);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} else {
|
|
52
|
-
console.log("[raycaster]special case 0.");
|
|
53
|
-
world = [
|
|
54
|
-
worldPos[0],
|
|
55
|
-
worldPos[1],
|
|
56
|
-
worldPos[2]
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
const rayOrigin = [camera.position[0], camera.position[1], camera.position[2]];
|
|
60
|
-
const rayDirection = vec3.normalize(vec3.subtract(world, rayOrigin));
|
|
61
|
-
rayDirection[2] = -rayDirection[2];
|
|
38
|
+
|
|
39
|
+
// NDC -> clip -> eye -> world
|
|
40
|
+
let clip = [x, y, 1, 1];
|
|
41
|
+
let eye = vec4.transformMat4(clip, invProjection);
|
|
42
|
+
eye = [eye[0], eye[1], -1, 0]; // direction in view space
|
|
43
|
+
|
|
44
|
+
let worldDir = vec4.transformMat4(eye, invView);
|
|
45
|
+
const rayDirection = vec3.normalize([worldDir[0], worldDir[1], worldDir[2]]);
|
|
46
|
+
|
|
47
|
+
const rayOrigin = [...camera.position];
|
|
62
48
|
return {rayOrigin, rayDirection};
|
|
63
49
|
}
|
|
50
|
+
// export function getRayFromMouse(event, canvas, camera) {
|
|
51
|
+
// const rect = canvas.getBoundingClientRect();
|
|
52
|
+
// let x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
|
53
|
+
// let y = ((event.clientY - rect.top) / rect.height) * 2 - 1;
|
|
54
|
+
// // simple invert
|
|
55
|
+
// x = -x;
|
|
56
|
+
// y = -y;
|
|
57
|
+
// const fov = Math.PI / 4;
|
|
58
|
+
// const aspect = canvas.width / canvas.height;
|
|
59
|
+
// const near = 0.1;
|
|
60
|
+
// const far = 1000;
|
|
61
|
+
// camera.projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 1000.0);
|
|
62
|
+
// const invProjection = mat4.inverse(camera.projectionMatrix);
|
|
63
|
+
// const invView = mat4.inverse(camera.view);
|
|
64
|
+
// const ndc = [x, y, 1, 1];
|
|
65
|
+
// let worldPos = multiplyMatrixVector(invProjection, ndc);
|
|
66
|
+
// worldPos = multiplyMatrixVector(invView, worldPos);
|
|
67
|
+
// let world;
|
|
68
|
+
// if(worldPos[3] !== 0) {
|
|
69
|
+
// world = [
|
|
70
|
+
// worldPos[0] / worldPos[3],
|
|
71
|
+
// worldPos[2] / worldPos[3],
|
|
72
|
+
// worldPos[1] / worldPos[3]
|
|
73
|
+
// ];
|
|
74
|
+
// } else {
|
|
75
|
+
// console.log("[raycaster]special case 0.");
|
|
76
|
+
// world = [
|
|
77
|
+
// worldPos[0],
|
|
78
|
+
// worldPos[1],
|
|
79
|
+
// worldPos[2]
|
|
80
|
+
// ];
|
|
81
|
+
// }
|
|
82
|
+
// const rayOrigin = [camera.position[0], camera.position[1], camera.position[2]];
|
|
83
|
+
// const rayDirection = vec3.normalize(vec3.subtract(world, rayOrigin));
|
|
84
|
+
// rayDirection[2] = -rayDirection[2];
|
|
85
|
+
// return {rayOrigin, rayDirection};
|
|
86
|
+
// }
|
|
64
87
|
|
|
65
88
|
export function getRayFromMouse2(event, canvas, camera) {
|
|
66
89
|
const rect = canvas.getBoundingClientRect();
|
|
@@ -114,17 +137,20 @@ export function addRaycastListener(canvasId = "canvas1") {
|
|
|
114
137
|
let camera = app.cameras.WASD;
|
|
115
138
|
const {rayOrigin, rayDirection} = getRayFromMouse(event, canvasDom, camera);
|
|
116
139
|
for(const object of app.mainRenderBundle) {
|
|
117
|
-
if(object.raycast.enabled ==
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
140
|
+
if(object.raycast.enabled == true) {
|
|
141
|
+
if(rayIntersectsSphere(rayOrigin, rayDirection, object.position, object.raycast.radius)) {
|
|
142
|
+
// Just like in matrix-engine webGL version "ray.hit.event"
|
|
143
|
+
canvasDom.dispatchEvent(new CustomEvent('ray.hit.event', {
|
|
144
|
+
detail: {
|
|
145
|
+
hitObject: object,
|
|
146
|
+
rayOrigin: rayOrigin,
|
|
147
|
+
rayDirection: rayDirection
|
|
148
|
+
}
|
|
149
|
+
}))
|
|
150
|
+
if(touchCoordinate.stopOnFirstDetectedHit == true) {
|
|
151
|
+
break;
|
|
126
152
|
}
|
|
127
|
-
}
|
|
153
|
+
}
|
|
128
154
|
}
|
|
129
155
|
}
|
|
130
156
|
});
|
|
@@ -200,6 +226,7 @@ export function addRaycastsAABBListener(canvasId = "canvas1") {
|
|
|
200
226
|
}
|
|
201
227
|
|
|
202
228
|
canvasDom.addEventListener('click', (event) => {
|
|
229
|
+
console.warn(`Canvas click ${event} `);
|
|
203
230
|
const camera = app.cameras.WASD;
|
|
204
231
|
const {rayOrigin, rayDirection} = getRayFromMouse2(event, canvasDom, camera);
|
|
205
232
|
for(const object of app.mainRenderBundle) {
|
|
@@ -212,6 +239,9 @@ export function addRaycastsAABBListener(canvasId = "canvas1") {
|
|
|
212
239
|
rayOrigin: rayOrigin,
|
|
213
240
|
rayDirection: rayDirection
|
|
214
241
|
}));
|
|
242
|
+
if(touchCoordinate.stopOnFirstDetectedHit == true) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
215
245
|
}
|
|
216
246
|
}
|
|
217
247
|
});
|
|
Binary file
|
|
Binary file
|