Combining three.js geometry and selecting objects with an octree

I have been utilizing Three.js to showcase a variety of custom geometries in different positions and rotations. These geometries are static and do not change frequently, but users have the ability to manipulate them by adding, deleting, or altering the shape of each individual object.

So far, I have been successful with the following code snippet:

var Mat=new THREE.MeshBasicMaterial( { color: 0xffff00, wireframe: false, opacity: 0.5 , transparent:true} )
var Geo=new THREE.CubeGeometry( 20, 100, 20 )
var Mesh=new THREE.Mesh(Geo, Mat);

//Applying rotation
m = new THREE.Matrix4().set(0.3,-0.3,0,0,0.3,0.3,0,0,0,0,1,0)
Mesh.applyMatrix(m);
Mesh.updateMatrix();

Mesh.position.x=50;
Mesh.position.y=50;
Mesh.position.z=50;
octree.add(Mesh);
Mesh.updateMatrix();

scene.add( Mesh );

The above method works fine, though it encounters challenges when dealing with a large number of objects. As per:

By merging the objects, I have experienced significant speed improvements, enabling smooth operations even with 10,000+ objects. However, I am currently facing difficulties with setting up selections again.

Based on the aforementioned link, maintaining the mesh in an array or octree facilitates selection while retaining the speed advantages of merged objects. Although I already have an octree in place, using it for selection proves to be challenging as the selection objects seem to lose their position relative to the merged scene object(s). The selection objects appear at the origin, indicating that the octree may not retain the position, and possibly the rotation, of its objects. The snippet below illustrates this issue:

var TotalGeo = new THREE.Geometry();
//Adding Objects
var Mat=new THREE.MeshBasicMaterial( { color: 0xffff00, wireframe: false, opacity: 0.5 , transparent:true} )
var Geo=new THREE.CubeGeometry( 20, 100, 20 )
var Mesh=new THREE.Mesh(Geo, Mat);

//Applying rotation
m = new THREE.Matrix4().set(0.3,-0.3,0,0,0.3,0.3,0,0,0,0,1,0)
Mesh.applyMatrix(m);
Mesh.updateMatrix();

Mesh.position.x=50;
Mesh.position.y=50;
Mesh.position.z=50;
octree.add(Mesh);
Mesh.updateMatrix();

//scene.add( Mesh );
TotalGeo.merge( Mesh.geometry, Mesh.matrix );

//Adding merged geometry 
var total = new THREE.Mesh(TotalGeo, Mat);
scene.add(total);

The manual adjustment of rotation and position remains crucial for the custom geometry. Any suggestions would be greatly appreciated! Thank you

Answer №1

For optimal performance with your octree, ensure that undeferred is set to true. Here is an example of how to do it:

octree = new THREE.Octree( {
    undeferred: true,
    depthMax: Infinity,
    objectsThreshold: 8,
    overlapPct: 0.15
  } );

Following these instructions should help you achieve the desired outcome!

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

unable to include Cross-Origin header in ajax request

Whenever I include the HTTP_X_REQUESTED_WITH header in my ajax requests to another server, I encounter an error stating: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.xxxxxxxxxxxx.com/checkurl.php? ...

Dealing with an empty request.FILES using FileUploadParser in Django Rest Framework and Angular file upload technique

Uploading files in an angular view can sometimes be tricky, especially when using templates. The code snippet below shows how to upload multiple and single files using Angular File Upload library. Multiple <input type="file" name="file" nv-file-select= ...

Is there a way to remove a dynamically rendered component from a list?

Whenever I click a button, the same component is dynamically rendered on top of the list. But now, I need to implement a feature where users can delete any component from the list by clicking a cancel button associated with each component. Here's my ...

How to extract part of a string delimited by certain characters within GET parameters?

I have a requirement to modify an iframe src attribute generated dynamically by a BrightCove video player. Specifically, I need to eliminate certain GET parameters such as width and height, so that the width and height of the parent element take precedence ...

I am unable to get the radio button checked in Angular 2

