What is the method for identifying the points where two faces of two bufferGeometryBox objects intersect?

I am currently working on a 3D configurator project. In this project, a cube is initially displayed on the scene. When a side of the cube is clicked, a rectangle is supposed to appear. However, the issue I am facing is that upon clicking the same side of the cube, another rectangle overlaps the existing one. I am looking for a solution to prevent this overlapping by blocking the clicked side. The geometry of my cubes and rectangles is buffer-based. I have the ability to obtain raycasting data such as face (a,b,c) and faceIndex. But I am unsure about how to calculate the intersection of two different faces belonging to two separate objects. Apologies for any language mistakes in my explanation.

For those interested, you can find more about my project here

https://i.sstatic.net/woZCs.png https://i.sstatic.net/5NMda.png https://i.sstatic.net/UEQQM.png

Here is a snippet of my code:

if (intersect) {
            var index = Math.floor( intersect.faceIndex / 6 );
                if ( intersect.object.name == 'cube' ) {

                    switch (index) {
                        case 0: load( intersect.object.position.x + 6.58, intersect.object.position.y, intersect.object.position.z, 'beam', 0, 0, 0 ); break;
                        case 1: load( intersect.object.position.x - 6.58, intersect.object.position.y, intersect.object.position.z, 'beam', 0, 0, 0 ); break;
                        case 2: load( intersect.object.position.x, intersect.object.position.y + 6.58, intersect.object.position.z, 'beam', 0, 0, 90 ); break;
                        case 3: load( intersect.object.position.x, intersect.object.position.y - 6.58, intersect.object.position.z, 'beam', 0, 0, 90 ); break;
                        case 4: load( intersect.object.position.x, intersect.object.position.y, intersect.object.position.z + 6.58, 'beam', 0, 90, 0 ); break;
                        case 5: load( intersect.object.position.x, intersect.object.position.y, intersect.object.position.z - 6.58, 'beam', 0, 90, 0 ); break;
                    }

                }

Answer №1

It is likely that the duplicated newly created object will share the same global position as the original one. You can refer to the documentation for more information on this. To address this issue, you can iterate over the existing objects and compare their positions. If the positions match or have only a slight difference, take appropriate action.

For efficiency, consider storing the global position values of objects in a list upon creation. This way, you can iterate over the list for comparisons instead of traversing the objects directly.

Answer №2

take a look at this pseudo-code that explains the concept:

let newObj = createObject(...);
mainObj.append(newObj);
newObj.setPosition(new_x, new_y, new_z);
let globalPos = new THREE.Vector3();
newObj.getGlobalPosition(globalPos);
for (let j = 0; j < positionsArray.length; j++){
    if(     positionsArray[j].x === globalPos.x
        &&  positionsArray[j].y === globalPos.y
        &&  positionsArray[j].z === globalPos.z) {
            mainObj.delete(newObj);
            return;
    }
}
positionsArray.push(globalPos);

Answer №3

Sharing this approach could benefit individuals encountering a similar challenge. The strategy involves creating rectangles and cubes with userData containing 6 parameters set to "false". Rays are cast from each face, and if they intersect with a face from another object, that face is marked as "true". Learn more

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

Changing pricing on pricing table with a click

Looking to implement a price changing button that functions similar to the one found at this LINK: If anyone knows of any JavaScript or other solution, please provide me with some guidance. Thank you in advance. ...

Searching by multiple parameters in Angular.js

I have a script that scans through a field and highlights the words related to the search input. I want this script to not only filter by title, but also by name. How can I adjust the code to filter both the title and name when searching? <li ng-repeat ...

Tips for keeping notification icons in the upper right corner of the box?

I am facing an issue with absolute positioning where the notification icons I've positioned to the top-right corner of a box are moving away when the screen size changes. Desired appearance of the image Actual appearance when screen size is adjusted ...

Can you explain the exact meaning of XMLHttpRequest.XMLHttpRequest?

I find MDN's writing style to be confusing. On the MDN page about XMLHttpRequest, it states: XMLHttpRequest is an API ... Constructor XMLHttpRequest.XMLHttpRequest Properties XMLHttpRequest.onreadystatechange XMLHttpRequest.readyState XMLHttpReq ...

What is the best way to send data to a view in Laravel using Ajax?

I am facing an issue with my Ajax function that is supposed to call a Laravel view using the data in $paginatedResults returned from another function. However, it keeps returning error 500. I have confirmed that $paginatedResults has the correct data whe ...

Mapbox GL JS stops displaying layers once a specific zoom level or distance threshold is reached

My map is using mapbox-gl and consists of only two layers: a marker and a circle that is centered on a specific point. The distance is dynamic, based on a predefined distance in meters. The issue I'm facing is that as I zoom in and move away from the ...

Error encountered while trying to authenticate user through post request

I have written a post route request function below to handle user login. However, I keep encountering 401 unauthorized errors when making the request. Can anyone suggest any modifications or refactorings that could potentially fix this issue? Thank you i ...

Automating the process of uploading a file to a Github repository using JavaScript and HTML

Recently, I've been tinkering with updating a file in my GitHub repository using code to set up an automated system for pushing changes without manual intervention. My approach involved creating a function that utilizes a GitHub access token to ' ...

Executing synchronous functions in NodeJS

I've been attempting to retrieve the number of records from a database using Node.js, but I'm running into an issue with synchronous requests. When I try to print the number inside the function, it works fine, but outside the function, it doesn&a ...

Comparing JSON Objects in Javascript

I'm in the process of developing a web application that retrieves data from a server and displays it to the user. The script pulls data from the server every 10 seconds, and if there's any change in the data, it alerts the user. Currently, the co ...

Discovering the solution to populating and building a tree structure using jsTree in conjunction with SQL Server, addressing the challenges associated with the

My current challenge involves using JSTREE to display a list of system modules. The issue arises from the fact that, according to the jsTree documentation, I need to use # in my query to create the tree structure. However, when I execute the following quer ...

Tips for setting a value from an AJAX-created element into a concealed form field

There is a div that contains a button. When the button is clicked, a form appears. The div's id is then assigned to a hidden field within the form. This functionality works for the divs that are present on the page when it initially loads, but it does ...

Having trouble with my basic AJAX request; it's not functioning as expected

I am currently diving into the world of Ajax and I've hit a roadblock: 1. HTML : <body> <form> Username: <input type="text" id="username" name="username"/> <input type="submit" id="submit" /> </form> <scrip ...

Toggle the submit button using jQuery based on the comparison of the jml_automatic field with the id_km field

I recently learned jQuery last month, and now I am working on a form using jQuery to allow users to input gas requests. However, the script is not working to compare the values from #jml_km with #id_km, and the submit button is still not disabled when the ...

Guide on incorporating the ":gt" filter from sizzle into vanilla javascript

I am currently working on adapting a jQuery plugin to be compatible with the AngularJS JQlite API, but I have encountered some challenges along the way. Here is an overview of the plugin: (function (e) { var $product = $('#product'), ...

Conceal the scroll bar while still allowing for scrolling functionality

In this code snippet, I am trying to maintain the scroll position of two blocks by syncing them together. Specifically, I want to hide the scrollbar of the left block while scrolling the right one. If anyone has any suggestions or solutions for achieving ...

What makes the creation of Javascript objects so flexible and dynamic?

Recently, I've been exploring the concept of creating new objects in JavaScript. It's interesting to note that in JS, every object creation is dynamic. This allows you to create an object and then add properties later on. Even fields created in t ...

Tips for implementing Header Authorization on a POST FORM with JS/AJAX/JQUERY

Looking to gather user inputs through a form on my webpage and send those values to a PHP hosted on an external site. The Request maker extension indicates that the Header Authorization is included along with other inputs when data is submitted to the exte ...

What is the best way to achieve consistent alignment in Javascript?

I have been attempting to incorporate HTML code within JavaScript for alignment and styling. Despite searching on Google for 3 to 4 days, I have not found a suitable answer yet. What exactly am I looking for? Here is a snippet of my JavaScript code: funct ...

The initial invocation of the JavaScript function did not run

In my Grails view, I have a script tag set up like this: <script type="text/javascript"> /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( ...