我想将左半部分视频纹理加载到左侧几何体,将右半部分视频纹理加载到右侧几何体
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
});
这是左平面纹理
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
});
这是正确的平面纹理
var plane = new THREE.Mesh(new THREE.PlaneBufferGeometry(320, 240), material);
var plane2 = new THREE.Mesh(new THREE.PlaneBufferGeometry(320, 240), material2);
加载两个视频纹理不起作用,左侧平面确实显示但右侧没有,比我尝试复制纹理而不是加载相同的视频纹理:
texture2 = THREE.Texture.clone(texture);
或
texture = texture;
两者都不起作用。因为(在three.js参考中):
.clone(texture)
Make copy of texture. Note this is not a "deep copy", the image is shared.
如果我能做什么怎么办?
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
通过改变飞机的uvMapping来解决问题:)
答案 0 :(得分:0)
如果它在理论上起作用你需要在任一平面上改变UV坐标并将纹理添加到其中。我或多或少地对图像文件有类似的问题,请点击此处:
three.js webgl custom shader sharing texture with new offset
我有很多信息可以帮助你解决问题。