I have set up a form with two radio buttons for gender selection, and I want to ensure that the previously selected option is displayed as checked. Here's the code snippet I've added in my template: <div class="form-group"> <label& ...

"Emphasizing the Html.ActionLink menu for improved user navigation and

Currently, I am facing an issue with my menu. I want to clear previously visited links while keeping the current one styled as a:visited in CSS. Although I have attempted to achieve this, unfortunately, the code is not functioning properly. Here is what I ...

What is the best way to start data in an Angular service?

I'm currently navigating my way through building my first Angular application. One of the services I am using needs to be initialized with a schema defined in its constant block, but the schema/configuration is not yet finalized. Therefore, I am perfo ...

Transmitting an email form using AJAX, Bootstrap, and Jquery

I am attempting to email a form using the code snippet below. This is a modified version of Bootstrap Validator created by 1000hz. $('#form').validator().on('submit', function (e) { if (e.isDefaultPrevented()) { alert("not workin ...

Error: Primefaces ajax status failure (dialog has not been defined)

I incorporated the same code found on primefaces.org, specifically this link: http://www.primefaces.org/showcase/ui/ajaxStatusScript.jsf <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/> <p:dialog modal="true" ...

align all items centrally and customize Excel columns based on the length of the data

Is there a way to dynamically adjust the column width based on the length of data in an Excel report using PHPexcel? Additionally, how can I center all the data in the Excel sheet? Here is the current code snippet: <?php if (!isset($_POST['send&a ...

Retrieve a single element from each array stored in MongoDB

Can someone help me with a query in MongoDB? I have a document structure like this, and I am looking to utilize the $addToSet operator to add a value to one of the items within the 'votes' field. However, I also need to remove that value from all ...

Utilizing _.partial on a single-argument function

Currently, I am in the process of refactoring code within a react.js application. There is an element that utilizes Underscore.js _.partial on a function that already has one argument. Is there any real benefit to doing this? I can see how it works based ...

Split the string into individual parts and enclose each part in HTML using JavaScript

Currently, I am utilizing a content editable div to create tags. Upon pressing the return key, my objective is to select the preceding text (excluding the prior tags) and transform it into a new tag. The format for a tag will be enclosed within . For insta ...

What is the best way to combine multiple periods into a single range?

I am on a quest to find a way to transform sound frequency into light frequency, essentially turning sound into color. Currently, I have managed to come up with a straightforward formula that converts the sound frequency into the light frequency range: co ...

Troubleshooting a problem with AJAX returning the data

Currently, I have a javascript function that calls another javascript function called zConvertEmplidtoRowid. This second function utilizes an ajax call to execute a query and retrieve data stored in a variable named rowid. My challenge lies in figuring out ...

What is the best way to link the width and height of a div with form fields?

I need to implement a feature where I can create multiple div elements that are draggable and resizable, and have their properties like width, height, etc. linked to corresponding objects in an array. For example, if I create six divs, there should be six ...

While creating a NodeJS backend to complement a ReactJS frontend, I am continuously encountering a 500 error

I've been testing my NodeJS backend with Insomnia and it's working perfectly fine there. However, whenever I try to access the frontend, I keep getting a 500 error. It's puzzling because the endpoint is functioning correctly in the testing p ...

Is there a way to prevent the context menu from appearing when tapping on an image on a mobile phone?

When attempting to move an image on the screen with a touch event, a popup appears in Chrome when pressing and holding the image. This popup usually includes options to save the image. Is there a way to disable this popup so I can freely move the image w ...

Tips for retrieving the 'Created' value in vue.js

I am currently trying to fetch API JSON data for a weather widget, but unfortunately it is returning null. While I am able to retrieve the JSON data successfully, I am struggling to handle this value. Below is my HTML code snippet: <html> <head& ...

Implementing ui-sref-active for intricate routing states

I have implemented the menu link using AngularJS and UI-Router. <li ui-sref-active="active"> <a ui-sref="dashboard" title="Dashboard"><i class="fa fa-lg fa-fw fa-home"></i> <span class="menu-item-parent">Dashboard</spa ...