Pārlūkot izejas kodu

First MeshButton3D

David Rousset 7 gadi atpakaļ
vecāks
revīzija
604d9b23e0
2 mainītis faili ar 74 papildinājumiem un 0 dzēšanām
  1. 1 0
      Tools/Gulp/config.json
  2. 73 0
      gui/src/3D/controls/meshButton3D.ts

+ 1 - 0
Tools/Gulp/config.json

@@ -1750,6 +1750,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",

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

@@ -0,0 +1,73 @@
+/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
+
+module BABYLON.GUI {
+    /**
+     * Class used to create a button in 3D
+     */
+    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; 
+
+            this.pointerEnterAnimation = () => {
+                if (!this.mesh) {
+                    return;
+                }
+                //this.mesh.scaling.scaleInPlace(0.95);
+            }
+
+            this.pointerOutAnimation = () => {
+                
+            }    
+
+            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) {
+        }
+
+        /**
+         * Releases all associated resources
+         */
+        public dispose() {
+            super.dispose();
+
+            if (this._currentMesh) {
+                this._currentMesh.dispose();
+            }
+        }
+    }
+}