mage-engine 3.24.1 → 3.24.2

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 +153 -8
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -55052,14 +55052,36 @@ var Config$1 = new Config();let Universe = /*#__PURE__*/function () {
55052
55052
  }, {
55053
55053
  key: "find",
55054
55054
  value: function find(element) {
55055
- if (!element) return;
55056
- let found;
55055
+ if (!element) return; // Traverse up the THREE.js parent chain to find the closest Mage entity.
55056
+ // This ensures that when clicking on a child mesh that's nested inside
55057
+ // a parent entity's body, we find the child entity (not the parent).
55058
+
55059
+ let current = element;
55060
+
55061
+ while (current) {
55062
+ // Check if any entity's body IS this object directly
55063
+ let found;
55064
+ this.forEach(el => {
55065
+ if (!found && el.hasBody() && el.getBody() === current) {
55066
+ found = el;
55067
+ }
55068
+ });
55069
+
55070
+ if (found) {
55071
+ return found;
55072
+ }
55073
+
55074
+ current = current.parent;
55075
+ } // Fallback: use the original has() check for edge cases
55076
+
55077
+
55078
+ let fallback;
55057
55079
  this.forEach(el => {
55058
- if (el.has(element) && !found) {
55059
- found = el;
55080
+ if (el.has(element) && !fallback) {
55081
+ fallback = el;
55060
55082
  }
55061
55083
  });
55062
- return found;
55084
+ return fallback;
55063
55085
  }
55064
55086
  }, {
55065
55087
  key: "getByTag",
@@ -58219,7 +58241,7 @@ function applyMiddleware() {
58219
58241
 
58220
58242
  var thunk = createThunkMiddleware();
58221
58243
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
58222
- var version$1 = "3.24.1";
58244
+ var version$1 = "3.24.2";
58223
58245
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
58224
58246
  var main = "dist/mage.js";
58225
58247
  var author$1 = {
@@ -61085,6 +61107,67 @@ const tweenTo = function (origin, target) {
61085
61107
  value: function hasChildren() {
61086
61108
  return this.children.length > 0;
61087
61109
  }
61110
+ /**
61111
+ * Checks if the given ancestor is in this entity's parent chain.
61112
+ * Used to prevent circular references when reparenting.
61113
+ * @param {Entity} ancestor - The potential ancestor entity
61114
+ * @returns {boolean} True if ancestor is in the parent chain
61115
+ */
61116
+
61117
+ }, {
61118
+ key: "isDescendantOf",
61119
+ value: function isDescendantOf(ancestor) {
61120
+ if (!ancestor) return false;
61121
+ let current = this.getParent();
61122
+
61123
+ while (current) {
61124
+ if (current === ancestor || current.uuid && ancestor.uuid && current.uuid() === ancestor.uuid()) {
61125
+ return true;
61126
+ }
61127
+
61128
+ current = current.getParent ? current.getParent() : null;
61129
+ }
61130
+
61131
+ return false;
61132
+ }
61133
+ /**
61134
+ * Reparents this entity to a new parent while preserving world position.
61135
+ * Uses THREE.js attach() to maintain the entity's world transform.
61136
+ * @param {Entity|null} newParent - The new parent entity, or null to move to scene root
61137
+ * @returns {Entity} This entity for chaining
61138
+ */
61139
+
61140
+ }, {
61141
+ key: "reparent",
61142
+ value: function reparent(newParent) {
61143
+ if (!this.hasBody()) return this;
61144
+ const oldParent = this.getParent(); // Detach from old parent's Entity children array
61145
+
61146
+ if (oldParent && oldParent.children) {
61147
+ const index = oldParent.children.findIndex(c => c === this || c.uuid && this.uuid && c.uuid() === this.uuid());
61148
+ if (index !== -1) oldParent.children.splice(index, 1);
61149
+ } // Detach from old THREE.js parent
61150
+
61151
+
61152
+ const body = this.getBody();
61153
+
61154
+ if (body.parent) {
61155
+ body.parent.remove(body);
61156
+ }
61157
+
61158
+ if (newParent && newParent.hasBody()) {
61159
+ // Attach to new parent (preserves world position)
61160
+ newParent.children.push(this);
61161
+ this.setParent(newParent);
61162
+ newParent.getBody().attach(body);
61163
+ } else {
61164
+ // Move to scene root
61165
+ this.setParent(false);
61166
+ Scene$1.getScene().attach(body);
61167
+ }
61168
+
61169
+ return this;
61170
+ }
61088
61171
  }, {
61089
61172
  key: "getHierarchy",
61090
61173
  value: function getHierarchy() {
@@ -95434,7 +95517,7 @@ let Sky = /*#__PURE__*/function (_Element) {
95434
95517
  } catch (error) {
95435
95518
  console.error(IMPORTER_ERROR_ELEMENT_CREATION, elementData.name, elementData.entitySubType, error);
95436
95519
  }
95437
- } // adding children to elements
95520
+ } // adding children to elements (legacy children array format)
95438
95521
 
95439
95522
 
95440
95523
  for (const elementData of elements) {
@@ -95452,6 +95535,21 @@ let Sky = /*#__PURE__*/function (_Element) {
95452
95535
  }
95453
95536
  }
95454
95537
  }
95538
+ } // Handle parentUUID relationships (new format from database parentId)
95539
+ // Use parent.add(child) instead of child.reparent(parent) to preserve
95540
+ // the saved local position. reparent() uses attach() which preserves
95541
+ // world position, but for import we want to keep the saved local position.
95542
+
95543
+
95544
+ for (const elementData of elements) {
95545
+ if (elementData.parentUUID) {
95546
+ const child = Universe$1.getByUUID(elementData.uuid);
95547
+ const parent = Universe$1.getByUUID(elementData.parentUUID);
95548
+
95549
+ if (child && parent && parent.add) {
95550
+ await parent.add(child);
95551
+ }
95552
+ }
95455
95553
  }
95456
95554
 
95457
95555
  lights.forEach(data => {
@@ -95530,7 +95628,54 @@ let Sky = /*#__PURE__*/function (_Element) {
95530
95628
  } catch (error) {
95531
95629
  console.error(IMPORTER_ERROR_PARTICLE_CREATION, data.name, data.preset, error.stack);
95532
95630
  }
95533
- });
95631
+ }); // Handle parentUUID for lights
95632
+
95633
+ for (const lightData of lights) {
95634
+ if (lightData.parentUUID) {
95635
+ const child = Universe$1.getByUUID(lightData.uuid);
95636
+ const parent = Universe$1.getByUUID(lightData.parentUUID);
95637
+
95638
+ if (child && parent && parent.add) {
95639
+ await parent.add(child);
95640
+ }
95641
+ }
95642
+ } // Handle parentUUID for sounds
95643
+
95644
+
95645
+ for (const soundData of allSounds) {
95646
+ if (soundData.parentUUID) {
95647
+ const child = Universe$1.getByUUID(soundData.uuid);
95648
+ const parent = Universe$1.getByUUID(soundData.parentUUID);
95649
+
95650
+ if (child && parent && parent.add) {
95651
+ await parent.add(child);
95652
+ }
95653
+ }
95654
+ } // Handle parentUUID for particles
95655
+
95656
+
95657
+ for (const particleData of particles) {
95658
+ if (particleData.parentUUID) {
95659
+ const child = Universe$1.getByUUID(particleData.uuid);
95660
+ const parent = Universe$1.getByUUID(particleData.parentUUID);
95661
+
95662
+ if (child && parent && parent.add) {
95663
+ await parent.add(child);
95664
+ }
95665
+ }
95666
+ } // Handle parentUUID for cameras
95667
+
95668
+
95669
+ for (const cameraData of cameras) {
95670
+ if (cameraData.parentUUID) {
95671
+ const child = Universe$1.getByUUID(cameraData.uuid);
95672
+ const parent = Universe$1.getByUUID(cameraData.parentUUID);
95673
+
95674
+ if (child && parent && parent.add) {
95675
+ await parent.add(child);
95676
+ }
95677
+ }
95678
+ }
95534
95679
  }
95535
95680
  }]);
95536
95681
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.24.1",
3
+ "version": "3.24.2",
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": {