UNPKG

@xeokit/xeokit-convert

Version:

JavaScript utilities to create .XKT files

59 lines (58 loc) 1.89 kB
/** * @desc Creates torus-shaped geometry arrays. * * ## Usage * * In the example below we'll create an {@link XKTModel}, then create an {@link XKTMesh} with a torus-shaped {@link XKTGeometry}. * * [[Run this example](http://xeokit.github.io/xeokit-sdk/examples/#geometry_builders_buildTorusGeometry)] * * ````javascript * const xktModel = new XKTModel(); * * const torus = buildTorusGeometry({ * center: [0,0,0], * radius: 1.0, * tube: 0.5, * radialSegments: 32, * tubeSegments: 24, * arc: Math.PI * 2.0 * }); * * const xktGeometry = xktModel.createGeometry({ * geometryId: "torusGeometry", * primitiveType: torus.primitiveType, // Will be "triangles" * positions: torus.positions, * normals: torus.normals, * indices: torus.indices * }); * * const xktMesh = xktModel.createMesh({ * meshId: "redTorusMesh", * geometryId: "torusGeometry", * position: [-4, -6, -4], * scale: [1, 3, 1], * rotation: [0, 0, 0], * color: [1, 0, 0], * opacity: 1 * }); * * const xktEntity = xktModel.createEntity({ * entityId: "redTorus", * meshIds: ["redTorusMesh"] * }); * * xktModel.finalize(); * ```` * * @function buildTorusGeometry * @param {*} [cfg] Configs * @param {Number[]} [cfg.center] 3D point indicating the center position. * @param {Number} [cfg.radius=1] The overall radius. * @param {Number} [cfg.tube=0.3] The tube radius. * @param {Number} [cfg.radialSegments=32] The number of radial segments. * @param {Number} [cfg.tubeSegments=24] The number of tubular segments. * @param {Number} [cfg.arc=Math.PI*0.5] The length of the arc in radians, where Math.PI*2 is a closed torus. * @returns {Object} Geometry arrays for {@link XKTModel#createGeometry} or {@link XKTModel#createMesh}. */ export function buildTorusGeometry(cfg?: any): Object;