简体   繁体   English

复制纹理Three.js

[英]copy texture Three.js

I want to load the left half of video texture to left Geometry and right half of video texture to the right Geometry 我想将视频纹理的左半部分加载到左侧的Geometry中,并将视频纹理的右半部分加载到右侧的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 is the left plane texture 这是左平面纹理

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 is the right plane texture 这是正确的平面纹理

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

loading two video texture didn't work,the left plane does display but the right not ,Than I try to copy texture instead of loading the same video texture: 加载两个视频纹理无效,左侧平面显示,但右侧不显示,比我尝试复制纹理而不是加载相同的视频纹理:

 texture2 = THREE.Texture.clone(texture);

or 要么

 texture = texture;

both don't work,too.Because(in three.js reference): 两者都不起作用,因为(在three.js参考中):

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

What if anything can I 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 changging the uvMapping of planes i solve the problem :) 通过更改平面的uvMapping我解决了问题:)

If it was to work in theory You will need to change the UV co-ordinates on either plane and add the texture to that. 如果理论上可行,则需要在任一平面上更改UV坐标,然后在该平面上添加纹理。 I had a similar issue with an image file more or less, check here : 我或多或少有与图像文件类似的问题,请在此处检查:

three.js webgl custom shader sharing texture with new offset three.js webgl自定义着色器与新偏移共享纹理

There is a lot of info i had put there and should help you with a resolution. 我在那儿放了很多信息,应该可以帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM