The performance of Three.js is directly influenced by the quantity of objects present

Just completed a project in WebGL using Javascript and the 3D library known as three.js

Unfortunately, the performance of the project is less than impressive - slow from the start with occasional moments of adequacy.

In this game, there are: 1 car, 6 oranges, 161 cheerios, 1 table, 1 fork, and 6 candles.

  1. The player controls the car in a race-like game, navigating through a circuit enclosed by cheerios. The car consists of various three.js geometries like box, torus, cylinder, and sphere. When an orange collides with the car, the player restarts and loses a life.
  2. All oranges move uniformly in straight lines, posing a threat to the car upon collision. Their structure consists of sphere and cylinder geometries in three.js.
  3. A cube-shaped table scaled to be 300x1x300 in xyz coordinates.
  4. Each candle acts as a pointlight source, flickering for added effect.
  5. In addition to the 6 pointlights, there is ambient light and 1 directional light, all created with three.js.
  6. The fork behaves like a billboard, constantly pointing towards the active camera represented by a plane.
  7. An explosion of particles occurs when an orange reaches its destination or when the car completes a lap. Each explosion includes at least 100 small plane particles following a billboard-like movement pattern.
  8. Upon creation, each particle within an explosion is individually added to the scene before eventually expiring after a set period of time (usually around 1000 milliseconds).
  9. All objects within the game feature their own textures, some not optimized with dimensions as powers of 2. Textures are loaded using the deprecated method THREE.ImageUtils.loadTexture(URL).
  10. Everything within the game, including scenes, cameras, lights, meshes, geometries, and materials, was built using three.js.

It has come to my attention that adding numerous cheerios significantly impacted the performance. Is there a way to use a single model for all cheerios similar to OpenGL's VS libs?

How can I enhance the overall performance of the project?

Please feel free to request more specific information if needed regarding this issue.

Answer №1

To optimize your scene, start by constructing a geometric shape. Next, generate individual cheerios meshes without immediately adding them to the scene. Instead, merge each mesh into the geometry using:

var globalCheeriosGeometry = new THREE.Geometry();
// iterate through 161 cheerios meshes and merge them into the global geometry
globalCheeriosGeometry.mergeMesh( cheeriosMesh );

This approach consolidates all cheerios into a single geometry object. Afterwards, create a new mesh utilizing this combined geometry and then introduce it to the scene. By following this method, you can significantly reduce the number of draw calls required for your scene rendering.

Answer №2

It seems likely that the issue arises from calling a resource-intensive three.js method too frequently, leading to high computation demands. To address this, I suggest profiling your game to determine whether the bottleneck lies in CPU or GPU processing.

In addition to the presence of 6 pointlights, there exists ambient light and 1 directional light, all generated using three.js.

The calculations for lighting can be costly at an individual pixel level, necessitating computation for every pixel. Consider reducing the number of light sources to optimize performance.

Each explosion may consist of multiple particles (minimum 100), with each particle behaving like a small plane with billboard-like properties.

Ideally, utilize a billboard particle system instead of handling particles as individual planes to avoid potential inefficiencies where three.js may perform one draw call per plane.

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

Upload a JSON file to a server using a JavaScript app

I am in the process of creating a basic JavaScript application that allows users to annotate images stored on their machine and save these annotations as a JSON file. This application is lightweight and straightforward, not requiring an app server. Howeve ...

React Native's state changes dynamically, however, the JSX conditional rendering fails to update the user interface accordingly

Greetings and thank you in advance for your time! I'm currently facing a unique challenge with React where I am struggling to render a specific UI element based on a check function. My goal is to create a multiple selection filter menu, where clickin ...

Sending data with React using POST request

Currently in my React application, I have a form that includes fields for username and password (with plans to add "confirm password" as well). When submitting the form, I need it to send JSON data containing the email and password in its body. The passwo ...

Is there a way to incorporate external HTML files into my webpage?

Looking to update an existing project that currently uses iFrames for loading external HTML files, which in this case are actually part of the same project and not from external sites. However, I've heard that using iFrames for this purpose is general ...

steps to verify the status of a sent request

