matrix-engine-wgpu 1.3.5 → 1.3.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matrix-engine-wgpu",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
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": [
@@ -139,6 +139,30 @@ export function computeAABBFromVertices(vertices) {
139
139
  return [min, max];
140
140
  }
141
141
 
142
+ export function computeWorldAABB(vertices, modelMatrix) {
143
+ const min = [Infinity, Infinity, Infinity];
144
+ const max = [-Infinity, -Infinity, -Infinity];
145
+ const v = [0, 0, 0];
146
+
147
+ for (let i = 0; i < vertices.length; i += 3) {
148
+ v[0] = vertices[i];
149
+ v[1] = vertices[i + 1];
150
+ v[2] = vertices[i + 2];
151
+
152
+ const worldV = vec3.transformMat4([], v, modelMatrix);
153
+
154
+ min[0] = Math.min(min[0], worldV[0]);
155
+ min[1] = Math.min(min[1], worldV[1]);
156
+ min[2] = Math.min(min[2], worldV[2]);
157
+
158
+ max[0] = Math.max(max[0], worldV[0]);
159
+ max[1] = Math.max(max[1], worldV[1]);
160
+ max[2] = Math.max(max[2], worldV[2]);
161
+ }
162
+
163
+ return [min, max];
164
+ }
165
+
142
166
  export function addRaycastsAABBListener(canvasId = "canvas1") {
143
167
  const canvasDom = document.getElementById(canvasId);
144
168
  if(!canvasDom) {
@@ -153,26 +177,23 @@ export function addRaycastsAABBListener(canvasId = "canvas1") {
153
177
  for(const object of app.mainRenderBundle) {
154
178
  // Compute AABB min/max from object position and size
155
179
  const pos = [object.position.x,object.position.y,object.position.z]; // [x,y,z]
156
-
157
- ////////////
158
- const [boxMinLocal, boxMaxLocal] = computeAABBFromVertices(object.mesh.vertices);
180
+ // Works only for 0,0,0 static object
181
+ // const [boxMinLocal, boxMaxLocal] = computeAABBFromVertices(object.mesh.vertices);
182
+ const [boxMin, boxMax] = computeWorldAABB(object.mesh.vertices, object.viewMatrix);
159
183
  // Optionally transform to world space using object.position
160
184
  // const pos = object.position;
161
-
162
- const boxMin = [
163
- boxMinLocal[0] + pos[0],
164
- boxMinLocal[1] + pos[1],
165
- boxMinLocal[2] + pos[2]
166
- ];
167
-
168
- const boxMax = [
169
- boxMaxLocal[0] + pos[0],
170
- boxMaxLocal[1] + pos[1],
171
- boxMaxLocal[2] + pos[2]
172
- ];
185
+ // const boxMin = [
186
+ // boxMinLocal[0] + pos[0],
187
+ // boxMinLocal[1] + pos[1],
188
+ // boxMinLocal[2] + pos[2]
189
+ // ];
190
+ // const boxMax = [
191
+ // boxMaxLocal[0] + pos[0],
192
+ // boxMaxLocal[1] + pos[1],
193
+ // boxMaxLocal[2] + pos[2]
194
+ // ];
173
195
  //////////////
174
196
  // const size = object.size || [1, 1, 1]; // Replace with actual object size or default 1x1x1
175
-
176
197
  // const boxMin = [
177
198
  // pos[0] - size[0] / 2,
178
199
  // pos[1] - size[1] / 2,