Przeglądaj źródła

Merge pull request #4530 from BabylonJS/MRTKdavrous

MRTK davrous
David Catuhe 7 lat temu
rodzic
commit
91090c7e05
2 zmienionych plików z 69 dodań i 0 usunięć
  1. 1 0
      Tools/Gulp/config.json
  2. 68 0
      gui/src/3D/controls/meshButton3D.ts

+ 1 - 0
Tools/Gulp/config.json

@@ -1752,6 +1752,7 @@
                     "../../gui/src/3D/controls/container3D.ts",
                     "../../gui/src/3D/controls/abstractButton3D.ts",
                     "../../gui/src/3D/controls/button3D.ts",
+                    "../../gui/src/3D/controls/meshButton3D.ts",
                     "../../gui/src/3D/controls/holographicButton.ts",
                     "../../gui/src/3D/controls/stackPanel3D.ts",
                     "../../gui/src/3D/controls/volumeBasedPanel.ts",

+ 68 - 0
gui/src/3D/controls/meshButton3D.ts

@@ -0,0 +1,68 @@
+/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
+
+module BABYLON.GUI {
+    /**
+     * Class used to create an interactable object. It's a 3D button using a mesh coming from the current scene
+     */
+    export class MeshButton3D extends Button3D {
+        /** @hidden */
+        protected _currentMesh: Mesh;
+
+        /**
+         * Creates a new 3D button based on a mesh
+         * @param mesh mesh to become a 3D button
+         * @param name defines the control name
+         */
+        constructor(mesh: Mesh, name?: string) {
+            super(name);
+            this._currentMesh = mesh; 
+
+            /**
+             * Provides a default behavior on hover/out & up/down
+             * Override those function to create your own desired behavior specific to your mesh
+             */
+            this.pointerEnterAnimation = () => {
+                if (!this.mesh) {
+                    return;
+                }
+                this.mesh.scaling.scaleInPlace(1.1);
+            }
+
+            this.pointerOutAnimation = () => {
+                if (!this.mesh) {
+                    return;
+                }
+                this.mesh.scaling.scaleInPlace(1.0 / 1.1);
+            }    
+
+            this.pointerDownAnimation = () => {
+                if (!this.mesh) {
+                    return;
+                }
+                this.mesh.scaling.scaleInPlace(0.95);
+            }
+
+            this.pointerUpAnimation = () => {
+                if (!this.mesh) {
+                    return;
+                }
+                this.mesh.scaling.scaleInPlace(1.0 / 0.95);
+            }                     
+        }
+
+        protected _getTypeName(): string {
+            return "MeshButton3D";
+        }        
+
+        // Mesh association
+        protected _createNode(scene: Scene): TransformNode {
+            this._currentMesh.getChildMeshes().forEach((mesh)=>{
+                mesh.metadata = this;
+            });
+            return this._currentMesh;
+        }
+
+        protected _affectMaterial(mesh: AbstractMesh) {
+        }
+    }
+}