فهرست منبع

Canvas2d: Intersection/Interaction are now working in Cached Canvas/Group.

nockawa 9 سال پیش
والد
کامیت
8742bcc615

+ 1 - 16
src/Canvas2d/babylon.canvas2d.ts

@@ -510,22 +510,7 @@
                 return;
             }
 
-            // Special case __cachedCanvasSprite__ (WIP)
-            if (this.id.indexOf("__cachedCanvasSprite__") === 0) {
-                
-            }
-
-
-            // Special case __cachedSpriteOfGroup__
-            else if (this.id.indexOf("__cachedSpriteOfGroup__") === 0) {
-                let ownerGroup = this.getExternalData<Group2D>("__cachedGroup__");
-                ownerGroup.intersect(ii);
-            }
-
-            // Common case
-            else {
-                this.intersect(ii);
-            }
+            this.intersect(ii);
 
             this._previousIntersectionList = this._actualIntersectionList;
             this._actualIntersectionList = ii.intersectedPrimitives;

+ 1 - 1
src/Canvas2d/babylon.group2d.ts

@@ -119,7 +119,7 @@
         }
 
         static _createCachedCanvasGroup(owner: Canvas2D): Group2D {
-            var g = new Group2D({ parent: owner, id: "__cachedCanvasGroup__", position: Vector2.Zero(), origin: Vector2.Zero(), size: null, isVisible: true });
+            var g = new Group2D({ parent: owner, id: "__cachedCanvasGroup__", position: Vector2.Zero(), origin: Vector2.Zero(), size: null, isVisible: true, isPickable: false });
             return g;
 
         }

+ 12 - 0
src/Canvas2d/babylon.prim2dBase.ts

@@ -2417,6 +2417,18 @@
                 return ownerGroup.intersect(intersectInfo);
             }
 
+            // If we're testing a cachedGroup, we must reject pointer outside its levelBoundingInfo because children primitives could be partially clipped outside so we must not accept them as intersected when it's the case (because they're not visually visible).
+            let isIntersectionTest = false;
+            if (this instanceof Group2D) {
+                let g = <Group2D><any>this;
+                isIntersectionTest = g.isCachedGroup;
+            }
+            if (isIntersectionTest && !this.levelBoundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
+                // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
+                intersectInfo._exit(firstLevel);
+                return false;
+            }
+
             // Fast rejection test with boundingInfo
             if (this.isPickable && !this.boundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
                 // Important to call this before each return to allow a good recursion next time this intersectInfo is reused

+ 1 - 1
src/Canvas2d/babylon.renderablePrim2d.ts

@@ -434,7 +434,7 @@
                     usedCount += td._partData.usedElementCount;
                 }
 
-                if (usedCount === 0) {
+                if (usedCount === 0 && gii.modelRenderCache!=null) {
                     this.renderGroup._renderableData._renderGroupInstancesInfo.remove(gii.modelRenderCache.modelKey);
                     gii.dispose();
                 }