Numerous obj elements simultaneously loaded within a single viewport

My goal is to incorporate multiple obj models into separate scenes, following the concept from webgl_multiple_elements.html. I have successfully loaded a single obj file and now want to add it to each individual scene. Although the obj file loads without errors, I am facing difficulties in displaying the model within the scenes. When running the geometries shown in the example provided above, everything works as intended. However, when substituting the basic geometries with the obj model, the model remains invisible.

<style>
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }
    body {
        background-color: #fff;
        color: #444;
    }
    a {
        color: #08f;
    }
    #content {
        position: absolute;
        top: 0; width: 100%;
        z-index: 1;
        padding: 3em 0 0 0;
    }
    #c {
        position: absolute;
        left: 0;
        width: 100%;
        height: 100%;
    }
    .list-item {
        display: inline-block;
        margin: 1em;
        padding: 1em;
        box-shadow: 1px 2px 4px 0px rgba(0,0,0,0.25);
    }
    .list-item .scene {
        width: 200px;
        height: 200px;
    }
    .list-item .description {
        color: #888;
        font-family: sans-serif;
        font-size: large;
        width: 200px;
        margin-top: 0.5em;
    }
</style>
</head>
<body>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="592d312b3c3c196977616c7769">[email protected]</a>/build/three.min.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d29352f38381d6d736568736d">[email protected]</a>/examples/js/controls/OrbitControls.js"></script>
<canvas id="c"></canvas>

<div id="content">
    <div id="info"><a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - multiple elements - webgl</div>
</div>

<script id="template" type="notjs">
    <div class="scene"></div>
    <div class="description">Scene $</div>
</script>
<script>
    var canvas;
    var scenes = [], renderer;

    var loader = new THREE.ObjectLoader();
    var objFlag = null;

    loadObject();

    function loadObject(){
        loader.load("./test_obj.json", 

        function( objectLoaded ) {
            objFlag = objectLoaded;
            init();
            animate();
        }, 
        // called when loading is in progresses
        function ( xhr ) {
            console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
        },
        // called when loading has errors
        function ( error ) {
            console.log( 'An error happened' ,error);
        }
        );
    }

    function init() {
        ...
        ...
        ... (remaining code unchanged)
    }
</script>

Answer №1

After making some adjustments, I successfully enhanced the rendering process by moving the init and animate functions outside the loop and calling them separately. Additionally, following @Mugen87's advice regarding the scale of rendered objects, I made necessary changes to adjust the camera settings. As a result, each cell now displays individual objects, allowing me to render up to 50 cells within the same viewport simultaneously.

<!DOCTYPE html>
<html lang="en">
<!-- Rest of the code goes here -->

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 URLs with Ajax Requests in CakePHP

How can ajax calls in javascript files located in the webroot be handled without PHP interpretation? In my project using CakePHP and require.js, I avoid placing javascript directly in views. To address this issue, I set a variable in the layout to store t ...

Dealing with potential AngularJS challenges related to scope (or so I believe)

