Is there a way to verify if a node within the scene includes a geometryid that matches?

In my code, there is a function that runs through my scene in search of a specific node. When it finds this node, it goes through its children and checks if any of them have properties like geometry or material. If they do, I use the dispose() method to remove those children.

Now, before calling dispose(), I want to compare the geometry.id of the child with the geometry ids of other children in the scene. If there is a match, then instead of disposing it, I just remove it. However, if there are no matching geometry ids, then I proceed to call dispose() and remove the child.

Answer №1

One possible solution could be implementing reference counting.


var objectCounts = {};

// Increase count when adding a new mesh
objectCounts[mesh.geometry.id] = (objectCounts[mesh.geometry.id] || 0) + 1;

// Decrease count when removing a mesh
objectCounts[mesh.geometry.id]--;
if (objectCounts[mesh.geometry.id] == 0) {
    // It is now safe to dispose of the mesh
}

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

Vue Template ref Error: Unable to access scrollHeight property of null object

I'm currently working on creating a responsive sidebar in Vue, and I encountered an issue after refactoring my project to remove the state.js file. The problem is related to the dropdown/collapse elements, and it's throwing a TypeError: Cannot re ...

Preserving specific image status when closing a popup in a React component

I'm currently facing a challenge with a React component involving image uploading functionality. The issue arises when a user chooses an image using the file input, and the selected image gets displayed in a popup. However, upon clicking the closePopu ...

What is the best way to implement validation for ngModelCtrl based on user input within a directive?

I have created a unique directive and I am looking to incorporate the validators from an input field used within this directive template. Is there a way to expand ngModelCtrl validators with the input validators? This is my custom directive implementation ...

Troubleshooting issues with Ajax and Jena

Whenever I attempt to utilize AJAX to call Jena in my servlet, I encounter this error: java.lang.ClassNotFoundException: com.hp.hpl.jena.sparql.core.Prologue at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516) at org.apa ...

What is the most effective way to show an error message within the login form itself?

I'm currently dealing with a dilemma involving my login.php and login_process.php files. The login form is in the former, while the validation process occurs in the latter. I'm struggling to figure out how to display error messages on the login f ...

Clear out duplicate elements from array instruction

I am currently working with a div that displays names and I need to remove any duplicates from my array. I have successfully achieved this with a filter, but now I would like to explore creating a directive to extend this functionality. <div ng-control ...

The depth buffer in Webgl FrameBuffer is not being cleared properly

Currently, I am working on developing a 2D sprite renderer that utilizes render textures for custom compositing. However, I have encountered an issue where the depth buffer on the FrameBuffer is not clearing properly. Due to this, all the sprites leave a p ...

Jquery Visualization Chart not displaying

I am struggling to get the jquery visualization to work properly. Although the table and caption appear fine, there is no data showing up in the chart. I've carefully followed the example and searched for any issues, but I can't identify what&apo ...

How can you access the URL of a resource action in Angular?

In my Angular application, I have created a resource named 'Files' with the following definition: app.factory('Files', function($resource) { return $resource('/api/accounts/:account_id/sites/:site_id/files/:file_id'); }); ...

Generating a sequential array of dates and times in Angular

Currently, I am working on implementing a feature that will allow users to see the available visit times between two dates they select, specifically from 8:00 to 17:00 every day. For instance: If a user selects 1 Sep to 4 Sep, the system should return [1. ...

Toggle a div using jQuery with a distinctive identifier

I need to display all products that a client has ordered from the database and I want to be able to show/hide them when clicking on a specific div element. http://prntscr.com/7c5q6t Below is my PHP code which displays all the ordered products: <td cla ...

I'm working on an Angular2 project and I'm looking for a way to concatenate all my JavaScript files that were created from TypeScript in Gulp and then include them in my index

How can I concatenate all JavaScript files generated from typescript in my Angular2 project with Gulp, and then add them to my index.html file? I am using Angular2, typescript, and gulp, but currently, I am not concatenating the javascript files it genera ...

Sharing information between controllers from diverse modules

We are currently in the process of developing a Telecom App dashboard. Our goal is to retrieve logs using Logstash and Elastic search, and then present them on the UI using the ng-Table directive of Angularjs. While we have successfully obtained the logs, ...

I'm interested in knowing if it's feasible to develop unique jQuery selectors that can navigate ancestors, such as a :closest or :parents selector

As a developer who frequently creates jQuery plugins, I often find myself using custom jQuery selectors like :focusable and :closeto to simplify common filters in my code. For example, the :focusable selector is defined as follows: jQuery.extend(jQuery.e ...

How can I iterate through a dictionary and then apply a function to the values in each key of the dictionary?

I have a Data Set that contains Objects and Arrays: {React Basic Structures: Array(2)} Or {"React Basic Stuructures": [{"Topic": "send_AAFBLrk_f0NHXdU.mp4"}, {"Topic": "send_zHeTppE.mp4"}]} I am lookin ...

The react-editor-js encountered an issue: "Attempting to invoke a class as a function is not allowed."

Trying to configure an editor using react-editor-js has been quite the challenge. After installing react-editor-js, @editorjs/editorjs, and nearly every official editor.js plugin, I thought I had everything I needed. Within my code, I've implemented ...

Is there a way to incorporate a Laravel foreach loop within a JavaScript file?

I recently added a select-box using jQuery: <span onclick="createProduct()">Add New<i class="fa fa-plus"></i></span> <script> function createProduct() { var html = ''; html += ' <div clas ...

Ensure the browser only reloads a single file

In the midst of my project, I realized that the CSS and JS files are being loaded separately onto the webpage with query strings like .css?1234 to ensure the browsers refresh the files on load. However, upon returning to the project, I discovered that one ...

The alternating colors in the sorting table are not visible due to the divs being hidden with the display set

I've come across a problem that has me stumped. So, there are two sorting filters on a table and one of them hides rows that don't apply, messing up the alternating colors. Take a look at the function that sorts and the CSS below. The issue is pr ...

The scope of this variable in Node.js results in an undefined response

Have you ever noticed the difference in behavior when executing JavaScript code in Google Chrome's console compared to running the same logic in a file using Node.js? function foo() { console.log( this.bar ); } var bar = "global"; foo(); In Chr ...