mage-engine 3.24.5 → 3.24.7

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 +33 -3
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -56867,7 +56867,13 @@ var Physics$1 = new Physics();let Scene = /*#__PURE__*/function () {
56867
56867
  value: function add(body, element, addUniverse = true) {
56868
56868
  this.scene.add(body);
56869
56869
  if (element) {
56870
- this.elements.push(element);
56870
+ // Prevent duplicate entries in elements array (same element instance
56871
+ // or same body UUID). Duplicates can occur from double-renders, HMR,
56872
+ // or race conditions between Importer and ensure* methods.
56873
+ const alreadyExists = this.elements.some(e => e === element || e.hasBody() && e.getBody().uuid === body.uuid);
56874
+ if (!alreadyExists) {
56875
+ this.elements.push(element);
56876
+ }
56871
56877
  }
56872
56878
  if (addUniverse) {
56873
56879
  Universe$3.set(body.uuid, element);
@@ -56879,9 +56885,20 @@ var Physics$1 = new Physics();let Scene = /*#__PURE__*/function () {
56879
56885
  const camera = this.getCamera();
56880
56886
  // Only include camera in hierarchy if it's serializable (scene camera is not)
56881
56887
  const cameraChildren = camera && camera.isSerializable() ? [camera.getHierarchy(options)] : [];
56888
+
56889
+ // Deduplicate elements by UUID to prevent showing the same element twice
56890
+ // in the hierarchy (can happen from race conditions or double-adds)
56891
+ const seenUUIDs = new Set();
56892
+ const deduplicatedElements = this.elements.filter(e => {
56893
+ if (!e.hasBody()) return false;
56894
+ const uuid = e.getBody().uuid;
56895
+ if (seenUUIDs.has(uuid)) return false;
56896
+ seenUUIDs.add(uuid);
56897
+ return !e.hasParent() && !e.isHelper() && e.isSerializable();
56898
+ });
56882
56899
  return [{
56883
56900
  element: this.toJSON(options.parseJSON),
56884
- children: [...cameraChildren, ...this.elements.filter(e => !e.hasParent() && !e.isHelper() && e.isSerializable()).map(e => e.getHierarchy(options))]
56901
+ children: [...cameraChildren, ...deduplicatedElements.map(e => e.getHierarchy(options))]
56885
56902
  }];
56886
56903
  }
56887
56904
  }, {
@@ -58162,7 +58179,7 @@ function applyMiddleware() {
58162
58179
 
58163
58180
  var thunk = createThunkMiddleware();
58164
58181
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
58165
- var version$1 = "3.24.5";
58182
+ var version$1 = "3.24.7";
58166
58183
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
58167
58184
  var main = "dist/mage.js";
58168
58185
  var author$1 = {
@@ -63367,6 +63384,19 @@ let Sprite = /*#__PURE__*/function (_Element) {
63367
63384
  key: "toJSON",
63368
63385
  value: function toJSON(parseJSON = false) {
63369
63386
  if (this.isSerializable()) {
63387
+ // Sync position from holder before serializing to ensure the
63388
+ // serialized position matches the holder (which the user drags).
63389
+ // Without this, the camera body can lag the holder by one frame.
63390
+ if (this.hasHolder()) {
63391
+ const holderBody = this.holder.getBody();
63392
+ this.setPosition({
63393
+ x: holderBody.position.x,
63394
+ y: holderBody.position.y,
63395
+ z: holderBody.position.z
63396
+ }, {
63397
+ updateHolder: false
63398
+ });
63399
+ }
63370
63400
  return {
63371
63401
  ..._superPropGet(Camera, "toJSON", this, 3)([parseJSON]),
63372
63402
  fov: this.getFov(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.24.5",
3
+ "version": "3.24.7",
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": {