2

I'm loading an FBX Object into the scene

const loader = new FBXLoader();
        loader.load( '{{asset('models/model.fbx')}}', function ( logo ) {
            scene.add( logo );
            logo.position.y = 0;
            logo.position.x = 0;
            logo.position.z = 0;
            logo.updateMatrix();
        });

Since "logo" is an async loaded FBX object, I cannot access its properties outside the loader function.

How do I achieve to make its attributes like position, rotation and so on, accessable outside the loader?

I already tried to put anything (including the animate() function) into the loader - but this seems to be not the "clean" way...

Mike
  • 493
  • 5
  • 14

1 Answers1

3

Consider to utilize the async/await pattern in your app which makes the code easier to understand. And cleaner.

const loader = new FBXLoader();
const logo = await loader.loadAsync( '{{asset('models/model.fbx')}}' );
scene.add( logo );

Notice the usage of loadAsync() which is available for all loaders. You most likely have to refactor your code so the new await does not break your app. You can avoid this by making the surrounding method/function async.

Mugen87
  • 28,829
  • 4
  • 27
  • 50