matrix-engine-wgpu 1.0.2 → 1.0.4

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 (44) hide show
  1. package/app-worker.js +45 -0
  2. package/empty.js +12 -0
  3. package/examples/load-obj-file.js +48 -0
  4. package/examples/unlit-textures.js +27 -0
  5. package/examples.js +7 -0
  6. package/index.js +18 -5
  7. package/main.js +34 -23
  8. package/package.json +11 -2
  9. package/public/app-worker.js +47 -0
  10. package/public/app.js +2678 -310
  11. package/public/css/style.css +1 -2
  12. package/public/empty.html +25 -0
  13. package/public/empty.js +9107 -0
  14. package/public/examples.html +25 -0
  15. package/public/examples.js +9180 -0
  16. package/public/res/meshes/blender/piramyd.blend +0 -0
  17. package/public/res/meshes/blender/piramyd.blend1 +0 -0
  18. package/public/res/meshes/blender/piramyd.js +42 -0
  19. package/public/res/meshes/blender/piramyd.mtl +10 -0
  20. package/public/res/meshes/blender/piramyd.obj +18696 -0
  21. package/public/res/meshes/blender/piramyd1.js +42 -0
  22. package/public/res/meshes/blender/welcomeTextblend.blend +0 -0
  23. package/public/res/meshes/dragon/stanfordDragonData.js +5 -0
  24. package/public/res/meshes/obj/armor.obj +319 -0
  25. package/public/res/meshes/obj/armor.png +0 -0
  26. package/public/worker.html +25 -0
  27. package/readme.md +45 -37
  28. package/src/engine/ball.js +26 -10
  29. package/src/engine/cube.js +96 -81
  30. package/src/engine/engine.js +466 -4
  31. package/src/engine/final/adaptJSON1.js +53 -0
  32. package/src/engine/final/utils2.js +63 -0
  33. package/src/engine/loader-obj.js +469 -0
  34. package/src/engine/matrix-class.js +5 -4
  35. package/src/engine/matrix-mesh.js +49 -0
  36. package/src/engine/mesh-obj.js +526 -0
  37. package/src/engine/mesh.js +477 -0
  38. package/src/engine/utils.js +2 -0
  39. package/src/shaders/fragment.wgsl.js +48 -0
  40. package/src/shaders/shaders.js +4 -124
  41. package/src/shaders/vertex.wgsl.js +49 -0
  42. package/src/shaders/vertexShadow.wgsl.js +20 -0
  43. package/src/world.js +263 -0
  44. package/src/meWGPU.js +0 -173
