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.
Files changed (69) 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 +3 -5
  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 +65 -28
  9. package/examples/unlit-textures.js +26 -23
  10. package/examples.js +35 -3
  11. package/main.js +442 -48
  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 +28 -13
  16. package/public/app.js +11405 -9375
  17. package/public/css/style.css +371 -110
  18. package/public/empty.html +1 -1
  19. package/public/empty.js +9887 -9264
  20. package/public/examples.html +10 -8
  21. package/public/examples.js +553 -193
  22. package/public/index.html +3 -5
  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/meshes/jamb/bg.blend +0 -0
  29. package/public/res/meshes/jamb/bg.blend1 +0 -0
  30. package/public/res/meshes/jamb/bg.mtl +12 -0
  31. package/public/res/meshes/jamb/bg.obj +17 -0
  32. package/public/res/meshes/jamb/bg.png +0 -0
  33. package/public/res/meshes/jamb/dice-default.png +0 -0
  34. package/public/res/meshes/jamb/dice-mark.png +0 -0
  35. package/public/res/meshes/jamb/dice.mtl +12 -0
  36. package/public/res/meshes/jamb/dice.obj +40 -0
  37. package/public/res/meshes/jamb/dice.png +0 -0
  38. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  39. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  40. package/public/res/meshes/jamb/jamb.blend +0 -0
  41. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  42. package/public/res/meshes/jamb/logo.png +0 -0
  43. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  44. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  45. package/public/res/meshes/jamb/pile.blend +0 -0
  46. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  47. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  48. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  49. package/public/res/meshes/jamb/text.png +0 -0
  50. package/public/res/multilang/en.json +27 -0
  51. package/public/res/multilang/sr.json +27 -0
  52. package/public/test.html +636 -0
  53. package/public/three-test.js +165 -0
  54. package/public/worker.html +1 -1
  55. package/readme.md +189 -115
  56. package/src/engine/cube.js +10 -1
  57. package/src/engine/engine.js +1 -5
  58. package/src/engine/loader-obj.js +9 -6
  59. package/src/engine/matrix-class.js +237 -204
  60. package/src/engine/mesh-obj.js +605 -515
  61. package/src/engine/raycast-test.js +93 -0
  62. package/src/engine/utils.js +69 -3
  63. package/src/multilang/lang.js +35 -0
  64. package/src/physics/matrix-ammo.js +168 -15
  65. package/src/shaders/fragment.wgsl.js +4 -2
  66. package/src/shaders/shaders.js +1 -1
  67. package/src/shaders/vertexShadow.wgsl.js +1 -1
  68. package/src/sounds/sounds.js +47 -0
  69. 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
- ## Logo:
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
- ### 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)
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
- <span>WebGPU logo by <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a></span>.
12
- The logos are licensed under Creative Commons Attribution 4.0 International.
13
- Download from https://www.w3.org/2023/02/webgpu-logos.html
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
- Used npm package `wgpu-matrix` for replacment of glmatrix library.Classis "modelViewProjectionMatrix" calculations.
16
- I publish (this repo) npm package with name `matrix-engine-wgpu`.
35
+ ---
17
36
 
18
- ## Objective
37
+ ## Features
19
38
 
20
- - scene objects feature [objects/scene/transformation]
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
- ## Support list
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
- For now only `addMeshObj` works [Obj file loader].
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
- mainCameraParams: {
39
- type: 'WASD',
40
- responseCoef: 1000
41
- }
65
+ mainCameraParams: {
66
+ type: 'WASD',
67
+ responseCoef: 1000
68
+ }
42
69
  ```
43
70
 
44
- ### Position
45
- #### app.mainRenderBundle[0] -> position
71
+ ---
72
+
73
+ ### Object Positioning
46
74
 
47
- Position is taken from matrix-engine[webgl] same struct.
75
+ Control object position with:
48
76
 
49
77
  ```js
50
78
  app.mainRenderBundle[0].position.translateByX(12);
51
79
  ```
52
80
 
53
- Teleport/ direct set
81
+ Teleport / Direct set:
54
82
 
55
83
  ```js
56
84
  app.mainRenderBundle[0].position.SetX(-2);
57
85
  ```
58
86
 
59
- Change speed of translation
87
+ Change movement speed:
60
88
 
61
89
  ```js
