小编PBV*_*PBV的帖子

如何在三个JS中的自定义非方形四边形上映射纹理

和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)

shader texture-mapping webgl uv-mapping three.js

5
推荐指数
0
解决办法
1794
查看次数

标签 统计

shader ×1

texture-mapping ×1

three.js ×1

uv-mapping ×1

webgl ×1