UNPKG

whs-cube-spheres

Version:

This plugin has a container with multiple spheres.

69 lines (58 loc) 1.47 kB
import { Mesh, RingGeometry, RingBufferGeometry } from 'three'; import {MeshComponent} from '../../core/MeshComponent'; class Ring extends MeshComponent { static defaults = { ...MeshComponent.defaults, geometry: { innerRadius: 0, outerRadius: 50, thetaSegments: 8, phiSegments: 8, thetaStart: 0, thetaLength: Math.PI * 2 } }; static defaults = { ...MeshComponent.defaults, geometry: [ 'innerRadius', 'outerRadius', 'thetaSegments', 'phiSegments', 'thetaStart', 'thetaLength' ] }; constructor(params = {}) { super(params, Ring.defaults, Ring.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 = {}) { const GConstruct = params.buffer && !params.softbody ? RingBufferGeometry : RingGeometry; return new GConstruct( params.geometry.innerRadius, params.geometry.outerRadius, params.geometry.thetaSegments, params.geometry.phiSegments, params.geometry.thetaStart, params.geometry.thetaLength ); } } export { Ring };