What is the method used by three.js to render video with spherical UV mapping?

I have a streaming video displayed in a 3*3 format. I am able to splice the entire video into individual sections using THREE,

   // Creating a 3x3 PlaneGeometry
   var geometry = new THREE.PlaneGeometry(400, 200, 3, 3);
    const video1 = document.getElementById("videos1");
       ...................
       ...................
    const texture1 = new THREE.VideoTexture(video3);
    texture1.maxFilter = THREE.NearestFilter;
    texture1.minFilter = THREE.NearestFilter;
       ...................
       ...................
    var geometryfaces = geometry.faces;
      for (let i = 0; i < geometryfaces.length; i++) {
        const faces = geometryfaces[i];
        materials[i] = new THREE.MeshBasicMaterial({
          map: textures[i],
        });
      }
    var uv = [
        new THREE.Vector2(0, 0),
        new THREE.Vector2(0, 1),
        new THREE.Vector2(1, 1),
        new THREE.Vector2(1, 0),
      ];
     // Assigning texture coordinates
      for (var m = 0; m < geometryfaces.length; m += 2) {
        geometry.faces[m].materialIndex = faceId;
        console.log(geometry.faces);
        geometry.faces[m + 1].materialIndex = faceId;
        geometry.faceVertexUvs[0][m] = [uv[2], uv[3], uv[1]];
        geometry.faceVertexUvs[0][m + 1] = [uv[3], uv[0], uv[1]];
        faceId++;
      }
      var bufferGeometry = new THREE.BufferGeometry().fromGeometry(geometry);
      var material = new THREE.MeshFaceMaterial(materials);
      var mesh = new THREE.Mesh(bufferGeometry, material); // Mesh model object

Although I can achieve a flat video display with this method, the video itself is panoramic and I need to project it onto a sphere, but I lack understanding of how UV mapping works on a spherical surface.

I would appreciate any help or guidance on this matter. Thank you

Picture:enter image description here

Picture2:enter image description here

Answer №1

When using Three.js SphereGeometry, the UV mapping is automatically generated for you. For an equirectangular image, you can simply map the image onto the inside of the sphere to achieve the desired effect:

var camera, scene, renderer, vp, sphere;
vp = new THREE.Vector2(window.innerWidth, window.innerHeight);

// Initializing WebGL components
function init() {
    // Setting up WebGL Renderer
    renderer = new THREE.WebGLRenderer({antialias: true});
    renderer.setSize(vp.x, vp.y);
    renderer.domElement.classList.add("canvasWebGL");

    // Appending to DOM
    document.body.appendChild(renderer.domElement);

    // Creating scene
    scene = new THREE.Scene();
    scene.background = new THREE.Color(0xe1e1e1);

    // Adding camera
    camera = new THREE.PerspectiveCamera(55, vp.x / vp.y, 0.05, 100);

  // Sphere geometry with a radius large enough to encompass the camera
  let sphereGeom = new THREE.SphereGeometry(20, 128, 128);
  
  // Using the equirectangular image as the texture
    // Rendering the INSIDE of the sphere, not the outside
    const tex = new THREE.TextureLoader().load("https://i.imgur.com/1VECsLy.jpg");
  let sphereMat = new THREE.MeshBasicMaterial({
            map: tex,
            side: THREE.BackSide
        });
  sphere = new THREE.Mesh(sphereGeom, sphereMat);
    scene.add(sphere);
}

function animate(s) {
    sphere.rotation.set(
        Math.cos(s / 3000), s / 3000, 0
    );

    renderer.render(scene, camera);
    requestAnimationFrame(animate);
}

init();
animate(0);
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="23574b51464663130d121110">[email protected]</a>/build/three.js"></script>

For more information on sphere geometry, visit:

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

Display the content of a Vue file directly on the webpage

I am currently developing a website to showcase UI components using plain CSS. The project is built with Vue, utilizing standard HTML and CSS. One of the key features I am working on is providing users with two views for each component: 'Preview' ...

Error: The property 'parentNode' cannot be read because it is null

I wanted to test if my laptop can handle WebGL by loading examples from my instructor's webpage. The examples on the webpage worked fine, just showing a square within a square. I then decided to copy the exact codes into a notepad text editor, saved t ...

Is it possible to trigger the @click event in Vuejs when utilizing v-html to render HTML content?

Here is an interesting HTML scenario: errorText: '<a class="button" @click.prevent="enableExceedable(issue.mapping)">Enable exceedable limits</a>'; I am trying to insert this string into the following div: <div v-if="hasIssue != ...

