mage-engine 3.25.7 → 3.25.8

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 (2) hide show
  1. package/dist/mage.js +60 -23
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -56057,6 +56057,34 @@ const parseBoundingBoxSize = (boundingBox = {}) => {
56057
56057
  };
56058
56058
  }
56059
56059
  };
56060
+
56061
+ /**
56062
+ * Compute the world-space AABB size for a body using Box3.setFromObject().
56063
+ * Returns { width, height, length } or null if the box is degenerate (all zeros).
56064
+ */
56065
+ const getWorldBoundingBoxSize = body => {
56066
+ const worldBox = new Box3().setFromObject(body);
56067
+ const worldSize = new Vector3$1();
56068
+ worldBox.getSize(worldSize);
56069
+ if (worldSize.x === 0 && worldSize.y === 0 && worldSize.z === 0) {
56070
+ return null;
56071
+ }
56072
+ return {
56073
+ width: worldSize.x,
56074
+ height: worldSize.y,
56075
+ length: worldSize.z
56076
+ };
56077
+ };
56078
+
56079
+ /**
56080
+ * Derive a bounding sphere radius from the world-space AABB.
56081
+ * Returns the radius (half the longest axis) or null if the box is degenerate.
56082
+ */
56083
+ const getWorldBoundingSphereRadius = body => {
56084
+ const size = getWorldBoundingBoxSize(body);
56085
+ if (!size) return null;
56086
+ return Math.max(size.width, size.height, size.length) / 2;
56087
+ };
56060
56088
  const extractPositionAndQuaternion$1 = element => {
56061
56089
  const {
56062
56090
  x,
@@ -56099,29 +56127,24 @@ const extractBoxDescription = element => {
56099
56127
  // More accurate for imported models whose geometry may be offset from the
56100
56128
  // element origin, but can produce unexpected results for complex hierarchies.
56101
56129
  const extractWorldBoxDescription = element => {
56102
- const body = element.getBody();
56103
- const worldBox = new Box3().setFromObject(body);
56104
- const worldSize = new Vector3$1();
56105
- worldBox.getSize(worldSize);
56130
+ const size = getWorldBoundingBoxSize(element.getBody());
56106
56131
 
56107
56132
  // Fall back to the legacy path if the world box is degenerate.
56108
- if (worldSize.x === 0 && worldSize.y === 0 && worldSize.z === 0) {
56133
+ if (!size) {
56109
56134
  return extractBoxDescription(element);
56110
56135
  }
56111
56136
  return {
56112
- width: worldSize.x,
56113
- height: worldSize.y,
56114
- length: worldSize.z,
56137
+ ...size,
56115
56138
  size: {
56116
- x: worldSize.x,
56117
- y: worldSize.y,
56118
- z: worldSize.z
56139
+ x: size.width,
56140
+ y: size.height,
56141
+ z: size.length
56119
56142
  },
56120
56143
  ...extractPositionAndQuaternion$1(element)
56121
56144
  };
56122
56145
  };
56123
56146
  const extractSphereDescription = element => {
56124
- const radius = element.boundingSphere.radius;
56147
+ const radius = getWorldBoundingSphereRadius(element.getBody()) ?? element.boundingSphere.radius;
56125
56148
  return {
56126
56149
  radius,
56127
56150
  ...extractPositionAndQuaternion$1(element)
@@ -56140,7 +56163,7 @@ const getSphereDescriptionForElement = element => ({
56140
56163
  });
56141
56164
  const getPlayerDescriptionForElement = element => ({
56142
56165
  ...DEFAULT_PLAYER_DESCRIPTION,
56143
- ...extractBoxDescription(element)
56166
+ ...extractWorldBoxDescription(element)
56144
56167
  });
56145
56168
  const mapColliderTypeToDescription$1 = (colliderType = COLLIDER_TYPES$2.BOX) => ({
56146
56169
  [COLLIDER_TYPES$2.BOX]: getBoxDescriptionForElement$1,
@@ -56179,7 +56202,7 @@ const convertAmmoVector = ({
56179
56202
  x: z,
56180
56203
  y,
56181
56204
  z: x
56182
- });var physicsUtils=/*#__PURE__*/Object.freeze({__proto__:null,DEFAULT_DESCRIPTION:DEFAULT_DESCRIPTION$1,mapColliderTypeToAddEvent:mapColliderTypeToAddEvent$1,extractBoundingBox:extractBoundingBox,extractBiggestBoundingBox:extractBiggestBoundingBox,extractBoundingSphere:extractBoundingSphere,extractBiggestBoundingSphere:extractBiggestBoundingSphere,parseBoundingBoxSize:parseBoundingBoxSize,extractPositionAndQuaternion:extractPositionAndQuaternion$1,extractBoxDescription:extractBoxDescription,extractSphereDescription:extractSphereDescription,getBoxDescriptionForElement:getBoxDescriptionForElement$1,getSphereDescriptionForElement:getSphereDescriptionForElement,getPlayerDescriptionForElement:getPlayerDescriptionForElement,mapColliderTypeToDescription:mapColliderTypeToDescription$1,iterateGeometries:iterateGeometries$1,convertAmmoVector:convertAmmoVector});const getHostURL = () => `${document.location.protocol}//${document.location.host}`;
56205
+ });var physicsUtils=/*#__PURE__*/Object.freeze({__proto__:null,DEFAULT_DESCRIPTION:DEFAULT_DESCRIPTION$1,mapColliderTypeToAddEvent:mapColliderTypeToAddEvent$1,extractBoundingBox:extractBoundingBox,extractBiggestBoundingBox:extractBiggestBoundingBox,extractBoundingSphere:extractBoundingSphere,extractBiggestBoundingSphere:extractBiggestBoundingSphere,parseBoundingBoxSize:parseBoundingBoxSize,getWorldBoundingBoxSize:getWorldBoundingBoxSize,getWorldBoundingSphereRadius:getWorldBoundingSphereRadius,extractPositionAndQuaternion:extractPositionAndQuaternion$1,extractBoxDescription:extractBoxDescription,extractSphereDescription:extractSphereDescription,getBoxDescriptionForElement:getBoxDescriptionForElement$1,getSphereDescriptionForElement:getSphereDescriptionForElement,getPlayerDescriptionForElement:getPlayerDescriptionForElement,mapColliderTypeToDescription:mapColliderTypeToDescription$1,iterateGeometries:iterateGeometries$1,convertAmmoVector:convertAmmoVector});const getHostURL = () => `${document.location.protocol}//${document.location.host}`;
56183
56206
  const {
56184
56207
  COLLIDER_TYPES: COLLIDER_TYPES$1
56185
56208
  } = PHYSICS_CONSTANTS;
@@ -61360,7 +61383,7 @@ function applyMiddleware() {
61360
61383
 
61361
61384
  var thunk = createThunkMiddleware();
61362
61385
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
61363
- var version$1 = "3.25.7";
61386
+ var version$1 = "3.25.8";
61364
61387
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
61365
61388
  var main = "dist/mage.js";
61366
61389
  var author$1 = {
@@ -64806,14 +64829,21 @@ let Element$1 = /*#__PURE__*/function (_Entity) {
64806
64829
  value: function getComputedColliderSize() {
64807
64830
  const result = {};
64808
64831
  try {
64809
- if (this.boundingBox) {
64832
+ const body = this.getBody();
64833
+ const worldSize = body ? getWorldBoundingBoxSize(body) : null;
64834
+ if (worldSize) {
64835
+ result.width = parseFloat(worldSize.width.toFixed(3));
64836
+ result.height = parseFloat(worldSize.height.toFixed(3));
64837
+ result.length = parseFloat(worldSize.length.toFixed(3));
64838
+ result.radius = parseFloat(getWorldBoundingSphereRadius(body).toFixed(3));
64839
+ } else if (this.boundingBox) {
64810
64840
  const size = parseBoundingBoxSize(this.boundingBox);
64811
64841
  const scale = this.getScale();
64812
64842
  result.width = parseFloat((size.x * scale.x).toFixed(3));
64813
64843
  result.height = parseFloat((size.y * scale.y).toFixed(3));
64814
64844
  result.length = parseFloat((size.z * scale.z).toFixed(3));
64815
64845
  }
64816
- if (this.boundingSphere) {
64846
+ if (result.radius == null && this.boundingSphere) {
64817
64847
  result.radius = parseFloat(this.boundingSphere.radius.toFixed(3));
64818
64848
  }
64819
64849
  } catch {
@@ -99117,11 +99147,18 @@ const getBoxHitbox = element => {
99117
99147
  h = (opts.colliderHeight ?? 1) + HIT_BOX_INCREASE;
99118
99148
  l = (opts.colliderLength ?? 1) + HIT_BOX_INCREASE;
99119
99149
  } else {
99120
- const size = new Vector3$1();
99121
- element.boundingBox.getSize(size);
99122
- w = size.x + HIT_BOX_INCREASE;
99123
- h = size.y + HIT_BOX_INCREASE;
99124
- l = size.z + HIT_BOX_INCREASE;
99150
+ const size = getWorldBoundingBoxSize(element.getBody());
99151
+ if (size) {
99152
+ w = size.width + HIT_BOX_INCREASE;
99153
+ h = size.height + HIT_BOX_INCREASE;
99154
+ l = size.length + HIT_BOX_INCREASE;
99155
+ } else {
99156
+ const fallback = new Vector3$1();
99157
+ element.boundingBox.getSize(fallback);
99158
+ w = fallback.x + HIT_BOX_INCREASE;
99159
+ h = fallback.y + HIT_BOX_INCREASE;
99160
+ l = fallback.z + HIT_BOX_INCREASE;
99161
+ }
99125
99162
  }
99126
99163
  const box = new Box(w, h, l, HIT_BOX_COLOR, DEFAULT_HITBOX_OPTIONS);
99127
99164
  box.setWireframe(true);
@@ -99130,7 +99167,7 @@ const getBoxHitbox = element => {
99130
99167
  };
99131
99168
  const getSphereHitbox = element => {
99132
99169
  const opts = element.getPhysicsOptions() || {};
99133
- const radius = opts.colliderRadius != null ? opts.colliderRadius : element.boundingSphere.radius;
99170
+ const radius = opts.colliderRadius ?? getWorldBoundingSphereRadius(element.getBody()) ?? element.boundingSphere.radius;
99134
99171
  const sphere = new Sphere(radius, HIT_BOX_COLOR, DEFAULT_HITBOX_OPTIONS);
99135
99172
  sphere.setWireframe(true);
99136
99173
  sphere.setWireframeLineWidth(2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.25.7",
3
+ "version": "3.25.8",
4
4
  "description": "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.",
5
5
  "main": "dist/mage.js",
6
6
  "author": {