Bladeren bron

Don't overwrite the metadata entry for GUI3D usage

Popov72 4 jaren geleden
bovenliggende
commit
cbeeb44640
3 gewijzigde bestanden met toevoegingen van 10 en 4 verwijderingen
  1. 7 1
      gui/src/3D/controls/control3D.ts
  2. 1 1
      gui/src/3D/controls/meshButton3D.ts
  3. 2 2
      gui/src/3D/gui3DManager.ts

+ 7 - 1
gui/src/3D/controls/control3D.ts

@@ -259,7 +259,7 @@ export class Control3D implements IDisposable, IBehaviorAware<Control3D> {
             if (!this.node) {
                 return;
             }
-            this._node!.metadata = this; // Store the control on the metadata field in order to get it when picking
+            this._injectGUI3DMetadata(this._node!).control = this; // Store the control on the metadata field in order to get it when picking
             this._node!.position = this.position;
             this._node!.scaling = this.scaling;
 
@@ -272,6 +272,12 @@ export class Control3D implements IDisposable, IBehaviorAware<Control3D> {
         }
     }
 
+    protected _injectGUI3DMetadata(node: TransformNode): any {
+        node.metadata = node.metadata ?? {};
+        node.metadata.GUI3D = node.metadata.GUI3D ?? {};
+        return node.metadata.GUI3D;
+    }
+
     /**
      * Node creation.
      * Can be overriden by children

+ 1 - 1
gui/src/3D/controls/meshButton3D.ts

@@ -61,7 +61,7 @@ export class MeshButton3D extends Button3D {
     // Mesh association
     protected _createNode(scene: Scene): TransformNode {
         this._currentMesh.getChildMeshes().forEach((mesh) => {
-            mesh.metadata = this;
+            this._injectGUI3DMetadata(mesh).control = this;
         });
         return this._currentMesh;
     }

+ 2 - 2
gui/src/3D/gui3DManager.ts

@@ -65,7 +65,7 @@ export class GUI3DManager implements IDisposable {
         this._utilityLayer.onlyCheckPointerDownEvents = false;
         this._utilityLayer.pickUtilitySceneFirst = false;
         this._utilityLayer.mainSceneTrackerPredicate = (mesh: Nullable<AbstractMesh>) => {
-            return mesh && mesh.metadata && mesh.metadata._node;
+            return mesh && mesh.metadata?.GUI3D?.control?._node;
         };
 
         // Root
@@ -121,7 +121,7 @@ export class GUI3DManager implements IDisposable {
             return false;
         }
 
-        let control = <Control3D>(pickingInfo.pickedMesh!.metadata);
+        let control = <Control3D>(pickingInfo.pickedMesh!.metadata?.GUI3D?.control);
         if (pickingInfo.pickedPoint) {
             this.onPickedPointChangedObservable.notifyObservers(pickingInfo.pickedPoint);
         }