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.
- package/.codesandbox/tasks.json +46 -0
- package/.devcontainer/devcontainer.json +22 -0
- package/.github/dependabot.yml +12 -0
- package/REFERENCE.md +5 -2
- package/dev.md +460 -0
- package/empty.js +7 -6
- package/examples/games/jamb/jamb.js +1127 -0
- package/examples/load-obj-file.js +67 -37
- package/examples/unlit-textures.js +26 -23
- package/examples.js +35 -3
- package/main.js +441 -43
- 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 +50 -41
- package/public/app.js +11409 -8893
- package/public/css/style.css +376 -112
- package/public/empty.html +1 -1
- package/public/empty.js +9890 -8885
- package/public/examples.html +10 -8
- package/public/examples.js +945 -203
- package/public/index.html +5 -7
- 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/fonts/Accuratist.ttf +0 -0
- package/public/res/fonts/Closeness.ttf +0 -0
- package/public/res/fonts/WARGAMES.TTF +0 -0
- package/public/res/fonts/readme.txt +5 -0
- package/public/res/fonts/stormfaze.ttf +0 -0
- package/public/res/meshes/blender/cube.blend +0 -0
- package/public/res/meshes/blender/cube.blend1 +0 -0
- package/public/res/meshes/blender/cube.mtl +12 -0
- package/public/res/meshes/blender/cube.obj +46 -0
- package/public/res/meshes/blender/cube.png +0 -0
- package/public/res/meshes/blender/cubeSmartUV.blend +0 -0
- package/public/res/meshes/blender/cubeSmartUV.mtl +12 -0
- package/public/res/meshes/blender/cubeSmartUV.obj +46 -0
- package/public/res/meshes/blender/sphepe.blend +0 -0
- package/public/res/meshes/blender/sphepe.blend1 +0 -0
- package/public/res/meshes/blender/sphere.mtl +10 -0
- package/public/res/meshes/blender/sphere.obj +3402 -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 +232 -116
- package/src/engine/cube.js +10 -5
- package/src/engine/engine.js +3 -9
- package/src/engine/loader-obj.js +9 -6
- package/src/engine/matrix-class.js +240 -202
- package/src/engine/mesh-obj.js +605 -525
- package/src/engine/mesh.js +476 -0
- package/src/engine/raycast-test.js +93 -0
- package/src/engine/utils.js +129 -15
- package/src/multilang/lang.js +35 -0
- package/src/physics/matrix-ammo.js +204 -30
- 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 +312 -236
- package/src/engine/matrix-mesh.js +0 -49
package/readme.md
CHANGED
|
@@ -1,189 +1,305 @@
|
|
|
1
|
-
# matrix-wgpu
|
|
1
|
+
# matrix-engine-wgpu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Author:** Nikola Lukić
|
|
4
|
+
📧 [zlatnaspirala@gmail.com](mailto:zlatnaspirala@gmail.com)
|
|
5
|
+
📅 2025
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
---
|
|
6
8
|
|
|
7
|
-
## Logo
|
|
9
|
+
## Logo
|
|
8
10
|
|
|
9
|
-
<img width="
|
|
11
|
+
<img width="320" height="320" src="https://github.com/zlatnaspirala/matrix-engine-wgpu/blob/main/public/res/icons/512.png?raw=true" />
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
> Logo includes the official WebGPU logo.
|
|
14
|
+
> **WebGPU logo by [W3C](https://www.w3.org/)**
|
|
15
|
+
> Licensed under [Creative Commons Attribution 4.0](https://www.w3.org/2023/02/webgpu-logos.html)
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
The logos are licensed under Creative Commons Attribution 4.0 International.
|
|
15
|
-
Download from https://www.w3.org/2023/02/webgpu-logos.html
|
|
17
|
+
---
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
I publish (this repo) npm package with name `matrix-engine-wgpu`.
|
|
19
|
+
## Description
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
This project is a work-in-progress WebGPU engine inspired by the original **matrix-engine** for WebGL.
|
|
22
|
+
It uses the `wgpu-matrix` npm package as a modern replacement for `gl-matrix` for handling model-view-projection matrices.
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
- Make it similar to the matrix-engine webGL features.
|
|
24
|
+
Published on npm as: **`matrix-engine-wgpu`**
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
- Main base example is `shadowMapping` from [webgpu-samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
|
|
26
|
+
---
|
|
27
27
|
|
|
28
|
-
##
|
|
28
|
+
## Goals
|
|
29
|
+
|
|
30
|
+
* ✔️ Support for 3D objects and scene transformations
|
|
31
|
+
* 🎯 Replicate matrix-engine (WebGL) features
|
|
32
|
+
* 📦 Based on the `shadowMapping` sample from [webgpu-samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
|
|
33
|
+
* ✔️ Ammo.js physics integration (basic cube)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
### Scene Management
|
|
40
|
+
|
|
41
|
+
* A canvas is dynamically created in JavaScript — no `<canvas>` in HTML required.
|
|
42
|
+
|
|
43
|
+
* Access the main scene using:
|
|
29
44
|
|
|
30
|
-
- Only access to the object scene instance look like:
|
|
31
|
-
`mainRenderBundle` is scene holder.
|
|
32
45
|
```js
|
|
33
46
|
app.mainRenderBundle[0];
|
|
34
47
|
```
|
|
35
48
|
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
* Add meshes using `.addMeshObj()`
|
|
50
|
+
(Supports `.obj` loading, unlit textures, cubes, spheres, etc.)
|
|
51
|
+
|
|
52
|
+
* Cleanly destroy the current scene:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
app.destroyProgram();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
### Camera Options
|
|
61
|
+
|
|
62
|
+
Supported types: `WASD`, `arcball`
|
|
63
|
+
|
|
38
64
|
```js
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
65
|
+
mainCameraParams: {
|
|
66
|
+
type: 'WASD',
|
|
67
|
+
responseCoef: 1000
|
|
68
|
+
}
|
|
43
69
|
```
|
|
44
70
|
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### Object Positioning
|
|
47
74
|
|
|
48
|
-
|
|
75
|
+
Control object position with:
|
|
49
76
|
|
|
50
77
|
```js
|
|
51
78
|
app.mainRenderBundle[0].position.translateByX(12);
|
|
52
79
|
```
|
|
53
80
|
|
|
54
|
-
Teleport/
|
|
81
|
+
Teleport / Direct set:
|
|
55
82
|
|
|
56
83
|
```js
|
|
57
84
|
app.mainRenderBundle[0].position.SetX(-2);
|
|
58
85
|
```
|
|
59
86
|
|
|
60
|
-
Change speed
|
|
87
|
+
Change movement speed:
|
|
61
88
|
|
|
62
89
|
```js
|
|
63
90
|
app.mainRenderBundle[0].position.thrust = 0.1;
|
|
64
91
|
```
|
|
65
92
|
|
|
66
|
-
|
|
67
|
-
|
|
93
|
+
> ⚠️ For physics-enabled objects, use Ammo.js functions.
|
|
94
|
+
> `.position` and `.rotation` won't apply visually but can be read.
|
|
95
|
+
|
|
96
|
+
Example:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
app.matrixAmmo.rigidBodies[0].setAngularVelocity(new Ammo.btVector3(0, 2, 0));
|
|
100
|
+
app.matrixAmmo.rigidBodies[0].setLinearVelocity(new Ammo.btVector3(0, 7, 0));
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### Object Rotation
|
|
106
|
+
|
|
107
|
+
Rotate manually:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
app.mainRenderBundle[0].rotation.x = 45;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Auto-rotate:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
app.mainRenderBundle[0].rotation.rotationSpeed.y = 10;
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Stop rotation:
|
|
68
120
|
|
|
69
|
-
Rotate object by axis by degree:
|
|
70
121
|
```js
|
|
71
|
-
app.mainRenderBundle[0].rotation.
|
|
122
|
+
app.mainRenderBundle[0].rotation.rotationSpeed.y = 0;
|
|
72
123
|
```
|
|
73
124
|
|
|
74
|
-
|
|
125
|
+
> ⚠️ Same note as position: `.rotation.x/y/z` has no effect for physics-enabled objects.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### Camera Example
|
|
130
|
+
|
|
131
|
+
Manipulate WASD camera:
|
|
132
|
+
|
|
75
133
|
```js
|
|
76
|
-
app.
|
|
134
|
+
app.cameras.WASD.pitch = 0.2;
|
|
77
135
|
```
|
|
78
136
|
|
|
79
|
-
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Object Interaction (Raycasting)
|
|
140
|
+
|
|
141
|
+
Manual raycast:
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
window.addEventListener('click', (event) => {
|
|
145
|
+
let canvas = document.querySelector('canvas');
|
|
146
|
+
let camera = app.cameras.WASD;
|
|
147
|
+
const { rayOrigin, rayDirection } = getRayFromMouse(event, canvas, camera);
|
|
148
|
+
|
|
149
|
+
for (const object of app.mainRenderBundle) {
|
|
150
|
+
if (rayIntersectsSphere(rayOrigin, rayDirection, object.position, 2)) {
|
|
151
|
+
console.log('Object clicked:', object.name);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
80
155
|
```
|
|
81
|
-
|
|
156
|
+
|
|
157
|
+
Automatic raycast:
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
addRaycastListener();
|
|
161
|
+
window.addEventListener('ray.hit.event', (event) => {
|
|
162
|
+
console.log(event.detail);
|
|
163
|
+
});
|
|
82
164
|
```
|
|
83
165
|
|
|
84
|
-
|
|
85
|
-
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## How to Load `.obj` Models
|
|
169
|
+
|
|
86
170
|
```js
|
|
87
|
-
import MatrixEngineWGPU from "./src/
|
|
88
|
-
import {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
171
|
+
import MatrixEngineWGPU from "./src/world.js";
|
|
172
|
+
import { downloadMeshes } from './src/engine/loader-obj.js';
|
|
173
|
+
|
|
174
|
+
export let application = new MatrixEngineWGPU({
|
|
175
|
+
useSingleRenderPass: true,
|
|
176
|
+
canvasSize: 'fullscreen',
|
|
177
|
+
mainCameraParams: {
|
|
178
|
+
type: 'WASD',
|
|
179
|
+
responseCoef: 1000
|
|
180
|
+
}
|
|
181
|
+
}, () => {
|
|
182
|
+
addEventListener('AmmoReady', () => {
|
|
183
|
+
downloadMeshes({
|
|
184
|
+
welcomeText: "./res/meshes/blender/piramyd.obj",
|
|
185
|
+
armor: "./res/meshes/obj/armor.obj",
|
|
186
|
+
sphere: "./res/meshes/blender/sphere.obj",
|
|
187
|
+
cube: "./res/meshes/blender/cube.obj",
|
|
188
|
+
}, onLoadObj);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
function onLoadObj(meshes) {
|
|
192
|
+
application.myLoadedMeshes = meshes;
|
|
193
|
+
for (const key in meshes) {
|
|
194
|
+
console.log(`%c Loaded obj: ${key} `, LOG_MATRIX);
|
|
104
195
|
}
|
|
105
196
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
197
|
+
application.addMeshObj({
|
|
198
|
+
position: {x: 0, y: 2, z: -10},
|
|
199
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
200
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
201
|
+
texturesPaths: ['./res/meshes/blender/cube.png'],
|
|
202
|
+
name: 'CubePhysics',
|
|
203
|
+
mesh: meshes.cube,
|
|
204
|
+
physics: {
|
|
205
|
+
enabled: true,
|
|
206
|
+
geometry: "Cube"
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
application.addMeshObj({
|
|
211
|
+
position: {x: 0, y: 2, z: -10},
|
|
212
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
213
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
214
|
+
texturesPaths: ['./res/meshes/blender/cube.png'],
|
|
215
|
+
name: 'SpherePhysics',
|
|
216
|
+
mesh: meshes.sphere,
|
|
217
|
+
physics: {
|
|
218
|
+
enabled: true,
|
|
219
|
+
geometry: "Sphere"
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
110
225
|
window.app = application;
|
|
111
226
|
```
|
|
112
227
|
|
|
228
|
+
---
|
|
229
|
+
|
|
113
230
|
## NPM Scripts
|
|
114
231
|
|
|
115
|
-
|
|
232
|
+
Uses `watchify` to bundle JavaScript.
|
|
116
233
|
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
234
|
+
```json
|
|
235
|
+
"main-worker": "watchify app-worker.js -p [esmify --noImplicitAny] -o public/app-worker.js",
|
|
236
|
+
"examples": "watchify examples.js -p [esmify --noImplicitAny] -o public/examples.js",
|
|
237
|
+
"main": "watchify main.js -p [esmify --noImplicitAny] -o public/app.js",
|
|
238
|
+
"empty": "watchify empty.js -p [esmify --noImplicitAny] -o public/empty.js",
|
|
239
|
+
"build-all": "npm run main-worker && npm run examples && npm run main && npm run build-empty"
|
|
123
240
|
```
|
|
124
241
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
242
|
+
Script summary:
|
|
243
|
+
|
|
244
|
+
1. `main-worker`: For core instance with root wrapper.
|
|
245
|
+
2. `examples`: Current example build from `./examples/`.
|
|
246
|
+
3. `main`: Main project build (YAMB).
|
|
247
|
+
4. `empty`: Build minimal setup for environments like CodePen or StackOverflow.
|
|
248
|
+
5. `build-all`: Run all the above builds at once.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Resources
|
|
253
|
+
|
|
254
|
+
* All resources and output go into `./public` — a single folder with everything you need.
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Proof of Concept
|
|
259
|
+
|
|
260
|
+
🎲 The first full app example will be a WebGPU-powered **Ultimate Yahtzee** game.
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Live Demos & Dev Links
|
|
265
|
+
|
|
266
|
+
* [Jamb WebGPU Demo (WIP)](https://maximumroulette.com/apps/webgpu/)
|
|
131
267
|
|
|
132
|
-
|
|
268
|
+
* [CodePen Demo](https://codepen.io/zlatnaspirala/pen/VwNKMar?editors=0011)
|
|
269
|
+
→ Uses `empty.js` build from:
|
|
270
|
+
[https://maximumroulette.com/apps/megpu/empty.js](https://maximumroulette.com/apps/megpu/empty.js)
|
|
133
271
|
|
|
134
|
-
|
|
135
|
-
after all you get all needed stuff in one public folder (www).
|
|
272
|
+
* [CodeSandbox Implementation](https://codesandbox.io/p/github/zlatnaspirala/matrix-engine-wgpu/main?file=%2Fpackage.json%3A14%2C16)
|
|
136
273
|
|
|
137
|
-
|
|
274
|
+
* 📘 Learning Resource:
|
|
275
|
+
[WebGPU Ray Tracing](https://maierfelix.github.io/2020-01-13-webgpu-ray-tracing/)
|
|
138
276
|
|
|
139
|
-
|
|
140
|
-
https://codepen.io/zlatnaspirala/pen/VwNKMar?editors=0011
|
|
141
|
-
I use empty build then i add/upload to my VPS public server you can use it:
|
|
142
|
-
Usually last night build stable/unstable version.
|
|
143
|
-
https://maximumroulette.com/apps/megpu/empty.js
|
|
144
|
-
You can build your own with `npm run build-empty`.
|
|
277
|
+
---
|
|
145
278
|
|
|
146
|
-
##
|
|
279
|
+
## License
|
|
147
280
|
|
|
148
|
-
### Note
|
|
281
|
+
### Usage Note
|
|
149
282
|
|
|
150
|
-
|
|
151
|
-
and you can sell or what ever you want with your project."
|
|
283
|
+
> You may use, modify, and even sell your project with this code — just keep this notice and any included references in place.
|
|
152
284
|
|
|
153
|
-
|
|
154
|
-
https://webgpu.github.io/webgpu-samples/samples/renderBundles also
|
|
155
|
-
https://webgpu.github.io/webgpu-samples/?sample=shadowMapping
|
|
285
|
+
---
|
|
156
286
|
|
|
157
|
-
|
|
158
|
-
Obj loader source http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html
|
|
287
|
+
### Attribution & Credits
|
|
159
288
|
|
|
160
|
-
|
|
289
|
+
* Engine design and scene structure inspired by:
|
|
290
|
+
[WebGPU Samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
|
|
161
291
|
|
|
162
|
-
|
|
292
|
+
* OBJ Loader adapted from:
|
|
293
|
+
[http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html](http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html)
|
|
163
294
|
|
|
164
|
-
|
|
295
|
+
* Dice roll sound `roll1.wav` sourced from:
|
|
296
|
+
[https://wavbvkery.com/dice-rolling-sound/](https://wavbvkery.com/dice-rolling-sound/)
|
|
165
297
|
|
|
166
|
-
|
|
167
|
-
modification, are permitted provided that the following conditions are met:
|
|
298
|
+
---
|
|
168
299
|
|
|
169
|
-
|
|
170
|
-
this list of conditions and the following disclaimer.
|
|
300
|
+
### BSD 3-Clause License (from WebGPU Samples)
|
|
171
301
|
|
|
172
|
-
|
|
173
|
-
this list of conditions and the following disclaimer in the documentation
|
|
174
|
-
and/or other materials provided with the distribution.
|
|
302
|
+
[Full License Text](https://github.com/webgpu/webgpu-samples/blob/main/LICENSE.txt)
|
|
175
303
|
|
|
176
|
-
|
|
177
|
-
contributors may be used to endorse or promote products derived from this
|
|
178
|
-
software without specific prior written permission.
|
|
304
|
+
---
|
|
179
305
|
|
|
180
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
181
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
182
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
183
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
184
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
185
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
186
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
187
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
188
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
189
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/src/engine/cube.js
CHANGED
|
@@ -31,6 +31,8 @@ export default class MECube {
|
|
|
31
31
|
|
|
32
32
|
this.texturesPaths = [];
|
|
33
33
|
|
|
34
|
+
// useUVShema4x2 pass this from top !
|
|
35
|
+
|
|
34
36
|
o.texturesPaths.forEach((t) => {
|
|
35
37
|
this.texturesPaths.push(t)
|
|
36
38
|
})
|
|
@@ -116,7 +118,6 @@ export default class MECube {
|
|
|
116
118
|
this.transform = mat4.create();
|
|
117
119
|
mat4.identity(this.transform);
|
|
118
120
|
|
|
119
|
-
// Create one large central planet surrounded by a large ring of asteroids
|
|
120
121
|
this.planet = this.createGeometry({
|
|
121
122
|
scale: this.scale,
|
|
122
123
|
useUVShema4x2: false
|
|
@@ -268,6 +269,14 @@ export default class MECube {
|
|
|
268
269
|
return bindGroup;
|
|
269
270
|
}
|
|
270
271
|
|
|
272
|
+
|
|
273
|
+
// TEST
|
|
274
|
+
getViewMatrix () {
|
|
275
|
+
const camera = this.cameras[this.mainCameraParams.type];
|
|
276
|
+
const viewMatrix = camera.update(deltaTime, this.inputHandler());
|
|
277
|
+
return viewMatrix;
|
|
278
|
+
}
|
|
279
|
+
|
|
271
280
|
getTransformationMatrix(pos) {
|
|
272
281
|
const now = Date.now();
|
|
273
282
|
const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
|
|
@@ -333,10 +342,6 @@ export default class MECube {
|
|
|
333
342
|
}
|
|
334
343
|
|
|
335
344
|
|
|
336
|
-
draw = () => {}
|
|
337
|
-
drawElements = () => {}
|
|
338
|
-
drawShadows = () => {}
|
|
339
|
-
|
|
340
345
|
// Render bundles function as partial, limited render passes, so we can use the
|
|
341
346
|
// same code both to render the scene normally and to build the render bundle.
|
|
342
347
|
renderScene(passEncoder) {
|
package/src/engine/engine.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// 'wgpu-matrix' library, so produces many temporary vectors and matrices.
|
|
3
3
|
// This is intentional, as this sample prefers readability over performance.
|
|
4
4
|
import { Mat4, Vec3, Vec4, mat4, vec3 } from 'wgpu-matrix';
|
|
5
|
+
import {LOG_INFO} from './utils';
|
|
5
6
|
// import Input from './input';
|
|
6
7
|
|
|
7
8
|
// // Common interface for camera implementations
|
|
@@ -123,17 +124,15 @@ export class WASDCamera extends CameraBase {
|
|
|
123
124
|
vec3.copy(vec, this.velocity_);
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
// Construtor
|
|
127
127
|
constructor(options) {
|
|
128
128
|
super();
|
|
129
129
|
if (options && (options.position || options.target)) {
|
|
130
130
|
const position = options.position ?? vec3.create(0, 0, 0);
|
|
131
131
|
const target = options.target ?? vec3.create(0, 0, 0);
|
|
132
|
-
|
|
133
132
|
const forward = vec3.normalize(vec3.sub(target, position));
|
|
134
133
|
this.recalculateAngles(forward);
|
|
135
134
|
this.position = position;
|
|
136
|
-
console.log(
|
|
135
|
+
// console.log(`%cCamera pos: ${position}`, LOG_INFO);
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
|
|
@@ -338,9 +337,7 @@ function lerp(a, b, s) {
|
|
|
338
337
|
return vec3.addScaled(a, vec3.sub(b, a), s);
|
|
339
338
|
}
|
|
340
339
|
|
|
341
|
-
//
|
|
342
|
-
|
|
343
|
-
// // Input holds as snapshot of input state
|
|
340
|
+
// Input holds as snapshot of input state
|
|
344
341
|
// export default interface Input {
|
|
345
342
|
// // Digital input (e.g keyboard state)
|
|
346
343
|
// readonly digital: {
|
|
@@ -359,10 +356,8 @@ function lerp(a, b, s) {
|
|
|
359
356
|
// readonly touching: boolean;
|
|
360
357
|
// };
|
|
361
358
|
// }
|
|
362
|
-
|
|
363
359
|
// InputHandler is a function that when called, returns the current Input state.
|
|
364
360
|
// export type InputHandler = () => Input;
|
|
365
|
-
|
|
366
361
|
// createInputHandler returns an InputHandler by attaching event handlers to the window and canvas.
|
|
367
362
|
export function createInputHandler(window, canvas) {
|
|
368
363
|
let digital = {
|
|
@@ -467,4 +462,3 @@ export function createInputHandler(window, canvas) {
|
|
|
467
462
|
return out;
|
|
468
463
|
};
|
|
469
464
|
}
|
|
470
|
-
|
package/src/engine/loader-obj.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* information can then be used later on when creating your VBOs. See
|
|
5
5
|
* OBJ.initMeshBuffers for an example of how to use the newly created Mesh
|
|
6
6
|
*
|
|
7
|
+
* Nidza Note:
|
|
8
|
+
* There is difference from me source obj loader and me-wgpu obj loader
|
|
9
|
+
* Here we need scele in comp x,y,z because we use also primitive [cube, sphere etc...]
|
|
7
10
|
* @class Mesh
|
|
8
11
|
* @constructor
|
|
9
12
|
*
|
|
@@ -21,7 +24,7 @@ export class constructMesh {
|
|
|
21
24
|
this.create(this.objectData, this.inputArg)
|
|
22
25
|
};
|
|
23
26
|
this.updateBuffers = () => {
|
|
24
|
-
this.inputArg.scale = 1;
|
|
27
|
+
this.inputArg.scale = [0.1,0.1,0.1];
|
|
25
28
|
this.create(this.objectData, this.inputArg);
|
|
26
29
|
};
|
|
27
30
|
}
|
|
@@ -184,9 +187,9 @@ export class constructMesh {
|
|
|
184
187
|
This same process is repeated for verts and textures.
|
|
185
188
|
*/
|
|
186
189
|
// vertex position
|
|
187
|
-
unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[0]] * inputArg.scale);
|
|
188
|
-
unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[1]] * inputArg.scale);
|
|
189
|
-
unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[2]] * inputArg.scale);
|
|
190
|
+
unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[0]] * inputArg.scale[0]);
|
|
191
|
+
unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[1]] * inputArg.scale[1]);
|
|
192
|
+
unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[2]] * inputArg.scale[2]);
|
|
190
193
|
|
|
191
194
|
// vertex textures
|
|
192
195
|
if (textures.length) {
|
|
@@ -263,11 +266,11 @@ export var downloadMeshes = function (nameAndURLs, completionCallback, inputArg)
|
|
|
263
266
|
// a new object is created. this will be passed into the completionCallback
|
|
264
267
|
if (typeof inputArg === 'undefined') {
|
|
265
268
|
var inputArg = {
|
|
266
|
-
scale: 1,
|
|
269
|
+
scale: [0.1,0.1,0.1],
|
|
267
270
|
swap: [null]
|
|
268
271
|
};
|
|
269
272
|
}
|
|
270
|
-
if (typeof inputArg.scale === 'undefined') inputArg.scale = 0.1;
|
|
273
|
+
if (typeof inputArg.scale === 'undefined') inputArg.scale = [0.1,0.1,0.1];
|
|
271
274
|
if (typeof inputArg.swap === 'undefined') inputArg.swap = [null];
|
|
272
275
|
|
|
273
276
|
var meshes = {};
|