MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / makeSphereVertices

Function makeSphereVertices

examples/renderer-test/main.ts:147–167  ·  view source on GitHub ↗
(radius: number, segs: number, rings: number)

Source from the content-addressed store, hash-verified

145// ---- Mesh generation ----
146
147function makeSphereVertices(radius: number, segs: number, rings: number): number[] {
148 const v: number[] = [];
149 for (let r = 0; r <= rings; r = r + 1) {
150 const phi = PI * r / rings;
151 const sp = Math.sin(phi);
152 const cp = Math.cos(phi);
153 for (let s = 0; s <= segs; s = s + 1) {
154 const theta = TWO_PI * s / segs;
155 const st = Math.sin(theta);
156 const ct = Math.cos(theta);
157 const x = sp * ct;
158 const y = cp;
159 const z = sp * st;
160 v.push(x * radius, y * radius, z * radius); // position
161 v.push(x, y, z); // normal
162 v.push(1, 1, 1, 1); // color (white)
163 v.push(s / segs, r / rings); // uv
164 }
165 }
166 return v;
167}
168
169function makeSphereIndices(segs: number, rings: number): number[] {
170 const idx: number[] = [];

Callers 1

initSharedMeshesFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected