Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Three.js 三个JS-缩放纹理以完美匹配(任意大小)平面_Three.js - Fatal编程技术网

Three.js 三个JS-缩放纹理以完美匹配(任意大小)平面

Three.js 三个JS-缩放纹理以完美匹配(任意大小)平面,three.js,Three.js,本质上,我想复制CSS的行为,background size:cover是如何工作的 var repeatX, repeatY; repeatX = w * this.textureHeight / (h * this.textureWidth); if (repeatX > 1) { //fill the width and adjust the height accordingly repeatX = 1; repeatY = h * this.textureWid

本质上,我想复制CSS的行为,
background size:cover
是如何工作的

    var repeatX, repeatY;
repeatX = w * this.textureHeight / (h * this.textureWidth);
if (repeatX > 1) {
  //fill the width and adjust the height accordingly
  repeatX = 1;
  repeatY = h * this.textureWidth / (w * this.textureHeight);
  mat.map.repeat.set(repeatX, repeatY);
  mat.map.offset.y = (repeatY - 1) / 2 * -1;
} else {
  //fill the height and adjust the width accordingly
  repeatX = w * this.textureHeight / (h * this.textureWidth);
  repeatY = 1;
  mat.map.repeat.set(repeatX, repeatY);
  mat.map.offset.x = (repeatX - 1) / 2 * -1;
}
看这里,您可以看到图像正在缩放,以保持其纵横比,但它并没有真正正常工作,因为图像没有填充平面,任一侧都留有边距-

代码片段(第170-175行)-

我想做的是让它如此放大,然后将自己重新定位在中心位置(封面的效果如何)

更新

    var repeatX, repeatY;
repeatX = w * this.textureHeight / (h * this.textureWidth);
if (repeatX > 1) {
  //fill the width and adjust the height accordingly
  repeatX = 1;
  repeatY = h * this.textureWidth / (w * this.textureHeight);
  mat.map.repeat.set(repeatX, repeatY);
  mat.map.offset.y = (repeatY - 1) / 2 * -1;
} else {
  //fill the height and adjust the width accordingly
  repeatX = w * this.textureHeight / (h * this.textureWidth);
  repeatY = 1;
  mat.map.repeat.set(repeatX, repeatY);
  mat.map.offset.x = (repeatX - 1) / 2 * -1;
}