Progressive rendering of a substantial mesh using three.js

How can I efficiently render a large static mesh in three.js, even if it's 2 GB with tens of millions of polygons?

My plan is to stream the mesh geometry buffers into indexedDB and render them progressively to the screen, all while maintaining an interactive frame rate. I will implement a MemoryManager class to prevent crashing the browser by loading data into a fixed-size buffer from indexedDB. In my animation loop, I will render as many geometries as possible within 16ms, continuing to render meshes until the user stops interacting.

While I have a high-level strategy in place, I know there will be numerous optimizations required (such as object pools, octree, occlusion queries, etc).

My main question is: Is there a more efficient way to achieve this, and has it been attempted before? (Considering I am using WebGL1, knowing WebGL2 occlusion queries would simplify this process)

Additionally, what is the optimal method for customizing the Three.js WebGLRenderer class? I know there are private closure variables (like WebGLState) that I may need to access in order to enhance performance for my specific scenario.

Answer №1

Utilizing WebGL2 occlusion queries may not provide significant benefits in this context. It could be feasible to implement them, but performing culling on the CPU might be a more effective option, especially if your scene is mostly static.

If you aim to gradually render geometry when the user stops interacting, you can simply refrain from clearing the render buffer. In THREE.js, you can achieve this by enabling preserveDrawingBuffer on the renderer and setting autoClear to false.

In case the camera moves or the scene undergoes changes requiring a reset, you can clear the view by calling renderer.clear().

When it comes to streaming data in, employing BufferGeometry and adjusting the necessary BufferAttributes each frame would be recommended. It seems like you already have some strategies in place for optimizing and determining which geometry needs to be rendered.

Example

The scene redraws continuously on the same frame. Click on the scene to clear it and initiate the drawing process again. The crucial JavaScript lines are marked with NOTE:

// NOT: enabling preserveDrawingBuffer
const renderer = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true });
renderer.setClearColor(0x263238);
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.clear();
document.body.appendChild( renderer.domElement );

// NOTE: disabling autoclear
renderer.autoClear = false;

// Scene setup
const scene = new THREE.Scene();
const dirLight = new THREE.DirectionalLight(0xffffff);
dirLight.position.set(.4, 1, .1);
scene.add(dirLight);

// Camera setup
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000)
camera.position.z = 10;

const geom = new THREE.TorusKnotGeometry(.5, .2, 200, 100);
const mesh = new THREE.Mesh(geom, new THREE.MeshPhongMaterial({ color: 0xE91E63 }));
scene.add(mesh);


// NOTE: Clearing on user interaction
renderer.domElement.addEventListener('click', () => renderer.clear());

(function renderLoop() {
    mesh.position.y = Math.sin(performance.now() * 0.001);
    renderer.render( scene, camera );
    requestAnimationFrame( renderLoop );
})();
<script type="text/javascript" src="https://rawgit.com/mrdoob/three.js/r92/build/three.js"></script>

<style>
  canvas {
    width: 100%;
    height: 100%;
  }

  * {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
  }

  div {
    color: white;
    position: absolute;
    text-align: center;
    width: 100%;
  }
</style>

<div>Click to clear</div>

I hope this information is beneficial to you!

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

Controller unable to properly increment values

