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
|
@@ -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
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
position: {x: 0, y:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
73
|
+
}
|
|
39
74
|
})
|
|
40
75
|
|
|
41
|
-
window.app =
|
|
76
|
+
window.app = loadObjFile;
|
|
77
|
+
|
|
78
|
+
}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import MatrixEngineWGPU from "../src/
|
|
1
|
+
import MatrixEngineWGPU from "../src/world.js";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export var unlitTextures = function() {
|
|
4
|
+
let unlitTextures = new MatrixEngineWGPU({
|
|
5
|
+
useSingleRenderPass: false,
|
|
6
|
+
canvasSize: 'fullscreen'
|
|
7
|
+
}, () => {
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
17
|
+
let o = {
|
|
18
|
+
scale: 2,
|
|
19
|
+
position: {x: 3, y: 0, z: -10},
|
|
20
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
21
|
+
rotationSpeed: {x: 10, y: 0, z: 0},
|
|
22
|
+
texturesPaths: ['./res/textures/default.png']
|
|
23
|
+
};
|
|
24
|
+
unlitTextures.addBall(c)
|
|
25
|
+
unlitTextures.addCube(o)
|
|
26
|
+
})
|
|
26
27
|
|
|
27
|
-
window.app =
|
|
28
|
+
window.app = unlitTextures;
|
|
29
|
+
|
|
30
|
+
}
|
package/examples.js
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @examples
|
|
3
|
-
*
|
|
3
|
+
* MATRIX_ENGINE_WGPU EXAMPLE WORKSPACE
|
|
4
|
+
* Nikola Lukic 2024
|
|
4
5
|
*/
|
|
5
|
-
import { application } from "./examples/load-obj-file.js";
|
|
6
6
|
|
|
7
|
-
|
|
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
|
+
})
|
package/index.js
CHANGED
|
@@ -6,19 +6,25 @@
|
|
|
6
6
|
import {degToRad} from "wgpu-matrix/dist/2.x/utils.js";
|
|
7
7
|
import {downloadMeshes} from "./src/engine/loader-obj.js";
|
|
8
8
|
import MatrixEngineWGPU from "./src/meWGPU.js";
|
|
9
|
+
import {getRayFromMouse, rayIntersectsSphere} from "./src/engine/raycast.js";
|
|
9
10
|
|
|
10
11
|
var about = () => {
|
|
11
12
|
console.log("Hi npm. matrix-engine for webgpu is ready...")
|
|
12
13
|
console.log("--------------------------------------------")
|
|
13
|
-
console.log("List of features
|
|
14
|
+
console.log("List of features: ")
|
|
14
15
|
console.log(" - Loading obj files with uvs")
|
|
15
|
-
console.log(" - Scene
|
|
16
|
+
console.log(" - Scene camera use -z front")
|
|
16
17
|
console.log(" - position, rotation - same like matrix-engine")
|
|
18
|
+
console.log(" - Physics used Ammo.js build")
|
|
19
|
+
console.log(" - Raycaster HIT/CLICK on object scene")
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export {
|
|
20
23
|
MatrixEngineWGPU,
|
|
21
24
|
downloadMeshes,
|
|
25
|
+
rayIntersectsSphere,
|
|
26
|
+
getRayFromMouse,
|
|
27
|
+
addRaycastListener,
|
|
22
28
|
degToRad,
|
|
23
29
|
about
|
|
24
30
|
}
|