Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
longNbr = i - 1 + (i == ringStart ? longLines + 1 : 0),
latNbr = i <= longLines + 1 ? 0 : i - longLines - 1,
latLongNbr = longNbr - longLines - 1;
// fill in the tri/quad connecting this vert to the sphereA
this.triangles.push(i, longNbr, latNbr);
if (latLongNbr > 0)
this.triangles.push(longNbr, latLongNbr, latNbr);
}
}
// generate south pole
const south = new Vertex({
position: new Vector3(0, -radius, 0),
normal: new Vector3(0, -1, 0),
texCoord0: new Vector2(0.5, 0)
});
const southIdx = this.vertices.push(south) - 1;
// connect last long ring to the south pole
const ringStart = southIdx - longLines - 1;
for (let i = southIdx - longLines - 1; i < southIdx; i++) {
const longNbr = i - 1 + (i == ringStart ? longLines + 1 : 0);
this.triangles.push(longNbr, i, southIdx);
}
}
}
this.vertices.push(north);
const longAngle = 2 * Math.PI / longLines,
latAngle = Math.PI / latLines;
// generate verts in rings starting from the north pole
for (let lat = latAngle; lat < Math.PI - 0.001; lat += latAngle) {
const ringStart = this.vertices.length;
for (let long = 0; long < 2 * Math.PI + 0.001; long += longAngle) {
// generate a vertex
const normal = new Vector3(Math.sin(lat) * Math.cos(long), Math.cos(lat), Math.sin(lat) * Math.sin(long))
const vert = new Vertex({
position: normal.scale(radius),
normal: normal,
texCoord0: new Vector2(1 - long / (2 * Math.PI), lat / Math.PI)
});
// get the indices of the neighboring verts
const i = this.vertices.push(vert) - 1,
longNbr = i - 1 + (i == ringStart ? longLines + 1 : 0),
latNbr = i <= longLines + 1 ? 0 : i - longLines - 1,
latLongNbr = longNbr - longLines - 1;
// fill in the tri/quad connecting this vert to the sphereA
this.triangles.push(i, longNbr, latNbr);
if (latLongNbr > 0)
this.triangles.push(longNbr, latLongNbr, latNbr);
}
}
// generate south pole
public constructor(radius: number, longLines = 12, latLines = 8, material: Material = null) {
super({material});
// generate north pole
const north = new Vertex({
position: new Vector3(0, radius, 0),
normal: new Vector3(0, 1, 0),
texCoord0: new Vector2(0.5, 1)
});
this.vertices.push(north);
const longAngle = 2 * Math.PI / longLines,
latAngle = Math.PI / latLines;
// generate verts in rings starting from the north pole
for (let lat = latAngle; lat < Math.PI - 0.001; lat += latAngle) {
const ringStart = this.vertices.length;
for (let long = 0; long < 2 * Math.PI + 0.001; long += longAngle) {
// generate a vertex
const normal = new Vector3(Math.sin(lat) * Math.cos(long), Math.cos(lat), Math.sin(lat) * Math.sin(long))
const vert = new Vertex({
position: normal.scale(radius),
normal: normal,
new Vector3(init.normal[0], init.normal[1], init.normal[2]);
}
if (init.tangent) {
this.tangent = init.tangent instanceof Vector4 ?
init.tangent :
new Vector4(init.tangent[0], init.tangent[1], init.tangent[2], init.tangent[3]);
}
if (init.texCoord0) {
this.texCoord0 = init.texCoord0 instanceof Vector2 ?
init.texCoord0 :
new Vector2(init.texCoord0[0], init.texCoord0[1]);
}
if (init.texCoord1) {
this.texCoord1 = init.texCoord1 instanceof Vector2 ?
init.texCoord1 :
new Vector2(init.texCoord1[0], init.texCoord1[1]);
}
if (init.color0) {
this.color0 = init.color0 instanceof Vector3 ?
init.color0 :
new Vector3(init.color0[0], init.color0[1], init.color0[2]);
}
}
new Vector3(init.position[0], init.position[1], init.position[2]);
}
if (init.normal) {
this.normal = init.normal instanceof Vector3 ?
init.normal :
new Vector3(init.normal[0], init.normal[1], init.normal[2]);
}
if (init.tangent) {
this.tangent = init.tangent instanceof Vector4 ?
init.tangent :
new Vector4(init.tangent[0], init.tangent[1], init.tangent[2], init.tangent[3]);
}
if (init.texCoord0) {
this.texCoord0 = init.texCoord0 instanceof Vector2 ?
init.texCoord0 :
new Vector2(init.texCoord0[0], init.texCoord0[1]);
}
if (init.texCoord1) {
this.texCoord1 = init.texCoord1 instanceof Vector2 ?
init.texCoord1 :
new Vector2(init.texCoord1[0], init.texCoord1[1]);
}
if (init.color0) {
this.color0 = init.color0 instanceof Vector3 ?
init.color0 :
new Vector3(init.color0[0], init.color0[1], init.color0[2]);
}
}