Prevent overlap of plane geometry in Three.js

Within the scene, I have introduced both sphere and plane geometry elements using X and Y coordinates to position the plane geometry. Unfortunately, some of the plane geometries are overlapping each other, causing an issue that needs to be addressed. The goal is to identify these overlapping instances and relocate them to different positions in order to prevent any overlap, all while keeping the X and Y values constant. If anyone could provide guidance on how to solve this problem, it would be greatly appreciated. I have shared the code on jsfiddle but I am unsure how to display the result accurately. An image showcasing the complication can be viewed here: https://jsfiddle.net/lakers1234/ek7fcx9L/https://i.sstatic.net/hrkkm.png

window.onload = createsphere();
function createsphere() 
{
var controls,scene,camera,renderer;

function init() 
{

var spriteResponse = [];
spriteResponse[0] = {ID:1, x: 0, y: 0, name:'Hello'};
spriteResponse[1] = {ID:2, x: 0, y: 0.01, name:'Hello world'};
spriteResponse[2] = {ID:3, x: 0, y: 0.5, name:'los Angles united states of america'};
spriteResponse[3] = {ID:4, x: 0.5, y: 0, name:'Canada'};
spriteResponse[4] = {ID:5, x: 0.25, y: 0.5, name:'London united kingdom' };

scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
//camera.position.y = 1;
camera.position.z = 1 ;             
var width = window.innerWidth;
var height = window.innerHeight;
renderer = new THREE.WebGLRenderer( {antialias:true} );
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);      

/* ------------------------ creating the geometry of sphere------------------------------*/

var radius = 2.5;
var spheregeometry = new THREE.SphereGeometry(radius, 20, 20, 0, -6.283, 1, 1);
var texture =  THREE.ImageUtils.loadTexture ('rbi00000083.jpg');
texture.minFilter = THREE.NearestFilter;
//var spherematerial = new THREE.MeshBasicMaterial({map: texture});
var spherematerial = new THREE.MeshBasicMaterial({color: '#A9A9A9'});
var sphere = new THREE.Mesh(spheregeometry, spherematerial); 
scene.add(sphere);
scene.add(camera);
scene.autoUpdate = true;                
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.minPolarAngle = Math.PI/4;
controls.maxPolarAngle = 3*Math.PI/4;   

}

Answer №1

Referencing an answer on Stack Overflow.

By understanding the quaternion of your camera, you can effectively apply it to your planes.

Start by placing your planes in an array:

var planes = [];

In the animation loop, we will execute the following code:

planes.forEach(function(p){
  p.quaternion.copy(camera.quaternion);
})

Check out this jsfiddle example for a demonstration.

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

Can you please let me know if it's possible to store an ajax function/call for future reuse?

While developing a web app using JavaScript and PHP, I've noticed that I keep rewriting the same ajax calls repeatedly. Is there a way to create a reusable function or variable for these calls, with or without parameters? I'm fairly new to JavaS ...

Animating the scaling of a shape using Three.js

Currently, I am embarking on my JavaScript coding journey and experimenting with Three.js as well. I have created a scale animation for a geometry in order to achieve a subtle breathing effect using the following code: var frame = 0; function animat ...

How to choose elements using jQuery according to their CSS properties?

Seeking a solution to a unique challenge I've encountered. The website I frequent has found a way to bypass my uBlock extension by using a script that generates random element classes, such as: <div class="lcelqilne1471483619510ttupv"></div& ...

How can you implement WriteFile in a GET Request without causing the response to be blocked

During the initialization of the app, I require a specific request to be made. This request entails parsing a portion of the JSON response into JavaScript and then saving it to a file. Simultaneously, the rest of the response needs to be sent to the front ...

The script ceases to function once the page is loaded from a JSON file

I'm facing an issue on my shopping website where the items and products are loaded from a JSON file. The problem is that once the page has loaded, the script fails to work properly. If the items take a little longer to load on the page, the script doe ...

