和ThreeJS一起玩时,我遇到了一个非正方形四边形纹理的经典问题:http ://www.xyzw.us/~cass/qcoord/
问题是ThreeJS只允许您使用vec2设置纹理坐标(据我所知..),并花了几个小时,最后找到了一个可行的解决方案,我想与社区分享它,也许能得到一些更好的主意? 所以这是代码:
首先,使用三个JS制作我的Quad的javascript:
var planeGeom = new THREE.Geometry();
planeGeom.vertices.push(new THREE.Vector3(0, 0, 10));
planeGeom.vertices.push(new THREE.Vector3(10, 0, 10));
planeGeom.vertices.push(new THREE.Vector3(20, 0,0));
planeGeom.vertices.push(new THREE.Vector3(-10, 0, 0));
//create the 2 faces , maybe i should play with CW or CCW order... ;)
planeGeom.faces.push(new THREE.Face3(0,1,3));
planeGeom.faces.push(new THREE.Face3(1,2,3));
//Compute widths ratio
var topWidth = Math.abs(Plane.TR.x - Plane.TL.x);
var bottomWidth = Math.abs(Plane.BR.x - Plane.BL.x);
var ratio = topWidth / bottomWidth;
//create UV's as barely explained in the link above (www.xyzw.us)
var UVS = …Run Code Online (Sandbox Code Playgroud)