Display complex 3D models using three.js

This question is widely known, but unfortunately, I have been unable to find a satisfactory answer.

My Approach

I utilize three.js for showcasing 3D models generated from drone images (example here).

The Issue

I face difficulty rendering large models (1M vertices, 2M faces) as Chrome or WebGL crashes.

Attempted Solutions

I conducted tests using examples from Threejs.org to ensure it wasn't an issue with my code. These tests were carried out on a x64 Chrome with the --max_old_space_size=6144 flag.

  • Importing model in .dae format using ColladaLoader results in the utilization of 2.5GB RAM and Chrome crashing due to insufficient memory.
  • Importing model in .obj format with OBJLoader + MTLLoader consumes 2.8GB RAM leading to WebGL crash.
  • I read numerous posts about Three.js and memory allocation, however, most focus on removing objects from the scene which is not applicable in this scenario.

Potential Resolutions

  • .stl (binary) files are more compact, but lack texture support which makes them unsuitable for my use case.
  • Using BinaryLoader with GeometryBuffer output requires converting .dae or .obj files to binary, a process I am unfamiliar with.
  • Breaking down the model into multiple parts for incremental loading could be an option, although I haven't found any references supporting this approach.

Reproduction Steps

For coding, I refer to basic examples on Threejs.org. Regarding models:

  • If experimenting with .dae files, you can access working and non-working examples in this folder.
  • Similarly, if dealing with .obj files, check out samples in this folder.

Any suggestions on how to load the larger model? Thanks!

EDIT 1 :

To determine if the RAM overload occurs during or after the load, I attempted to set a breakpoint in the SuccessCallback without success. This suggests that the RAM overuse transpires before reaching the SuccessCallback.

I proceeded to delve into the ColladaLoader step by step to identify what's consuming excessive RAM. Here is the "callstack":

  • myCollada.load()
  • ColladaLoader.parse()
  • Geometry.parse()
  • Mesh.parse()
    • Source.parse (triggered 3 times) = +400MB in RAM
    • Vertices.parse = no increase in RAM
    • Triangles.parse = +1500MB in RAM
    • this.geometry3js.computeVertexNormals() = RAM exceeds 2600MB causing Chrome to crash

Are there any other tests I can perform to pinpoint the root cause of this problem? Thank you.

Answer №1

Your textures are way too large, and there is no need for them since your model already has baked vertex colors with lighting included. UV mapping is unnecessary for your model.

Try using ColladaLoader2 along with this method. It should do the trick.

var loader = new THREE.ColladaLoader();

loader.load( 'BigModel.dae', function ( collada ) {

        var dae = collada.scene;

        dae.traverse( function( child ) {

            if ( child instanceof THREE.Mesh ) {

                child.geometry.removeAttribute( 'uv' ); // not needed

                child.material = new THREE.MeshBasicMaterial( { // scene lights not necessary

                    vertexColors: THREE.VertexColors // utilize the baked vertex colors

                } );

                scene.add( child );
            }

        } );

} );

Using three.js r.86

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

Prevent the add to cart button from being clicked if the product is out of stock in Laravel

How can I control the cart button's availability based on the contents of the cart? @if (!isset($data['cart'])) <div class="tt-cart-list"> @if( isset($data['cartlist']['count'])) @ ...

Is it possible to use Three.js camera lookAt function without any rolling?

In my game, there is a square level where a ball can roll around. I am trying to adjust the camera position so that it follows the ball but always looks at 0, 0, 0. Moving the camera x and z towards the ball's position gets me close, but as seen in th ...

Guide to initializing modules in Angular 2+ using server-side responses