Reacting to the content within a directory through a dynamic TreeView

I am working on displaying the content of a directory inside a material TreeView while parsing it. Here is my current progress: const displayDirectoryContent = (path: string) => { fs.readdir(path, (_: any, elements: any) => { elements.forEach(( ...

Concurrent Openlayers maps in Rails - A Viable Option

I've been playing around with Openlayers maps on my website. The map functionality is working perfectly, but I'm having trouble getting the maps to display correctly on my page. My goal is to show a map in each search result on my screen - one m ...

Printing long contents on Chrome's ion-modal-view is not supported on every page

I have tried various solutions found in articles but have not been successful. Here is an example of one such attempt: @media print { .modal { position: absolute; left: 0; top: 0; margin: 0; padding: 0; visibility: visible; / ...

Cannot assign border to an undefined element - JavaScript

Currently, I am attempting to validate some code using javascript. However, I am encountering a frustrating issue where I keep getting an "Uncaught TypeError: Cannot set property 'border' of undefined". Being relatively new to javascript, I ...

AngularJS: Customizable URL Prefix for Dynamic Routing

I am facing a challenge with my large Angular app that is currently accessible through the following URL: http://myangularapp.com/app/index.html#/ In order to support multiple users, I need to dynamically inject a name into the URL that I will be sharing ...

I have a JSON object with a nested "src" value that I want to display on my webpage using Vue. How can I target and select this specific value?

I am currently working with an API and attempting to access a nested object within the JSON data named "Species Illustration Photo". Inside this object is an "img" property with the source link. How can I display this nested img source in my HTML using Vue ...

Is it possible to transfer an HTML table to a PowerPoint presentation directly from the client

Is there a specific jquery or javascript solution available for converting an HTML table directly into a PowerPoint presentation? So far, the only solution I have come across is html table export, which provides export options for various file formats. H ...

Is it possible to modify the text depending on the chosen option from the dropdown menu

When a user selects "First Name" from a select box, I want the placeholder text 'Enter your First Name' to appear next to the textbox. Below is a snippet of my code: HTML: <select id="selectionType"> <option value="-1">Select One< ...

Is it possible to modify the sub/child divs within a draggable parent div and assign them a different class?

Greetings, after being a long-time reader, I have finally decided to post for the first time. In the process of creating a webpage with jQuery drag and drop divs, I am curious about how to change the class of a child div within a draggable div once it is d ...

Validation scheme for the <speak> element

When using validators in an angular formarray for input fields, I encountered a challenge with the regex to check the <speak> tag. https://i.sstatic.net/ogFA3.png The content provided was considered valid. https://i.sstatic.net/ar5FJ.png An error ...

Is there a way to access the HTML and CSS source code without using the inspect feature

I'm working on a project that involves an "edit box" where users can write text, add emojis, change the background color, insert images, and more. After users finish creating their content, I want them to be able to send it via email. This means I ne ...

What is the best way to display an image/jpeg blob retrieved from an API call on screen using NextJS?

When using Next.js, I make an API call like this: const response = await fetch('/api/generateimageHG2'); This triggers the following function: import { HfInference } from "@huggingface/inference"; export default async function genera ...

Is there a way to use jQuery to make a div fade in and toggle over another

I have created a test page and I am looking to achieve a specific effect when the page loads. I want everything on the page to be hidden initially. When I click on the "About" text, I want it to fade in using fadeToggle(); however, when I click on "My work ...

obtain the string representation of the decimal HTML entity value

Similar Question: how to create iphone apps similar to ibeer, imilk, ibug, ibeer Using javascript to obtain raw html code Imagine having an html section like this: <div id="post_content"> <span>&#9654;<span> </div> ...

Can you outline the distinctions between React Native and React?

Recently delving into the world of React sparked my curiosity, leading me to wonder about the distinctions between React and React Native. Despite scouring Google for answers, I came up short on finding a comprehensive explanation. Both React and React N ...