From 9d9045b4d3e5f21ca5b8f83020f4ef5469c57b97 Mon Sep 17 00:00:00 2001 From: blobt Date: Wed, 5 May 2021 10:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90primitives?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/render/core/Primitives.ts | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/render/core/Primitives.ts b/src/render/core/Primitives.ts index deb58d9c..67c5ba2a 100755 --- a/src/render/core/Primitives.ts +++ b/src/render/core/Primitives.ts @@ -223,4 +223,43 @@ export class Cube { ret.indices.push(2, 6, 4, 2, 4, 0); // 下面 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; + } } \ No newline at end of file