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.
- 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 +1127 -0
- package/examples/load-obj-file.js +65 -28
- package/examples/unlit-textures.js +26 -23
- package/examples.js +35 -3
- package/main.js +442 -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 +28 -13
- package/public/app.js +11405 -9375
- 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 +553 -193
- 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 +189 -115
- package/src/engine/cube.js +10 -1
- package/src/engine/engine.js +1 -5
- package/src/engine/loader-obj.js +9 -6
- package/src/engine/matrix-class.js +237 -204
- package/src/engine/mesh-obj.js +605 -515
- package/src/engine/raycast-test.js +93 -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
package/readme.md
CHANGED
|
@@ -1,101 +1,175 @@
|
|
|
1
1
|
# matrix-engine-wgpu
|
|
2
|
-
## [not fully operative for now - WIP]
|
|
3
|
-
## Author Nikola Lukic zlatnaspirala@gmail.com 2024
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
**Author:** Nikola Lukić
|
|
4
|
+
📧 [zlatnaspirala@gmail.com](mailto:zlatnaspirala@gmail.com)
|
|
5
|
+
📅 2025
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Logo
|
|
6
10
|
|
|
7
11
|
<img width="320" height="320" src="https://github.com/zlatnaspirala/matrix-engine-wgpu/blob/main/public/res/icons/512.png?raw=true" />
|
|
8
12
|
|
|
9
|
-
|
|
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)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Description
|
|
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.
|
|
23
|
+
|
|
24
|
+
Published on npm as: **`matrix-engine-wgpu`**
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Goals
|
|
10
29
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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)
|
|
14
34
|
|
|
15
|
-
|
|
16
|
-
I publish (this repo) npm package with name `matrix-engine-wgpu`.
|
|
35
|
+
---
|
|
17
36
|
|
|
18
|
-
##
|
|
37
|
+
## Features
|
|
19
38
|
|
|
20
|
-
|
|
21
|
-
- Make it similar to the matrix-engine webGL features.
|
|
22
|
-
- Main base example is `shadowMapping` from [webgpu-samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
|
|
23
|
-
- Integrate ammojs
|
|
39
|
+
### Scene Management
|
|
24
40
|
|
|
25
|
-
|
|
41
|
+
* A canvas is dynamically created in JavaScript — no `<canvas>` in HTML required.
|
|
42
|
+
|
|
43
|
+
* Access the main scene using:
|
|
26
44
|
|
|
27
|
-
- Only access to the object scene instance look like:
|
|
28
|
-
`mainRenderBundle` is scene holder.
|
|
29
45
|
```js
|
|
30
46
|
app.mainRenderBundle[0];
|
|
31
47
|
```
|
|
32
48
|
|
|
33
|
-
|
|
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`
|
|
34
63
|
|
|
35
|
-
### Camera
|
|
36
|
-
Camera type: `WASD | arcball`
|
|
37
64
|
```js
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
65
|
+
mainCameraParams: {
|
|
66
|
+
type: 'WASD',
|
|
67
|
+
responseCoef: 1000
|
|
68
|
+
}
|
|
42
69
|
```
|
|
43
70
|
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### Object Positioning
|
|
46
74
|
|
|
47
|
-
|
|
75
|
+
Control object position with:
|
|
48
76
|
|
|
49
77
|
```js
|
|
50
78
|
app.mainRenderBundle[0].position.translateByX(12);
|
|
51
79
|
```
|
|
52
80
|
|
|
53
|
-
Teleport/
|
|
81
|
+
Teleport / Direct set:
|
|
54
82
|
|
|
55
83
|
```js
|
|
56
84
|
app.mainRenderBundle[0].position.SetX(-2);
|
|
57
85
|
```
|
|
58
86
|
|
|
59
|
-
Change speed
|
|
87
|
+
Change movement speed:
|
|
60
88
|
|
|
61
89
|
```js
|
|
62
90
|
app.mainRenderBundle[0].position.thrust = 0.1;
|
|
63
91
|
```
|
|
64
92
|
|
|
65
|
-
|
|
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
|
+
|
|
68
115
|
```js
|
|
69
|
-
app.
|
|
70
|
-
app.matrixAmmo.rigidBodies[0].setLinearVelocity(new Ammo.btVector3(0,7,0))
|
|
116
|
+
app.mainRenderBundle[0].rotation.rotationSpeed.y = 10;
|
|
71
117
|
```
|
|
72
118
|
|
|
73
|
-
|
|
74
|
-
#### app.mainRenderBundle[0].rotation
|
|
119
|
+
Stop rotation:
|
|
75
120
|
|
|
76
|
-
Rotate object by axis by degree:
|
|
77
121
|
```js
|
|
78
|
-
app.mainRenderBundle[0].rotation.
|
|
122
|
+
app.mainRenderBundle[0].rotation.rotationSpeed.y = 0;
|
|
79
123
|
```
|
|
80
124
|
|
|
81
|
-
|
|
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
|
+
|
|
82
133
|
```js
|
|
83
|
-
app.
|
|
134
|
+
app.cameras.WASD.pitch = 0.2;
|
|
135
|
+
```
|
|
136
|
+
|
|
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
|
+
});
|
|
84
155
|
```
|
|
85
156
|
|
|
86
|
-
|
|
157
|
+
Automatic raycast:
|
|
158
|
+
|
|
87
159
|
```js
|
|
88
|
-
|
|
160
|
+
addRaycastListener();
|
|
161
|
+
window.addEventListener('ray.hit.event', (event) => {
|
|
162
|
+
console.log(event.detail);
|
|
163
|
+
});
|
|
89
164
|
```
|
|
90
165
|
|
|
91
|
-
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## How to Load `.obj` Models
|
|
92
169
|
|
|
93
|
-
## How to load obj [with uvs] file:
|
|
94
|
-
Main instance script:
|
|
95
170
|
```js
|
|
96
171
|
import MatrixEngineWGPU from "./src/world.js";
|
|
97
|
-
import {downloadMeshes} from './src/engine/loader-obj.js';
|
|
98
|
-
import {LOG_FUNNY, LOG_INFO, LOG_MATRIX} from "./src/engine/utils.js";
|
|
172
|
+
import { downloadMeshes } from './src/engine/loader-obj.js';
|
|
99
173
|
|
|
100
174
|
export let application = new MatrixEngineWGPU({
|
|
101
175
|
useSingleRenderPass: true,
|
|
@@ -105,20 +179,19 @@ export let application = new MatrixEngineWGPU({
|
|
|
105
179
|
responseCoef: 1000
|
|
106
180
|
}
|
|
107
181
|
}, () => {
|
|
108
|
-
|
|
109
182
|
addEventListener('AmmoReady', () => {
|
|
110
183
|
downloadMeshes({
|
|
111
184
|
welcomeText: "./res/meshes/blender/piramyd.obj",
|
|
112
185
|
armor: "./res/meshes/obj/armor.obj",
|
|
113
186
|
sphere: "./res/meshes/blender/sphere.obj",
|
|
114
187
|
cube: "./res/meshes/blender/cube.obj",
|
|
115
|
-
}, onLoadObj)
|
|
116
|
-
})
|
|
188
|
+
}, onLoadObj);
|
|
189
|
+
});
|
|
117
190
|
|
|
118
|
-
function onLoadObj(
|
|
119
|
-
application.myLoadedMeshes =
|
|
120
|
-
for(
|
|
121
|
-
console.log(`%c Loaded
|
|
191
|
+
function onLoadObj(meshes) {
|
|
192
|
+
application.myLoadedMeshes = meshes;
|
|
193
|
+
for (const key in meshes) {
|
|
194
|
+
console.log(`%c Loaded obj: ${key} `, LOG_MATRIX);
|
|
122
195
|
}
|
|
123
196
|
|
|
124
197
|
application.addMeshObj({
|
|
@@ -127,12 +200,12 @@ export let application = new MatrixEngineWGPU({
|
|
|
127
200
|
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
128
201
|
texturesPaths: ['./res/meshes/blender/cube.png'],
|
|
129
202
|
name: 'CubePhysics',
|
|
130
|
-
mesh:
|
|
203
|
+
mesh: meshes.cube,
|
|
131
204
|
physics: {
|
|
132
205
|
enabled: true,
|
|
133
206
|
geometry: "Cube"
|
|
134
207
|
}
|
|
135
|
-
})
|
|
208
|
+
});
|
|
136
209
|
|
|
137
210
|
application.addMeshObj({
|
|
138
211
|
position: {x: 0, y: 2, z: -10},
|
|
@@ -140,92 +213,93 @@ export let application = new MatrixEngineWGPU({
|
|
|
140
213
|
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
141
214
|
texturesPaths: ['./res/meshes/blender/cube.png'],
|
|
142
215
|
name: 'SpherePhysics',
|
|
143
|
-
mesh:
|
|
216
|
+
mesh: meshes.sphere,
|
|
144
217
|
physics: {
|
|
145
218
|
enabled: true,
|
|
146
219
|
geometry: "Sphere"
|
|
147
220
|
}
|
|
148
|
-
})
|
|
221
|
+
});
|
|
149
222
|
}
|
|
150
|
-
})
|
|
223
|
+
});
|
|
151
224
|
|
|
152
|
-
window.app = application
|
|
225
|
+
window.app = application;
|
|
153
226
|
```
|
|
154
227
|
|
|
228
|
+
---
|
|
229
|
+
|
|
155
230
|
## NPM Scripts
|
|
156
231
|
|
|
157
|
-
|
|
232
|
+
Uses `watchify` to bundle JavaScript.
|
|
158
233
|
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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"
|
|
165
240
|
```
|
|
166
241
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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/)
|
|
173
267
|
|
|
174
|
-
|
|
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)
|
|
175
271
|
|
|
176
|
-
|
|
177
|
-
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)
|
|
178
273
|
|
|
179
|
-
|
|
274
|
+
* 📘 Learning Resource:
|
|
275
|
+
[WebGPU Ray Tracing](https://maierfelix.github.io/2020-01-13-webgpu-ray-tracing/)
|
|
180
276
|
|
|
181
|
-
|
|
182
|
-
https://codepen.io/zlatnaspirala/pen/VwNKMar?editors=0011
|
|
183
|
-
I use empty build then i add/upload to my VPS public server you can use it:
|
|
184
|
-
Usually last night build stable/unstable version.
|
|
185
|
-
https://maximumroulette.com/apps/megpu/empty.js
|
|
186
|
-
You can build your own with `npm run build-empty`.
|
|
277
|
+
---
|
|
187
278
|
|
|
188
|
-
##
|
|
279
|
+
## License
|
|
189
280
|
|
|
190
|
-
### Note
|
|
281
|
+
### Usage Note
|
|
191
282
|
|
|
192
|
-
|
|
193
|
-
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.
|
|
194
284
|
|
|
195
|
-
|
|
196
|
-
https://webgpu.github.io/webgpu-samples/samples/renderBundles also
|
|
197
|
-
https://webgpu.github.io/webgpu-samples/?sample=shadowMapping
|
|
285
|
+
---
|
|
198
286
|
|
|
199
|
-
|
|
200
|
-
Obj loader source http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html
|
|
287
|
+
### Attribution & Credits
|
|
201
288
|
|
|
202
|
-
|
|
289
|
+
* Engine design and scene structure inspired by:
|
|
290
|
+
[WebGPU Samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
|
|
203
291
|
|
|
204
|
-
|
|
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)
|
|
205
294
|
|
|
206
|
-
|
|
295
|
+
* Dice roll sound `roll1.wav` sourced from:
|
|
296
|
+
[https://wavbvkery.com/dice-rolling-sound/](https://wavbvkery.com/dice-rolling-sound/)
|
|
207
297
|
|
|
208
|
-
|
|
209
|
-
modification, are permitted provided that the following conditions are met:
|
|
298
|
+
---
|
|
210
299
|
|
|
211
|
-
|
|
212
|
-
this list of conditions and the following disclaimer.
|
|
300
|
+
### BSD 3-Clause License (from WebGPU Samples)
|
|
213
301
|
|
|
214
|
-
|
|
215
|
-
this list of conditions and the following disclaimer in the documentation
|
|
216
|
-
and/or other materials provided with the distribution.
|
|
302
|
+
[Full License Text](https://github.com/webgpu/webgpu-samples/blob/main/LICENSE.txt)
|
|
217
303
|
|
|
218
|
-
|
|
219
|
-
contributors may be used to endorse or promote products derived from this
|
|
220
|
-
software without specific prior written permission.
|
|
304
|
+
---
|
|
221
305
|
|
|
222
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
223
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
224
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
225
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
226
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
227
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
228
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
229
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
230
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
231
|
-
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;
|
package/src/engine/engine.js
CHANGED
|
@@ -337,9 +337,7 @@ function lerp(a, b, s) {
|
|
|
337
337
|
return vec3.addScaled(a, vec3.sub(b, a), s);
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
//
|
|
341
|
-
|
|
342
|
-
// // Input holds as snapshot of input state
|
|
340
|
+
// Input holds as snapshot of input state
|
|
343
341
|
// export default interface Input {
|
|
344
342
|
// // Digital input (e.g keyboard state)
|
|
345
343
|
// readonly digital: {
|
|
@@ -358,10 +356,8 @@ function lerp(a, b, s) {
|
|
|
358
356
|
// readonly touching: boolean;
|
|
359
357
|
// };
|
|
360
358
|
// }
|
|
361
|
-
|
|
362
359
|
// InputHandler is a function that when called, returns the current Input state.
|
|
363
360
|
// export type InputHandler = () => Input;
|
|
364
|
-
|
|
365
361
|
// createInputHandler returns an InputHandler by attaching event handlers to the window and canvas.
|
|
366
362
|
export function createInputHandler(window, canvas) {
|
|
367
363
|
let digital = {
|
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 = {};
|