Combining Imported Models in Three.js: A Guide

I'm working on optimizing the draw calls in my THREE.js scene by reducing the amount of rendering required. I have a grid of large 32x32 tiles that are .gtlf models imported from the disk. Each tile has a model with just 8 vertices and a texture. However, when inspecting the canvas using tools like Spector, I noticed that there are 151 draw calls being made, with each model being rendered separately.

These tiles are generated by looping through the grid for every tile, checking if it needs a model, and then retrieving the model data from a Map where it was loaded using THREE.GLTFLoader. Occasionally, the material or rotation of the tiles may change, but only during setup.

Since these tiles will remain static and do not require any transformations, I am looking for optimization techniques to group the rendering of these tiles into as few draw calls as possible, considering they are essentially the same object.

Answer №1

To combine your tiles into a single geometry, you can use the following approach:

Try something like the code snippet below:

const mergedGeometry = new THREE.BufferGeometry();
tiles.forEach( tile => {
  const geometry = tile.geometry.clone();
  geometry.applyMatrix(tile.matrixWorld);
  mergedGeometry.merge(geometry);
});

If you have multiple materials and textures, you will need to find a way to handle them as well.

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

Regex tips: Matching multiple words in regex

I am struggling with creating a simple regex. My challenge is to write a regex that ensures a string contains all 3 specific words, instead of just any one of them: /advancebrain|com_ixxocart|p\=completed/ I need the regex to match only if all thre ...

Unlocking the secret dropdown menu with Java Selenium WebDriver

Is there a way to retrieve a hidden dropdown menu on a webpage using selenium webdriver? The process involves selecting an option from a navigation bar, which triggers the appearance of the dropdown menu. I then need to choose a value from the list on the ...

Create a password variable while typing

Looking to avoid interference from browsers with autocomplete and password suggestions while maintaining the show/hide letters feature. The goal is to keep the password stored as a variable, regardless of whether the characters are shown or hidden. The is ...

Angular 5 - Strategies for excluding specific properties from Observable updates

Currently, I am in the process of developing a webpage where users can view and like various videos. The video content and user likes are stored in a database, and I have implemented two Angular services for handling data retrieval and storage. However, I ...

Create a customizable Tree structure that includes checkboxes for each item and features drag

I am currently working on incorporating a Tree view with checkboxes and drag & drop functionality in Vue. However, I am unsure of where to begin. While I have successfully implemented checkboxes, I am struggling to figure out how to enable the feature whe ...

Converting PHP JSON encode to an Ajax array proved to be quite challenging for me at first, as it was a new concept to

Managing Students Data public function retrieveStudentsInformation() { $studentsData = $this->member->getStudentsPosts(); $formattedStudents = array(); for($i=0; $i<count($studentsData); $i++) { $formattedStudents[$i][&a ...

Building a custom search modal using RenderPartial in Yii

I'm currently working on developing a modal box that will enable users to filter and search through a grid. The main objective is to allow users to retrieve information from one database while simultaneously completing a form in another database. Alt ...

retrieving the value of a field within an array

Here is my code snippet: <div class="label">{{ item.data[0] }}</div> and in the view, this is what I have: { "id": 6, "firtname": "JHON ", "lastname": "SCALA", "fullname& ...

The field "addWorkout" cannot be queried on the type "Mutation"

My journey with GraphQL has just begun, and after resolving a reference error in my previous question, I have encountered a new challenge. It appears that adding a workout is not working as expected, as the schema does not recognize it as a mutation field. ...

The useEffect hook is executed only once and will not fetch data again upon refreshing the page

There's this component in my project that fetches data from a website and attempts to extract its keys. The issue I'm facing is that it functions correctly the first time, but upon refreshing the page or saving the project in VSCode (which trig ...

I purchased a code that was functioning properly on JQuery 1.3.2, but now it's not working on version 1.5. What steps

I purchased a gallery photo popup code about six months ago that included jQuery 1.3.2. It functions well with jQuery 1.4.1 as well, but anything beyond that version results in the big photo not opening when clicked. I have some knowledge of Javascript edi ...

Encountering difficulties with updating an object in Angular

Currently, I have the ability to generate objects and store them in a rails database using a json api. The application is a basic todo list where adding an object places it into the todo list above the input fields. Furthermore, I can access all objects on ...

Apple Safari 14.0.3 restricts JavaScript from setting a cookie expiry date beyond one week from the current date

This is my second time reaching out with this question, but after plenty of trial and error experimentation, I have gathered much more information to share. I have been attempting different methods to set a cookie in Safari using JavaScript 'document ...

When the background image URL is altered, the button size automatically adjusts

Presently, I am working with a button <input id="fireAction" type="button" class="submit" onclick="disableSubmit('preFlight');"><br> Afterwards, I modify the background image of the button under different circumstances For example ...

IsContainer and IsModel properties in Dragular are not functioning properly with the accept or canBeAccepted methods

Scenario 1 : Let's consider using two containers, named A (Drag Source) and B (Drop Source). Code snippet : dragularService(containerLeft, { containersModel: [DragularconTainer], copy: true, canBeAccepted: function(el, source) { ...

Interacting with HTML elements in Java programming

I am facing a challenging situation that requires some brainstorming. I would greatly appreciate any advice or guidance in the right direction. My goal is to incorporate a Google Map into my Java Swing project, with the map being specified as a URL wit ...

Using v-bind:class in Vue.js does not successfully assign a value in the method

Why is the width of my div not changing when I try to bind it to a data attribute that ranges from 0 to 100? <div class="bar" :style="{ width: percentage + '%' }"></div> <script> export default { name: 'app&ap ...

The Checkbox handler in Material-UI component fails to update the state - Version 5.0

Hey everyone, I'm facing an issue with my "Checkbox" component in React. After clicking on it, the state doesn't update to 'true' as expected. The checkbox works visually in the DOM but the state remains 'false'. Can someone p ...

Encountered a MongoNetworkError while attempting to establish a connection with the server at localhost:27017. The initial connection failed due to an ECONNREFUSED error at 127.0.0.1:

Encountered a MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017 If I reinstall MongoDB, the code works fine. However, I am looking for a permanent solution. [error:MongoNetworkE ...

Using the getAttribute method in Edge with JavaScript

My goal is to dynamically load videos on the page after it has fully loaded. I have a script that successfully works in Firefox and Chrome, but I encounter errors when using Edge/IE. The specific error message I receive is SCRIPT5007: Unable to get propert ...