playcanvas
Version:
PlayCanvas WebGL game engine
47 lines (44 loc) • 2.38 kB
JavaScript
import { ConeBaseGeometry } from './cone-base-geometry.js';
import { calculateTangents } from './geometry-utils.js';
/**
* A procedural cone-shaped geometry.
*
* The size, shape and tesselation properties of the cone can be controlled via constructor
* parameters. By default, the function will create 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.
*
* Note that the cone is created with UVs in the range of 0 to 1.
*
* @category Graphics
*/ class ConeGeometry extends ConeBaseGeometry {
/**
* Create a new ConeGeometry instance.
*
* @param {object} [opts] - An object that specifies optional inputs for the function as follows:
* @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.0).
* @param {number} [opts.height] - The length of the body of the cone (defaults to 1.0).
* @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).
*/ constructor(opts = {}){
var _opts_baseRadius;
// Check the supplied options and provide defaults for unspecified ones
var baseRadius = (_opts_baseRadius = opts.baseRadius) != null ? _opts_baseRadius : 0.5;
var _opts_peakRadius;
var peakRadius = (_opts_peakRadius = opts.peakRadius) != null ? _opts_peakRadius : 0;
var _opts_height;
var height = (_opts_height = opts.height) != null ? _opts_height : 1;
var _opts_heightSegments;
var heightSegments = (_opts_heightSegments = opts.heightSegments) != null ? _opts_heightSegments : 5;
var _opts_capSegments;
var capSegments = (_opts_capSegments = opts.capSegments) != null ? _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 };