Parcourir la source

Fix WorldSpaceCanvas with custom Node

nockawa il y a 9 ans
Parent
commit
3d132d833c
2 fichiers modifiés avec 12 ajouts et 15 suppressions
  1. 1 7
      src/Canvas2d/babylon.canvas2d.ts
  2. 11 8
      src/Canvas2d/babylon.group2d.ts

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

@@ -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;
         }
     }
 

+ 11 - 8
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();
         }