Browse Source

完成primitives

master
blobt 3 years ago
parent
commit
9d9045b4d3
  1. 39
      src/render/core/Primitives.ts

39
src/render/core/Primitives.ts

@ -224,3 +224,42 @@ export class Cube {
return ret; return ret;
} }
} }
export class GridPlane {
/**
* @var
*/
public sx: number;
public sy: number;
public nx: number;
public ny: number;
public constructor(sx: number = 10, sy: number = 10, nx: number = 10, ny: number = 10) {
this.sx = sx;
this.sy = sy;
this.nx = nx;
this.ny = ny;
}
public makeGeometryData(): GeometryData {
let ret: GeometryData = new GeometryData();
for (let iy: number = 0; iy <= this.ny; iy++) {
for (let ix: number = 0; ix <= this.nx; ix++) {
let u: number = ix / this.nx;
let v: number = iy / this.ny;
let x: number = -this.sx / 2 + u * this.sx; // starts on the left
let y: number = this.sy / 2 - v * this.sy; // starts at the top
ret.positions.push(new vec3([x, y, 0]));
ret.uvs.push(new vec2([u, 1.0 - v]));
ret.normals.push(new vec3([0, 0, 1]));
if (iy < this.ny && ix < this.nx) {
{
ret.indices.push(iy * (this.nx + 1) + ix, (iy + 1) * (this.nx + 1) + ix + 1, iy * (this.nx + 1) + ix + 1);
ret.indices.push((iy + 1) * (this.nx + 1) + ix + 1, iy * (this.nx + 1) + ix, (iy + 1) * (this.nx + 1) + ix);
}
}
}
}
return ret;
}
}
Loading…
Cancel
Save