Guide on removing the <hr/> tag only from the final list item (li) in an Angular

This is my Angular view <li class= "riskmanagementlink" ng-repeat="link in links"> <h3> {{link.Description}} </h3> <a> {{link.Title}} </a> <hr/> </li> I need assistance with removing the hr tag for the l ...

Enter your text in the box to search for relevant results

I need assistance with a code that allows me to copy input from a text box to the Google search box using a copy button. Upon pressing the Google search box button, it should display the search results. Here is the code I have been working on: http://jsf ...

Failure occurred when attempting to link and display on the page container

I have created a simple app using jQuery Mobile. At some point in the app, I include the following code: <a href="test_es.html" data-role="button">Start!</a> This code snippet loads a new HTML file that contains several jQuery Mobile page ...

Exploring the benefits of integrating ES6 modules in Express server technology

Is it possible to utilize ES6 modules in my Express application without relying on babel or @std/esm? find an alternative method that doesn't involve transpiling or using esm? Once I have started working on app.js in Express, it seems challenging to ...

Issue with React.js button functionality not functioning as expected

import React, { Component } from 'react'; import './App.css'; class App extends Component { constructor(props) { super(props); this.state = { items: [] } } addItem(e) { var itemArray = this.state.items; ...

Show a pop-up window when a button is clicked, just before the page redirects

Is there a way to display a popup message before redirecting to another page when clicking on a button? Here's the scenario: <a href="addorder.php?id=<? echo $row01['id']; ?>" ><button id="myButton" class="btn btn-primary btn ...

Is it possible for images underneath to receive focus when hovering over them?

I'm struggling with a layout of thumbnails on my page. We'll refer to them as A, B, C, etc. They are currently displayed like this: A, B, C, D, E, F, G, H, I, J, K, L, M, N... and so on. When you hover over one thumbnail, it enlarges by 2.5 t ...

Significant delay in processing second jQuery Ajax call

Attempting a simple Ajax call with page content refresh using the following code snippet: $("a.ajaxify-watched").bind("click", function(event) { $item = $(this); $.ajax({ url: $(this).attr("href"), global: false, type: "G ...

`vue.js pagination for loading nested arrays`

I am currently working on implementing the vue-paginate component from this source: https://www.npmjs.com/package/vue-paginate . My goal is to set up pagination for questions retrieved from firebase. Here is the initial setup: new Vue({ el: '#app& ...

React 18 doesn't trigger component re-rendering with redux

In my code, I have implemented a custom hook to handle global data fetching based on user authentication. Here is an example of the hook: const userState = useSelector(state => state.user.state) useEffect(() => { if(userState === "authentic ...

Unlocking the power of translation in React: Implementing Amazon Translate or Google Translate for AXIOS responses

I'm currently working on converting Axios JSON responses in React. Here is the code snippet: axios.get('https://jsonplaceholder.typicode.com/users') .then(res => { ...translation_logic_here setU ...

Iterating through an array with conditional statements

I am currently considering the best approach to loop through an array in my code before proceeding further. I have some concerns about the link (var link = ... ) and the if statement. Is this the most optimal way to iterate over array1 and compare the val ...

How to add a jQuery function to a Rails 3 if statement?

I followed a Rails 3 tutorial on creating a multi-step form which you can check out here. Additionally, I incorporated Stripe payment functionality in my app using another railscast found here. Within my application, the payment form is hidden using jQuer ...

Encountering CORS issue despite employing a CORS library

Encountering a CORS error while attempting to deploy my project on render using expressjs and react. The project functions smoothly on localhost, but changing the URLs to match the website results in this error: Access to XMLHttpRequest at 'https:// ...

Parsing DOM data from an HTTP request in Node.js

Looking to extract data attributes from an SVG element on github.com/profile_name using a node.js HTTP request, and then parsing it into JSON format. <rect class="day" width="10" height="10" x="-36" y="10" fill="#ebedf0" data-count="0" data-date="2017- ...

A step-by-step guide on how to refresh a circular loading indicator

I have been researching how to create a circular progress bar using canvas, and I came across this code. After making some modifications to the code snippets that I found online, I encountered an issue - I can't seem to reload the circular path once i ...

What could be the reason for not just removing the pseudo-class, but instead deleting the entire CSS document altogether?

var style = document.styleSheets[1] style.deleteRule(`.block__header::after`) console.log(`.block__header::after`) What is preventing it from being removed from the CSS document? The pseudo-class is still found in the console, and when trying to dele ...