我正在尝试在 WebGL 中用三角形构建一个平面。我的构造函数代码如下所示:
function plane( points_transform )
{
shape.call(this); // Inherit class shape’s array members by calling parent constructor
if( !arguments.length) return; // Pass no arguments if you just want to make an empty dummy object that inherits everything, for populating other shapes
this.populate( this, points_transform ); // Otherwise, a new triangle immediately populates its own arrays with triangle points,
this.init_buffers(); // Then sends its arrays to the graphics card into new buffers
}
inherit(plane, shape);
plane.prototype.populate = function( recipient, points_transform)
{
var offset = recipient.vertices.length;
var index_offset = recipient.indices.length; // Recipient's previous size
recipient.vertices.push( vec3(0,0,0), vec3(1,1,0), vec3(0,1,0), vec3(1,0,0), vec3(2,1,0), vec3(2,0,0) );
recipient.normals.push( vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1) );
// recipient.texture_coords.push( vec2(0,0), vec2(0,1), vec2(1,0), vec2(1,1), vec2(2,0), vec2(2,1) );
recipient.indices.push( offset + 0, offset + 1, offset + 2, offset + 3, offset + 4, offset + 5 );
gl.drawArrays(gl.TRIANGLE_STRIP, 0, recipient.vertices);
}
但是,当我绘制它时,它看起来像这样脱节:
我想知道如何解决这个问题以及如何制作一个通用函数,该函数可以采用任意数量的行/列并计算必要的顶点以生成 MxN 网格。
我专门查看了这个站点,但我无法弄清楚 trianglestrip 变量的来源。