When using the Three.js FBX loader to add objects to the scene, the newly added objects may not be present in the children array

After following the example provided on threejs.org for loading FBX files, I managed to successfully load my model using the function below:

this.obj = null;

var loader = new THREE.FBXLoader();
var objs = []

function load_init( object ) {
    mixer = new THREE.AnimationMixer( object );

    console.log("Adding to objs...");
    objs.push(object);
    console.log(objs[0]);

    object.traverse( function ( child ) {
        if ( child.isMesh ) {
            const oldMat = child.material;
            var newMat = new THREE.MeshBasicMaterial();

            
        }
    } );

    object.position.z -= 200;
    object.position.y -= 250;
    var action = mixer.clipAction( object.animations[ 0 ] );
    action.play();
    scene.add( object );
} 

var true_load = load_init.bind(this);
console.log("Printing objects...");
loader.load( 'Anims/Capoeira.fbx', true_load);

console.log(objs);// It seems to have contents
console.log(objs[0]);// This prints out as undefined

The object is added successfully and I can observe the animation playing. However, my issue arises when trying to access the loaded object within the scene in order to make changes to its properties like material shading and color. By running console.log(scene.children), all children are printed which include a light, ground, grid helper, and the loaded object. But despite this, when checking the length it only shows 3 objects instead of 4. Attempts to directly access the loaded object through the children array or by ID/name result in it being undefined. I even tried modifying the function to return the loaded object or set a variable named loaded_object, but with no success.

Answer №1

Try utilizing THREE.LoadingManager. The challenges you are facing could be a result of the asynchronous nature of the loader.load method.

When using the THREE.LoadingManager.onLoad method, you should have proper access to all the required resources.

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

The search results fail to show the required information

I am trying to retrieve data from an API based on a search query. When the user enters the name of the film they are looking for and hits enter to submit the form, the matching films should be displayed on the screen. However, my console is showing errors ...

Bootstrap form validation solution

Utilizing bootstrap validation to validate a jsp page. The folder structure is as follows: WebContent ├── bootstrap-form-validation ├── js └── pages All three folders are under the web content. If I create another folder called teacher ...

What is the reason for JavaScript consistently returning the initial value as the result?

My current issue involves customizing Joomla article content using a module. I am attempting to hide a div until a user clicks on an input, such as a radio button labeled Test1. Once Test1 is selected, another hidden field within the div should display the ...

Navigating JSON/API data within a Vue.js component template: step-by-step guide

I've successfully implemented a code snippet that renders a list of songs here: https://jsfiddle.net/jeremypbeasley/guraav4r/8/ var apiURL = "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=thisisheroic&period=7day&limit= ...

Utilizing the indexOf Method in AngularJS

Here is my array: emp=["111","56"]. This is the code I have: <input type="text" placeholder="Enter" class="form-control" name="Emp" ng-model="myModel.Emp" ng-required="currentStep ==2"/> <input type="text" placeholder="Enter" class="form-contro ...

Anyone have a sample showcasing the integration of VueJS with the latest webpack 4 configuration?

VueJs templates now come with numerous examples and starting project skeletons. However, most of them still utilize webpack v3. Has anyone experimented with webpack 4? I'd love to see how you integrate version 4 of webpack into a VueJs project. Thank ...

Troubleshooting: Issue with Dependency Injection functionality in Angular 2 starter project

I’ve encountered a strange error whenever I attempt to inject any dependency TypeError: Cannot set property 'stack' of undefined at NoProviderError.set [as stack] (errors.js:64) at assignAll (zone.js:704) at NoProviderError.ZoneAwareError (zon ...

Having trouble retrieving information from the database using socket.io and node.js

As a beginner in node.js and socket.io, I am experimenting with my simple project to fetch data from a database. My index.html serves as a real-time chat example using socket.io with a basic ajax request. <!doctype html> <html> <head> ...

Wordpress functionality for filtering Ajax posts using radio buttons

I am in the process of creating an Ajax post filter system using radio buttons to allow users to filter through multiple categories. Below is the code I have implemented: Front-end form: <form id="filter"> <?php if( ...

Managing a prolonged press event in a React web application

Hello everyone! I am currently using React along with the Material UI library. I have a requirement to handle click events and long-press events separately. I suspect that the issue might be related to asynchronous state setting, but as of now, I am unsu ...

Unable to access parameter in Dialogflow fulfillment

I am currently experimenting with dialogflow fulfillment using NodeJS (dialogflow-fulfillment). My goal is to retrieve parameters from dialogflow, however, I encounter an error when trying to access the currency-name parameter: ReferenceError: name is not ...

Which design pattern would be best suited for monitoring the completion of multiple ajax requests?

In my code, I have combined 3 separate ajax calls in one function along with checkAjaxCompletion method to monitor each ajax completion flag. The current approach involves sending multiple independent ajax calls and using an interval method to continuousl ...

Tips for parsing data arrays in HTML templates

I have three variables and I created an array where I pushed all these three variables in. In my HTML template, I am using a table. I tried using *ngFor but it is not working, and also attempted string interpolation which also did not work. Currently, I ...

Strict mode does not allow duplicate data properties in object literals within JavaScript

Challenge Description I am facing an issue with handling an optional variable called ByteRange. To accommodate this, I included 2 different URLs in the $resource. Upon doing so, I encountered the following error: Message: Error in parsing: "tools/tes ...

When attempting to set a JSON array in state, the resulting JavaScript object does not display correctly

As part of my experimentation with fetch APIs in react, I have set up a server that provides dummy data. In the componentDidMount lifecycle hook of my component, I am making a fetch call to retrieve the data. componentDidMount(){ axios.get('http:// ...

A guide to sending props to a CSS class in Vue 3

I need to develop a custom toast component that includes a personalized message and class. While I have successfully passed the message as props, I am encountering difficulties in applying the bootstrap class. Component File: Toast.vue <script ...

Angular 2 - Graphic Representation Tool for Visualizing Workflows and Processes - Resource Center

Looking for a library that can meet specific requirements related to diagram creation and rendering. We have explored jsplumbtoolkit, mermaid, and gojs, but none of these fully satisfy our needs. For example, we need the ability to dynamically change con ...

Issue with Phong material not responding to area light in a three.js.obj model

Trying to incorporate both a phong material and a shader area light onto my .obj model has proven to be problematic. I attempted using an array within Meshface material to load both materials, but the model vanishes completely when both are applied simulta ...

Creating a shared component for restricting input to only numbers in ReactJS with Material-UI TextField

I am currently working with MUI TextField and my goal is to implement a validation that allows only numbers but not the eE+- keys. I aim to create a standard component for this using onChange event. I need to address the scenario where if the user enters ...

Unable to save array in global variable using Ajax, constantly receiving undefined

I'm attempting to store an array obtained from an ajax call in a global variable so that I can access it later, but I keep encountering an undefined error. <script> var items = []; function add(value){ items.push(value); ...