@@ -0,0 +1,319 @@
1
+ # Blender v2.77 (sub 0) OBJ File: 'rpg items 2.blend'
2
+ # www.blender.org
3
+ mtllib spider_drone.mtl
4
+ o armor_Plane.005
5
+ v 0.298489 -0.802792 0.189632
6
+ v 0.440916 -0.218482 0.241181
7
+ v 0.169933 0.316586 0.269533
8
+ v 0.294704 0.456258 0.115448
9
+ v 0.635841 0.378181 0.017608
10
+ v 0.575883 0.191020 0.172973
11
+ v 0.592626 -0.053642 0.254658
12
+ v 0.684469 -0.040584 0.072155
13
+ v 0.338253 -0.088105 0.220946
14
+ v 0.251449 0.287185 0.210654
15
+ v 0.376108 0.381851 0.092555
16
+ v -0.298489 -0.802792 0.189632
17
+ v -0.000000 -0.802792 0.259498
18
+ v -0.000000 -0.042422 0.380448
19
+ v -0.440916 -0.218482 0.241181
20
+ v -0.000000 0.277199 0.333237
21
+ v -0.169933 0.316586 0.269533
22
+ v -0.294704 0.456258 0.115448
23
+ v -0.635841 0.378181 0.017608
24
+ v -0.575883 0.191020 0.172973
25
+ v -0.592626 -0.053642 0.254658
26
+ v -0.000000 -0.114600 0.304054
27
+ v -0.684469 -0.040584 0.072155
28
+ v -0.338253 -0.088105 0.220946
29
+ v -0.251449 0.287185 0.210654
30
+ v -0.376108 0.381851 0.092555
31
+ v 0.339839 -0.802792 -0.205727
32
+ v 0.420581 -0.197667 -0.251268
33
+ v 0.143759 0.476682 -0.299714
34
+ v 0.279194 0.508063 -0.138994
35
+ v 0.635841 0.378181 -0.148389
36
+ v 0.597662 0.191020 -0.303754
37
+ v 0.415281 -0.802792 -0.011773
38
+ v 0.509713 -0.353713 -0.011773
39
+ v 0.684469 -0.040584 -0.202936
40
+ v 0.337962 -0.130996 -0.197246
41
+ v 0.235000 0.287185 -0.234200
42
+ v 0.376108 0.406804 -0.160230
43
+ v -0.339839 -0.802792 -0.205727
44
+ v -0.000000 -0.802792 -0.285120
45
+ v -0.420581 -0.197667 -0.251268
46
+ v -0.143759 0.476682 -0.299714
47
+ v -0.279194 0.508063 -0.138994
48
+ v -0.635841 0.378181 -0.148389
49
+ v -0.597662 0.191020 -0.303754
50
+ v -0.415281 -0.802792 -0.011773
51
+ v -0.509713 -0.353713 -0.011773
52
+ v -0.684469 -0.040584 -0.202936
53
+ v -0.337963 -0.130996 -0.197246
54
+ v -0.235000 0.287185 -0.234200
55
+ v -0.376108 0.406804 -0.160230
56
+ v -0.000000 0.031672 -0.374798
57
+ vt 0.3703 0.2382
58
+ vt 0.5280 0.2179
59
+ vt 0.3702 0.2670
60
+ vt 0.5620 0.2770
61
+ vt 0.4220 0.3722
62
+ vt 0.3704 0.3547
63
+ vt 0.5716 0.3534
64
+ vt 0.4598 0.4276
65
+ vt 0.5889 0.4450
66
+ vt 0.3706 0.0248
67
+ vt 0.4816 0.0261
68
+ vt 0.5667 0.0138
69
+ vt 0.6111 0.1593
70
+ vt 0.0982 0.8245
71
+ vt 0.0887 0.6751
72
+ vt 0.1905 0.7482
73
+ vt 0.6312 0.2762
74
+ vt 0.9626 0.2507
75
+ vt 0.8205 0.3620
76
+ vt 0.8136 0.1536
77
+ vt 0.7283 0.2228
78
+ vt 0.6907 0.1868
79
+ vt 0.7000 0.1615
80
+ vt 0.7306 0.1973
81
+ vt 0.7348 0.3264
82
+ vt 0.7309 0.3012
83
+ vt 0.7432 0.2614
84
+ vt 0.7001 0.0956
85
+ vt 0.7430 0.1146
86
+ vt 0.7768 0.0686
87
+ vt 0.9654 0.1836
88
+ vt 0.2115 0.2175
89
+ vt 0.3166 0.3727
90
+ vt 0.1770 0.2769
91
+ vt 0.2788 0.4287
92
+ vt 0.1668 0.3536
93
+ vt 0.1495 0.4458
94
+ vt 0.2594 0.0254
95
+ vt 0.1285 0.1582
96
+ vt 0.1742 0.0125
97
+ vt 0.0147 0.2420
98
+ vt 0.1073 0.2757
99
+ vt 0.7067 0.3651
100
+ vt 0.6958 0.3408
101
+ vt 0.7112 0.4308
102
+ vt 0.7528 0.4077
103
+ vt 0.7895 0.4503
104
+ vt 0.5900 0.5038
105
+ vt 0.5932 0.5930
106
+ vt 0.4548 0.4988
107
+ vt 0.5485 0.7480
108
+ vt 0.6410 0.8244
109
+ vt 0.5941 0.9865
110
+ vt 0.5099 0.9731
111
+ vt 0.7385 0.9746
112
+ vt 0.7369 0.7465
113
+ vt 0.8252 0.9768
114
+ vt 0.7943 0.5261
115
+ vt 0.7640 0.5944
116
+ vt 0.7224 0.5497
117
+ vt 0.7429 0.5110
118
+ vt 0.8651 0.5328
119
+ vt 0.8908 0.6014
120
+ vt 0.6573 0.5600
121
+ vt 0.6704 0.6424
122
+ vt 0.6552 0.7297
123
+ vt 0.3696 0.9700
124
+ vt 0.2292 0.9731
125
+ vt 0.1485 0.5045
126
+ vt 0.2831 0.4993
127
+ vt 0.1459 0.5935
128
+ vt 0.1451 0.9865
129
+ vt 0.9162 0.7484
130
+ vt 0.9144 0.5226
131
+ vt 0.9325 0.5607
132
+ vt 0.4121 0.5446
133
+ vt 0.3693 0.6786
134
+ vt 0.3266 0.5438
135
+ vt 0.9943 0.5728
136
+ vt 0.9802 0.6509
137
+ vt 0.9938 0.7340
138
+ vt 0.6505 0.6748
139
+ vt 0.9119 0.9764
140
+ vt 0.6828 0.4459
141
+ vt 0.6611 0.3929
142
+ vt 0.6507 0.3646
143
+ vt 0.6442 0.1675
144
+ vt 0.6527 0.1382
145
+ vt 0.6708 0.0833
146
+ vt 0.7235 0.2433
147
+ vt 0.8027 0.0135
148
+ vt 0.8592 0.0501
149
+ vt 0.9739 0.1333
150
+ vt 0.6868 0.9751
151
+ vt 0.9636 0.9780
152
+ vt 0.9816 0.3667
153
+ vt 0.9698 0.3174
154
+ vt 0.8728 0.4608
155
+ vt 0.8189 0.5027
156
+ vn -0.0731 -0.7249 0.6849
157
+ vn 0.4851 -0.3507 0.8011
158
+ vn -0.0000 -0.2274 0.9738
159
+ vn 0.6574 -0.1551 0.7374
160
+ vn 0.2753 0.2880 0.9172
161
+ vn -0.0000 0.1911 0.9816
162
+ vn 0.4494 0.4296 0.7832
163
+ vn 0.3549 0.7223 0.5936
164
+ vn 0.3449 0.8395 0.4198
165
+ vn 0.0000 -0.0937 0.9956
166
+ vn 0.5538 -0.1712 0.8148
167
+ vn 0.9767 -0.2141 0.0164
168
+ vn 0.9231 -0.3845 0.0029
169
+ vn -0.9231 -0.3845 0.0029
170
+ vn -0.6026 -0.4788 -0.6384
171
+ vn -0.4190 -0.2958 -0.8584
172
+ vn 0.8817 -0.3609 0.3039
173
+ vn -0.0000 0.0251 -0.9997
174
+ vn 0.4520 0.2386 -0.8595
175
+ vn -0.4520 0.2386 -0.8595
176
+ vn -0.4757 0.2802 -0.8338
177
+ vn -0.6965 -0.5299 -0.4839
178
+ vn -0.4476 -0.7237 -0.5253
179
+ vn -0.4431 -0.2005 -0.8737
180
+ vn 0.4431 -0.2005 -0.8737
181
+ vn 0.4757 0.2802 -0.8338
182
+ vn 0.0000 0.1247 -0.9922
183
+ vn -0.1520 -0.9177 -0.3671
184
+ vn -0.2728 -0.2248 -0.9355
185
+ vn -0.2918 0.8129 -0.5041
186
+ vn -0.5900 0.0681 -0.8045
187
+ vn 0.0731 -0.7249 0.6849
188
+ vn -0.4851 -0.3507 0.8011
189
+ vn -0.2753 0.2880 0.9172
190
+ vn -0.6574 -0.1551 0.7374
191
+ vn -0.3549 0.7223 0.5936
192
+ vn -0.4494 0.4296 0.7832
193
+ vn -0.3449 0.8395 0.4198
194
+ vn -0.5538 -0.1712 0.8148
195
+ vn -0.9767 -0.2141 0.0164
196
+ vn -0.8817 -0.3609 0.3039
197
+ vn 0.4476 -0.7237 -0.5253
198
+ vn 0.6965 -0.5299 -0.4839
199
+ vn 0.1520 -0.9177 -0.3671
200
+ vn 0.2728 -0.2248 -0.9355
201
+ vn 0.2918 0.8129 -0.5041
202
+ vn 0.2800 0.8712 -0.4033
203
+ vn 0.2430 0.1576 -0.9571
204
+ vn 0.3819 0.8630 -0.3307
205
+ vn 0.4190 -0.2958 -0.8584
206
+ vn 0.6174 -0.1495 -0.7723
207
+ vn -0.6539 -0.0114 0.7565
208
+ vn -0.3800 0.3314 0.8636
209
+ vn -0.0000 -0.0487 0.9988
210
+ vn -0.2244 0.1258 0.9663
211
+ vn -0.1213 -0.0315 0.9921
212
+ vn -0.3817 -0.7638 0.5204
213
+ vn -0.7232 -0.5203 0.4542
214
+ vn 0.2244 0.1258 0.9663
215
+ vn 0.1213 -0.0315 0.9921
216
+ vn -0.0639 -0.9116 0.4060
217
+ vn 0.0493 -0.1081 0.9929
218
+ vn -0.0732 0.8107 0.5808
219
+ vn -0.0000 -0.1062 -0.9943
220
+ vn -0.6174 -0.1495 -0.7723
221
+ vn -0.2800 0.8712 -0.4033
222
+ vn -0.3819 0.8630 -0.3307
223
+ vn -0.2430 0.1576 -0.9571
224
+ vn 0.3800 0.3314 0.8636
225
+ vn 0.7232 -0.5203 0.4542
226
+ vn 0.3817 -0.7638 0.5204
227
+ vn 0.1770 0.3508 -0.9196
228
+ vn 0.0000 -0.0255 -0.9997
229
+ vn -0.1770 0.3508 -0.9196
230
+ vn 0.0639 -0.9116 0.4060
231
+ vn -0.0493 -0.1081 0.9929
232
+ vn 0.0732 0.8107 0.5808
233
+ vn 0.6026 -0.4788 -0.6384
234
+ vn 0.6539 -0.0114 0.7565
235
+ vn -0.9985 0.0048 -0.0537
236
+ vn 0.9985 0.0048 -0.0537
237
+ vn 0.5900 0.0681 -0.8045
238
+ usemtl armor
239
+ s 1
240
+ f 22/1/1 2/2/2 14/3/3
241
+ f 14/3/3 7/4/4 3/5/5 16/6/6
242
+ f 14/3/3 2/2/2 7/4/4
243
+ f 3/5/5 7/4/4 6/7/7 4/8/8
244
+ f 5/9/9 4/8/8 6/7/7
245
+ f 13/10/10 1/11/11 2/2/2 22/1/10
246
+ f 2/2/2 1/11/11 33/12/12 34/13/13
247
+ f 47/14/14 48/15/15 41/16/16
248
+ f 7/4/4 2/2/2 8/17/17
249
+ f 7/4/4 8/17/17 6/7/7
250
+ f 13/18/18 24/19/19 9/20/20
251
+ f 3/21/21 4/22/22 11/23/23 10/24/24
252
+ f 25/25/25 17/26/26 16/27/27
253
+ f 5/28/28 6/29/29 10/24/24 11/23/23
254
+ f 6/29/29 8/30/30 9/20/20 10/24/24
255
+ f 1/31/31 13/18/18 9/20/20
256
+ f 22/1/32 14/3/3 15/32/33
257
+ f 14/3/3 16/6/6 17/33/34 21/34/35
258
+ f 14/3/3 21/34/35 15/32/33
259
+ f 17/33/34 18/35/36 20/36/37 21/34/35
260
+ f 19/37/38 20/36/37 18/35/36
261
+ f 13/10/10 22/1/10 15/32/33 12/38/39
262
+ f 15/32/33 47/39/14 46/40/40 12/38/39
263
+ f 48/41/15 47/39/14 23/42/41
264
+ f 21/34/35 23/42/41 15/32/33
265
+ f 21/34/35 20/36/37 23/42/41
266
+ f 25/25/25 16/27/27 24/19/19
267
+ f 17/26/26 25/25/25 26/43/42 18/44/43
268
+ f 24/19/19 16/27/27 9/20/20
269
+ f 19/45/44 26/43/42 25/25/25 20/46/45
270
+ f 20/46/45 25/25/25 24/19/19 23/47/46
271
+ f 16/27/27 10/24/24 9/20/20
272
+ f 31/48/47 32/49/48 30/50/49
273
+ f 28/51/50 34/52/13 33/53/12 27/54/51
274
+ f 27/55/52 36/56/53 40/57/54
275
+ f 5/9/9 31/48/47 30/50/49 4/8/8
276
+ f 29/58/55 37/59/56 38/60/57 30/61/58
277
+ f 29/58/55 42/62/59 50/63/60 37/59/56
278
+ f 31/64/61 38/60/57 37/59/56 32/65/62
279
+ f 32/65/62 37/59/56 36/56/53 35/66/63
280
+ f 40/67/64 39/68/65 41/16/16
281
+ f 44/69/66 43/70/67 45/71/68
282
+ f 27/54/51 40/67/64 28/51/50
283
+ f 41/16/16 39/68/65 46/72/40 47/14/14
284
+ f 47/39/14 15/32/33 23/42/41
285
+ f 49/73/69 40/57/54 36/56/53
286
+ f 19/37/38 18/35/36 43/70/67 44/69/66
287
+ f 42/62/59 43/74/70 51/75/71 50/63/60
288
+ f 29/76/72 52/77/73 42/78/74
289
+ f 44/79/75 45/80/76 50/63/60 51/75/71
290
+ f 45/80/76 48/81/77 49/73/69 50/63/60
291
+ f 50/63/60 49/73/69 36/56/53 37/59/56
292
+ f 28/51/50 32/49/48 35/82/78
293
+ f 28/51/50 40/67/64 52/77/73
294
+ f 48/15/15 45/71/68 41/16/16
295
+ f 43/70/67 42/78/74 45/71/68
296
+ f 29/76/72 30/50/49 32/49/48
297
+ f 28/51/50 52/77/73 32/49/48
298
+ f 41/16/16 52/77/73 40/67/64
299
+ f 41/16/16 45/71/68 52/77/73
300
+ f 45/71/68 42/78/74 52/77/73
301
+ f 29/76/72 32/49/48 52/77/73
302
+ f 40/57/54 49/73/69 39/83/79
303
+ f 44/84/75 51/85/71 26/43/42 19/45/44
304
+ f 18/44/43 26/43/42 51/85/71 43/86/70
305
+ f 4/22/22 30/87/58 38/88/57 11/23/23
306
+ f 31/89/61 5/28/28 11/23/23 38/88/57
307
+ f 35/90/78 8/17/17 34/13/13
308
+ f 34/52/13 28/51/50 35/82/78
309
+ f 34/13/13 8/17/17 2/2/2
310
+ f 9/20/20 8/30/30 35/91/63 36/92/53
311
+ f 33/93/80 1/31/31 9/20/20
312
+ f 33/94/80 36/56/53 27/55/52
313
+ f 9/20/20 36/92/53 33/93/80
314
+ f 46/95/81 39/83/79 49/73/69
315
+ f 46/96/81 24/19/19 12/97/82
316
+ f 49/98/69 24/19/19 46/96/81
317
+ f 24/19/19 49/98/69 48/99/77 23/47/46
318
+ f 24/19/19 13/18/18 12/97/82
319
+ f 3/21/21 10/24/24 16/27/27
Binary file
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <link rel="manifest" href="manifest.web" />
5
+ <title>Matrix Engine webGPU variant. Created by Nikola Lukic zlatnaspirala@gmail.com </title>
6
+ <meta name="description" content="The benefits of this project is offering an overview of the entire application logic, easy native implementations (hybrid app), object structural. " />
7
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
8
+ <link defer rel="stylesheet" href="css/style.css" />
9
+ <link rel="apple-touch-icon" href="res/icons/512.png" />
10
+ <meta name="apple-mobile-web-app-capable" content="yes" />
11
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
12
+ <meta name="theme-color" content="#000000" />
13
+ <!-- <script defer src="./lib/gl-matrix-min.js"></script> -->
14
+ <meta name="viewport" content="width=device-width,initial-scale=1.0,minimal-ui" />
15
+ <!-- <link rel="icon" type="image/png" sizes="96x96" href="res/icons/favicon-96x96.png" /> -->
16
+ <link rel="icon" type="image/png" sizes="512x512" href="res/icons/512.png" />
17
+ <!-- <link rel="icon" href="res/icons/favicon.ico" type="image/x-icon" /> -->
18
+ <!-- <meta name="msapplication-TileImage" content="res/icons/ms-icon.png" /> -->
19
+ <!-- <script src="https://webglfundamentals.org/webgl/resources/m4.js"></script> -->
20
+ </head>
21
+ <body allow="autoplay">
22
+ <div id="shaders"></div>
23
+ <script src="app-worker.js"></script>
24
+ </body>
25
+ </html>
package/readme.md CHANGED
@@ -12,69 +12,77 @@
12
12
  The logos are licensed under Creative Commons Attribution 4.0 International.
