Creating depth by overlapping mesh with panorama

Is it possible to have an equirectangular panorama in the foreground and a mesh in the background, allowing users to interact with both as they navigate through the scene?

I attempted to load a panorama using the code below but struggled to figure out how to incorporate a mesh in the background:

var sphereBufferGeometry = new THREE.SphereGeometry(500,60,40);
sphereBufferGeometry.scale( -1, 1, 1 );
var material = new THREE.MeshBasicMaterial( {
    map: new THREE.TextureLoader().load( [panorama image])});
var mesh = new THREE.Mesh( sphereBufferGeometry, material );
scene.add( mesh );

I also tried loading a mesh (.obj) using the following code, however, the 'object' variable is of type THREE.Group and the 'child' variable contains multiple objects of type THREE.MESH. Therefore, I'm unsure of how to layer a panorama in the foreground:

objLoader.load( [objfile], function ( object ) {
  object.traverse( function ( child ) {
  });
});

Any assistance on this matter would be greatly appreciated.

Thank you

Answer №1

Place the image onto the webpage and incorporate an image map. Feel free to customize any cell that triggers an event. As a demonstration, I recorded the coordinates - top-left pair and bottom-right pair - for cells clicked on.

You have the option to switch out click events for mouseover or mouseout events. By reducing the cell dimensions to 1px, you can precisely track the mouse's position as it moves across the image...just be cautious of potential event overload.

<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript"">
      // shortcut reference
      function locate(eId) {return document.getElementById(eId);};

      // incorporate area elements into an existing image map
      function createMapGrid(imageId, gridId, cellHeight, cellWidth) {
          var imgH = locate(imageId).height;
          var imgW = locate(imageId).width;
          var lastJ = Math.floor(imgW/cellWidth);
          var lastI = Math.floor(imgH/cellHeight);
          var gridContent = '';
          for (var i = 0; i < lastI; i++) {
             for (var j = 0; j < lastJ; j++) {
                var coords= (cellWidth*j) + ',' + (cellHeight*i) + ',' +(cellWidth*(j+1) + ',' + (cellHeight*(i + 1))); 
                  gridContent += '<area onclick="recordCoords(this);" shape="rect" coords="' + coords + '">';
             }
          }
          locate('gridElements').innerHTML = gridContent;
      };

      function recordCoords(cRef) {
          console.log(cRef.coords);
      };

      window.onload = function() {
         // create an image map on the image with id='mapImage', add the 
         // area elements to the map with id="gridElements"; each cell is 16x16
         createMapGrid('mapImage', 'gridElements', 16, 16);
      };
   </script>
</head>
<body>
    <div>
      <img src="yourPanoramicImage.jpg" alt="a panorama measuring 1024x668" 
         width="1024" height="668" usemap="#areas" id="mapImage"
      /> 
      <map name="areas" id="gridElements"></map>
   </div>
</body>
</html>

Considerations...it might be more efficient to generate each area element separately within the inner loop and attach it to its parent map instead of constructing the entire HTML string at once. Also, browsers may not handle 1px areas well, especially for larger images like 1024x668 which would require 684,032 area tags. In my example, 64x41 translated to 2624 area tags.

Answer №2

After some experimentation, I discovered a effective solution. By incorporating both spheregeometry and mesh within the scene and adjusting the initial position, rotation, and scale of the mesh to match the panorama, I was able to achieve alignment between the two objects. This approach ensures that any adjustments made to the camera will simultaneously impact both objects, creating the illusion of constant alignment.

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

Next-auth encounters a TypeError [ERR_INVALID_URL] when attempting to use an invalid URL exclusively in the production

When I attempt to sign in using next-auth in my Next.js app in production mode by running the command `yarn build && yarn start` on my local machine, the app fails. The error message displayed in the terminal is: TypeError [ERR_INVALID_URL]: Invalid URL ...

Enhance your figures with a unique Javascript magnifying tool that works seamlessly across all browsers

After searching the web for magnifying glasses, I found that most only work for one picture. So, I took matters into my own hands and created a magnifying glass that can magnify all pictures within a specific div. It functions perfectly on Chrome browser b ...

Is there a way to verify within the "if" statement without repeating the code?

