UNPKG

whs

Version:

Super-fast 3D framework for Web Applications & Games. Based on Three.js

111 lines (101 loc) 2.67 kB
import { Mesh, TetrahedronBufferGeometry, TetrahedronGeometry } from 'three'; import {MeshComponent} from '../../core/MeshComponent'; /** * @class Tetrahedron * @category components/meshes * @description In geometry, a tetrahedron is a polyhedron composed of four triangular faces, six straight edges, and four vertex corners. * The tetrahedron is the simplest of all the ordinary convex polyhedra and the only one that has fewer than 5 faces. * <br/><br/> * `Tetrahedron` creates a Tetrahedron object by its `radius` and `detail` * @classDesc * <iframe src="https://threejs.org/docs/scenes/geometry-browser.html#TetrahedronGeometry"></iframe> * @param {Object} [params] - The params. * @extends module:core.MeshComponent * @memberof module:components/meshes * @example <caption>Creating a Tetrahedron, and adding it to app</caption> * new Tetrahedron({ * geometry: { * radius: 2, * detail: 1 * }, * * material: new THREE.MeshBasicMaterial({ * color: 0xffffff * }), * * position: { * x: 0, * y: 100, * z: 0 * } * }).addTo(app); */ class Tetrahedron extends MeshComponent { /** * Default values for parameters * @member {Object} module:components/meshes.Tetrahedron#defaults * @static * @default <pre> * { * geometry: { * radius: 1, * detail: 0 * } * </pre> */ static defaults = { ...MeshComponent.defaults, geometry: { radius: 1, detail: 0 } }; /** * Instructions * @member {Object} module:components/meshes.Tetrahedron#instructions * @static * @default <pre> * { * geometry: ['radius', 'detail'] * } * </pre> */ static instructions = { ...MeshComponent.instructions, geometry: ['radius', 'detail'] }; constructor(params = {}) { super(params, Tetrahedron.defaults, Tetrahedron.instructions); if (params.build) { this.build(params); super.wrap(); } } /** * @method build * @description Build lifecycle creates a mesh using input params. * @param {Object} params Component parameters. * @return {THREE.Mesh} Built mesh * @memberof module:components/meshes.Tetrahedron */ build(params = this.params) { const {geometry, material} = this.applyBridge({ geometry: this.buildGeometry(params), material: params.material }); return this.applyBridge({mesh: new Mesh(geometry, material)}).mesh; } buildGeometry(params = {}) { return new (params.buffer ? TetrahedronBufferGeometry : TetrahedronGeometry)( params.geometry.radius, params.geometry.detail ); } } export { Tetrahedron };