UNPKG

awv3

Version:
43 lines (38 loc) 1.47 kB
import * as THREE from 'three'; import { getArcAngles } from '../geomutils'; import BaseGraphics from './base'; import RingGeometry from '../../../three/ringgeometry'; const material = new THREE.MeshBasicMaterial({ color: 0x6d67bd, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -10, }); const segments = 32; export default class Arc extends BaseGraphics { constructor() { super(); const materialClone = material.clone(); this.localMesh = new THREE.Mesh(new RingGeometry(segments), materialClone); this.localMesh.type = 'SketcherMesh'; this.localMesh.material.meta = {}; this.add(this.localMesh); } updateWithAngles(center, radius, startAngle, endAngle, scale) { this.localMesh.geometry.updateParameters({ innerRadius: radius - scale * 0.5, outerRadius: radius + scale * 0.5, thetaStart: startAngle, thetaLength: endAngle - startAngle, }); this.localMesh.position.copy(center); } updateFromGeomParams(geomParams) { super.updateFromGeomParams(geomParams); const angleParams = getArcAngles(geomParams); const radius = geomParams.radius === undefined ? angleParams.radius : geomParams.radius; this.updateWithAngles(geomParams.center, radius, angleParams.start, angleParams.end, geomParams.scale); this.updateMetaBox(); } }