Replicate the texture using Three.js

I am seeking to assign the left half of a video texture to the left Geometry and the right half of the video texture to the right Geometry.


var video = document.createElement("video");
var texture = new THREE.Texture(video);
texture.offset = new THREE.Vector2(0,0);
texture.repeat = new THREE.Vector2(0.5, 1);
var material = new THREE.MeshLambertMaterial({
    map: texture,
    side: THREE.DoubleSide
});

This represents the texture for the left plane.


var texture2 = new THREE.Texture(video);
texture2.minFilter = THREE.NearestFilter;
texture2.offset = new THREE.Vector2(0.5,0);
texture2.repeat = new THREE.Vector2(0.5, 1);
var material2 = new THREE.MeshLambertMaterial({
    map: texture2,
    side: THREE.DoubleSide
});

This represents the texture for the right plane.


var plane = new THREE.Mesh(new THREE.PlaneBufferGeometry(320, 240), material);
var plane2 = new THREE.Mesh(new THREE.PlaneBufferGeometry(320, 240), material2);

Initially when I attempted to load two video textures, the left plane displayed but the right did not. To address this, I tried duplicating the texture instead of loading the same video texture:


texture2 = THREE.Texture.clone(texture);

or


texture = texture;

However, both approaches were unsuccessful. This is because (as mentioned in the three.js reference):


.clone(texture)
Make a copy of the texture. Note that this is not a "deep copy", the image is shared.

Is there anything else I can do?


function change_uvs( geometry, unitx, unity, offsetx, offsety ) {
    var faceVertexUvs = geometry.faceVertexUvs[0];
    for (var i = 0; i < faceVertexUvs.length; i++) {
       var uvs = faceVertexUvs[i];
       for (var j = 0; j < uvs.length; j++) {
         var uv = uvs[j];
         uv.x = (uv.x + offsetx) * unitx;
         uv.y = (uv.y + offsety) * unity;
      }
   }
}
var p1 = new THREE.PlaneGeometry(320, 240);
var p2 = new THREE.PlaneGeometry(320, 240);
change_uvs(p1, 0.5, 1, 0, 0); //left plane
change_uvs(p2, 0.5, 1, 1, 0); //right plane

By adjusting the uvMapping of the planes, I was able to resolve the issue :)

Answer №1

In order to make it work theoretically, you would have to adjust the UV coordinates on both planes and apply the texture to them. I encountered a similar issue with an image file in the past, you can find more information here:

Exploring how three.js webgl custom shaders share texture with new offset

I provided a lot of details in that post which may guide you towards a solution.

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

Getting an image file to an API server using Node.js

I am looking to create an API server using node.js, and one of the requirements is to upload image files to it. While I have successfully implemented the logic for the GET method in my code, I am struggling with how to write the logic for the POST method ...

The code is functioning properly in the output, but it does not seem to be

I have been utilizing jquery chosen to implement a specific functionality, which is successfully demonstrated in the image below within the snippet. However, upon uploading the same code to my blog on Blogger, the functionality is not working as expected. ...

Achieve resumable uploads effortlessly with google-cloud-node

While this code works well for regular uploads, I am curious about how the resumable upload feature functions when a user loses connection during a large upload. Does simply setting 'resumable' to true in the writeStream options make it work effe ...

Exploring various queries in Firestore

Does anyone know if there is a way to create a sentence similar to this one: return this.db.collection('places', ref => ref.where("CodPais", "<>", pais)).valueChanges(); I have tried using != and <> but neither seem to be valid. ...

Checkbox in Angular FormGroup not triggering touched state

There seems to be an issue with the Angular form when checking if the form is touched, especially in relation to a checkbox element. Despite the value of the checkbox changing on click, I am seeing !newDeviceGroup.touched = true. I'm not quite sure wh ...

Issue with 'backface-visibility' CSS3 property not functioning on any versions of Internet Explorer

I'm looking to implement a specific animation in Internet Explorer. The goal is to rotate an image like a coin, displaying a different image on the other side. I suspect that the issue lies with Backface-visibility in IE, but I'm not entirely sur ...

Tips on transforming truncated surfaces into complete entities

When working in Three.js, I encountered a situation with a 3D object where local clipping planes were used to render only a specific part of the object. However, due to the nature of 3D objects being "hollow" (only rendering the outer surface), when somet ...

What is the best way to parse a JSON file in Angular?

Can you please explain how to read a JSON file? I have been able to successfully read a JSON file using a controller, but when I try to read it from a factory, the content is null. Why is this happening? http://plnkr.co/edit/THdlp00GuSk1NS6rqe5k?p=preview ...

What is the solution for addressing the absence of an 'Access-Control-Allow-Origin' header in the requested resource while using axios?

Here is my Vue script: <script> export default { ... methods : { login() { // uri -> http://my-app.test/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="472b28202e2978222a262e2b7a332234330720 ...

Error encountered: Attempting to render an object as a react component is invalid

I am attempting to query data from a Firestore database. My goal is to retrieve all the fields from the Missions collection that have the same ID as the field in Clients/1/Missions. Below, you can find the code for my query: However, when I tried to execu ...

Custom positioning of Mui Snackbar in V5

I've been attempting to position a Snackbar in the top right corner with some customization for the top property, but I'm struggling to get it to display correctly. Here's what I've tried: import React from "react"; import { ...

"Exploring the Passage of Regular Expression Objects in JavaScript: A Deep Dive into how they

Exploring the depths of JavaScript/OOP, I am intrigued by the way regular expression argument parameters are handled in JavaScript. While I have a good understanding of regular expressions themselves, my interest lies in how they are processed by JavaScrip ...

Show the Vue.js template in a Laravel Blade view

I have been struggling to integrate a Vue.js component into a Laravel blade file. Despite researching tutorials and Stack Overflow solutions, I have not been able to resolve the issue. Below is the template that I want to display: <template> < ...

Are web components capable of managing changes in CSS (maybe through cssChangedCallback)?

Is there a way to control the application of CSS to a web component similar to using attributes through attributeChangedCallback. I am currently developing a couple of web components that could benefit from being styled with CSS classes. However, I requir ...

Guide on transferring datetime information from a popup dialog to an MVC controller

My goal is to create a button that, when clicked, opens a dialog allowing the selection of start and end dates. Upon clicking ok/submit, the selected datetime should be passed to a controller [HttpPost] action method. Here's what I have attempted so f ...

When using the POST method with npm http-server, an error 405 is thrown

I'm attempting to send an Ajax request to execute a php file on a local http server. However, the browser console shows Error 405: method not allowed. Even after trying solutions from similar questions and enabling CORS on the http-server, I still ca ...

Utilizing class attributes within multiple classes

I have created a custom class called MutationValidator as follows: const ERR_MSG = 'Error1'; @Service() export class MutationValidator { .. } This class is used in another class like so: import { MutationValidator } from './mutation ...

Is there a way to utilize a POST request to pass a React component from server.js to App.js for rendering?

I am new to React and JavaScript and still in the learning process :) I'm working on a magic 8 ball application where, upon clicking the button using the post method, I aim to retrieve a random answer (one of the 20 in my server.js) back to the same ...

What is the best way to duplicate a Typescript class object while making changes to specific properties?

I have a Typescript cat class: class Kitty { constructor( public name: string, public age: number, public color: string ) {} } const mittens = new Kitty('Mittens', 5, 'gray') Now I want to create a clone of the inst ...