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,41 +1,78 @@
1
1
  import MatrixEngineWGPU from "../src/world.js";
2
2
  import {downloadMeshes} from '../src/engine/loader-obj.js';
3
+ // import MatrixEngineWGPU from "./src/world.js";
4
+ // import {downloadMeshes} from './src/engine/loader-obj.js';
5
+ import {LOG_FUNNY, LOG_INFO, LOG_MATRIX} from "../src/engine/utils.js";
3
6
 
4
- export let application = new MatrixEngineWGPU({
5
- useSingleRenderPass: false,
6
- canvasSize: 'fullscreen'
7
+ export var loadObjFile = function() {
8
+
9
+ let loadObjFile = new MatrixEngineWGPU({
10
+ useSingleRenderPass: true,
11
+ canvasSize: 'fullscreen',
12
+ mainCameraParams: {
13
+ type: 'WASD',
14
+ responseCoef: 1000
15
+ }
7
16
  }, () => {
8
17
 
9
- let c = {
10
- scale: 1,
11
- position: {x: -2, y: 2, z: -10},
12
- rotation: {x: 0, y: 0, z: 0},
13
- rotationSpeed: {x: 0, y: 0, z: 0},
14
- texturesPaths: ['./res/textures/rust.jpg']
15
- };
18
+ addEventListener('AmmoReady', () => {
19
+ downloadMeshes({
20
+ welcomeText: "./res/meshes/blender/piramyd.obj",
21
+ armor: "./res/meshes/obj/armor.obj",
22
+ sphere: "./res/meshes/blender/sphere.obj",
23
+ cube: "./res/meshes/blender/cube.obj",
24
+ }, onLoadObj)
25
+ })
16
26
 
17
- let o = {
18
- scale: 2,
19
- position: {x: 2, y: 0, z: -10},
20
- rotation: {x: 0, y: 45, z: 0},
21
- rotationSpeed: {x: 0, y: 0, z: 0},
22
- texturesPaths: ['./res/textures/rust.jpg']
23
- };
27
+ function onLoadObj(m) {
28
+ loadObjFile.myLoadedMeshes = m;
29
+ for(var key in m) {
30
+ console.log(`%c Loaded objs: ${key} `, LOG_MATRIX);
31
+ }
24
32
 
25
- application.addCube(o)
33
+ loadObjFile.addMeshObj({
34
+ position: {x: 0, y: 2, z: -10},
35
+ rotation: {x: 0, y: 0, z: 0},
36
+ rotationSpeed: {x: 0, y: 0, z: 0},
37
+ texturesPaths: ['./res/meshes/blender/cube.png'],
38
+ name: 'CubePhysics',
39
+ mesh: m.cube,
40
+ physics: {
41
+ enabled: true,
42
+ geometry: "Cube"
43
+ }
44
+ })
45
+
46
+ loadObjFile.addMeshObj({
47
+ position: {x: 0, y: 2, z: -10},
48
+ rotation: {x: 0, y: 0, z: 0},
49
+ rotationSpeed: {x: 0, y: 0, z: 0},
50
+ texturesPaths: ['./res/meshes/blender/cube.png'],
51
+ name: 'SpherePhysics',
52
+ mesh: m.sphere,
53
+ physics: {
54
+ enabled: true,
55
+ geometry: "Sphere"
56
+ }
57
+ })
26
58
 
27
- function onLoadObj(m) {
28
- console.log('Loaded obj:', m.armor);
29
59
 
30
- application.addMeshObj({
31
- position: {x: 0, y: 0, z: -5},
32
- texturesPaths: ['./res/meshes/obj/armor.png'],
33
- name: 'Armor',
34
- mesh: m.armor
60
+ loadObjFile.addMeshObj({
61
+ position: {x: 0, y: 2, z: -10},
62
+ rotation: {x: 0, y: 0, z: 0},
63
+ rotationSpeed: {x: 0, y: 0, z: 0},
64
+ texturesPaths: ['./res/meshes/blender/cube.png'],
65
+ name: 'CubePhysics',
66
+ mesh: m.welcomeText,
67
+ physics: {
68
+ enabled: true,
69
+ geometry: "Cube"
70
+ }
35
71
  })
36
- }
37
72
 
38
- downloadMeshes({armor: "./res/meshes/blender/piramyd.obj"}, onLoadObj)
73
+ }
39
74
  })
40
75
 
41
- window.app = application
76
+ window.app = loadObjFile;
77
+
78
+ }
@@ -1,27 +1,30 @@
1
- import MatrixEngineWGPU from "../src/meWGPU";
1
+ import MatrixEngineWGPU from "../src/world.js";
2
2
 
3
- export let application = new MatrixEngineWGPU({
4
- useSingleRenderPass: false,
5
- canvasSize: 'fullscreen'
6
- }, () => {
3
+ export var unlitTextures = function() {
4
+ let unlitTextures = new MatrixEngineWGPU({
5
+ useSingleRenderPass: false,
6
+ canvasSize: 'fullscreen'
7
+ }, () => {
7
8
 
8
- let c = {
9
- scale: 2,
10
- position: {x: -3, y: 0, z: -10},
11
- rotation: {x: 0, y: 0, z: 0},
12
- rotationSpeed: {x: 10, y: 0, z: 0},
13
- texturesPaths: ['./res/textures/rust.jpg']
14
- };
9
+ let c = {
10
+ scale: 2,
11
+ position: {x: -3, y: 0, z: -10},
12
+ rotation: {x: 0, y: 0, z: 0},
13
+ rotationSpeed: {x: 10, y: 0, z: 0},
14
+ texturesPaths: ['./res/textures/rust.jpg']
15
+ };
15
16
 
16
- let o = {
17
- scale: 2,
18
- position: {x: 3, y: 0, z: -10},
19
- rotation: {x: 0, y: 45, z: 0},
20
- rotationSpeed: {x: 0, y: 10, z: 0},
21
- texturesPaths: ['./res/textures/rust.jpg']
22
- };
23
- application.addBall(c)
24
- application.addCube(o)
25
- })
17
+ let o = {
18
+ scale: 2,
19
+ position: {x: 3, y: 0, z: -10},
20
+ rotation: {x: 0, y: 45, z: 0},
21
+ rotationSpeed: {x: 0, y: 10, z: 0},
22
+ texturesPaths: ['./res/textures/rust.jpg']
23
+ };
24
+ unlitTextures.addBall(c)
25
+ unlitTextures.addCube(o)
26
+ })
26
27
 
27
- window.app = application
28
+ window.app = unlitTextures;
29
+
30
+ }
package/examples.js CHANGED
@@ -1,7 +1,39 @@
1
1
  /**
2
2
  * @examples
3
- * Just import curent example/demo
3
+ * MATRIX_ENGINE_WGPU EXAMPLE WORKSPACE
4
+ * Nikola Lukic 2024
4
5
  */
5
- import { application } from "./examples/load-obj-file.js";
6
6
 
7
- window.app = application
7
+ import {loadJamb} from "./examples/games/jamb/jamb.js";
8
+ import {loadObjFile} from "./examples/load-obj-file.js";
9
+ import {unlitTextures} from "./examples/unlit-textures.js";
10
+ import {byId} from "./src/engine/utils.js";
11
+
12
+ // For future
13
+ var examples = {
14
+ loadJamb,
15
+ loadObjFile,
16
+ unlitTextures
17
+ };
18
+
19
+ byId('loadObjFile').addEventListener("click", () => {
20
+ byId('loadObjFile').setAttribute('disabled', true)
21
+ byId('unlitTextures').removeAttribute('disabled')
22
+ if (typeof app !== "undefined") app.destroyProgram()
23
+ loadObjFile()
24
+ })
25
+
26
+ byId('unlitTextures').addEventListener("click", () => {
27
+ byId('unlitTextures').setAttribute('disabled', true)
28
+ byId('loadObjFile').removeAttribute('disabled')
29
+ if (typeof app !== "undefined") app.destroyProgram()
30
+ unlitTextures()
31
+ })
32
+
33
+ byId('jamb').addEventListener("click", () => {
34
+ byId('unlitTextures').setAttribute('disabled', true)
35
+ byId('loadObjFile').setAttribute('disabled', true)
36
+ byId('jamb').removeAttribute('disabled')
37
+ if (typeof app !== "undefined") app.destroyProgram()
38
+ loadJamb()
39
+ })