Is there a way in javascript (or typescript) to prevent redundant object rewriting within an if statement condition? For example: if (A != null || A != B) { // do something here } // can it be done like this: if (A != null || != B) { // avoid repeating ...

PassportJS ensuring secure authentication across all routes

Currently, I am implementing passportJS to secure my API Endpoints within an Express application. So far, the following code is functioning properly. app.get("/route1", passport.authenticate('basic', { session: false }), (req, res) => { ...

React Redux fails to dispatch an action

Recently, I attempted to integrate Redux into my React application. I created a container called SignIn that instantiates a mapDispatchToProps and connects it to the component. The SignIn component renders a sub-component called SignInForm (code provided ...

Can you tell me how to implement a shopping basket in vue.js that only appears when an item has been added to it?

After numerous attempts, I often find myself clearing everything and starting from scratch. How can I make this work? Observing and learning from others will greatly assist me! This area is designated for shopping cart items. If it's empty, nothing ...

Update the field 'payments._id' in MongoDB to a timestamp

I need to change the value of 'payments._id' to a timestamp. In MongoDB, the 'payments._id' object is automatically generated when inserting a document into the collection. onMounted(async () => { const res = await axios.get(" ...

"Troubleshooting why React fails to update an array state

When I click the update name button, the state is not changing properly using setState. I want to update the persons variable and have it reflect in the DOM as well. Any ideas on how to achieve this? App.js import React, { Component } from "react"; impo ...

serving static content on subdomains with Express JS

I created an API using Node.js Express JS and utilized apidocjs.com to generate the static content. The issue I am currently facing is that I want the documentation file to be located under a subdomain such as docs.example.com or api.example.com/docs. What ...

Is it possible to convert this to a switch statement?

I am utilizing a code snippet to handle the response from an ajax request, which looks like this: success: function(results) { if(results.locations){ //do stuff here }else if(results.error){ //do stuff here }else if(results.mat ...

In order to dismiss the popup message in the component.ts file within Angular 4, I must figure

Currently in my component.html, I have a popup message with opening and closing functionality implemented in html. However, I now need the close functionality to be moved to a method. <ng-template #content let-c="close" let-d="dismiss"> < ...

Problem with the document.form in Javascript

I've encountered an issue while running the code and I'm having trouble figuring out what's causing it. The code was running fine before, but now I'm facing this problem: function makeUnderline(formName,editor) { var txt = window.p ...

Look through an array to find a particular string and send the result back to an AngularJS view

Currently, I am faced with the task of searching through a JSON output in my code to locate a specific string (for instance 'name_col_lbl') and then extracting its corresponding value ('Name' in this example) for AngularJS to display in ...

What is the process of using JavaScript code to read a text file?

Trying to use Google Charts while reading data from a text file. The code in JS is written for this purpose: function readTextFile(file){ var rawFile = new XMLHttpRequest(); rawFile.open("GET", file, false); // using synchronous call var allTe ...

Stop displaying AJAX requests in the console tab of Firebug, similar to how Twitter does it

I'm looking for a way to prevent my AJAX calls from being logged in Firebug's Console tab, similar to how Twitter does it. When using Twitter search, you'll see a live update feed showing "5 tweets since you searched." Twitter sends periodic ...

Encountering difficulty retrieving data upon initial click within an Android webview during server communication

I have encountered an issue when calling this method from JavaScript. The data is returning as null for the first time, but starting from the second time it works fine. Seeking assistance on this matter. @SuppressLint("JavascriptInterface") public Str ...

"Common Errors Encountered When Running 'npm start'

Each time I attempt to initiate my react project, it presents me with these errors npm ERR! code ENOENT npm ERR! syscall open npm ERR! path C:\Users\Mohamed Badrawy\Desktop\reactjs-basics-master\package.json npm ERR! errno -4058 n ...

Enhancing an array item with Vuex

Is there a way to change an object within an array using Vuex? I attempted the following approach, but it was unsuccessful: const state = { categories: [] }; // mutations: [mutationType.UPDATE_CATEGORY] (state, id, category) { const record = state. ...

how to attach a function to a dynamically generated element

Currently, I am in the process of developing a placeholder-enabling feature. var t=document.createElement("input"); "placeholder" in t||$("input").each(function(){ if("submit"!==$(this).attr("type")){ var n=$(this),l=n.attr("placeholder"); ...

Numerous slideshows using identical scripts

I am facing an issue with my code for multiple slideshows. Currently, it works fine for a single slideshow but when I have multiple slideshows and mouse over any of them, all the slideshows start running due to sharing the same class. However, if I try to ...