As a newcomer to angular, I have taken on the challenge of creating a complex directive. I have managed to get most of the directive working, but I am facing two issues that seem to be scope-related. Here is the code for my directive: angular.module(&apo ...

Adding an external JavaScript file to an Angular 5.0.0 project

Struggling to integrate hello.js into my Angular 5.0.2 project. See the CLI version below https://i.sstatic.net/RcGz5.jpg I have included the script file in angular-cli.json. "scripts": [ "./js/hello.js", "./js/hello.polyfill.js", ...

How to handle an unexpected token error when using a function within another function in

I'm encountering an issue where the function below is placed above my render function. It doesn't seem to allow me to nest a function within another function. Can you help me identify what's causing this problem? onSelected(i){ this.st ...

What indicators should we look for to decide if JavaScriptExecutor is needed in a Selenium C# project?

Encountering an exception with TestInChrome1 - "OpenQA.Selenium.ElementNotInteractableException: element not interactable". On the other hand, using JavaScriptExecutor in TestInChrome2 resolves the issue. Some key questions arise: What is causing the ...

Troubleshooting steps for resolving Heroku's "State changed from up to crashed" error caused by Mongoose connection issue

I am encountering an issue while deploying my Node.js/MongoDB app to Heroku. It crashes with the following error: MongooseServerSelectionError: connection <monitor> to 104.155.184.217:27017 closed Below are excerpts from my log: 2022-07-10T23:36:17. ...

The Html is not having JavaScript executed before it

Within my header, there is a script that is making a call to a web API in order to populate a view model. The script is as follows: @using GigHub.Controllers @using GigHub.ViewModel @model GigHub.ViewModel.ProjectsViewModel @{ ViewBag.Title = "Projects"; ...

What is causing the error message of "prop id does not match the rendered server output" to appear on my screen?

https://i.stack.imgur.com/VOLDT.png I've been working on a nextjs redux project and I keep running into this error whenever I refresh my page. Despite searching for a solution, I haven't been able to resolve it. The official next js blog suggest ...

Combining cells through the utilization of JavaScript

I've searched for ways to merge cells in a table using JavaScript but haven't been able to find any code that works. Is there a specific approach I can follow to implement cell merging like in MS-WORD tables? Your advice would be greatly apprec ...

The grid flex end is behaving differently than I anticipated

I am struggling to align two buttons vertically on the right side. Here is my code snippet: const WalletsContainer = () => { return ( <Grid style={{ background: 'red' }} direction={'column'} alignItems={'flex-end'} ...

Scrolling to top using jQuery - Problem with incorrect anchor

I am attempting to implement a scrollTop animation that scrolls to an anchor within a fullscreen <section>. However, the issue is that it does not scroll to the correct anchor on the first click. Below is the code snippet. <nav id="scroller"> ...

Tips for eliminating strings containing numbers and special characters with javascript regular expressions

let str = "[Account0].&[1]+[Account1].&[2]+[Account2].&[3]+[Account3].&[4]"; let numArray = str.match(/(\d+)/gi); alert(numArray.join(',')); The resulting numbers are: 0,1,1,2,2,3,3,4 I am looking to remove all strings with ...

Validating American phone numbers using regular expressions

I came across a Javascript regex that is used to validate the different formats in which US phone numbers can be written. However, there seems to be an issue with it: it fails to match the second rule within this specific group: The first group of three ...

ReactJS safeguarded route redirection/refresh obstacle

Utilizing react and react-router-dom: import React from 'react'; import { Switch, Route, Redirect } from 'react-router-dom'; To secure a route with the following: Router const Router = () => { return ( <Switch> ...

Having trouble getting my Sequelize model to export properly

For my school project, I am developing an e-commerce website and encountering an issue with connecting my GoogleStrategy to my SQLite database. The goal is to store user data in a table, but whenever I try to call the variable in my passport-setup file, an ...

Discrepancy in sorting order of key-value objects in JavaScript

Check out my jsFiddle demonstration illustrating the issue: Example Here is the HTML structure: <select id="drop1" data-jsdrop-data="countries"></select> <select id="drop2" data-jsdrop-data="countries2"></select>​ Below is the ...

What is the best method to access the query string or URL within an AJAX page?

I recently discovered how to extract query string parameters from this helpful resource. However, I am facing difficulty retrieving the URL within the requested page via ajax. For instance: <div class="result"></div> <script> $(func ...

Importing images with relative paths from a JSON file does not work as expected in Next.js

JSON file data portion: { "categories": [ { "id": 1, "category_slug": "food_supplements", "title": "Food Supplements", "image": "/../../public/images/foodSupplements.png", } ] } Component data portion that displays the ...

Creating a dynamic progress bar that scrolls for multiple elements

I am currently working on implementing a scrolling progress bar to show users how much of an article within a div they have read. For reference, something similar can be seen on this site. I have created my custom progress bar and coded it on fiddle, whe ...

Button click triggers CSS animation

Check out the interactive demo $(document).ready(function(){ $('#btn-animate').click(function(){ animate(); }); $('#btn-remove').click(function(){ $('.to-animate').removeClass('animate'); }); func ...