THREE.js code will only execute when a breakpoint is encountered

I've been working on the code below:

const toothLoader = new THREE.OBJLoader();
let xPos = -80;
let yPos= 15;
let teethCount=0;
toothLoader.addEventListener( 'load', function ( event ) {

const object = event.content;

teeth.push(object);

});
toothLoader.load( 'obj/tooth1.obj' );
toothLoader.load('obj/tooth2.obj');

for(let i = 0; i<32; i++)
{

teeth[i].position.x=xPos;
teeth[i].position.y=yPos;
scene.add(teeth[i]);
}

Strangely, the for loop only seems to work when I set a breakpoint on its statements. Any ideas?

Answer №1

Shouldn't you wait for the load event to fire before entering the loop?

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

Obtain the Unprocessed Product Details with the Shopify-Buy Software Development Kit

I want to create an e-commerce web application using ES6, react, react-redux, and your js-buy-sdk API. When fetching products from Shopify and storing them in the store, I noticed that I only have limited data about a product such as: { attrs, shopClient, ...

Unable to retrieve basic profile data from LinkedIn Members using their email ID unless they are signed in

I am struggling to retrieve the basic profile details of Linkedin Members using their email ID. Despite my efforts, I haven't been able to find relevant information in the documentation. My attempt involved creating an app, initializing the JavaScrip ...

Find the target element containing a child element with specific CSS attribute using JQuery

I am attempting to select the element with the class "keyimage" that contains an a tag with a specific background image. This is the code I have written: $( ".keyimage" ).has( "a[style^='background-image: url('https://example.com/wp-content/upl ...

Creating a list of prime numbers between 1 and 50 in JavaScript using a forEach loop

My code is not giving me the desired result. Can you please review it and provide a solution for finding prime numbers using a Foreach Loop between 1 to 50? I appreciate your help in advance! function isPrime(num) { for ( var i = 2; i < num; i++ ) ...

Utilizing the camera in three.js to focus on a specific plane

I am facing a challenge where I have 600 planes randomly added to a scene with clickable functionality. When a plane is clicked, it animates to the selected plane. Everything works fine, but I'm having trouble getting the camera to focus on the select ...

When examining a JavaScript object, it may seem null at first glance; however,

Having an issue trying to assign a variable to an object. It seems that I am unable to set a variable for this particular object, even though it still displays. Theme.opts.series = series_data.series; console.log(Theme.opts); console.log(Theme.opts. ...

When utilizing JavaScript's split method, an empty string returns an array size of one instead of zero

Is there a way to separate a string using commas to create an array in Node.js? exports.test = function(rq, rs){ var mailList = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16657e7764777856627365623875797b">[email ...

Modifying data within nested objects using Typescript

Imagine having an object like this: { b954WYBCC4YbsMM36trawb00xZ32: { activity1: "pending", activity2: "pending" }, ​ pby0CAqQ1hTlagIqBTQf6l2Ti9L2: { activity1: "pending", activity2: "pending" } } with the in ...

Set the background to be transparent while keeping the text opaque

Is there a way to make only my div transparent using the opacity property while keeping the font normal? I cannot assign a separate class or id to the content as it is dynamically generated. Also, using background: rgba(); is not an option for me. {opacit ...

Transformation of HTML occurs in React components upon saving in Visual Studio Code

As I embarked on my journey to learn React, I hit a roadblock early on. Searching for a particular setting, I somehow ended up selecting something different, like NodeJS. Now, the issue at hand is: Behold the First Image: https://i.sstatic.net/ETmDk.png ...

Can you provide me with the URL for the jQuery post function?

Could someone please clarify which URL I should use in the $.post call to the server for a node.js file? Most tutorials demonstrate with PHP files, but I'm unsure about calling node.js files. Should I post it to the app.js file or the route file? Thi ...

Optimal Approach for Rendering JSX in ReactJS Based on Conditions

I'm wondering what the best practice is for conditionally rendering JSX in a React component. In my component, I am fetching user data, and if the user array has less than 1 user, I want to display the "New User" text. Otherwise, I don't want to ...

Raphael's path adorned with arrow-shaped tips

Recently delving into raphael.js, I am attempting to create an arrow head on a raphael path element (or draw an arrow from point A to point B). Here is the raphael path (line) that I have sketched from point A to point B on my canvas. Assuming that the val ...

Guide to displaying aggregated table field values in an input field when checking the checkbox

How can I retrieve the value of the second span and display it in an input field when a checkbox is checked? For example, if there are values like 500 in the first row and 200 in the second row, when the checkbox in the first row is ticked, the value of 50 ...

"Exploring the power of Selenium with Chromedriver integration in a

Attempting to run integration tests using javascript for my application (Chrome being the browser of choice), I encountered an issue where Capybara failed to detect the Selenium driver. The testing environment consists of: Linux (Ubuntu 12.10) RoR 3.1 Rsp ...

Encountering a TypeError when the 'on' event is triggered by 'byId' in Do

Currently, I am facing an issue with a module that includes a switch statement generating content and various on events waiting based on the content inserted into the DOM and the trigger activated. The problem arises when using on event handlers with dom. ...

Creating PHP scripts that can securely handle cross-domain variables within an iframe

I am managing customer data on my server A. My customers, who have their own server B (over which I have no control), embed an IFRAME on their webpage (referred to as the page of origin) that calls a page on my server A to display some customer informatio ...

What is the best way to conceal a callback form once it has been successfully submitted?

In my callback form, everything seems to be functioning properly. However, there is a slight issue when the client hits the submit button multiple times. Each time they do so, a notification saying "Your request sent successfully" pops up next to the butto ...

Calculate the total length of the nested arrays within an object

Check out this object: const obj = { name: "abc", arr: [{ key1: "value1", arr1: [1, 2, 3] }, { key1: "value2", arr1: [4, 5, 6] }] } I'm looking to find a way to quickly calculate the sum of lengths of arrays arr1 and arr2. ...

"Integrating Prismic.io with Meteor js: A seamless way

Using THIS javascript developer kit from Prismic.io, I aim to fetch content into a meteor template. Initially, I am uncertain of the best approach, whether to construct my main meteor template with spacebars: {{title}} or utilize the predicate system fo ...