Jelajahi Sumber

Adding initial button change

rickfromwork 4 tahun lalu
induk
melakukan
43ca2ad933
2 mengubah file dengan 57 tambahan dan 0 penghapusan
  1. 1 0
      gui/src/3D/controls/index.ts
  2. 56 0
      gui/src/3D/controls/touchMeshButton3D.ts

+ 1 - 0
gui/src/3D/controls/index.ts

@@ -9,4 +9,5 @@ export * from "./planePanel";
 export * from "./scatterPanel";
 export * from "./spherePanel";
 export * from "./stackPanel3D";
+export * from "./touchMeshButton3D";
 export * from "./volumeBasedPanel";

+ 56 - 0
gui/src/3D/controls/touchMeshButton3D.ts

@@ -0,0 +1,56 @@
+import { TransformNode } from "babylonjs/Meshes/transformNode";
+import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
+import { Mesh } from "babylonjs/Meshes/mesh";
+import { Scene } from "babylonjs/scene";
+
+import { MeshButton3D } from "./meshButton3D";
+
+/**
+ * Class used to create an interactable object. It's a 3D button using a mesh coming from the current scene
+ */
+export class TouchMeshButton3D extends MeshButton3D {
+    /** @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(mesh, name);
+        this._currentMesh = mesh;
+    }
+
+    protected _getTypeName(): string {
+        return "TouchMeshButton3D";
+    }
+
+    // Mesh association
+    protected _createNode(scene: Scene): TransformNode {
+        this._currentMesh.getChildMeshes().forEach((mesh) => {
+            mesh.metadata = this;
+        });
+
+// this._currentMesh is the collidable mesh
+// this._currentMesh.forward() returns the forward vector
+        var _this = this;
+        scene.registerBeforeRender(function () {
+            //Check for collision with haaaaand
+            const thumbTipMeshes = scene.getMeshesByTags("indexTip");
+            thumbTipMeshes.forEach(function (thumbMesh: Mesh) {
+                const distance = _this._currentMesh.getAbsolutePosition().subtract(thumbMesh.getAbsolutePosition()).length();
+
+                if (distance < 1)
+                {
+                    _this._onPointerEnter(_this);// call Control3D._processObservables instead?
+                }
+            });
+        });
+
+        return this._currentMesh;
+    }
+
+    protected _affectMaterial(mesh: AbstractMesh) {
+    }
+}