Преглед на файлове

Merge pull request #1197 from nockawa/GroupTracker

WorldSpaceCanvas working with custom node
David Catuhe преди 9 години
родител
ревизия
55bcef337c
променени са 2 файла, в които са добавени 19 реда и са изтрити 17 реда
  1. 2 8
      src/Canvas2d/babylon.canvas2d.ts
  2. 17 9
      src/Canvas2d/babylon.group2d.ts

+ 2 - 8
src/Canvas2d/babylon.canvas2d.ts

@@ -104,7 +104,7 @@
             this._primPointerInfo               = new PrimitivePointerInfo();
             this._capturedPointers              = new StringDictionary<Prim2DBase>();
             this._pickStartingPosition          = Vector2.Zero();
-            this._hierarchyLevelMaxSiblingCount = 10;
+            this._hierarchyLevelMaxSiblingCount = 50;
             this._hierarchyDepthOffset          = 0;
             this._siblingDepthOffset            = 1 / this._hierarchyLevelMaxSiblingCount;
             this._scene                         = scene;
@@ -1202,14 +1202,8 @@
             //    throw new Error("CACHESTRATEGY_DONTCACHE cache Strategy can't be used for WorldSpace Canvas");
             //}
 
-            //let enableInteraction = settings ? settings.enableInteraction : true;
             let createWorldSpaceNode = !settings || (settings.customWorldSpaceNode == null);
-            //let isVisible = settings ? settings.isVisible || true : true;
             let id = settings ? settings.id || null : null;
-            //let rsf = settings ? settings.renderScaleFactor || 1 : 1;
-
-            //let c = new Canvas2D();
-            //c.setupCanvas(scene, id, new Size(size.width, size.height), rsf, false, cs, enableInteraction, new Vector2(0.5, 0.5), isVisible, null, null, null, null, null, null);
 
             if (createWorldSpaceNode) {
                 let plane = new WorldSpaceCanvas2DNode(id, scene, this);
@@ -1232,8 +1226,8 @@
                 this._worldSpaceNode = plane;
             } else {
                 this._worldSpaceNode = settings.customWorldSpaceNode;
+                this.applyCachedTexture(null, null);
             }
-            //            return c;
         }
     }
 

+ 17 - 9
src/Canvas2d/babylon.group2d.ts

@@ -98,15 +98,18 @@
         protected applyCachedTexture(vertexData: VertexData, material: StandardMaterial) {
             this._bindCacheTarget();
 
-            var uv = vertexData.uvs;
-            let nodeuv = this._renderableData._cacheNode.UVs;
-            for (let i = 0; i < 4; i++) {
-                uv[i * 2 + 0] = nodeuv[i].x;
-                uv[i * 2 + 1] = nodeuv[i].y;
+            if (vertexData) {
+                var uv = vertexData.uvs;
+                let nodeuv = this._renderableData._cacheNode.UVs;
+                for (let i = 0; i < 4; i++) {
+                    uv[i * 2 + 0] = nodeuv[i].x;
+                    uv[i * 2 + 1] = nodeuv[i].y;
+                }
+            }
+            if (material) {
+                material.diffuseTexture = this._renderableData._cacheTexture;
+                material.emissiveColor = new Color3(1, 1, 1);
             }
-
-            material.diffuseTexture = this._renderableData._cacheTexture;
-            material.emissiveColor = new Color3(1, 1, 1);
             this._renderableData._cacheTexture.hasAlpha = true;
             this._unbindCacheTarget();
         }
@@ -788,7 +791,9 @@
                 let cur = this.parent;
                 while (cur) {
                     if (cur instanceof Group2D && cur._isRenderableGroup) {
-                        cur._renderableData._childrenRenderableGroups.push(this);
+                        if (cur._renderableData._childrenRenderableGroups.indexOf(this) === -1) {
+                            cur._renderableData._childrenRenderableGroups.push(this);
+                        }
                         break;
                     }
                     cur = cur.parent;
@@ -817,6 +822,9 @@
             this._transparentSegments = new Array<TransparentSegment>();
             this._firstChangedPrim = null;
             this._transparentListChanged = false;
+            this._cacheNode = null;
+            this._cacheTexture = null;
+            this._cacheRenderSprite = null;
         }
 
         dispose() {