I used to initialize my Angular JS application by making a server call to fetch the user's access modules. I'm struggling to do the same in Angular 2+. Here is an example using AngularJS I only used ngMockE2E for demonstration purposes. (fu ...

Finding the data type based on the button clicked with javascript: A beginner's guide

I am trying to work with a PHP function that generates dynamically created divisions. Each of these divisions contains a different data type and a button. How can I extract the data type of a division when the user clicks on the submit button using JavaScr ...

Assign the values from the axios response to variables within the exported const

Currently, I am incorporating axios into my vue.js application to perform an HTTP POST request and retrieve some variables for a vue-echart. However, I have encountered a bit of a roadblock in determining the most effective approach. The snippet below is ...

Encountering issues with postback functionality on an ASP.NET webpage while attempting to integrate Google

Creating a small web app using ASP.NET has been going smoothly, until I encountered an issue with LinkButton controls after adding Google Analytics code to one of my pages. Every time I click on a link button, I receive this error message: Microsoft JSc ...

arrange data based on table heading using vue.js

I've recently upgraded to Vue 2.x and found out that the orderby directive is no longer supported as per this documentation. I'm trying to avoid adding another JavaScript library, but if using lodash is the only option, I'm willing to give ...

Is there a way to implement full-page scrolling in Vue?

Looking for a Vue equivalent of the fullpage.js library. Need a component that allows scrolling through elements similar to fullpage.js. ...

How to retrieve the current event handler's value with jQuery

To assign an onclick event handler using jQuery, I simply use the following code: $('#id').click(function(){ console.log('click!'); }); Now, my question is how can I retrieve a reference to the function that is currently handling th ...

Arrangement of watch attachment and $timeout binding

I recently encountered a component code that sets the HTML content using $scope.htmlContent = $sce.trustAsHtml(content). Subsequently, it calls a function within a $timeout to search for an element inside that content using $element.find('.stuff' ...

jQuery - Error: Unexpected token SyntaxError

I'm new to jQuery and facing a challenge with an AJAX request. I have a server on my local network running a Python service. When I make a request to the server through the browser using the URL: http://192.168.0.109:5000/api/environment?seconds=10 ...

Guide on how to set a custom image as the cursor when clicking on an image through javascript

Does anyone know how to use javascript to change the cursor to a custom image by updating the cursor property of the entire page? I'm getting an error in the Chrome console that says: projetFinalPage1.html:626 Uncaught TypeError: Cannot read property ...

Having trouble bringing in icons from the @mui/icons-material library

An error occurs when attempting to run the code. wait - compiling... error - ../../../../../node_modules/@mui/icons-material/esm/utils/createSvgIcon.js:1:0 Module not found: Can't resolve '@mui/material/utils' null Note: @mui/material pack ...

Please enter a string and I will locate it within an array. If found, I will provide you with information about that string as a fact

I have a specific challenge I need help with. I have a pre-defined array that contains country names and corresponding facts about each country. What I am trying to achieve is to check if the user-inputted word matches any of the countries in my array, a ...

The Facebook login pop-up is not visible, however, it is still delivering on its promise

I am currently utilizing the Angular Facebook service found at this link. Within my controller, I am attempting to invoke the method $facebook.login() when a button is clicked using ng-click. Although the promise is returned and the code inside is execute ...

Calculating the distance of the camera in Three.js with respect to the size of the object

Trying to figure out the optimal camera distance from my object3D, a set of meshes, to frame the entire model in the viewport. To get the object3D size: public getObjectSize ( target: THREE.Object3D ): Size { let box: THREE.Box3 = new THREE.Box3().setF ...

Transform a key:value string with multiple lines into a JSON format

I need to convert a multiline key:value string into JSON so that I can use it to create HTTP headers for an ajax request. Here is a sample data: content-type:text host:myhost.com I want the output to be: {"content-type":"text", "host":"myhost.com" } I ...

Customizing Webpack 4's Entry Point

Below is the layout of my project: -node_modules -src -client -js -styles -views -index.js -webpack.config.js -server -.babelrc -package -package-lock -README.md -webpack ...

Error: Encountered an unforeseen symbol '<' during AJAX request

I'm in the process of creating a JavaScript array to help me determine the online status of various streams. However, whenever I attempt to alert the output, I keep encountering an unexpected token '<' error at line 1 of my document. It&a ...

The manipulation of geometries in Three.js through rotation and positioning

I have been working on exporting a 3D plant modeling software to Three.js, but I am struggling with the rotations and translations of the objects. So far, I have experimented with using quaternions and transformation matrices, but neither approach has yie ...