What makes sphere geometry take longer to render compared to cube geometry, even though they have the same number of faces?

Upon creating a cube using BoxGeometry and a sphere using SphereGeometry (with both objects spinning around themselves), I noticed that the sphere takes longer to render compared to the cube when increasing the number of objects. For instance:

500 cubes achieve 60 FPS

500 spheres achieve 45 FPS

despite both objects having the same 12 faces.

This raises the question: why is there such a difference?

for(var i = 0; i <amount ; i++){
    posX = posX + size;

    if(i%20 == 0){
        posX = -105;
        posZ = posZ + size;
    }

    if(i%500 == 0){
        posX = -105;
        posZ = -500;
        posY = posY + size;
    } // To fit for view, five hundred objects were stacked per level.

        sphereGeo = new THREE.SphereGeometry(radius, widthSegments, heightSegments);
        sphereMat = new THREE.MeshPhongMaterial({ color: 0x219621, specular: 0xFFE7BA, shininess: 5, opacity: 1, transparent: true});
        sphereMesh = new THREE.Mesh(sphereGeo, sphereMat);
        sphereMesh.rotation.x =0;
        sphereMesh.rotation.y =0;
        sphereMesh.rotation.z =0;
        sphereMesh.position.x = posX;
        sphereMesh.position.y = posY;
        sphereMesh.position.z = posZ;
        sphereMesh.matrixAutoUpdate = false;
        sphereMesh.updateMatrix();
        sphereMesh.address = i;
        countID = i;

        objectsID[countID] = sphereMesh;
        addList[sphereMesh.address] = objectsID[countID];
        scene.add(objectsID[countID]);
    }

function render()
{
    var add_len = addList.length;
    for(var i=0; i< add_len; i++ )
        {
            addList[i].rotation.y += 1;
            addList[i].matrixAutoUpdate = false;
            addList[i].updateMatrix();
        }
    renderer.render( scene, camera );
    requestAnimationFrame( render ); 
}

Here are visuals for

500 spheres

500 cubes

I set radius = 25, WidthSegments = 3, and HeightSegments = 2 . With 12 faces, the output does not resemble a spherical shape (3 and 2 being the minimum values defined in three.js Docs for segment)

The method used for creating cubes also results in each cube having 12 faces. Both test cases were conducted in the same environment.

I am curious about the performance disparity between the two shapes. Could this be attributed to the internal structure of BoxGeometry and SphereGeometry?

Answer №1

Do both objects always have their faces pointing in the same direction (for example, did you turn a sphere into a '12 face cube')?

If not, then the normals and lighting would be more diverse on the non-cubed object because the cube has more faces that could share the same data, resulting in fewer calculations.

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

How to properly align slices in volume rendering using THREE.js?

I have managed to create a stack of volumes from planes using THREE.js, but the planes disappear when they become orthogonal to the viewing plane (which makes sense). How can I prevent this from happening? Is there a way to keep the slices aligned with t ...

Enhance state using the values from radio buttons in a React application

Seeking the best approach to update or set my state that stores values for radio button answers. This pertains to a personality test with 20 questions, and I aim to store all 20 answers. Each radio button input has an onChange event. My objective is to st ...

When clicking on a text, the .slideToggle(); function fails to activate

Clicking on a specific text should reveal a hidden div using .hide();. Clicking the text again should hide the div and so on... Although it sounds simple, it's not working as expected. Here is the HTML code: <div class="row"> < ...

Guide individuals towards two distinct web addresses depending on the information provided

I am currently working on a website for my upcoming wedding, which consists of 2 separate events with different sets of information regarding when and where they will take place. I would like to create a system where users can input some kind of prompt, su ...

Tips for accurately extracting values from a decoded JSON

Hello, I am posting this query because I recently encountered an issue with json encoding in PHP. When using the json_encode() function, my original JSON data gets converted to strings instead of maintaining its original variable type. For instance, let&a ...

