UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

52 lines (51 loc) 1.58 kB
import { SphereGeometry } from "./sphere-geometry.js"; class DomeGeometry extends SphereGeometry { /** * Create a new DomeGeometry instance. * * By default, the constructor creates a dome with a radius of 0.5, 16 latitude bands and 16 * longitude bands. The dome is created with UVs in the range of 0 to 1. * * @param {object} [opts] - Options object. * @param {number} [opts.latitudeBands] - The number of divisions along the latitudinal axis of * the sphere. Defaults to 16. * @param {number} [opts.longitudeBands] - The number of divisions along the longitudinal axis of * the sphere. Defaults to 16. * @example * const geometry = new pc.DomeGeometry({ * latitudeBands: 32, * longitudeBands: 32 * }); */ constructor(opts = {}) { const radius = 0.5; const latitudeBands = opts.latitudeBands ?? 16; const longitudeBands = opts.longitudeBands ?? 16; super({ radius, latitudeBands, longitudeBands }); const bottomLimit = 0.1; const curvatureRadius = 0.95; const curvatureRadiusSq = curvatureRadius * curvatureRadius; const positions = this.positions; for (let i = 0; i < positions.length; i += 3) { const x = positions[i] / radius; let y = positions[i + 1] / radius; const z = positions[i + 2] / radius; if (y < 0) { y *= 0.3; if (x * x + z * z < curvatureRadiusSq) { y = -bottomLimit; } } y += bottomLimit; y *= radius; positions[i + 1] = y; } } } export { DomeGeometry };