UNPKG

whs-cube-spheres

Version:

This plugin has a container with multiple spheres.

64 lines (54 loc) 1.27 kB
import { Mesh, TorusBufferGeometry, TorusGeometry } from 'three'; import {MeshComponent} from '../../core/MeshComponent'; class Torus extends MeshComponent { static defaults = { ...MeshComponent.defaults, geometry: { radius: 100, tube: 40, radialSegments: 8, tubularSegments: 6, arc: Math.PI * 2 } }; static instructions = { ...MeshComponent.instructions, geometry: [ 'radius', 'tube', 'radialSegments', 'tubularSegments', 'arc' ] }; constructor(params = {}) { super(params, Torus.defaults, Torus.instructions); if (params.build) { this.build(params); super.wrap(); } } 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 TorusGeometry( params.geometry.radius, params.geometry.tube, params.geometry.radialSegments, params.geometry.tubularSegments, params.geometry.arc ); } } export { Torus };