I am utilizing the contenteditable property in a p tag. My code is as follows: <p contenteditable="true" id="Option1_<?php echo $i ?>" style="width:98%;border:4px thin black; background-color:#D6D6D6;font-size:18px;color:black;padding:3px ">&l ...

How to remove an image input type using jQuery

Can anyone provide insight into the issue with these scripts? I am attempting to remove an input when it is clicked. The input is of type image, so CSS cannot be used. I have tried using JavaScript but it doesn't seem to be working. HTML <!doctyp ...

What is the process for using express and Postman to send a PUT request and modify a specific field in MongoDB?

I'm struggling to figure out how to use a MongoDB document's id in the route and manipulate the 'balance' field using Postman. Here's what my code currently looks like: My route: router.put('/:id', async (req, res) =&g ...

Issue with JQuery: Inability to deactivate an element after receiving an Ajax response

My dynamic dialogue box, generated via Ajax return, presents a challenge involving the dynamically changing drop-down list element $('#functionSelect'). I require this list to trigger disabling of input fields within the dialogue box upon changes ...

What are the steps to integrating D3js into a WordPress website?

After installing Wordpress and the d3js plugin, I'm looking for the most effective way to upload data in order to create and display graphs on my website. Should I directly upload csv files? And if so, where should I store them? If I prefer storing ...

Refreshable div element in a Code Igniter-powered web application

I am encountering difficulties with automatically refreshing my div using the CodeIgniter framework. My goal in the code snippet below is to have the particular div with id="lot_info" refresh every 1 second. The div is not refreshing, and an error message ...

Do not use unnecessary variables for storing references in ES6

Despite using react es6, I am still unsure how to refrain from needing to use the variable that for this scenario: const that = this; UploadApi.exec(file).then(data => { that.setState({ loading : false}); }); ...

To calculate the sum of input field rows that are filled in upon button click using predetermined values (HTML, CSS, JavaScript)

Greetings for exploring this content. I have been creating a survey that involves rows of buttons which, when clicked, populate input fields with ratings ranging from 5 to -5. The current code fills in one of two input fields located on opposite sides of ...

Unauthorized access detected during ajax request triggered by onpaste event

Recently, I encountered an issue with my asp.net mvc website where an ajax call to the server stopped working in IE 11, despite previously working fine in IE 8. The error message pointed to an access denied exception in jQuery 1.7.1 at h.open(c.type,c.url, ...

Why is it that a JSX element can take a method with parentheses or without as its child?

Why is it that when I attempt to pass a method without parentheses into a React component as a child of one of the JSX elements, an error appears in the console? However, simply adding parentheses resolves the issue. What's the deal? For example: ran ...

Securing page access with a straightforward password protection using Flask

Looking for a straightforward way to add password protection to a Flask app site. I've explored options like flask_login, but they seem overly complex for my needs. I don't need high security or login sessions - just something like: "enter passw ...

Jquery Validate doesn't consistently give a positive response

Having a button that triggers the jQuery validation plugin poses an issue where it consistently returns true, except when the fields are left empty. The rules set for validation seem to be disregarded. DEMO http://jsfiddle.net/sw87W/835/ $(document).read ...

Building custom directives on AngularJS pages without a specified ng-app module

On some of my basic pages, I don't need to specify a particular application module in the ng-app attribute. However, these pages do utilize some custom directives that I have created. To keep things organized, I have placed all of my directives withi ...

How does the 'this' variable function when it comes to models in embedded documents?

Being relatively new to node.js and sails, I find it quite easy to work with and enjoy it :) Currently, I am using the sails Framework version 0.10rc3 with MongoDB and sails-mongo. I understand that the contributors of waterline do not particularly like e ...

Allow all images on the webpage to be easily dragged and dropped into a designated upload section

I am in the process of developing a browser extension that allows users to save images from web pages into their favorites, similar to Pinterest. The functionality involves clicking on the extension icon which adds a special field to the HTML where users c ...

What is the best way to add an insert button to every row?

Take a look at the image provided. When I click on any register button, the last row is being inserted instead of the desired row. What I'm aiming for is this: when I click register, the entire selected row should be stored in a separate table. Whe ...