matrix-engine-wgpu 1.1.0 → 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/readme.md CHANGED
@@ -19,7 +19,7 @@
19
19
  ## Description
20
20
 
21
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.
22
+ It uses the `wgpu-matrix` npm package as a modern replacement for `gl-matrix` to handle model-view-projection matrices.
23
23
 
24
24
  Published on npm as: **`matrix-engine-wgpu`**
25
25
 
@@ -38,18 +38,17 @@ Published on npm as: **`matrix-engine-wgpu`**
38
38
 
39
39
  ### Scene Management
40
40
 
41
- * A canvas is dynamically created in JavaScript no `<canvas>` in HTML required.
41
+ * Canvas is dynamically created in JavaScript—no `<canvas>` element needed in HTML.
42
42
 
43
- * Access the main scene using:
43
+ * Access the main scene objects:
44
44
 
45
45
  ```js
46
46
  app.mainRenderBundle[0];
47
47
  ```
48
48
 
49
- * Add meshes using `.addMeshObj()`
50
- (Supports `.obj` loading, unlit textures, cubes, spheres, etc.)
49
+ * Add meshes with `.addMeshObj()`, supporting `.obj` loading, unlit textures, cubes, spheres, etc.
51
50
 
52
- * Cleanly destroy the current scene:
51
+ * Cleanly destroy the scene:
53
52
 
54
53
  ```js
55
54
  app.destroyProgram();
@@ -72,26 +71,25 @@ mainCameraParams: {
72
71
 
73
72
  ### Object Positioning
74
73
 
75
- Control object position with:
74
+ Control object position:
76
75
 
77
76
  ```js
78
77
  app.mainRenderBundle[0].position.translateByX(12);
79
78
  ```
80
79
 
81
- Teleport / Direct set:
80
+ Teleport / set directly:
82
81
 
83
82
  ```js
84
83
  app.mainRenderBundle[0].position.SetX(-2);
85
84
  ```
86
85
 
87
- Change movement speed:
86
+ Adjust movement speed:
88
87
 
89
88
  ```js
90
89
  app.mainRenderBundle[0].position.thrust = 0.1;
91
90
  ```
92
91
 
93
- > ⚠️ For physics-enabled objects, use Ammo.js functions.
94
- > `.position` and `.rotation` won't apply visually but can be read.
92
+ > ⚠️ For physics-enabled objects, use Ammo.js functions — `.position` and `.rotation` are not visually applied but can be read.
95
93
 
96
94
  Example:
97
95
 
@@ -104,7 +102,7 @@ app.matrixAmmo.rigidBodies[0].setLinearVelocity(new Ammo.btVector3(0, 7, 0));
104
102
 
105
103
  ### Object Rotation
106
104
 
107
- Rotate manually:
105
+ Manual rotation:
108
106
 
109
107
  ```js
110
108
  app.mainRenderBundle[0].rotation.x = 45;
@@ -122,7 +120,7 @@ Stop rotation:
122
120
  app.mainRenderBundle[0].rotation.rotationSpeed.y = 0;
123
121
  ```
124
122
 
125
- > ⚠️ Same note as position: `.rotation.x/y/z` has no effect for physics-enabled objects.
123
+ > ⚠️ For physics-enabled objects, use Ammo.js methods (e.g., `.setLinearVelocity()`).
126
124
 
127
125
  ---
128
126
 
@@ -138,7 +136,16 @@ app.cameras.WASD.pitch = 0.2;
138
136
 
139
137
  ## Object Interaction (Raycasting)
140
138
 
141
- Manual raycast:
139
+ The raycast returns:
140
+
141
+ ```js
142
+ {
143
+ rayOrigin: [x, y, z],
144
+ rayDirection: [x, y, z] // normalized
145
+ }
146
+ ```
147
+
148
+ Manual raycast example:
142
149
 
143
150
  ```js
