Explorar o código

Move interfaces to lambda only

sebastien %!s(int64=7) %!d(string=hai) anos
pai
achega
5cfb5d1d61

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

@@ -233,3 +233,4 @@
 
 - Fixing support for R and RG texture formats made us remove TextureFormat_R32F and TextureFormat_RG32F as they were mixing formats and types. Please, use the respective TextureFormat_R and TextureFormat_RG with the Float types ([sebavan](http://www.github.com/sebavan))
 - Replacing `scene.onRenderingGroupObservable` by `onBeforeRenderingGroupObservable` and `onAfterRenderingGroupObservable` to prevent the stage check ([sebavan](http://www.github.com/sebavan))
+- Replacing `IActiveMeshCandidateProvider` and the according scene setter by a set of custom predicates `scene.getActiveMeshCandidates`, `scene.getActiveSubMeshCandidates`, `scene.getIntersectingSubMeshCandidates` and `scene.getCollidingSubMeshCandidates` ([sebavan](http://www.github.com/sebavan)). This helps opening more customization to everybody.

+ 15 - 9
src/Culling/Octrees/babylon.octreeSceneComponent.ts

@@ -104,7 +104,7 @@
      * Defines the octree scene component responsible to manage any octrees
      * in a given scene.
      */
-    export class OctreeSceneComponent implements ISceneComponent, IActiveMeshCandidateProvider {
+    export class OctreeSceneComponent {
         /**
          * The component name helpfull to identify the component in the list of scene components.
          */
@@ -127,7 +127,11 @@
         constructor(scene: Scene) {
             this.scene = scene;
 
-            this.scene.setActiveMeshCandidateProvider(this);
+            this.scene.getActiveMeshCandidates = this.getActiveMeshCandidates.bind(this);
+
+            this.scene.getActiveSubMeshCandidates = this.getActiveSubMeshCandidates.bind(this);
+            this.scene.getCollidingSubMeshCandidates = this.getCollidingSubMeshCandidates.bind(this);
+            this.scene.getIntersectingSubMeshCandidates = this.getIntersectingSubMeshCandidates.bind(this);
         }
 
         /**
@@ -155,12 +159,14 @@
 
         /**
          * Return the list of active meshes
-         * @param scene defines the current scene
          * @returns the list of active meshes
          */
-        public getMeshes(scene: Scene): ISmartArrayLike<AbstractMesh> {
-            var selection = scene._selectionOctree.select(scene.frustumPlanes);
-            return selection;
+        public getActiveMeshCandidates(): ISmartArrayLike<AbstractMesh> {
+            if (this.scene._selectionOctree) {
+                var selection = this.scene._selectionOctree.select(this.scene.frustumPlanes);
+                return selection;
+            }
+            return this.scene._getDefaultMeshCandidates();
         }
 
         /**
@@ -168,7 +174,7 @@
          * @param scene defines the current scene
          * @returns the list of active sub meshes
          */
-        public getSubMeshes(mesh: AbstractMesh): ISmartArrayLike<SubMesh> {
+        public getActiveSubMeshCandidates(mesh: AbstractMesh): ISmartArrayLike<SubMesh> {
             if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
                 var intersections = mesh._submeshesOctree.select(this.scene.frustumPlanes);
                 return intersections;
@@ -183,7 +189,7 @@
          * @param localRay defines the ray in local space
          * @returns the list of intersecting sub meshes
          */
-        public getActiveCanditates(mesh: AbstractMesh, localRay: Ray): ISmartArrayLike<SubMesh> {
+        public getIntersectingSubMeshCandidates(mesh: AbstractMesh, localRay: Ray): ISmartArrayLike<SubMesh> {
             if (mesh._submeshesOctree && mesh.useOctreeForPicking) {
                 Ray.TransformToRef(localRay, mesh.getWorldMatrix(), this._tempRay);
                 var intersections = mesh._submeshesOctree.intersectsRay(this._tempRay);
@@ -199,7 +205,7 @@
          * @param collider defines the collider to evaluate the collision against
          * @returns the list of colliding sub meshes
          */
-        public getCollidingCandidates(mesh: AbstractMesh, collider: Collider): ISmartArrayLike<SubMesh> {
+        public getCollidingSubMeshCandidates(mesh: AbstractMesh, collider: Collider): ISmartArrayLike<SubMesh> {
             if (mesh._submeshesOctree && mesh.useOctreeForCollisions) {
                 var radius = collider._velocityWorldLength + Math.max(collider._radius.x, collider._radius.y, collider._radius.z);
                 var intersections = mesh._submeshesOctree.intersects(collider._basePointWorld, radius);

+ 2 - 2
src/Mesh/babylon.abstractMesh.ts

@@ -1336,7 +1336,7 @@
 
         /** @hidden */
         public _processCollisionsForSubMeshes(collider: Collider, transformMatrix: Matrix): AbstractMesh {
-            const subMeshes = this._scene.getSubMeshCandidateProvider().getCollidingCandidates(this, collider);
+            const subMeshes = this._scene.getCollidingSubMeshCandidates(this, collider);
             const len = subMeshes.length;
 
             for (var index = 0; index < len; index++) {
@@ -1390,7 +1390,7 @@
 
             var intersectInfo: Nullable<IntersectionInfo> = null;
 
-            var subMeshes = this._scene.getSubMeshCandidateProvider().getIntersectingCandidates(this, ray);
+            var subMeshes = this._scene.getIntersectingSubMeshCandidates(this, ray);
             var len: number = subMeshes.length;
             for (var index = 0; index < len; index++) {
                 var subMesh = subMeshes.data[index];

+ 1 - 1
src/Tools/babylon.smartArray.ts

@@ -126,7 +126,7 @@
          * @returns true if found in the active data otherwise false
          */
         public contains(value: T): boolean {
-            return this.data.indexOf(value) !== -1;
+            return this.indexOf(value) !== -1;
         }
 
         // Statics

+ 41 - 87
src/babylon.scene.ts

@@ -9,49 +9,6 @@
         dispose(): void;
     }
 
-    /**
-     * Interface used to let developers provide their own mesh selection mechanism
-     */
-    export interface IActiveMeshCandidateProvider {
-        /**
-         * Return the list of active meshes
-         * @param scene defines the current scene
-         * @returns the list of active meshes
-         */
-        getMeshes(scene: Scene): ISmartArrayLike<AbstractMesh>;
-
-        /** 
-         * Indicates if the meshes have been checked to make sure they are isEnabled()
-         */
-        readonly checksIsEnabled: boolean;
-    }
-
-    /**
-     * Interface used to let developers provide their own sub mesh selection mechanism
-     */
-    export interface ISubMeshCandidateProvider {
-        /**
-         * Return the list of active sub meshes
-         * @param mesh defines the mesh to find the submesh for
-         * @returns the list of active sub meshes
-         */
-        getActiveCanditates(mesh: AbstractMesh): ISmartArrayLike<SubMesh>;
-        /**
-         * Return the list of sub meshes intersecting with a given local ray
-         * @param mesh defines the mesh to find the submesh for
-         * @param localRay defines the ray in local space
-         * @returns the list of intersecting sub meshes
-         */
-        getIntersectingCandidates(mesh: AbstractMesh, localRay: Ray): ISmartArrayLike<SubMesh>;
-        /**
-         * Return the list of sub meshes colliding with a collider
-         * @param mesh defines the mesh to find the submesh for
-         * @param collider defines the collider to evaluate the collision against
-         * @returns the list of colliding sub meshes
-         */
-        getCollidingCandidates(mesh: AbstractMesh, collider: Collider): ISmartArrayLike<SubMesh>;
-    }
-
     /** @hidden */
     class ClickInfo {
         private _singleClick = false;
@@ -1251,7 +1208,7 @@
                 this._imageProcessingConfiguration = new ImageProcessingConfiguration();
             }
 
-            this._setDefaultCandidateProviders();
+            this.setDefaultCandidateProviders();
         }
 
         private _defaultMeshCandidates: ISmartArrayLike<AbstractMesh> = {
@@ -1283,19 +1240,16 @@
         }
 
         /**
-         * Sets the default candidate provider for the scene.
+         * Sets the default candidate providers for the scene.
+         * This sets the getActiveMeshCandidates, getActiveSubMeshCandidates, getIntersectingSubMeshCandidates
+         * and getCollidingSubMeshCandidates to their default function
          */
-        private _setDefaultCandidateProviders() {
-            this.setActiveMeshCandidateProvider({
-                getMeshes: this._getDefaultMeshCandidates.bind(this),
-                checksIsEnabled: true
-            });
+        public setDefaultCandidateProviders(): void {
+            this.getActiveMeshCandidates = this._getDefaultMeshCandidates.bind(this);
 
-            this.setSubMeshCandidateProvider({
-                getActiveCanditates: this._getDefaultSubMeshCandidates.bind(this),
-                getIntersectingCandidates: this._getDefaultSubMeshCandidates.bind(this),
-                getCollidingCandidates: this._getDefaultSubMeshCandidates.bind(this),
-            });
+            this.getActiveSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);
+            this.getIntersectingSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);
+            this.getCollidingSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);
         }
 
         /**
@@ -1631,6 +1585,16 @@
             var isMeshPicked = (pickResult && pickResult.hit && pickResult.pickedMesh) ? true : false;
             if (isMeshPicked) {
                 this.setPointerOverMesh(pickResult!.pickedMesh);
+
+                if (this._pointerOverMesh && this._pointerOverMesh.actionManager && this._pointerOverMesh.actionManager.hasPointerTriggers) {
+                    if (this._pointerOverMesh.actionManager.hoverCursor) {
+                        canvas.style.cursor = this._pointerOverMesh.actionManager.hoverCursor;
+                    } else {
+                        canvas.style.cursor = this.hoverCursor;
+                    }
+                } else {
+                    canvas.style.cursor = this.defaultCursor;
+                }
             } else {
                 this.setPointerOverMesh(null);
             }
@@ -4069,44 +4033,34 @@
             return this._intermediateRendering
         }
 
-        private _activeMeshCandidateProvider: IActiveMeshCandidateProvider;
-        private _activeMeshCandidateCheckIsReady: boolean = true;
-
         /**
-         * Defines the current active mesh candidate provider
-         * Please note that in case of octree, the activeMeshCandidateProvider will be the octree one
-         * @param provider defines the provider to use
+         * Return the list of potentially active meshes.
+         * @returns the list of active meshes candidates
          */
-        public setActiveMeshCandidateProvider(provider: IActiveMeshCandidateProvider): void {
-            this._activeMeshCandidateProvider = provider;
-            this._activeMeshCandidateCheckIsReady = provider.checksIsEnabled;
-        }
+        public getActiveMeshCandidates: () => ISmartArrayLike<AbstractMesh>;
+
         /**
-         * Gets the current active mesh candidate provider
-         * Please note that in case of octree, the activeMeshCandidateProvider will be the octree one
-         * @returns the current active mesh candidate provider
+         * Return the list of potentially active sub meshes.
+         * @param mesh The mesh to get the candidates sub meshes from
+         * @returns the list of active sub meshes candidates
          */
-        public getActiveMeshCandidateProvider(): IActiveMeshCandidateProvider {
-            return this._activeMeshCandidateProvider;
-        }
+        public getActiveSubMeshCandidates: (mesh: AbstractMesh) => ISmartArrayLike<SubMesh>;
 
-        private _subMeshCandidateProvider: ISubMeshCandidateProvider;
         /**
-         * Defines the current sub mesh candidate provider
-         * Please note that in case of octree, the subMeshCandidateProvider will be the octree one
-         * @param provider defines the provider to use
+         * Return the list of potentially intersecting sub meshes.
+         * @param mesh The mesh to get the candidates sub meshes from
+         * @param localRay defines the ray in local space
+         * @returns the list of intersecting sub meshes candidates
          */
-        public setSubMeshCandidateProvider(provider: ISubMeshCandidateProvider): void {
-            this._subMeshCandidateProvider = provider;
-        }
+        public getIntersectingSubMeshCandidates: (mesh: AbstractMesh, localRay: Ray) => ISmartArrayLike<SubMesh>;
+
         /**
-         * Gets the current sub mesh candidate provider
-         * Please note that in case of octree, the subMeshCandidateProvider will be the octree one
-         * @returns the current provider
+         * Return the list of potentially colliding sub meshes.
+         * @param mesh The mesh to get the candidates sub meshes from
+         * @param collider defines the collider to evaluate the collision against
+         * @returns the list of colliding sub meshes candidates
          */
-        public getSubMeshCandidateProvider(): ISubMeshCandidateProvider {
-            return this._subMeshCandidateProvider;
-        }
+        public getCollidingSubMeshCandidates: (mesh: AbstractMesh, collider: Collider) => ISmartArrayLike<SubMesh>;
 
         private _activeMeshesFrozen = false;
 
@@ -4160,7 +4114,7 @@
             }
 
             // Determine mesh candidates
-            const meshes = this._activeMeshCandidateProvider.getMeshes(this);
+            const meshes = this.getActiveMeshCandidates();
             
             // Check each mesh
             const len = meshes.length;
@@ -4172,7 +4126,7 @@
 
                 this._totalVertices.addCount(mesh.getTotalVertices(), false);
 
-                if (!mesh.isReady() || (this._activeMeshCandidateCheckIsReady && !mesh.isEnabled())) {
+                if (!mesh.isReady() || !mesh.isEnabled()) {
                     continue;
                 }
 
@@ -4246,7 +4200,7 @@
                 mesh !== undefined && mesh !== null
                 && mesh.subMeshes !== undefined && mesh.subMeshes !== null && mesh.subMeshes.length > 0
             ) {
-                const subMeshes = this._subMeshCandidateProvider.getActiveCanditates(mesh);
+                const subMeshes = this.getActiveSubMeshCandidates(mesh);
                 const len = subMeshes.length;
                 for (let i = 0; i < len; i++) {
                     const subMesh = subMeshes.data[i];