62
90
  app.mainRenderBundle[0].position.thrust = 0.1;
63
91
  ```
64
92
 
65
- ####Note: Position for Physics enabled object look like:
66
- No working `.position` and `.rotation` in physics enabled regime.
67
- You must use Ammo body funcs like : applyForce, setAngularVelocity, setLinearVelocity etc...
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.matrixAmmo.rigidBodies[0].setAngularVelocity(new Ammo.btVector3(0,2,0))
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
- ### Rotation
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.x = 45
122
+ app.mainRenderBundle[0].rotation.rotationSpeed.y = 0;
79
123
  ```
80
124
 
81
- 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
+
82
133
  ```js
83
- app.mainRenderBundle[0].rotation.rotationSpeed.y = 10
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
- Stop rotating
157
+ Automatic raycast:
158
+
87
159
  ```js
88
- app.mainRenderBundle[0].rotation.rotationSpeed.y = 0
160
+ addRaycastListener();
161
+ window.addEventListener('ray.hit.event', (event) => {
162
+ console.log(event.detail);
163
+ });
89
164
  ```
90
165
 
91
- #### Note: In physics enabled object `.rotation` have no affect.
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(m) {
119
- application.myLoadedMeshes = m;
120
- for(var key in m) {
121
- console.log(`%c Loaded objs: ${key} `, LOG_MATRIX);
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: m.cube,
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: m.sphere,
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
- Bundle compiler: `watchify`
232
+ Uses `watchify` to bundle JavaScript.
158
233
 
159
- ```js
160
- "main-worker": "watchify app-worker.js -p [esmify --noImplicitAny] -o public/app-worker.js",
161
- "examples": "watchify examples.js -p [esmify --noImplicitAny] -o public/examples.js",
162
- "main": "watchify main.js -p [esmify --noImplicitAny] -o public/app.js",
163
- "build-empty": "watchify empty.js -p [esmify --noImplicitAny] -o public/empty.js",
164
- "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"
165
240
  ```
166
241
 
167
- 1. "main-worker" use same endpoint but with root wrapper.
168
- 2. "examples" for now build just one current (just import script from ./examples/) instance.
169
- 3. "main" this is build for main.js main instance.
170
- 4. "build-empty" when you wanna use this engine on codepen or stackoverflow just build one empty instance
171
- and you can write megpu code.
172
- 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/)
173
267
 
174
- ## 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)
175
271
 
176
- - Resources place is ./public also this folder is root for output js builds,
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
- ## LINKS
274
+ * 📘 Learning Resource:
275
+ [WebGPU Ray Tracing](https://maierfelix.github.io/2020-01-13-webgpu-ray-tracing/)
180
276
 
181
- - How to use it on codepen
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
- ## LICENCE
279
+ ## License
189
280
 
190
- ### Note:
281
+ ### Usage Note
191
282
 
192
- "Just keep this text also any other about textual file / or code commnet with ref...
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
- - Structural shema for project and personal learning inspired by:
196
- https://webgpu.github.io/webgpu-samples/samples/renderBundles also
197
- https://webgpu.github.io/webgpu-samples/?sample=shadowMapping
285
+ ---
198
286
 
199
- - Obj loader [same like matrix-engine webgl engine]
200
- Obj loader source http://math.hws.edu/graphicsbook/source/webgl/cube-camera.html
287
+ ### Attribution & Credits
201
288
 
202
- ### BSD 3-Clause
289
+ * Engine design and scene structure inspired by:
290
+ [WebGPU Samples](https://webgpu.github.io/webgpu-samples/?sample=shadowMapping)
203
291
 
204
- 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)
205
294
 
206
- 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/)
207
297
 
208
- Redistribution and use in source and binary forms, with or without
209
- modification, are permitted provided that the following conditions are met:
298
+ ---
210
299
 
211
- 1. Redistributions of source code must retain the above copyright notice,
212
- this list of conditions and the following disclaimer.
300
+ ### BSD 3-Clause License (from WebGPU Samples)
213
301
 
214
- 2. Redistributions in binary form must reproduce the above copyright notice,
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
- 3. Neither the name of the copyright holder nor the names of its
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.
@@ -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;
@@ -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
- // IMPUT
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 = {
@@ -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 = {};