UNPKG

playcanvas

Version:

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

43 lines (42 loc) 1.78 kB
import { ConeBaseGeometry } from "./cone-base-geometry.js"; import { calculateTangents } from "./geometry-utils.js"; class ConeGeometry extends ConeBaseGeometry { /** * Create a new ConeGeometry instance. * * By default, the constructor creates a cone standing vertically centered on the XZ-plane with * a base radius of 0.5, a height of 1.0, 5 height segments and 18 cap segments. The cone is * created with UVs in the range of 0 to 1. * * @param {object} [opts] - Options object. * @param {number} [opts.baseRadius] - The base radius of the cone. Defaults to 0.5. * @param {number} [opts.peakRadius] - The peak radius of the cone. Defaults to 0. * @param {number} [opts.height] - The length of the body of the cone. Defaults to 1. * @param {number} [opts.heightSegments] - The number of divisions along the length of the cone. * Defaults to 5. * @param {number} [opts.capSegments] - The number of divisions around the tubular body of the * cone. Defaults to 18. * @param {boolean} [opts.calculateTangents] - Generate tangent information. Defaults to false. * @example * const geometry = new pc.ConeGeometry({ * baseRadius: 1, * height: 2, * heightSegments: 2, * capSegments: 20 * }); */ constructor(opts = {}) { const baseRadius = opts.baseRadius ?? 0.5; const peakRadius = opts.peakRadius ?? 0; const height = opts.height ?? 1; const heightSegments = opts.heightSegments ?? 5; const capSegments = opts.capSegments ?? 18; super(baseRadius, peakRadius, height, heightSegments, capSegments, false); if (opts.calculateTangents) { this.tangents = calculateTangents(this.positions, this.normals, this.uvs, this.indices); } } } export { ConeGeometry };