瀏覽代碼

Merge pull request #7885 from Ludevik/master

Fix `TexturePacker` cross origin, fix default values
David Catuhe 5 年之前
父節點
當前提交
227ec77c61
共有 2 個文件被更改,包括 16 次插入13 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 15 13
      src/Materials/Textures/Packer/packer.ts

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

@@ -93,5 +93,6 @@
 - Fix bug in PBR with translucency when irradiance texture is 2D ([Popov72](https://github.com/Popov72)
 - Fix bug in PBR when specific combinations of parameters are used ([Popov72](https://github.com/Popov72)
 - Fix texture being inverted on the Y axis by default when using TextureAsset or AssetManager ([broederj](https://github.com/broederj))
+- Fix `TexturePacker` cross-origin image requests, fix falsy default options ([ludevik](https://github.com/ludevik))
 
 ## Breaking changes

+ 15 - 13
src/Materials/Textures/Packer/packer.ts

@@ -10,6 +10,7 @@ import { Vector2 } from "../../../Maths/math.vector";
 import { Color3, Color4 } from "../../../Maths/math.color";
 import { TexturePackerFrame } from "./frame";
 import { Logger } from "../../../Misc/logger";
+import { Tools } from '../../../Misc/tools';
 
 /**
 * Defines the basic options interface of a TexturePacker
@@ -175,7 +176,7 @@ export class TexturePacker{
          * Run through the options and set what ever defaults are needed that where not declared.
          */
         this.options = options;
-        this.options.map = this.options.map || [
+        this.options.map = this.options.map ?? [
                 'ambientTexture',
                 'bumpTexture',
                 'diffuseTexture',
@@ -187,26 +188,26 @@ export class TexturePacker{
                 'specularTexture'
             ];
 
-        this.options.uvsIn = this.options.uvsIn || VertexBuffer.UVKind;
-        this.options.uvsOut = this.options.uvsOut || VertexBuffer.UVKind;
-        this.options.layout = this.options.layout || TexturePacker.LAYOUT_STRIP;
+        this.options.uvsIn = this.options.uvsIn ?? VertexBuffer.UVKind;
+        this.options.uvsOut = this.options.uvsOut ?? VertexBuffer.UVKind;
+        this.options.layout = this.options.layout ?? TexturePacker.LAYOUT_STRIP;
 
         if (this.options.layout === TexturePacker.LAYOUT_COLNUM) {
-            this.options.colnum = this.options.colnum || 8;
+            this.options.colnum = this.options.colnum ?? 8;
         }
 
-        this.options.updateInputMeshes = this.options.updateInputMeshes || true;
-        this.options.disposeSources = this.options.disposeSources || true;
+        this.options.updateInputMeshes = this.options.updateInputMeshes ?? true;
+        this.options.disposeSources = this.options.disposeSources ?? true;
         this._expecting = 0;
 
-        this.options.fillBlanks = this.options.fillBlanks || true;
+        this.options.fillBlanks = this.options.fillBlanks ?? true;
 
         if (this.options.fillBlanks === true) {
-            this.options.customFillColor = this.options.customFillColor || 'black';
+            this.options.customFillColor = this.options.customFillColor ?? 'black';
         }
 
-        this.options.frameSize = this.options.frameSize || 256;
-        this.options.paddingRatio = this.options.paddingRatio || 0.0115;
+        this.options.frameSize = this.options.frameSize ?? 256;
+        this.options.paddingRatio = this.options.paddingRatio ?? 0.0115;
 
         this._paddingValue = Math.ceil(this.options.frameSize * this.options.paddingRatio);
 
@@ -215,10 +216,10 @@ export class TexturePacker{
             this._paddingValue++;
         }
 
-        this.options.paddingMode = this.options.paddingMode || TexturePacker.SUBUV_WRAP;
+        this.options.paddingMode = this.options.paddingMode ?? TexturePacker.SUBUV_WRAP;
 
         if (this.options.paddingMode === TexturePacker.SUBUV_COLOR) {
-            this.options.paddingColor = this.options.paddingColor || new Color4(0, 0, 0, 1.0);
+            this.options.paddingColor = this.options.paddingColor ?? new Color4(0, 0, 0, 1.0);
         }
 
         this.sets = {};
@@ -322,6 +323,7 @@ export class TexturePacker{
                     } else {
                         img.src = setTexture!.url;
                     }
+                    Tools.SetCorsBehavior(img.src, img);
 
                     img.onload = () => {
                         tcx.fillStyle = 'rgba(0,0,0,0)';