13
13
  Download from https://www.w3.org/2023/02/webgpu-logos.html
14
14
 
15
- Used npm package `wgpu-matrix` for replacment of glmatrix library.
16
15
 
16
+ Used npm package `wgpu-matrix` for replacment of glmatrix library.Classis "modelViewProjectionMatrix" calculations.
17
17
  I publish (this repo) npm package with name `matrix-engine-wgpu`.
18
18
 
19
-
20
19
  ## Objective
21
20
  - scene objects feature [objects/scene/transformation]
22
21
  - Make it similar to the matrix-engine webGL features.
23
22
 
24
- For now i will use `createRenderBundleEncoder` for multi object scene draws.
25
-
26
-
23
+ For now i will use `createRenderBundleEncoder` for multi object scene draws but mix also with shadows pipline.
27
24
 
28
25
 
26
+ ## How to load obj file:
29
27
  Main instance script:
30
28
  ```js
31
- let application = new MatrixEngineWGPU(()=> {
32
-
33
- let c = {
34
- position: { x: -5, y: 3, z: -10}
35
- };
36
-
37
- let o = {
38
- position: { x: 5, y: 2, z: -10}
39
- };
40
-
41
- application.addCube(c)
42
- application.addBall(o)
29
+ import MatrixEngineWGPU from "./src/meWGPU";
30
+ import {testCUSTOMGEO} from "./public/res/meshes/blender/piramida.js";
31
+ import {downloadMeshes} from './src/engine/loader-obj.js';
32
+
33
+ let application = new MatrixEngineWGPU({
34
+ useSingleRenderPass: true,
35
+ canvasSize: 'fullscreen' }, () => {
36
+
37
+ function onLoadObj (m) {
38
+ application.addMeshObj({
39
+ position: {x: 0, y: 0, z: -5},
40
+ texturesPaths: ['./res/meshes/obj/armor.png'],
41
+ name: 'Armor',
42
+ mesh: m.armor
43
+ })
44
+ }
43
45
 
46
+ downloadMeshes(
47
+ {armor: "./res/meshes/obj/armor.obj"},
48
+ onLoadObj
49
+ )
44
50
  })
51
+ // just for dev
52
+ window.app = application
45
53
  ```