144
151
  window.addEventListener('click', (event) => {
@@ -147,19 +154,20 @@ window.addEventListener('click', (event) => {
147
154
  const { rayOrigin, rayDirection } = getRayFromMouse(event, canvas, camera);
148
155
 
149
156
  for (const object of app.mainRenderBundle) {
150
- if (rayIntersectsSphere(rayOrigin, rayDirection, object.position, 2)) {
157
+ if (rayIntersectsSphere(rayOrigin, rayDirection, object.position, object.raycast.radius)) {
151
158
  console.log('Object clicked:', object.name);
152
159
  }
153
160
  }
154
161
  });
155
162
  ```
156
163
 
157
- Automatic raycast:
164
+ Automatic raycast listener:
158
165
 
159
166
  ```js
160
167
  addRaycastListener();
168
+
161
169
  window.addEventListener('ray.hit.event', (event) => {
162
- console.log(event.detail);
170
+ console.log('Ray hit:', event.detail.hitObject);
163
171
  });
164
172
  ```
165
173
 
@@ -227,6 +235,16 @@ window.app = application;
227
235
 
228
236
  ---
229
237
 
238
+ ## About `main.js`
239
+
240
+ `main.js` is the main instance for the Ultimate Yahtzee game template.
241
+ It contains the game context, e.g., `dices`.
242
+
243
+ For a clean startup without extra logic, use `empty.js`.
244
+ This minimal build is ideal for online editors like CodePen or StackOverflow snippets.
245
+
246
+ ---
247
+
230
248
  ## NPM Scripts
231
249
 
232
250
  Uses `watchify` to bundle JavaScript.
@@ -239,19 +257,11 @@ Uses `watchify` to bundle JavaScript.
239
257
  "build-all": "npm run main-worker && npm run examples && npm run main && npm run build-empty"
240
258
  ```
241
259
 
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
260
  ---
251
261
 
252
262
  ## Resources
253
263
 
254
- * All resources and output go into `./public` — a single folder with everything you need.
264
+ All resources and output go into the `./public` folder everything you need in one place.
255
265
 
256
266
  ---
257
267
 
@@ -264,15 +274,11 @@ Script summary:
264
274
  ## Live Demos & Dev Links
265
275
 
266
276
  * [Jamb WebGPU Demo (WIP)](https://maximumroulette.com/apps/webgpu/)
267
-
268
277
  * [CodePen Demo](https://codepen.io/zlatnaspirala/pen/VwNKMar?editors=0011)
269
278
  → Uses `empty.js` build from:
270
279
  [https://maximumroulette.com/apps/megpu/empty.js](https://maximumroulette.com/apps/megpu/empty.js)
271
-
272
280
  * [CodeSandbox Implementation](https://codesandbox.io/p/github/zlatnaspirala/matrix-engine-wgpu/main?file=%2Fpackage.json%3A14%2C16)
273
-
274
- * 📘 Learning Resource:
275
- [WebGPU Ray Tracing](https://maierfelix.github.io/2020-01-13-webgpu-ray-tracing/)
281
+ * 📘 Learning Resource: [WebGPU Ray Tracing](https://maierfelix.github.io/2020-01-13-webgpu-ray-tracing/)
276
282
 
277
283
  ---
278
284
 
@@ -280,7 +286,7 @@ Script summary:
280
286
 
281
287
  ### Usage Note
282
288
 
283
- > You may use, modify, and even sell your project with this code — just keep this notice and any included references in place.
289
+ You may use, modify, and sell projects based on this code — just keep this notice and included references intact.
284
290
 
285
291
  ---
286
292
 
@@ -288,12 +294,11 @@ Script summary:
288
294
 
289
295
  * Engine design and scene structure inspired by:
290
296
  [WebGPU Samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
291
-
292
297
  * OBJ Loader adapted from:
293
298
  [http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html](http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html)
294
-
295
299
  * Dice roll sound `roll1.wav` sourced from:
296
300
  [https://wavbvkery.com/dice-rolling-sound/](https://wavbvkery.com/dice-rolling-sound/)
301
+ * Raycasting logic assisted by ChatGPT
297
302
 
298
303
  ---
299
304
 
@@ -301,5 +306,4 @@ Script summary:
301
306
 
302
307
  [Full License Text](https://github.com/webgpu/webgpu-samples/blob/main/LICENSE.txt)
303
308
 
304
- ---
305
-
309
+ ---