matrix-engine-wgpu 1.3.0 → 1.3.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/package.json +1 -1
- package/readme.md +6 -8
- package/src/engine/mesh-obj.js +11 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matrix-engine-wgpu",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "obj sequence anim +HOTFIX raycast, webGPU powered pwa application. Crazy fast rendering with AmmoJS physics support. Simple raycaster hit object added.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
package/readme.md
CHANGED
|
@@ -69,7 +69,7 @@ mainCameraParams: {
|
|
|
69
69
|
|
|
70
70
|
---
|
|
71
71
|
|
|
72
|
-
### Object
|
|
72
|
+
### Object Position
|
|
73
73
|
|
|
74
74
|
Control object position:
|
|
75
75
|
|
|
@@ -134,7 +134,7 @@ app.cameras.WASD.pitch = 0.2;
|
|
|
134
134
|
|
|
135
135
|
---
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
### Object Interaction (Raycasting)
|
|
138
138
|
|
|
139
139
|
The raycast returns:
|
|
140
140
|
|
|
@@ -173,7 +173,7 @@ window.addEventListener('ray.hit.event', (event) => {
|
|
|
173
173
|
|
|
174
174
|
---
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
### How to Load `.obj` Models
|
|
177
177
|
|
|
178
178
|
```js
|
|
179
179
|
import MatrixEngineWGPU from "./src/world.js";
|
|
@@ -234,13 +234,11 @@ window.app = application;
|
|
|
234
234
|
```
|
|
235
235
|
|
|
236
236
|
|
|
237
|
-
|
|
237
|
+
### 🔁 Load OBJ Sequence Animation
|
|
238
238
|
|
|
239
239
|
This example shows how to load and animate a sequence of .obj files to simulate mesh-based animation (e.g. walking character).
|
|
240
240
|
|
|
241
|
-
js
|
|
242
|
-
Copy
|
|
243
|
-
Edit
|
|
241
|
+
```js
|
|
244
242
|
import MatrixEngineWGPU from "../src/world.js";
|
|
245
243
|
import { downloadMeshes, makeObjSeqArg } from "../src/engine/loader-obj.js";
|
|
246
244
|
import { LOG_MATRIX } from "../src/engine/utils.js";
|
|
@@ -396,4 +394,4 @@ You may use, modify, and sell projects based on this code — just keep this not
|
|
|
396
394
|
|
|
397
395
|
Top level main.js instance (Ultimate Yahtzee)
|
|
398
396
|
|
|
399
|
-
---
|
|
397
|
+
---
|
package/src/engine/mesh-obj.js
CHANGED
|
@@ -25,15 +25,17 @@ export default class MEMeshObj {
|
|
|
25
25
|
this.context = context;
|
|
26
26
|
this.entityArgPass = o.entityArgPass;
|
|
27
27
|
|
|
28
|
-
// Mesh stuff
|
|
28
|
+
// Mesh stuff - for single mesh or t-posed (fiktive-first in loading order)
|
|
29
29
|
this.mesh = o.mesh;
|
|
30
30
|
this.mesh.uvs = this.mesh.textures;
|
|
31
31
|
console.log(`%c Mesh loaded: ${o.name}`, LOG_FUNNY_SMALL);
|
|
32
32
|
|
|
33
|
-
//
|
|
34
|
-
//
|
|
33
|
+
// ObjSequence animation
|
|
35
34
|
if(typeof o.objAnim !== 'undefined' && o.objAnim != null) {
|
|
36
35
|
this.objAnim = o.objAnim;
|
|
36
|
+
for (var key in this.objAnim.animations){
|
|
37
|
+
if (key != 'active') this.objAnim.animations[key].speedCounter = 0;
|
|
38
|
+
}
|
|
37
39
|
console.log(`%c Mesh objAnim exist: ${o.objAnim}`, LOG_FUNNY_SMALL);
|
|
38
40
|
this.drawElements = this.drawElementsAnim;
|
|
39
41
|
}
|
|
@@ -699,18 +701,21 @@ export default class MEMeshObj {
|
|
|
699
701
|
}
|
|
700
702
|
|
|
701
703
|
drawElementsAnim = (renderPass) => {
|
|
702
|
-
console.log('render is for anim')
|
|
703
704
|
renderPass.setBindGroup(0, this.sceneBindGroupForRender);
|
|
704
705
|
renderPass.setBindGroup(1, this.modelBindGroup);
|
|
705
706
|
const mesh = this.objAnim.meshList[this.objAnim.id + this.objAnim.currentAni];
|
|
706
|
-
|
|
707
707
|
renderPass.setVertexBuffer(0, mesh.vertexBuffer);
|
|
708
708
|
renderPass.setVertexBuffer(1, mesh.vertexNormalsBuffer);
|
|
709
709
|
renderPass.setVertexBuffer(2, mesh.vertexTexCoordsBuffer);
|
|
710
710
|
renderPass.setIndexBuffer(mesh.indexBuffer, 'uint16');
|
|
711
711
|
renderPass.drawIndexed(mesh.indexCount);
|
|
712
712
|
if(this.objAnim.playing == true) {
|
|
713
|
-
this.objAnim.
|
|
713
|
+
if (this.objAnim.animations[this.objAnim.animations.active].speedCounter >= this.objAnim.animations[this.objAnim.animations.active].speed) {
|
|
714
|
+
this.objAnim.currentAni++;
|
|
715
|
+
this.objAnim.animations[this.objAnim.animations.active].speedCounter = 0;
|
|
716
|
+
} else {
|
|
717
|
+
this.objAnim.animations[this.objAnim.animations.active].speedCounter++;
|
|
718
|
+
}
|
|
714
719
|
if(this.objAnim.currentAni >= this.objAnim.animations[this.objAnim.animations.active].to) {
|
|
715
720
|
this.objAnim.currentAni = this.objAnim.animations[this.objAnim.animations.active].from;
|
|
716
721
|
}
|