Three.js 三个JS-缩放纹理以完美匹配(任意大小)平面
本质上,我想复制CSS的行为,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
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;
}