Having trouble displaying a group of threeJs renderers

I am working on a project that involves displaying multiple renderer, scene, and camera "groups" on a single HTML page. However, I encountered challenges when attempting to implement a render loop using requestAnimationFrame across all these groups. Despite trying to iterate over the list, I have been unsuccessful in rendering even a single frame.

Initially, calling renderer.render on each of the groups within the same function where they are instantiated worked well. But upon refactoring the code to enable rendering outside of that function, my blue spheres disappeared.

The HTML elements include...

<div class="1"></div>
 <div class="2"></div>
 <div class="3"></div>
 <div class="4"></div>

...to which I add some Three.js components.

$(document).ready(function(){
    addResizeandCenterListener(window, $("#container"), 4/3);
    addResizeListener($("#container"), $(".playerhalf"), 2/1);
    for (let item of [".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8"]) {
        var threeDetails = addThreeRendererToElem($(item), item);
        var scene = threeDetails["scene"];
        addClickListenerToElem($(item), scene);
    }
});
threeList = [];

function addThreeRendererToElem(elem, name){
    var width = elem.innerWidth();
    var height = elem.innerHeight();
    var scene = newScene();
    scene.name = name;
    addDefaultLight(scene);
    addBlueBall(scene);
    var camera = addDefaultCamera(scene, width, height);
    var renderer = newRenderer(width, height);
    elem[0].appendChild(renderer.domElement);
    
    var threeDict = {"renderer":renderer, "scene":scene, "camera":camera}
    threeList.push(threeDict)
    
    renderList();
}

function renderList() {
    var tlist = threeList;
    for (var i = 0; i < tlist.length;i++) {
        var threeDict = tlist[i];
        threeDict["renderer"].render(threeDict["scene"], 
                                     threeDict["camera"]);
    }
}

// Remaining functions will be added here...

Despite expecting to see the blue spheres rendered like before, this time only blank canvases appear instead of the expected visual output. While inspecting threeList confirms that all objects are present, there are no error messages displayed.

Answer №1

Issue with the termination condition in the for loop within the renderList function.

You have overlooked .length. It should be:

function renderList() {
    var tlist = threeList;
    for ( var i = 0; i < tlist.length; i++ ) {
        var threeDict = tlist[i];
        threeDict["renderer"].render( threeDict["scene"], threeDict["camera"] );
    }
}

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

Conceal flexbox item depending on neighboring element dimensions or content

I've encountered an issue while using a flexbox to display two elements side by side. The left element contains text, while the right one holds a number. When the value in the right element has at least 7 digits ( > 999,999 or < -999,999), I ne ...

Objects undergo invisible transformations with 3D morph targets

Whenever I add an object to my scene and resize it using morph targets, a strange issue occurs. Check out this example for reference If I move the camera beyond the original size of the object, but still focus on the resized parts, the object disappears. ...

Experiencing a lack of data within the local storage feature of ReactJS

I'm encountering an issue where, upon clicking the submit button, my local storage remains empty even though I have data in my array of objects. Despite assigning values to the localArray variable using titleDesMap, the data is not being stored in th ...

Concentrate on Input in the Middle of the Text

Is it feasible to target a specific character within an input using JavaScript/jQuery for focus? Consider this input field: Would it be achievable to focus on the element and position the cursor after the first sentence, as an illustration? ...

Scrolling horizontally without needing to press the Shift key

I've had no luck finding results in any of my searches so far. Is there a way to implement 'horizontal scrolling' without requiring the user to hold down the shift key while scrolling? ...

Exploring the process of retrieving data from localStorage in Next.js 13

Having recently delved into the realm of Next JS, I've encountered a hurdle when it comes to creating middleware within Next. My aim is to retrieve data from local storage, but I keep hitting roadblocks. middleware.ts import { key, timeEncryptKey, to ...

Customizing CSS for displayed MDBootrap components