46
54
 
47
- Not the best solution but works for now.
48
- Next level is draw in one scene different shaders different pipline...
55
+ ## NPM Scripts
49
56
 
50
- System draws func:
51
57
  ```js
52
- frame = () => {
53
- let commandEncoder = this.device.createCommandEncoder();
54
- this.rbContainer = [];
58
+ "main-worker": "watchify app-worker.js -p [esmify --noImplicitAny] -o public/app-worker.js",
59
+ "examples": "watchify examples.js -p [esmify --noImplicitAny] -o public/examples.js",
60
+ "main": "watchify main.js -p [esmify --noImplicitAny] -o public/app.js",
61
+ "build-empty": "watchify empty.js -p [esmify --noImplicitAny] -o public/empty.js",
62
+ "build-all": "npm run main-worker.js | npm run examples | npm run main | npm run build-empty"
63
+ ```
55
64
 
56
- let passEncoder;
65
+ 1) "main-worker" use same endpoint but with root wrapper.
66
+ 2) "examples" for now build just one current (just import script from ./examples/) instance.
67
+ 3) "main" this is build for main.js main instance.
68
+ 4) "build-empty" when you wanna use this engine on codepen or stackoverflow just build one empty instance
69
+ and you can write megpu code.
70
+ 5) "build-all" build all at once [every output is diff name].
57
71
 
