Переглянути джерело

Merge pull request #7580 from BabylonJS/master

Nightly
mergify[bot] 5 роки тому
батько
коміт
e213e29413

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

@@ -224,6 +224,7 @@
 - Added `_getSVGAttribs` functionality for loading multiple svg icons from an external svg file via icon id. Fixed bug for Chrome. Strip icon id from image url for firefox.([lockphase](https://github.com/lockphase/))
 - Scroll Viewer extended to include the use of images in the scroll bars([JohnK](https://github.com/BabylonJSGuide/))
 - Added `ScrollViewer.freezeControls` property to speed up rendering ([Popov72](https://github.com/Popov72))
+- Added `ImageScrollBar.num90RotationInVerticalMode` property to let the user rotate the pictures when in vertical mode ([Popov72](https://github.com/Popov72))
 
 ### Particles
 

+ 9 - 6
gui/src/2D/controls/sliders/imageScrollBar.ts

@@ -17,6 +17,9 @@ export class ImageScrollBar extends BaseSlider {
     private _barImageHeight: number = 1;
     private _tempMeasure = new Measure(0, 0, 0, 0);
 
+    /** Number of 90° rotation to apply on the images when in vertical mode */
+    public num90RotationInVerticalMode = 1;
+
     /**
      * Gets or sets the image used to render the background for horizontal bar
      */
@@ -31,10 +34,10 @@ export class ImageScrollBar extends BaseSlider {
 
         this._backgroundBaseImage = value;
 
-        if (this.isVertical) {
+        if (this.isVertical && this.num90RotationInVerticalMode !== 0) {
             if (!value.isLoaded) {
                 value.onImageLoadedObservable.addOnce(() => {
-                    const rotatedValue = value._rotate90(1, true);
+                    const rotatedValue = value._rotate90(this.num90RotationInVerticalMode, true);
                     this._backgroundImage = rotatedValue;
                     if (!rotatedValue.isLoaded) {
                         rotatedValue.onImageLoadedObservable.addOnce(() => {
@@ -44,7 +47,7 @@ export class ImageScrollBar extends BaseSlider {
                     this._markAsDirty();
                 });
             } else {
-                this._backgroundImage = value._rotate90(1, true);
+                this._backgroundImage = value._rotate90(this.num90RotationInVerticalMode, true);
                 this._markAsDirty();
             }
         }
@@ -74,10 +77,10 @@ export class ImageScrollBar extends BaseSlider {
 
         this._thumbBaseImage = value;
 
-        if (this.isVertical) {
+        if (this.isVertical && this.num90RotationInVerticalMode !== 0) {
             if (!value.isLoaded) {
                 value.onImageLoadedObservable.addOnce(() => {
-                    var rotatedValue = value._rotate90(-1, true);
+                    var rotatedValue = value._rotate90(-this.num90RotationInVerticalMode, true);
                     this._thumbImage = rotatedValue;
                     if (!rotatedValue.isLoaded) {
                         rotatedValue.onImageLoadedObservable.addOnce(() => {
@@ -87,7 +90,7 @@ export class ImageScrollBar extends BaseSlider {
                     this._markAsDirty();
                 });
             } else {
-                this._thumbImage = value._rotate90(-1, true);
+                this._thumbImage = value._rotate90(-this.num90RotationInVerticalMode, true);
                 this._markAsDirty();
             }
         }

+ 2 - 2
loaders/src/glTF/glTFFileLoader.ts

@@ -795,7 +795,7 @@ export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISc
         }
 
         // Bail if there are no other chunks.
-        if (dataReader.byteOffset + chunkLength === dataReader.buffer.byteLength) {
+        if (dataReader.byteOffset + chunkLength === length) {
             return dataReader.loadAsync(chunkLength).then(() => {
                 return { json: this._parseJson(dataReader.readString(chunkLength)), bin: null };
             });
@@ -829,7 +829,7 @@ export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISc
                     }
                 }
 
-                if (dataReader.byteOffset !== dataReader.buffer.byteLength) {
+                if (dataReader.byteOffset !== length) {
                     return dataReader.loadAsync(8).then(readAsync);
                 }
 

+ 9 - 1
tests/unit/babylon/src/Loading/babylon.sceneLoader.tests.ts

@@ -414,11 +414,17 @@ describe('Babylon Scene Loader', function() {
 
             const setRequestHeaderCalls = new Array<string>();
             const origSetRequestHeader = BABYLON.WebRequest.prototype.setRequestHeader;
-            sinon.stub(BABYLON.WebRequest.prototype, "setRequestHeader").callsFake(function(...args) {
+            const setRequestHeaderStub = sinon.stub(BABYLON.WebRequest.prototype, "setRequestHeader").callsFake(function(...args) {
                 setRequestHeaderCalls.push(args.join(": "));
                 origSetRequestHeader.apply(this, args);
             });
 
+            // Simulate default CORS policy on some web servers that reject getResponseHeader calls with `Content-Range`.
+            const origGetResponseHeader = BABYLON.WebRequest.prototype.getResponseHeader;
+            const getResponseHeaderStub = sinon.stub(BABYLON.WebRequest.prototype, "getResponseHeader").callsFake(function(...args) {
+                return (args[0] === "Content-Range") ? null : origGetResponseHeader.apply(this, args);
+            });
+
             BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
                 loader.useRangeRequests = true;
                 promises.push(loader.whenCompleteAsync());
@@ -426,6 +432,8 @@ describe('Babylon Scene Loader', function() {
 
             promises.push(BABYLON.SceneLoader.AppendAsync("/Playground/scenes/", "LevelOfDetail.glb", scene).then(() => {
                 expect(setRequestHeaderCalls, "setRequestHeaderCalls").to.have.ordered.members(expectedSetRequestHeaderCalls);
+                setRequestHeaderStub.restore();
+                getResponseHeaderStub.restore();
             }));
 
             return Promise.all(promises);