$scope.isChecked = function(id){ var i=0,j=0,k=0; //$scope.abc[i].usertype[j].keywords[0].key_bool=true; if($scope.abc[i].type_selected == true){ while($scope.abc[i].usertype.length){ while($scope.abc[i].userty ...

When jQuery's `foo.html("<span>bar</span>")` doesn't alter `foo[0]`, what implications does it have?

While using jQuery in Firebug, the following actions are taken one by one: foo = $('<div>foo</div>') foo[0] // => <div> foo.html('<span>bar</span>') foo.html() // => "<span>bar</span> ...

Which special characters are restricted in a JSON.parse function?

I have been encountering a parse error repeatedly after receiving my response. Could it be due to the presence of illegal characters? Below is the response data: [{"businessID": ChIJ49DlQ5NiwokRQ_noyKqlchQ,"latitude": 40.733038,"longitude":-73.6840691,"a ...

Top method for handling chained ajax requests with jQuery

I'm facing a scenario where I have to make 5 ajax calls. The second call should only be made once the first call returns a response, the third call after the second completes, and so on for the fourth and fifth calls. There are two approaches that I ...

Creating a series of image files from CSS and Javascript animations using Selenium in Python

Looking to convert custom CSS3/Javascript animations into PNG files on the server side and then combine them into a single video file? I found an interesting solution using PhantomJS here. As I am not very familiar with Selenium, adapting it for use with S ...

Maximizing Python efficiency - the ultimate strategy for parallel computing

I am currently developing a Python script that requires sending over 1500 packets simultaneously within less than 5 seconds each. In essence, the main requirements are: def send_packets(ip): #craft packet while True: #send packet ...

Is there a way to store div content in a PHP Session?

Just starting to learn php & ajax, so be patient with me. I have a clickable map. When the user clicks on a point, the value is displayed in a div. Once they select a point, they should be able to proceed to the next step. Now I want to save the content ...

What's a quick way in Javascript to add a string to all elements in an array?

I'm working with an array = ["a", "b", "c"]; What I need to do is concatenate a string, let's say "Hello", to each value in this array. The desired output should look like this: ["Hello_a", "Hello_b", "Hello_c"] Is there a quicker way in java ...

The following item in the .each() sequence

How can I move on to the next element within a jQuery .each() loop? $(".row").each( function() { if ( ... ) //move to the next iteration in the .each() loop }); Appreciate any assistance. Thank you. ...

NextJS was throwing a warning at me, while Firebase hosting was giving me an error regarding the absence of unique keys for children in lists, even though I

I've been troubleshooting this warning for quite some time, but I can't seem to resolve it. The warning reads as follows: Warning: Each child in a list should have a unique "key" prop. Check the top-level render call using <ul>. ...

The issue with logging out feature

Operating an ASP.NET Web application, I have a Logout feature implemented in JavaScript. However, my current code closes the browser upon Logout, which is not the desired behavior. Instead, I am looking to clear cookies/session and redirect the user to the ...

I'm looking to integrate Jest in my React project with npm. How can I achieve

I've developed my application with create react app and npm. While reviewing the official documentation for jest at https://jestjs.io/docs/tutorial-react, I noticed that they only provide information on testing CRA apps using yarn. Does this suggest t ...

Creating an array object in TypeScript is a straightforward process

Working on an Angular 4 project, I am attempting to declare an attribute in a component class that is an object containing multiple arrays, structured like this: history: { Movies: Array<Media>, Images: Array<Media>, Music: Array<Medi ...

Ways to eliminate an item in a JSON structure?

Allow me to elaborate. I received a JSON containing numerous objects: data = [{"id":"784","label":"blah","publisher":"me"},{"id":"785","label":"bleh","publisher":"you"},{"id":"786","label":"blih","publisher":"she"}]; For instance, I am looking to elim ...

Encountering a problem when trying to send an API request for multer in order to save

I encountered an issue with my node API that uses multer to store files. I am receiving an error when calling it and seeking assistance. Below is the code snippet along with the specific error message - Code - const storage = multer.diskStorage({ d ...

Seamless transitions while deactivating a conditionally displayed component in React

Here is my code snippet from App.js: export const App = () => { const [toggled, setToggled] = useState(false); const [ordering, setOrdering] = useState(false); const handleColorModeClick = () => { setToggled((s) => !s); }; const ha ...

What is the best way to extract valid objects from a string in JavaScript?

Currently, my data is being received through a TCP connection. To determine if a string is a valid JSON object, we use the following method: let body = ''; client.on('data', (chunk) => { body += chunk.toString(); try { ...

Ajax seems to be interacting with an empty session variable

I am facing some issues with a piece of code that I've written. Here's the function in question from my PHP class: public function generalSettings(){ $totalPrice = 0; foreach($_SESSION['items'] as $key => $value){ ...

Tips on capturing a URL using JQuery

Currently, I am in the process of importing an external HTML file into my webpage. Within this file, there is a JavaScript method linked to a form submission event. function ValidateInput(){ //some code if(validationFailed){ ...

What is the best way to implement rate limiting for Next.js server actions?

In my current project, I have implemented server actions in next.js following the guidelines provided on Server Actions Although everything is functioning properly, I am now looking to add rate limiting to the server action to prevent potential spam or at ...