matrix-engine-wgpu 1.0.5 → 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 (88) 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 +5 -2
  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 +67 -37
  9. package/examples/unlit-textures.js +26 -23
  10. package/examples.js +35 -3
  11. package/main.js +441 -43
  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 +50 -41
  16. package/public/app.js +11409 -8893
  17. package/public/css/style.css +376 -112
  18. package/public/empty.html +1 -1
  19. package/public/empty.js +9890 -8885
  20. package/public/examples.html +10 -8
  21. package/public/examples.js +945 -203
  22. package/public/index.html +5 -7
  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/fonts/Accuratist.ttf +0 -0
  29. package/public/res/fonts/Closeness.ttf +0 -0
  30. package/public/res/fonts/WARGAMES.TTF +0 -0
  31. package/public/res/fonts/readme.txt +5 -0
  32. package/public/res/fonts/stormfaze.ttf +0 -0
  33. package/public/res/meshes/blender/cube.blend +0 -0
  34. package/public/res/meshes/blender/cube.blend1 +0 -0
  35. package/public/res/meshes/blender/cube.mtl +12 -0
  36. package/public/res/meshes/blender/cube.obj +46 -0
  37. package/public/res/meshes/blender/cube.png +0 -0
  38. package/public/res/meshes/blender/cubeSmartUV.blend +0 -0
  39. package/public/res/meshes/blender/cubeSmartUV.mtl +12 -0
  40. package/public/res/meshes/blender/cubeSmartUV.obj +46 -0
  41. package/public/res/meshes/blender/sphepe.blend +0 -0
  42. package/public/res/meshes/blender/sphepe.blend1 +0 -0
  43. package/public/res/meshes/blender/sphere.mtl +10 -0
  44. package/public/res/meshes/blender/sphere.obj +3402 -0
  45. package/public/res/meshes/jamb/bg.blend +0 -0
  46. package/public/res/meshes/jamb/bg.blend1 +0 -0
  47. package/public/res/meshes/jamb/bg.mtl +12 -0
  48. package/public/res/meshes/jamb/bg.obj +17 -0
  49. package/public/res/meshes/jamb/bg.png +0 -0
  50. package/public/res/meshes/jamb/dice-default.png +0 -0
  51. package/public/res/meshes/jamb/dice-mark.png +0 -0
  52. package/public/res/meshes/jamb/dice.mtl +12 -0
  53. package/public/res/meshes/jamb/dice.obj +40 -0
  54. package/public/res/meshes/jamb/dice.png +0 -0
  55. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  56. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  57. package/public/res/meshes/jamb/jamb.blend +0 -0
  58. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  59. package/public/res/meshes/jamb/logo.png +0 -0
  60. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  61. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  62. package/public/res/meshes/jamb/pile.blend +0 -0
  63. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  64. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  65. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  66. package/public/res/meshes/jamb/text.png +0 -0
  67. package/public/res/multilang/en.json +27 -0
  68. package/public/res/multilang/sr.json +27 -0
  69. package/public/test.html +636 -0
  70. package/public/three-test.js +165 -0
  71. package/public/worker.html +1 -1
  72. package/readme.md +232 -116
  73. package/src/engine/cube.js +10 -5
  74. package/src/engine/engine.js +3 -9
  75. package/src/engine/loader-obj.js +9 -6
  76. package/src/engine/matrix-class.js +240 -202
  77. package/src/engine/mesh-obj.js +605 -525
  78. package/src/engine/mesh.js +476 -0
  79. package/src/engine/raycast-test.js +93 -0
  80. package/src/engine/utils.js +129 -15
  81. package/src/multilang/lang.js +35 -0
  82. package/src/physics/matrix-ammo.js +204 -30
  83. package/src/shaders/fragment.wgsl.js +4 -2
  84. package/src/shaders/shaders.js +1 -1
  85. package/src/shaders/vertexShadow.wgsl.js +1 -1
  86. package/src/sounds/sounds.js +47 -0
  87. package/src/world.js +312 -236
  88. package/src/engine/matrix-mesh.js +0 -49
@@ -1,48 +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
- };
16
-
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
- };
24
-
25
- // let mesh = adaptJSON1(stanfordDragonData)
26
- // application.addBall(o)
27
- // application.addCube(c)
28
- application.addCube(o)
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
+ })
29
26
 
30
27
  function onLoadObj(m) {
31
- console.log('Loaded obj:', m.armor);
32
- // console.log('APP2 ', jsonPiramyd);
33
- // jsonPiramyd.vertexNormals = jsonPiramyd.normals;
34
- // jsonPiramyd.indices = jsonPiramyd.faces;
35
- // jsonPiramyd.textures = jsonPiramyd.uvs;
36
- application.addMeshObj({
37
- position: {x: 0, y: 0, z: -5},
38
- texturesPaths: ['./res/meshes/obj/armor.png'],
39
- name: 'Armor',
40
- mesh: m.armor
28
+ loadObjFile.myLoadedMeshes = m;
29
+ for(var key in m) {
30
+ console.log(`%c Loaded objs: ${key} `, LOG_MATRIX);
31
+ }
32
+
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
+ }
41
57
  })
42
- }
43
58
 
44
- // downloadMeshes({armor: "./res/meshes/obj/armor.obj"}, onLoadObj)
45
- downloadMeshes({armor: "./res/meshes/blender/piramyd.obj"}, onLoadObj)
59
+
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
+ }
71
+ })
72
+
73
+ }
46
74
  })
47
75
 
48
- 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
+ })