Browse Source

Canvas2D: Bug fixing time!

Actual ZDepth is more accurate
Intersection enabled on Sprite2D and Text2D (hit on the whole surface)
NeedPrepare bug fixed...
nockawa 9 years ago
parent
commit
d98122321a

+ 7 - 25
src/Canvas2d/babylon.canvas2d.ts

@@ -123,17 +123,15 @@
             }
             this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", k => new Canvas2DEngineBoundData());
             this._cachingStrategy = cachingstrategy;
-            this._depthLevel = 0;
-            this._hierarchyMaxDepth = 100;
-            this._hierarchyLevelZFactor = 1 / this._hierarchyMaxDepth;
-            this._hierarchyLevelMaxSiblingCount = 1000;
-            this._hierarchySiblingZDelta = this._hierarchyLevelZFactor / this._hierarchyLevelMaxSiblingCount;
             this._primPointerInfo = new PrimitivePointerInfo();
             this._capturedPointers = new StringDictionary<Prim2DBase>();
             this._pickStartingPosition = Vector2.Zero();
 
             this.setupGroup2D(this, null, name, Vector2.Zero(), size, this._cachingStrategy===Canvas2D.CACHESTRATEGY_ALLGROUPS ? Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE : Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY);
 
+            this._hierarchyLevelMaxSiblingCount = 100;
+            this._hierarchyDepthOffset = 0;
+            this._siblingDepthOffset = 1 / this._hierarchyLevelMaxSiblingCount;
             this._scene = scene;
             this._engine = engine;
             this._renderingSize = new Size(0, 0);
@@ -168,6 +166,10 @@
             this._setupInteraction(enableInteraction);
         }
 
+        public get hierarchyLevelMaxSiblingCount(): number {
+            return this._hierarchyLevelMaxSiblingCount;
+        }
+
         private _setupInteraction(enable: boolean) {
             // No change detection
             if (enable === this._interactionEnabled) {
@@ -740,23 +742,6 @@
             }
         }
 
-        /**
-         * Read-only property that return the Z delta to apply for each sibling primitives inside of a given one.
-         * Sibling Primitives are defined in a specific order, the first ones will be draw below the next ones.
-         * This property define the Z value to apply between each sibling Primitive. Current implementation allows 1000 Siblings Primitives per level.
-         * @returns The Z Delta
-         */
-        public get hierarchySiblingZDelta(): number {
-            return this._hierarchySiblingZDelta;
-        }
-
-        /**
-         * Return the Z Factor that will be applied for each new hierarchy level.
-         * @returns The Z Factor
-         */
-        public get hierarchyLevelZFactor(): number {
-            return this._hierarchyLevelZFactor;
-        }
 
         private __engineData: Canvas2DEngineBoundData;
         private _interactionEnabled: boolean;
@@ -782,10 +767,7 @@
         private _isScreeSpace: boolean;
         private _cachedCanvasGroup: Group2D;
         private _cachingStrategy: number;
-        private _hierarchyMaxDepth: number;
-        private _hierarchyLevelZFactor: number;
         private _hierarchyLevelMaxSiblingCount: number;
-        private _hierarchySiblingZDelta: number;
         private _groupCacheMaps: MapTexture[];
         private _beforeRenderObserver: Observer<Scene>;
         private _afterRenderObserver: Observer<Scene>;

+ 6 - 9
src/Canvas2d/babylon.prim2dBase.ts

@@ -709,11 +709,9 @@
         }
 
         private addChild(child: Prim2DBase) {
-            child._siblingDepthOffset = (this._children.length + 1) * this.owner.hierarchySiblingZDelta;
-            child._depthLevel = this._depthLevel + 1;
-            child._hierarchyDepthOffset = child._depthLevel * this.owner.hierarchyLevelZFactor;
+            child._hierarchyDepthOffset = this._hierarchyDepthOffset + ((this._children.length + 1) * this._siblingDepthOffset);
+            child._siblingDepthOffset = this._siblingDepthOffset / this.owner.hierarchyLevelMaxSiblingCount;
             this._children.push(child);
-
         }
 
         public dispose(): boolean {
@@ -746,7 +744,7 @@
         }
 
         public getActualZOffset(): number {
-            return this._zOrder || 1 - (this._siblingDepthOffset + this._hierarchyDepthOffset);
+            return this._zOrder || (1 - this._hierarchyDepthOffset);
         }
 
         protected onPrimBecomesDirty() {
@@ -756,7 +754,7 @@
         }
 
         public _needPrepare(): boolean {
-            return this._visibilityChanged && (this._modelDirty || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep));
+            return this._visibilityChanged || this._modelDirty || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
         }
 
         public _prepareRender(context: Render2DContext) {
@@ -875,9 +873,8 @@
         protected _children: Array<Prim2DBase>;
         private _renderGroup: Group2D;
         private _hierarchyDepth: number;
-        protected _depthLevel: number;
-        private _hierarchyDepthOffset: number;
-        private _siblingDepthOffset: number;
+        protected _hierarchyDepthOffset: number;
+        protected _siblingDepthOffset: number;
         private _zOrder: number;
         private _levelVisible: boolean;
         public _pointerEventObservable: Observable<PrimitivePointerInfo>;

+ 5 - 0
src/Canvas2d/babylon.sprite2d.ts

@@ -174,6 +174,11 @@
             return res;
         }
 
+        protected levelIntersect(intersectInfo: IntersectInfo2D): boolean {
+            // If we've made it so far it means the boundingInfo intersection test succeed, the Sprite2D is shaped the same, so we always return true
+            return true;
+        }
+
         protected setupSprite2D(owner: Canvas2D, parent: Prim2DBase, id: string, position: Vector2, texture: Texture, spriteSize: Size, spriteLocation: Vector2, invertY: boolean) {
             this.setupRenderablePrim2D(owner, parent, id, position, true);
             this.texture = texture;

+ 5 - 0
src/Canvas2d/babylon.text2d.ts

@@ -237,6 +237,11 @@
             return text2d;
         }
 
+        protected levelIntersect(intersectInfo: IntersectInfo2D): boolean {
+            // For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
+            return true;
+        }
+
         protected createModelRenderCache(modelKey: string, isTransparent: boolean): ModelRenderCache {
             let renderCache = new Text2DRenderCache(this.owner.engine, modelKey, isTransparent);
             return renderCache;