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
package/readme.md CHANGED
@@ -1,189 +1,305 @@
1
- # matrix-wgpu
1
+ # matrix-engine-wgpu
2
2
 
3
- ## [underconstruct - not fully operative for now - deeply WIP]
3
+ **Author:** Nikola Lukić
4
+ 📧 [zlatnaspirala@gmail.com](mailto:zlatnaspirala@gmail.com)
5
+ 📅 2025
4
6
 
5
- ## Author Nikola Lukic zlatnaspirala@gmail.com 2024
7
+ ---
6
8
 
7
- ## Logo:
9
+ ## Logo
8
10
 
9
- <img width="350" height="350" src="https://github.com/zlatnaspirala/matrix-engine-wgpu/blob/main/public/res/icons/512.png?raw=true" />
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
- ### In logo i used webGPU logo from:
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
- <span>WebGPU logo by <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a></span>.
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
- Used npm package `wgpu-matrix` for replacment of glmatrix library.Classis "modelViewProjectionMatrix" calculations.
18
- I publish (this repo) npm package with name `matrix-engine-wgpu`.
19
+ ## Description
19
20
 
20
- ## Objective
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
- - scene objects feature [objects/scene/transformation]
23
- - Make it similar to the matrix-engine webGL features.
24
+ Published on npm as: **`matrix-engine-wgpu`**
24
25
 
25
- - For now i will use `createRenderBundleEncoder` for multi object scene draws but mix also with shadows pipline.
26
- - Main base example is `shadowMapping` from [webgpu-samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
26
+ ---
27
27
 
28
- ## Support list
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
- ### Camera
37
- Camera type: `WASD | arcball`
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
- mainCameraParams: {
40
- type: 'WASD',
41
- responseCoef: 1000
42
- }
65
+ mainCameraParams: {
66
+ type: 'WASD',
67
+ responseCoef: 1000
68
+ }
43
69
  ```
44
70
 
45
- ### Position
46
- #### app.mainRenderBundle[0] -> position
71
+ ---
72
+
73
+ ### Object Positioning
47
74
 
48
- Position is taken from matrix-engine[webgl] same struct.
75
+ Control object position with:
49
76
 
50
77
  ```js
51
78
  app.mainRenderBundle[0].position.translateByX(12);
52
79
  ```
53
80
 
54
- Teleport/ direct set
81
+ Teleport / Direct set:
55
82
 
56
83
  ```js
57
84
  app.mainRenderBundle[0].position.SetX(-2);
58
85
  ```
59
86
 
60
- Change speed of translation
87
+ Change movement speed:
61
88
 
62
89
  ```js
63
90
  app.mainRenderBundle[0].position.thrust = 0.1;
64
91
  ```
65
92
 
66
- ### Rotation
67
- #### app.mainRenderBundle[0].rotation
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.x = 45
122
+ app.mainRenderBundle[0].rotation.rotationSpeed.y = 0;
72
123
  ```
73
124
 
74
- Active rotation
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.mainRenderBundle[0].rotation.rotationSpeed.y = 10
134
+ app.cameras.WASD.pitch = 0.2;
77
135
  ```
78
136
 
79
- Stop rotating
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
- app.mainRenderBundle[0].rotation.rotationSpeed.y = 0
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
- ## How to load obj [with uvs] file:
85
- Main instance script:
166
+ ---
167
+
168
+ ## How to Load `.obj` Models
169
+
86
170
  ```js
87
- import MatrixEngineWGPU from "./src/meWGPU";
88
- import {testCUSTOMGEO} from "./public/res/meshes/blender/piramida.js";
89
- import {downloadMeshes} from "./src/engine/loader-obj.js";
90
-
91
- let application = new MatrixEngineWGPU(
92
- {
93
- useSingleRenderPass: true,
94
- canvasSize: "fullscreen",
95
- },
96
- () => {
97
- function onLoadObj(m) {
98
- application.addMeshObj({
99
- position: {x: 0, y: 0, z: -5},
100
- texturesPaths: ["./res/meshes/obj/armor.png"],
101
- name: "Armor",
102
- mesh: m.armor,
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
- downloadMeshes({armor: "./res/meshes/obj/armor.obj"}, onLoadObj);
107
- },
108
- );
109
- // just for dev
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
- Bundle compiler: `watchify`
232
+ Uses `watchify` to bundle JavaScript.
116
233
 
117
- ```js
118
- "main-worker": "watchify app-worker.js -p [esmify --noImplicitAny] -o public/app-worker.js",
119
- "examples": "watchify examples.js -p [esmify --noImplicitAny] -o public/examples.js",
120
- "main": "watchify main.js -p [esmify --noImplicitAny] -o public/app.js",
121
- "build-empty": "watchify empty.js -p [esmify --noImplicitAny] -o public/empty.js",
122
- "build-all": "npm run main-worker.js | npm run examples | npm run main | npm run build-empty"
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
- 1. "main-worker" use same endpoint but with root wrapper.
126
- 2. "examples" for now build just one current (just import script from ./examples/) instance.
127
- 3. "main" this is build for main.js main instance.
128
- 4. "build-empty" when you wanna use this engine on codepen or stackoverflow just build one empty instance
129
- and you can write megpu code.
130
- 5. "build-all" build all at once [every output is diff name].
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
- ## Resource
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
- - Resources place is ./public also this folder is root for output js builds,
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
- ## LINKS
274
+ * 📘 Learning Resource:
275
+ [WebGPU Ray Tracing](https://maierfelix.github.io/2020-01-13-webgpu-ray-tracing/)
138
276
 
139
- - How to use it on codepen
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
- ## LICENCE
279
+ ## License
147
280
 
148
- ### Note:
281
+ ### Usage Note
149
282
 
150
- "Just keep this text also any other about textual file / or code commnet with ref...
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
- - Structural shema for project and personal learning inspired by:
154
- https://webgpu.github.io/webgpu-samples/samples/renderBundles also
155
- https://webgpu.github.io/webgpu-samples/?sample=shadowMapping
285
+ ---
156
286
 
157
- - Obj loader [same like matrix-engine webgl engine]
158
- Obj loader source http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html
287
+ ### Attribution & Credits
159
288
 
160
- ### BSD 3-Clause
289
+ * Engine design and scene structure inspired by:
290
+ [WebGPU Samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
161
291
 
162
- https://github.com/webgpu/webgpu-samples/blob/main/LICENSE.txt
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
- Copyright 2019 WebGPU Samples Contributors
295
+ * Dice roll sound `roll1.wav` sourced from:
296
+ [https://wavbvkery.com/dice-rolling-sound/](https://wavbvkery.com/dice-rolling-sound/)
165
297
 
166
- Redistribution and use in source and binary forms, with or without
167
- modification, are permitted provided that the following conditions are met:
298
+ ---
168
299
 
169
- 1. Redistributions of source code must retain the above copyright notice,
170
- this list of conditions and the following disclaimer.
300
+ ### BSD 3-Clause License (from WebGPU Samples)
171
301
 
172
- 2. Redistributions in binary form must reproduce the above copyright notice,
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
- 3. Neither the name of the copyright holder nor the names of its
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.
@@ -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) {
@@ -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('camera postion:', position);
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
- // IMPUT
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
-
@@ -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 = {};