Enhance CDN packages and playground
Amp-Thread-ID: https://ampcode.com/threads/T-01a02485-5574-707c-bff4-5668d83bee8a Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Mesh, type MeshOptions } from "../Mesh";
|
||||
import type { Scene } from "../Scene";
|
||||
|
||||
export type PlaneOptions = Omit<MeshOptions, "geometryId" | "vertexData"> & {
|
||||
size?: number;
|
||||
width?: number;
|
||||
depth?: number;
|
||||
};
|
||||
|
||||
function dimension(value: number, name: string) {
|
||||
if (!Number.isFinite(value) || value <= 0) throw new RangeError(name);
|
||||
return value / 2;
|
||||
}
|
||||
|
||||
/** A horizontal, upward-facing plane centered on its transform. */
|
||||
export class Plane extends Mesh {
|
||||
constructor(scene: Scene, options: PlaneOptions = {}) {
|
||||
const { size = 1, width = size, depth = size, ...meshOptions } = options;
|
||||
const x = dimension(width, "width");
|
||||
const z = dimension(depth, "depth");
|
||||
super(scene, {
|
||||
...meshOptions,
|
||||
vertexData: {
|
||||
positions: [-x, 0, -z, x, 0, -z, x, 0, z, -x, 0, z],
|
||||
normals: [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0],
|
||||
uvs: [0, 0, 1, 0, 1, 1, 0, 1],
|
||||
indices: [0, 2, 1, 0, 3, 2],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user