I see the actual drawMesh() implementation, it is still quad focused, but now more efficient than calling Quad3D2 repeatedly, instead uses internal formats for batching (webgl version):
DrawMesh(posArr, uvArr, indexArr) {
const vd = this._vertexData;
const td = this._texcoordData;
// Ensure the index array length is a multiple of 3
if (indexArr.length % 3 !== 0) {
throw new Error("Invalid index buffer length");
}
// Iterate over index array in steps of 3
for (let i = 0, len = indexArr.length; i < len; ) {
const index0 = indexArr[i++];
const index1 = indexArr[i++];
const index2 = indexArr[i++];
// Calculate position and UV indices
const pos0 = index0 * 3;
const pos1 = index1 * 3;
const pos2 = index2 * 3;
const uv0 = index0 * 2;
const uv1 = index1 * 2;
const uv2 = index2 * 2;
// Extend quad batch
this._ExtendQuadBatch();
// Update vertex and texture coordinate data
let v = this._vertexPtr;
let t = this._texPtr;
// Vertex positions
vd[v++] = posArr[pos0];
vd[v++] = posArr[pos0 + 1];
vd[v++] = posArr[pos0 + 2];
vd[v++] = posArr[pos1];
vd[v++] = posArr[pos1 + 1];
vd[v++] = posArr[pos1 + 2];
vd[v++] = posArr[pos2];
vd[v++] = posArr[pos2 + 1];
vd[v++] = posArr[pos2 + 2];
vd[v++] = posArr[pos2];
vd[v++] = posArr[pos2 + 1];
vd[v++] = posArr[pos2 + 2];
// UV coordinates
td[t++] = uvArr[uv0];
td[t++] = uvArr[uv0 + 1];
td[t++] = uvArr[uv1];
td[t++] = uvArr[uv1 + 1];
td[t++] = uvArr[uv2];
td[t++] = uvArr[uv2 + 1];
td[t++] = uvArr[uv2];
td[t++] = uvArr[uv2 + 1];
// Update pointers
this._vertexPtr = v;
this._texPtr = t;
}
}
webGPU version (you can see how close we are to having color per quad here, one step away from adding in the color array input and updating the color batch buffer)
DrawMesh(posArr, uvArr, indexArr) {
const vd = this._vertexData;
const td = this._texcoordData;
const cd = this._colorData;
if (indexArr.length % 3 !== 0)
throw new Error("invalid index buffer length");
const currentMultiTextureIndex = this._currentMultiTextureIndex;
const currentColor = this._currentColor;
const currentColorR = currentColor.getR();
const currentColorG = currentColor.getG();
const currentColorB = currentColor.getB();
const currentColorA = currentColor.getA();
for (let i = 0, len = indexArr.length; i < len; ) {
const index0 = indexArr[i++];
const index1 = indexArr[i++];
const index2 = indexArr[i++];
const pos0 = index0 * 3;
const pos1 = index1 * 3;
const pos2 = index2 * 3;
const uv0 = index0 * 2;
const uv1 = index1 * 2;
const uv2 = index2 * 2;
this._AddQuadToDrawBatch();
const qPtr = this._quadPtr++;
let v = qPtr * 12;
let t = qPtr * 12;
let c = qPtr * 4;
vd[v++] = posArr[pos0 + 0];
vd[v++] = posArr[pos0 + 1];
vd[v++] = posArr[pos0 + 2];
vd[v++] = posArr[pos1 + 0];
vd[v++] = posArr[pos1 + 1];
vd[v++] = posArr[pos1 + 2];
vd[v++] = posArr[pos2 + 0];
vd[v++] = posArr[pos2 + 1];
vd[v++] = posArr[pos2 + 2];
vd[v++] = posArr[pos2 + 0];
vd[v++] = posArr[pos2 + 1];
vd[v++] = posArr[pos2 + 2];
td[t++] = uvArr[uv0 + 0];
td[t++] = uvArr[uv0 + 1];
td[t++] = currentMultiTextureIndex;
td[t++] = uvArr[uv1 + 0];
td[t++] = uvArr[uv1 + 1];
td[t++] = currentMultiTextureIndex;
td[t++] = uvArr[uv2 + 0];
td[t++] = uvArr[uv2 + 1];
td[t++] = currentMultiTextureIndex;
td[t++] = uvArr[uv2 + 0];
td[t++] = uvArr[uv2 + 1];
td[t++] = currentMultiTextureIndex;
cd[c++] = currentColorR;
cd[c++] = currentColorG;
cd[c++] = currentColorB;
cd[c++] = currentColorA
}
}