What is the process of encapsulating a callback function within another callback function and invoking it from there?

Here is the code snippet I am working with: var me = this; gapi.auth.authorize({ client_id: client, scope: scope, immediate: true }, function (authResult: any) { if (authResult && !authResult.error) { me ...

"React's ambiguous understanding of 'this' within a function

Can anyone help me understand why the value in the renderInput function is showing as undefined? I've checked the code and everything seems fine. Here is the error: Uncaught TypeError: Cannot read property 'renderError' of undefined This ...

SCORM: moving between SCOs by clicking a button in the presentation

Currently, I am developing a website that allows users to create presentations. One of the website's features is the ability to export presentations in SCORM format (either 1.2 or 2004). This is my first time working with SCORM and I am currently impl ...

Unable to submit POST request in Node.js

Seeking assistance to resolve a persistent error that has been causing me trouble for quite some time. This issue is preventing me from adding data to my database successfully. Any help or guidance on this matter would be greatly appreciated. This sectio ...

Send a string from an AJAX request to a PHP script

My goal is to retrieve a value from an input field, send it through ajax to PHP, and then store the data in a MySQL table. The database structure is already in place, so I just need to insert the values. Here is my JavaScript file: var address = $("input ...

how to ensure a consistent property value across all scopes in AngularJS

Here is my perspective <div ng-if="isMultiChoiceQuestion()"> <li class="displayAnswer" ng-repeat="choice in getMultiChoice() track by $index" ng-if="isNotEmpty(choice.text.length)"> <input type= ...

Generate an image instantly from text using ajax when a key is pressed

Currently, I am immersed in a stencil project where my goal is to convert text into an image. In this particular task, there's a textbox that captures the user input on key up event. Once the user enters text, my aim is to display that text as an imag ...

What is the process of turning an SVG element into a clickable link?

Is there a way to transform each element within an SVG image embedded in an HTML file into an active link? I want to create an SVG image with clickable elements. Here is a snippet of the SVG image: <svg version="1.1" id="Layer_1" xmlns="http://www.w3 ...

Managing an array based on its individual elements

const grid = { squares: Array(20).fill(null) } Within my grid object, I have an array called squares which fills with values when a square is clicked. I am trying to check if all elements in the array are not null. const squaresCopy = grid.square ...

Retrieve the audio file from the server endpoint and stream it within the Vue application

I am working on a listing module which includes an audio element for each row. I need to fetch mp3/wav files from an API and bind them correctly with the src attribute of the audio element. Below is my code snippet: JS methods:{ playa(recording_file) ...

What is the process for integrating a third-party JavaScript Node.js library into a Cordova plugin?

I'm in the process of creating a Cordova plugin for an internal project and I am considering integrating a third-party open source Javascript library called bluebird promise. My initial thought was to simply copy and paste the bluebird JS files into m ...

How can I use jQuery to rotate a DIV to a specific angle?

Similar Question: How to Rotate a Div Element using JavaScript Is there a way to rotate a DIV and its contents by a specific degree in jQuery? I'm looking for a solution that allows me to set the rotation angle to any value, not just fixed angles ...

Is there a way to refresh the page in NextJs whenever the parameters are modified without the need for reloading?

Currently, I am navigating on http://localhost:3000/?groupId=chicago&dayOfWeek=tuesday. Despite pressing a button on a component, the desired outcome of transitioning to another day, like Thursday, is not occurring. import { useRouter, usePathname, use ...

Node.js population process

Hello, I am currently exploring Node.js and facing an issue with the populate() method. My goal is to populate the user model with forms. Here is the structure of the model: const UserSchema = new Schema({ firstName: { type: 'string&a ...

Clicking to reveal a v-date-picker v-menu and automatically focusing on a v-text-field within it?

I implemented a date-picker component in my app following the instructions from Vuetify. To enhance usability for desktop users, I removed the readonly attribute to allow manual input. Now, desktop users can easily navigate through form fields using th ...