Kaynağa Gözat

GUI getMeshPosition()

Returns the position of a mesh for use in AdvancedDynamicTexture as a 2d point - use only x and y of the returned vector?
Royi Bernthal 8 yıl önce
ebeveyn
işleme
04f74cb35d
1 değiştirilmiş dosya ile 16 ekleme ve 0 silme
  1. 16 0
      gui/src/advancedDynamicTexture.ts

+ 16 - 0
gui/src/advancedDynamicTexture.ts

@@ -512,6 +512,22 @@ module BABYLON.GUI {
             this._attachToOnPointerOut(scene);
         }
 
+        public getMeshPosition(mesh: BABYLON.Mesh): BABYLON.Vector3 {
+            var scene = this.getScene();
+
+            if (!scene) {
+                return BABYLON.Vector3.Zero();
+            }
+
+            var globalViewport = this._getGlobalViewport(scene);
+            var position = mesh.getBoundingInfo().boundingSphere.center;
+            var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
+
+            projectedPosition.scaleInPlace(this.renderScale);
+            
+            return projectedPosition;
+        }
+
         public moveFocusToControl(control: IFocusableControl): void {
             this.focusedControl = control;
             this._lastPickedControl = <any>control;