Browse Source

added scene.pickSpriteWithRay

David Catuhe 7 years ago
parent
commit
685b8f0f4b
2 changed files with 25 additions and 0 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 24 0
      src/babylon.scene.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -58,6 +58,7 @@
 
 ### Core Engine
 
+- Added `scene.pickSpriteWithRay` function ([Deltakosh](https://github.com/deltakosh))
 - Added support for muyltiple clip planes. [Demo](https://www.babylonjs-playground.com/#Y6W087) ([Deltakosh](https://github.com/deltakosh))
 - Added new `MixMaterial` to the Materials Library allowing to mix up to 8 textures ([julien-moreau](https://github.com/julien-moreau))
 - Added new `BoundingInfo.scale()` function to let users control the size of the bounding info ([Deltakosh](https://github.com/deltakosh))

+ 24 - 0
src/babylon.scene.ts

@@ -5409,6 +5409,30 @@
 
         private _cachedRayForTransform: Ray;
 
+        /** Use the given ray to pick a sprite in the scene
+         * @param ray The ray (in world space) to use to pick meshes
+         * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true
+         * @param fastCheck Launch a fast check only using the bounding boxes. Can be set to null.
+         * @param camera camera to use. Can be set to null. In this case, the scene.activeCamera will be used
+         * @returns a PickingInfo
+         */
+        public pickSpriteWithRay(ray: Ray, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean, camera?: Camera): Nullable<PickingInfo> {
+            if (!this._cachedRayForTransform) {
+                this._cachedRayForTransform = Ray.Zero();
+            }
+
+            if (!camera) {
+                if (!this.activeCamera) {
+                    return null;
+                }
+                camera = this.activeCamera;
+            }
+
+            Ray.TransformToRef(ray, camera.getViewMatrix(), this._cachedRayForTransform);
+
+            return this._internalPickSprites(this._cachedRayForTransform, predicate, fastCheck, camera);
+        }       
+
         /** Use the given ray to pick a mesh in the scene
          * @param ray The ray to use to pick meshes
          * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true