Generating numerous visual scenes using the identical renderer

I've been working on rendering multiple scenes using a single renderer, but I'm facing some challenges in getting it right. Despite referring to other Stack Overflow answers, I haven't been able to achieve the desired outcome.

My approach involves loading each gltf model individually and assigning them to the same canvas element in my HTML file. However, when I try to render the scenes, the first one doesn't show up at all, and the second displays as a black box!

Essentially, I aim to render two meshes without resorting to using separate WebGL renderers. As far as I understand, this method allows me to render one scene, clear it, then render the second one while retaining the visibility of the first render in the initial scene.

Below are snippets of relevant code:

// Load a glTF resource
loader.load(
    // insert path to first gltf file here
    function ( gltf ) {

        scene.add( gltf.scene );

    },
  
 // Load a glTF resource
loader.load(
    // insert path to second gltf file here
    function ( gltf ) {

        scene2.add( gltf.scene );

    },
  
  // Canvas
    const canvas = document.querySelector('canvas name here')
    
    // Scene
    const scene = new THREE.Scene()
    const scene2 = new THREE.Scene();

// Renderer
const renderer = new THREE.WebGLRenderer({
  canvas: canvas,
  antialias: true,
  alpha: true
})

renderer.autoClear = false
renderer.clear()
renderer.render(scene, camera)
renderer.clearDepth()
renderer.render(scene2, camera)

Edit: Just to clarify, I am attempting to replicate the effect showcased on this webpage: . Take note of how each scene has its own container in different locations on the webpage while utilizing the same renderer. I am not altering my geometry randomly.

Answer №1

Replacing scene1 with scene2 in the renderer seems to be causing an issue as the renderer may only support one scene at a time.

You have the option of including both GLTFs in the same scene.

loader.load('exampleOne.gltf', (gltf) => {
  scene.add(gltf.scene);
});

loader.load('exampleTwo.gltf', (gltf) => {
  scene.add(gltf.scene);
});

To streamline the process, consider creating a single GLTFLoader and utilizing it multiple times.

const onLoad = (gltf: any) => {
  scene.add(gltf.scene);
}

loader.load('exampleOne.gltf', onLoad);
loader.load('exampleTwo.gltf', onLoad);

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

Unshifting values in a JavaScript array only if they exist in another array

I have two arrays of objects - one containing selected data and the other containing general data that needs to be displayed General data for display const arr = [ { id: "1", name: "Skoda - Auto" }, { id: "2" ...

Navigating through nested JSON objects in React to display data effectively

I have been struggling for hours to find a solution to this problem with no success. I really need your assistance. The task at hand involves looping through a JSON file and creating a user interface that consists of multiple columns, each containing vari ...

AngularFire and Ionic - There is no data being sent to the server from the form

I am using Ionic and AngularFire to build my app, but I have encountered a new issue: the form data is empty! Only the fields in my Firebase database are visible. How can I retrieve the user-entered form data from the Firebase database? Here is a screensh ...

Firestore TimeStamp.fromDate is not based on UTC timing

Does anyone have a solution for persisting UTC Timestamps in Firestore? In my Angular application, when I convert today's date to a Timestamp using the code below, it stores as UTC+2 (due to summer time in Switzerland). import {firebase} from ' ...

Obtain a list of all users who have a specific custom claim using Vue and

I have a unique claim "admin" attached to each user, containing a boolean value. Currently, in the frontend of my application, I am attempting to create a list of all administrators. To do so, I need to retrieve all users who have this specific custom clai ...

Select the directory for downloading the file in your REACTJS application

I am working on a code snippet that generates a URL containing a .csv file for downloading. const getCSVURL = async () => { const response = await PerformanceFilterManager.getCSVURL(); setCSVUrl(response); }; This function is triggered by click ...

Node.js environment variable returns a value of 'undefined'

One method I use to safeguard my bot tokens is by utilizing dotenv to keep them separate from the main app. However, a problem arises when running the code - the environment variables appear as undefined, resulting in an error message: Error: An invalid to ...

What specific blur algorithm is utilized by the Flash platform within their blur filter implementation?

I'm in the process of translating AS3 code to JavaScript, and I've come across an AS3 application that utilizes Flash's built-in Blur Filter Could someone provide insight into the blurring algorithm used by this filter or suggest ways to re ...

A tutorial on creating circular patterns within a pyramid structure using p5.js and matter.js

I've been attempting to create a pyramid shape using multiple circles, similar to this: balls in pyramid shape To achieve this, I've developed a 'Balls' class: class Balls { constructor(x, y, radius, color, ballCount) { this.x = ...

Struggling to display the retrieved data on the webpage

Code in pages/index.js import React from 'react'; import axios from 'axios'; import ListProducts from '@/components/products/ListProducts'; const getProducts = async () => { const data = await axios.get(`${process.env.AP ...

The error message "TypeError: Cannot access 'url' property of undefined in Strapi

I am facing an issue with a list of items where some have download links while others do not. Whenever I try to render an undefined URL, it triggers an error. To resolve this, I attempted the following: if (spectacle.pdf.url) { const pdf = spectacle.p ...

Using Buttons to Filter Data in React

My goal is to implement button functionality that filters data from a JSON file. Upon clicking a button, the state should be updated with the filtered JSON data and display the list with the updated information. Currently, I have four buttons for filteri ...

What is the reason skip does not function properly at the start of the aggregation pipeline, yet performs as expected at the conclusion of it?

Initially, the skip stage in this MongoDB database aggregation framework pipeline isn't functioning as expected: [ { $skip: (!offset)? 0 :(offset-1)*limit }, { $match: (query)? query : {} } , { $lookup: ..., ...

How can I trigger an API call 30 seconds after my React Native app switches to the background?

Seeking assistance with my React Native app: I am trying to make an API call 30 seconds after the app goes into the background. I am using AppState from react-native to detect when the app goes into the background, but I'm not receiving any callback a ...

Create a customized selection based on input changes

<select id="gameid"> //<option is a number 1-999> </select> <select id="netid"> //<option is a number 1-999> </select> <select id="camp_id"> <script> var a = $("#gameid").val(); var b = $("#ne ...

Explore the capabilities of redux independent of the react framework

I've been searching for hours trying to find a way to access the store (to dispatch and observe) without using React Components, but have had no luck. Here's my situation. I created the store in the root of the App: import { Provider } from &ap ...

An arrow function fails to activate

Here is the code snippet that I am dealing with: class App extends React.Component { loginComponent = <button onClick={this.signUp}>Sign Up</button>; signUp = () => { alert("test"); } rende ...

The fixed position setting does not anchor the elements to the bottom of a container

When applying the following styles: #fullpage-menu > .gradient { position: fixed; bottom: 0; left: 0; width: 100%; height: 0.3rem; } To the element with ID #fullpage-menu, which is styled as follows: #fullpage-menu { height: 100 ...

Implementing Object-Oriented Programming (OOP) to insert data into a database in PHP

Seeking a method to insert data into a MySQL database without the need to refresh the page and ensuring no security vulnerabilities. After several hours of experimenting and researching, I have come up with this solution: <form name="form1" action="" ...

How to resolve a TypeError saying "Object(...) is not a function"?

I've been attempting to display material-ui tabs as a component on another page, but I'm encountering an error that causes the code to break when loading the page with this component. I've tried two different methods of rendering this compo ...