Updating the attributes of an FBX object in ThreeJS post asynchronous loading

I have successfully loaded an FBX Object into the scene

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

Despite loading "object" as an async FBX object, its properties are inaccessible outside the loader function.

How can I make attributes such as position and rotation of the object accessible outside the loader?

I attempted to place everything inside the loader, including the animate() function, but this doesn't seem like the most efficient solution...

Answer №1

Consider incorporating the async/await pattern into your application to enhance code readability and maintainability.

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

Take note of the use of loadAsync(), applicable for all loaders. You may need to adjust your code structure to accommodate the new await without disrupting your app. Ensure the surrounding method/function is made async to prevent any issues.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating through JSON arrays can be achieved by utilizing iteration techniques

I'm having trouble with a script and can't figure out how to make it display in the designated div. It may have something to do with how I'm handling the response. In Chrome devtools, the response looks like this: { "[\"record one& ...

Struggling to align images side by side using HTML and CSS along with figcaption and buttons

Adding buttons below images on my webpage is proving to be a bit challenging. I tried using the figcaption tag, but it resulted in the images stacking on top of each other instead of side by side. **My HTML:** <section class="mostpurch"> ...

Combining duplicate objects in a JavaScript array

I am looking to identify duplicates by country code and merge them into a single object The array structure is: [{...},{...}] Objects {Country_Code: "RU", Country: "Russia", Provider: "Shell1", Price: "0.123"}, {Country_Code: "EN", Country: "Russia", P ...

Converting form input to JSON and then parsing it into an object

I'm currently working on converting form data to update a JSON object upon submission. Here's my progress so far: var app = { slidePreviews: "", selectedTheme: "", slideDuration: 7000, slides: [] }; $(document).ready(function() ...

JSplumb - retrieve a connection targeting a particular endpoint

There are multiple endpoints on my elements. By using the following code snippet, I am able to retrieve all the connections linked to a specific element: // My JSPlumb instance object is named plumber connSet = plumber.getConnections({target:eltID}); Th ...

Transferring information within React components

Looking for some assistance with the code below. I'm facing an issue where the data is not being submitted along with the form, even though the correct values are displayed in the form. I have included a user query to fetch data from another object an ...

Utilizing the $cond operator within a subset in MongoDB/Mongoose aggregation operations

Imagine having the following data in a document: { "_id" : 1, "first_name" : "Matt", "roles": ['editor', 'publisher', 'siteAdmin'] } { "_id" : 1, "first_name" : "Harry", "roles": ['publisher', 'siteAdmin'] ...

Rows on bootstrap do not have columns in alignment

Something peculiar is happening to me. I have the following snippet of HTML code, but the issue lies in the fact that the panelPrincipal begins hidden with the following JavaScript code: var panelPrincipal = document.getElementById('panelPrincipal&apo ...

Creating a unique JavaScript script that gradually adjusts the background color using the setTimeout() function

Is there a way to create a function that continuously changes the background color every 15 seconds by picking colors from an array that starts over once all colors have been used, without having the function run just one time? $(document).ready(() => ...

The dynamic duo of Threejs and Cesium's 3D Tiles

Currently, I am tasked with finding ways to showcase large 3D geological models on a website. These models are created by geologists using GeoModeller and exported using Cinema 4D to .DAE or .OBJ formats. Once displayed, the model needs to be interactive a ...

Tips for sending a Postgres Pool or Client over a socket

After deploying my server to Heroku, I encountered an issue with sending a request to my Raspberry Pi for running a scraping function and updating a table in the Heroku Postgres database. The problem seems to be related to the client.query() function not b ...

Triggering the body onunload event

I am currently developing a HTA that needs to make final modifications on the onunload event. However, I am facing an issue as the event does not appear to be triggered. Can someone confirm if this event is still supported? Is there an equivalent event in ...

Enhancing the Efficiency of JavaScript's indexOf Method

I am currently developing a basic search algorithm in JavaScript. var title = "Discovering the Best Book of All Time"; var search1 = "of DiscoverinG boOk Best"; var search2 = "Of TIme best all" var search3 = "Book discovering time" When using indexOf(), ...

How do I retrieve the enclosure URL in the Alexa Skill FeedHelper.js file?

I am currently working on a project to create an Alexa feed skill using a blueprint provided by Amazon. The blueprint involves calling RSS feeds from a URL, transforming them into JSON format, and saving them on Amazon S3. The code responsible for this fu ...

Customize the font color in Material UI to make it uniquely yours

How can I customize the default Text Color in my Material UI Theme? Using primary, secondary, and error settings are effective const styles = { a: 'red', b: 'green', ... }; createMuiTheme({ palette: { primary: { ...

Console displaying message of comfort twice - ReactJS

I have a simple app that increments the count from 10 to 11 in the componentDidMount life cycle, but for some reason, the numbers 10 and 11 are appearing twice in the console. I would like to understand why this is happening. Here is the code snippet: im ...

Ensure accurate detection of invalid values for SVG Elements in React using jest testing framework

When testing my react app, I am attempting to capture any errors that are thrown or logged to the console. If a regular HTML element such as <p> contains invalid attributes like <p color={false}></p>, react will display an error via cons ...

In JavaScript, use the following code to replace "(" with "(":

Is there a way to dynamically transform the string "Test(5)" into "Test\(5\)" using JQuery or Javascript? I attempted this approach, but it did not work as expected var str = "Test(5)"; str = str.replace("(","\("); str = str.replace(")"," ...

Creating clickable div elements within a loop

In the .JS file I have the function below (which I later call in an HTML file): function writeDiv(){ x = 1 myArray.forEach(item => { htmlText += '<div class="divsArray">'; htmlText += '<h5> Value of X ...

The error message "MVC JS deletethisproduct is not defined at HTMLAnchorElement.onclick (VM457 Index:40)" indicates that there

Upon clicking the button, I encounter this error: "deletethisproduct is not defined at HTMLAnchorElement.onclick" While I understand that using onclick is not the ideal approach, I am employing it because I need to retrieve the product id from the mode ...