I am currently using MDBoostrap, a styling tool similar to Bootstrap, in my React application. I have a select element that is coded like so: <div> <select id="Regions" style={errorSelect} value={this.state.userRegionId} onChange={this.handle ...

Dispose the inputpicker filter after setting the value

I am currently utilizing the "Jquery inputpicker plugin" for creating dropdown menus. More information about this plugin can be found here. To initialize my dropdown, I use the following code: $('#test').inputpicker({ data:[ {value:"1 ...

The AJAX request is failing to retrieve the id and pass it along to the PHP script

I manage a page where I review and either accept or deny new users. Once a user is accepted, they are directed to a section labeled Accepted Users, where the admin can modify their permission level or group number. In the following code snippet, I am retri ...

The integration of Paystack payment is operating smoothly, however, there is a 404 error being returned from the PUT API in

I am facing an issue with integrating paystack into my ecommerce website. Despite troubleshooting extensively, I cannot locate the source of the errors that are occurring. The integration of other payment platforms is successful, but paystack is causing pr ...

How can we prevent components from rendering in React when their state or props have not changed?

I encountered a problem in my project where I have a main component that serves as the parent component of my project. Inside this main component, I have defined routes for other components and directly imported some components like a Side Navbar and Login ...

Sending an AJAX request will only transmit a portion of an array when using the JSON.stringify

I have a JavaScript array that is constantly updated. Here's how I initially set up the array... columnArray = ["userID", "Date", "trialType", "cue", "target", "response", "accuracy", "lenAcc", "strictAcc", "fkpl", "totalTime"]; var dataArray = []; ...

Making a jQuery AJAX request for JSON from a separate domain

My goal is to send an AJAX request to , expecting JSON data in return (not sure if JSONP) However, when I click on the button to make the AJAX request, I encounter this issue: http://prntscr.com/8xswr1 (Google Chrome Console) Upon double-clicking ' ...

Guide on dynamically changing the color of polymer 1.0 paper-button from an array of colors

I have an array called buttonColors that contains a set of colors in hex format. I am looking to create paper-buttons, each with the color from the buttonColors array. How can I achieve this in Polymer 1.0? <template is="dom-repeat" items="{{buttonCo ...

Removing an object from a JSON array based on checkbox selection in Angular 4

0: CategoryId: "31b7a227-9fda-4d14-8e1f-1dee5beeccb4" Code: "GMA0300" Description: "PA-5215: Renamed" Enabled: true Favorite: false Id: "26cfdb68-ef69-4df0-b4dc-5b9c6501b0dd" InstrumentType: null Moniker: "1GMA0300" Name: "Celiac Disease Panel (tTG IgG, tT ...

Browser page caching is a way for web browsers to store copies

I am currently investigating how Internet Explorer caches page content (such as input and textarea) in the browsing history. Steps taken: User visits Page1 with a textarea, then navigates to Page2, and returns to Page1 where the textarea data is automati ...

Transferring the bundle files of one Next.js app to another Next.js app

Currently, I manage two distinct Next.js applications that handle separate sets of routes. Additionally, I have developed a custom Next.js server that determines which page to display based on the requested URL. I am interested in utilizing the custom ser ...

Tips for transferring variables between different variables

I'm having trouble transferring the value from a declared variable into another variable. I'm not sure about the correct syntax. Currently, in the code below, the <span id="xevalue1"></span> in my HTML returns nothing, i.e., blank. H ...

The statement "document.getElementById('grand_total_display').innerHTML = "Total is : $"+variable;" is causing issues in Internet Explorer versions 6 and 7

document.getElementById('grand_total_display).innerHTML = "Total is : $"+variable; seems to be causing an error specifically in IE6 and IE7 Within my HTML, I have an element <li> identified as grand_total_display which contains some existing te ...

JavaScript: Converting an Array to a String

Having trouble making the string method work with an array - it keeps showing up as empty. let url = "https://api.myjson.com/bins/be7fc" let data =[]; fetch(url) .then(response => response.json()) .then(result => data.push(r ...