UNPKG

whs

Version:

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

106 lines (96 loc) 2.69 kB
import { Mesh, DodecahedronBufferGeometry, DodecahedronGeometry } from 'three'; import {MeshComponent} from '../../core/MeshComponent'; /** * @class Dodecahedron * @category components/meshes * @description In geometry, a dodecahedron is any polyhedron with twelve flat faces. <br/><br/> * The most familiar dodecahedron is the regular dodecahedron, which is a Platonic solid. <br/> * There are also three regular star dodecahedra, which are constructed as stellations of the convex form. <br/> * All of these have icosahedral symmetry, order 120. * Dodecahedron creates Dodecahedron object by it's radius and detail. * @classDesc * <iframe src="https://threejs.org/docs/scenes/geometry-browser.html#DodecahedronGeometry"></iframe> * @param {Object} [params] - The params. * @extends module:core.MeshComponent * @memberof module:components/meshes * @example <caption>Creating a Dodecahedron, and adding to app</caption> * new Dodecahedron({ * geometry: { * radius: 2 * }, * * material: new THREE.MeshBasicMaterial({ * color: 0xffffff * }), * * position: { * y: 10 * } * }).addTo(app); */ class Dodecahedron extends MeshComponent { /** * Default values for parameters * @member {Object} module:components/meshes.Dodecahedron#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.Dodecahedron#instructions * @static * @default <pre> * geometry: ['radius', 'detail'] * </pre> */ static instructions = { ...MeshComponent.instructions, geometry: ['radius', 'detail'] }; constructor(params = {}) { super(params, Dodecahedron.defaults, Dodecahedron.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.Dodecahedron */ 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 ? DodecahedronBufferGeometry : DodecahedronGeometry)( params.geometry.radius, params.geometry.detail ); } } export { Dodecahedron };