58
- this.mainRenderBundle.forEach((meItem, index) => {
59
- meItem.draw();
60
- this.rbContainer.push(meItem.renderBundle)
61
- if(index == 0) passEncoder = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
62
- })
72
+ ## Resource
73
+ Resources place is ./public also this folder is root for output js builds.
74
+ After all you get all needed stuff in one public folder (www).
75
+
63
76
 
64
- // passEncoder.executeBundles([NIK.renderBundle, NIK2.renderBundle]);
65
- passEncoder.executeBundles(this.rbContainer);
66
- passEncoder.end();
67
- this.device.queue.submit([commandEncoder.finish()]);
68
-
69
- requestAnimationFrame(this.frame);
70
- }
71
- ```
72
77
 
73
78
  ## LICENCE
74
79
 
75
80
  - Structural shema for project and personal learning inspired by:
76
81
  https://webgpu.github.io/webgpu-samples/samples/renderBundles
77
82
 
83
+ - Obj loader [same like matrix-engine webgl engine]
84
+ Obj loader source http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html
85
+
78
86
  ### BSD 3-Clause
79
87
 
80
88
  https://github.com/webgpu/webgpu-samples/blob/main/LICENSE.txt
@@ -1,6 +1,7 @@
1
- import {BALL_SHADER} from "../shaders/shaders";
1
+ import {UNLIT_SHADER} from "../shaders/shaders";
2
2
  import {mat4, vec3} from 'wgpu-matrix';
3
3
  import {Position, Rotation} from "./matrix-class";
4
+ import {createInputHandler} from "./engine";
4
5
 
5
6
  export default class MEBall {
6
7
 
@@ -8,6 +9,18 @@ export default class MEBall {
8
9
  this.context = context;
9
10
  this.device = device;
10
11
 
12
+ // The input handler
13
+ this.inputHandler = createInputHandler(window, canvas);
14
+ this.cameras = o.cameras;
15
+ this.scale = o.scale;
16
+ console.log('passed : o.mainCameraParams.responseCoef ', o.mainCameraParams.responseCoef)
17
+ this.cameraParams = {
18
+ type: o.mainCameraParams.type,
19
+ responseCoef: o.mainCameraParams.responseCoef
20
+ } // | WASD 'arcball' };
21
+
22
+ this.lastFrameMS = 0;
23
+
11
24
  this.entityArgPass = o.entityArgPass;
12
25
 
13
26
  this.SphereLayout = {
@@ -29,7 +42,7 @@ export default class MEBall {
29
42
  this.rotation.rotationSpeed.y = o.rotationSpeed.y;
30
43
  this.rotation.rotationSpeed.z = o.rotationSpeed.z;
31
44
 
32
- this.shaderModule = device.createShaderModule({code: BALL_SHADER});
45
+ this.shaderModule = device.createShaderModule({code: UNLIT_SHADER});
33
46
  this.presentationFormat = navigator.gpu.getPreferredCanvasFormat();
34
47
 
35
48
  this.pipeline = device.createRenderPipeline({
@@ -113,8 +126,6 @@ export default class MEBall {
113
126
 
114
127
  this.loadTex0(this.texturesPaths, device).then(() => {
115
128
  this.loadTex1(device).then(() => {
116
-
117
- console.log('NICE THIS', this)
118
129
  this.sampler = device.createSampler({
119
130
  magFilter: 'linear',
120
131
  minFilter: 'linear',
@@ -124,12 +135,11 @@ export default class MEBall {
124
135
  mat4.identity(this.transform);
125
136
 
126
137
  // Create one large central planet surrounded by a large ring of asteroids
127
- this.planet = this.createSphereRenderable(1.0);
138
+ this.planet = this.createGeometry(this.scale);
128
139
  this.planet.bindGroup = this.createSphereBindGroup(this.texture0, this.transform);
129
140
 
130
141
  var asteroids = [
131
- this.createSphereRenderable(0.2, 8, 6, 0.15),
132
- this.createSphereRenderable(0.13, 8, 6, 0.15)
142
+ this.createGeometry(12, 8, 6, 0.15),
133
143
  ];
134
144
 
135
145
  this.renderables = [this.planet];
@@ -218,7 +228,7 @@ export default class MEBall {
218
228
  this.renderBundle = renderBundleEncoder.finish();
219
229
  }
220
230
 
221
- createSphereRenderable(radius, widthSegments = 8, heightSegments = 4, randomness = 0) {
231
+ createGeometry(radius, widthSegments = 8, heightSegments = 4, randomness = 0) {
222
232
 
223
233
  const sphereMesh = this.createSphereMesh(radius, widthSegments, heightSegments, randomness);
224
234
  // Create a vertex buffer from the sphere data.
@@ -280,10 +290,16 @@ export default class MEBall {
280
290
  }
281
291
 
282
292
  getTransformationMatrix(pos) {
293
+ // const viewMatrix = mat4.identity();
294
+ const now = Date.now();
295
+ const deltaTime = (now - this.lastFrameMS) / this.cameraParams.responseCoef;
296
+ this.lastFrameMS = now;
297
+
298
+ // const viewMatrix = mat4.identity(); ORI
299
+ const camera = this.cameras[this.cameraParams.type];
300
+ const viewMatrix = camera.update(deltaTime, this.inputHandler());
283
301
 
284
- const viewMatrix = mat4.identity();
285
302
  mat4.translate(viewMatrix, vec3.fromValues(pos.x, pos.y, pos.z), viewMatrix);
286
- const now = Date.now() / 1000;
287
303
 
288
304
  mat4.rotateX(viewMatrix, Math.PI * this.rotation.getRotX(), viewMatrix);
289
305
  mat4.rotateY(viewMatrix, Math.PI * this.rotation.getRotY(), viewMatrix);