Skip to content

Commit e52749e

Browse files
committed
IFCLoader: Use async/await to make sure the wasm is loaded at parse time.
1 parent bb832fd commit e52749e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/jsm/loaders/IFCLoader.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
} from '../../../../build/three.module.js';
1818

1919
var ifcAPI = new IfcAPI();
20-
ifcAPI.Init();
2120

2221
function IFCLoader( manager ) {
2322

@@ -40,11 +39,11 @@ IFCLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
4039
loader.setWithCredentials( scope.withCredentials );
4140
loader.load(
4241
url,
43-
function ( buffer ) {
42+
async function ( buffer ) {
4443

4544
try {
4645

47-
onLoad( scope.parse( buffer ) );
46+
onLoad( await scope.parse( buffer ) );
4847

4948
} catch ( e ) {
5049

@@ -69,9 +68,13 @@ IFCLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
6968

7069
},
7170

72-
parse: ( function () {
71+
parse: async function ( buffer ) {
7372

74-
return function ( buffer ) {
73+
if ( ifcAPI.wasmModule === undefined ) {
74+
75+
await ifcAPI.Init();
76+
77+
}
7578

7679
var data = new Uint8Array( buffer );
7780
var modelID = ifcAPI.OpenModel( 'example.ifc', data );
@@ -168,9 +171,7 @@ IFCLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
168171

169172
}
170173

171-
};
172-
173-
} )(),
174+
}
174175
} );
175176

176177
export { IFCLoader };

0 commit comments

Comments
 (0)