import { Utils } from '../common/Utils'
import { MathUtils } from '../math/MathUtils';
import { BaseLine } from './BaseLine';
/**
* @class PolygonLine
* The polygon line object.
* @memberof THING
* @extends THING.BaseLine
* @public
*/
class PolygonLine extends BaseLine {
_radius = 0.5;
_cornerRadius = 0.3;
_cornerSplit = 10;
_radialSegments = 8;
_startDegree = 0;
static defaultTagArray = ['Line'];
/**
* The polygon line object in scene.
* @param {Object} param The initial parameters.
*/
constructor(param = {}) {
super(param);
this._syncOptions(param);
}
// #region Private Functions
_syncOptions(param) {
this.begin();
{
super.onSyncOptions(param);
Utils.syncOptions(this, [
'radius',
'cornerRadius',
'cornerSplit',
'radialSegments',
'startDegree'
], param, param['extras'] || param['external']);
}
this.end();
}
// #endregion
// #region Overrides
onBeforeSetup(param) {
param['renderableNode'] = param['renderableNode'] || Utils.createObject('PolygonLine');
super.onBeforeSetup(param);
}
onAfterSetup(param) {
super.onAfterSetup(param);
}
onRefreshAttributes() {
let bodyNode = this.bodyNode;
bodyNode.setRadius(this._radius);
bodyNode.setCornerRadius(this._cornerRadius);
bodyNode.setCornerSplit(this._cornerSplit);
bodyNode.setRadialSegments(this._radialSegments);
bodyNode.setStartRad(MathUtils.degToRad(this._startDegree));
}
onImportExternalData(external, options) {
super.onImportExternalData(external, options);
if (external) {
this._syncOptions(external);
}
}
onExportExternalData() {
let external = Object.assign({}, super.onExportExternalData());
Utils.setAttributeIfExist(external, 'radius', this);
Utils.setAttributeIfExist(external, 'cornerRadius', this);
Utils.setAttributeIfExist(external, 'cornerSplit', this);
Utils.setAttributeIfExist(external, 'radialSegments', this);
Utils.setAttributeIfExist(external, 'startDegree', this);
return external;
}
// #endregion
// #region Accessor
/**
* Get/Set radius, default is 0.1 (Can not be negative number).
* @type {Number}
* @public
*/
get radius() {
return this._radius;
}
set radius(value) {
this._radius = value;
this.bodyNode.setRadius(this._radius);
}
/**
* Get/Set radius of corner (Should be greater than radius).
* @type {Number}
* @public
*/
get cornerRadius() {
return this._cornerRadius;
}
set cornerRadius(value) {
this._cornerRadius = value;
this.bodyNode.setCornerRadius(this._cornerRadius);
}
/**
* Get/Set split of corner, only works with integer type.
* @type {Number}
* @public
*/
get cornerSplit() {
return this._cornerSplit;
}
set cornerSplit(value) {
this._cornerSplit = MathUtils.toInteger(value);
this.bodyNode.setCornerSplit(this._cornerSplit);
}
/**
* Get/Set radial segments (Must be integer type and greater than 2).
* @type {Number}
* @public
*/
get radialSegments() {
return this._radialSegments;
}
set radialSegments(value) {
this._radialSegments = value;
this.bodyNode.setRadialSegments(this._radialSegments);
}
/**
* Get/Set start of degree.
* @type {Number}
* @public
*/
get startDegree() {
return this._startDegree;
}
set startDegree(value) {
this._startDegree = value;
this.bodyNode.setStartRad(MathUtils.degToRad(this._startDegree));
}
// #endregion
get isPolygonLine() {
return true;
}
}
export { PolygonLine }