three.js平面缓冲测量uvs

时间:2014-04-13 10:35:04

标签: javascript three.js uv-mapping buffer-geometry

我试图创建一个缓冲测量平面,但我遇到了紫外线坐标问题。我试图关注Correct UV mapping Three.js但我没有得到正确的结果。

uv代码如下。我还将整个缓冲区几何代码保存在http://jsfiddle.net/94xaL/

我非常感谢我在这里做错的提示!

谢谢!

    var uvs = terrainGeom.attributes.uv.array;
    var gridX = gridY = TERRAIN_RES - 1;
    for ( iy = 0; iy < gridY; iy++ ) {
        for ( ix = 0; ix < gridX; ix++ ) {

            var i = (iy * gridY + ix) * 12;

            //0,0
            uvs[ i ] = ix / gridX
            uvs[ i + 1 ] = iy / gridY;

            //0,1
            uvs[ i + 2 ] = ix / gridX
            uvs[ i + 3 ] = ( iy + 1 ) / gridY;

            //1,0
            uvs[ i + 4 ] = ( ix + 1 ) / gridX
            uvs[ i + 5 ] = iy / gridY;

            //0,1
            uvs[ i + 6 ] = ix / gridX
            uvs[ i + 7 ] = ( iy + 1 ) / gridY;

            //1,1
            uvs[ i + 8 ] = ( ix + 1 ) / gridX
            uvs[ i + 9 ] = ( iy + 1 ) / gridY;

            //1,0
            uvs[ i + 10 ] = ( ix + 1 ) / gridX
            uvs[ i + 11 ] = iy / gridY;
        }
    }

1 个答案:

答案 0 :(得分:0)

dev分支中最新的three.js版本现在使用BufferGeometry构建平面:https://github.com/mrdoob/three.js/blob/dev/src/extras/geometries/PlaneGeometry.js

如果你仍想建立自己的,你可以在那里获得灵感。