1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /*
- * CircularSectorBuilder.js
- *
- * @author realor
- */
- import { CircleBuilder } from './CircleBuilder.js'
- import { ObjectBuilder } from './ObjectBuilder.js'
- import { ProfileBuilder } from './ProfileBuilder.js'
- import { ProfileGeometry } from '../core/ProfileGeometry.js'
- import * as THREE from '../lib/three.module.js'
- class CircularSectorBuilder extends CircleBuilder {
- constructor(radius = 1, angle = 180, segments = 32) {
- super(radius, segments)
- this.angle = angle
- }
- performBuild(profile) {
- if (this.angle < 0) throw 'Unsupported negative angle'
- const shape = new THREE.Shape()
- if (this.angle >= 360) {
- this.drawCircle(shape, this.radius, this.segments)
- } else {
- this.drawSector(shape, this.radius, this.angle, this.segments)
- }
- profile.updateGeometry(new ProfileGeometry(shape))
- return true
- }
- drawSector(path, radius = 1, angle = 180, segments = 32) {
- const steps = Math.ceil((segments * angle) / 360)
- const angleRad = THREE.MathUtils.degToRad(angle)
- const incr = angleRad / steps
- path.moveTo(0, 0)
- for (let i = 0; i <= steps; i++) {
- let rad = incr * i
- path.lineTo(radius * Math.cos(rad), radius * Math.sin(rad))
- }
- path.closePath()
- }
- copy(source) {
- this.radius = source.radius
- this.segments = source.segments
- this.angle = source.angle
- return this
- }
- }
- ObjectBuilder.addClass(CircularSectorBuilder)
- export { CircularSectorBuilder }
|