File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 17
17
import '@babylonjs/core/Materials/Textures/Loaders/basisTextureLoader' ;
18
18
import '@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader' ;
19
19
import '@babylonjs/loaders/glTF' ;
20
+ import { AssetContainer } from '@babylonjs/core/assetContainer' ;
20
21
import { LoadAssetContainerAsync , LoadAssetContainerOptions } from '@babylonjs/core/Loading/sceneLoader' ;
21
22
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh' ;
22
23
import { IDisposable } from '@babylonjs/core/scene' ;
@@ -121,7 +122,18 @@ export class ModelLoader implements IDisposable {
121
122
this . _sceneManager . scene . getEngine ( ) . displayLoadingUI ( ) ;
122
123
}
123
124
124
- const container = await LoadAssetContainerAsync ( url , this . _sceneManager . scene , loadAssetContainerOptions ) ;
125
+ let container : AssetContainer ;
126
+ try {
127
+ container = await LoadAssetContainerAsync ( url , this . _sceneManager . scene , loadAssetContainerOptions ) ;
128
+ } catch ( error ) {
129
+ // Fallback to full download on range request failure
130
+ if ( error instanceof Error && error . message . includes ( 'RangeError' ) ) {
131
+ loadAssetContainerOptions . pluginOptions ! . gltf ! . useRangeRequests = false ;
132
+ container = await LoadAssetContainerAsync ( url , this . _sceneManager . scene , loadAssetContainerOptions ) ;
133
+ } else {
134
+ throw error ;
135
+ }
136
+ }
125
137
126
138
// Add everything from the container into the scene
127
139
container . addAllToScene ( ) ;
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ describe('ModelLoader', () => {
46
46
} ) ;
47
47
48
48
afterEach ( ( ) => {
49
+ nock . cleanAll ( ) ;
49
50
modelLoader ?. dispose ( ) ;
50
51
sceneManager ?. dispose ( ) ;
51
52
observableManager ?. dispose ( ) ;
@@ -89,6 +90,22 @@ describe('ModelLoader', () => {
89
90
await modelLoader ?. loadGltf ( 'http://localhost/public/model/mannequin.glb' , true ) ;
90
91
91
92
expect ( sceneManager ?. models . size ) . toBe ( 1 ) ;
92
- nock . restore ( ) ;
93
+ } ) ;
94
+
95
+ it ( 'should be able to load glb asset with full download when HTTP range requests failed' , async ( ) => {
96
+ const data = fs . readFileSync ( 'public/model/mannequin.glb' ) ;
97
+ nock ( 'http://localhost' )
98
+ . get ( '/public/model/mannequin.glb' )
99
+ . matchHeader ( 'range' , 'bytes=0-19' )
100
+ . reply ( 206 , Buffer . from ( '' ) , {
101
+ 'content-Range' : 'bytes 0-19/760664' ,
102
+ 'content-length' : '20' ,
103
+ } )
104
+ . get ( '/public/model/mannequin.glb' )
105
+ . reply ( 200 , data ) ;
106
+
107
+ await modelLoader ?. loadGltf ( 'http://localhost/public/model/mannequin.glb' , true ) ;
108
+
109
+ expect ( sceneManager ?. models . size ) . toBe ( 1 ) ;
93
110
} ) ;
94
111
} ) ;
You can’t perform that action at this time.
0 commit comments