How to delete vertices and their properties from a BufferGeometry using Three.js

In my Three.js project, I have a large collection of point cloud forms grouped together in a single Points object for efficient rendering using BufferGeometry in WebGLRenderer. The program allows users to interactively select a form from the point cloud, which should disappear and be replaced by a new form.

To achieve this functionality, I loop through the ID numbers assigned to each vertex to identify and remove the vertices associated with the selected form. I then slice the corresponding elements from the attribute arrays within the BufferGeometry and update them to reflect the change. However, after editing the arrays, I encounter erratic behavior where the forms seem to recede from the screen in a patchy manner instead of disappearing as intended.

I'm questioning whether the array length once uploaded to the graphics card is fixed or dynamic, as I've been struggling to find a solution to this issue for several days now. Below, I've isolated the key functions that appear to be causing the problem:

function extractFormFromTypedArray( startIndex, endIndex, itemSize, typedArray ) {
    // Logic to remove selected points from the array
}

function swapForm( formID ) {
    // Function to swap out the selected form
}

Running on Three.js v74

Answer №1

After reading @WestLangley's insightful comment, I finally understand the situation at hand. It seems that once buffers are set to a fixed length, they cannot be resized to accommodate additional values or remove existing ones. However, based on the helpful information provided in this link, there is a workaround that involves emulating buffer editing:

It is important to note that you can only update the content of buffers and not resize them (as it incurs significant costs similar to creating new geometry).

To mimic resizing, you can pre-allocate a larger buffer and then mask out unnecessary vertices by collapsing or hiding them.

Make sure to set flags only for attributes requiring updates as these operations can be resource-intensive. Once buffer changes occur, these flags will automatically reset to false. If ongoing updates are needed, remember to set them back to true.

Many thanks for the valuable insights!

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

I am encountering an error with setTimeout(): Timeout { _called: false }

I have been experimenting with creating a function that generates a random number and then adds 5 to it after a 3-second delay This is what I have attempted: const add5 = (randomNum) => { return randomNum + 5 } // Function for you to get start ...

Whenever I press the view button, all the cards open instead of just the one I chose from the index. Can anyone tell me where I am going wrong?

I've encountered an issue with the View buttons I added to display more detailed information about the characters in the card bodies. When I click on the view button, it opens all the boxes instead of the one I selected. I've tried using a for lo ...

Verifying Array Position Availability with Python's Boto Library

I attempted to create a specific list of AMI and save it in an array. usubuntuamilist = {} for i, image in enumerate(conn.get_all_images()): if image.location.startswith("ubuntu-images-us/ubuntu-lucid-10.04-i386-serve"): print "%s - %s" % (i, ...

What is the appropriate way to notify Gulp when a task has been completed?

I have been working on developing a gulp plugin that counts the number of files in the stream. Taking inspiration from a helpful thread on Stack Overflow (source), I started implementing the following code: function count() { var count = 0; function ...

Looping through an array of nested objects using Vue

I have encountered a challenge with accessing specific data within an array that I am iterating over. The array is structured as follows, using Vue.js: companies: [ name: "company1" id: 1 type: "finance" additionalData: "{& ...

Displaying images retrieved from firebase on a React.js application

Currently, I am attempting to retrieve images from Firebase storage and then exhibit them in a React component. As a newcomer to React/Javascript, I find it challenging to grasp the asynchronous nature of React/JS. The issue I'm facing is that althoug ...

Storing Vue.js components as objects in a database: A step-by-step guide

Is there a way to serialize Vue.js components and store them in a database? For example, I am looking to save components like the HelloWorld component typically found in a fresh Vue installation. Any suggestions on a serialization process or package that ...

Issue: Headers cannot be set after they have been sent. This is a problem in node.js

I'm trying to create an application that allows users to execute commands via a URL, but I keep encountering this error message: _http_outgoing.js:346 throw new Error('Can\'t set headers after they are sent.'); ^Error: Can't ...

Python code to transform an integer array into a binary array

I'm attempting to convert an array of integers into binary format using Python 2.7. Here's a simplified version of the code I'm working with: #!/usr/bin/python import numpy as np a = np.array([6, 1, 5, 0, 2]) b = np.zeros((5)) for i i ...

The Ajax success callback is failing to update the background-image property after receiving a successful JSON response

I am struggling with setting a background image in wordpress despite receiving a successful ajax response. The image url is being returned successfully in the json response, but I can't seem to set it as a background image. Here is the ajax function ...

Creating a custom function that targets a specific element

When working with JavaScript, you may often encounter functions written in the form of document.getElementById("element").someFunction(); or $("element").someFunction(); rather than the traditional someFunction($("element"));. This is similar to a function ...

Is it possible to utilize $.each() in combination with $.ajax() to query an API?

I am dealing with an array containing 2 values, and for each value, I need to make an AJAX query to an API to check the stock availability. If there is stock for both values, a certain message should be executed, otherwise, a different message. This check ...

Boot up 4 collapse feature to conveniently close all other collapsible items at once

Utilizing the Bootstrap 4 Collapse component. My goal is to toggle between collapsible sections like "Categories" and "Brands", displaying only one at a time. The current issue is that multiple collapsible elements are visible simultaneously. .view-cust ...

Is there a way to tally the frequency of a specific property appearing in one array within another, and then transfer those matches into a separate array?

My goal is to match the fk_city with the $id of each city in the 'list_cities' array, and then calculate the number of occurrences. const list_cities = [ { $id: '15FG', name: 'Pittsburg' }, { $id: '50HS', name: & ...

Implement a mandatory route in Express

Is it possible to enforce a specific route? Scenario: Consider the following route A: notiSchema = notification model router.get('/set', function(req, res){ User.findById("userId", function(err, foundUser){ foundUser.notiSchemaSen ...

The client sent a risky Request.Path value that raised red flags

For a university project, I am attempting to access an English translation of the Quran from quran.com using the provided link: Although this link works correctly when entered directly into a browser, I encounter an error when trying to use it in my Angul ...

ADVENTURE BLOCKED - Intercept error: net::ERR_BLOCKED_BY_CLIENT

I've encountered an issue where my initialize function doesn't run properly when a user has an ad blocker enabled. It seems that the ads-script.js file is being blocked by the client with a net::ERR_BLOCKED_BY_CLIENT error, leading to my .done ca ...

Exploring the functionality of a Vue component designed solely through a template

I currently have a basic Vue application set up: <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'& ...

Preloading web page with Flash animation for seamless transitions and stylish fade in/out effects

My customer is requesting a loading animation or movie (already created in Flash CS5) to be displayed on the initial page of the website (root, '/' - the first thing visitors see when they go to domain.tld). After the animation finishes, it sho ...

A step-by-step guide on incorporating Google Ads Manager Ads units (Banners) into your website with NuxtJs and VueJs

I currently have an Ads unit set up on my website <script type="text/javascript"> google_ad_client = "ca-pub-2158343444694791";/* AD7 */ google_ad_slot = "AD7"; google_ad_width = 300; google_ad_height = 250; </script ...