import { Flags } from '@uino/base-thing';
import { Utils } from '../common/Utils'
import { BaseDynamicPoints } from './BaseDynamicPoints';
import { UVModeType } from '../const';
// [0-15] index is reserved for BaseObject and Object3D, so index starts from 16
const Flag = {
Closure: 1 << 16,
}
/**
* @class BaseLine
* The base line object.
* @memberof THING
* @extends THING.BaseDynamicPoints
*/
class BaseLine extends BaseDynamicPoints {
_uvModeType = UVModeType.Tile;
_groups = [];
_groupPickedIds = [];
static defaultTagArray = ['Line'];
/**
* The base line object.
* @param {Object} param The initial parameters.
*/
constructor(param = {}) {
super(param);
this._flags.enable(Flag.Closure, Utils.parseValue(param['closure'], false));
}
// #region Private
// #endregion
// #region Overrides
onSyncOptions(param) {
super.onSyncOptions(param);
Utils.syncOptions(this, [
'closure',
'progress',
'uvModeType',
'groups',
'groupPickedIds'
], param, param['extras'] || param['external']);
}
onExportExternalData() {
let external = Object.assign({}, super.onExportExternalData());
Utils.setAttributeIfExist(external, 'closure', this);
Utils.setAttributeIfExist(external, 'progress', this);
Utils.setAttributeIfExist(external, 'uvModeType', this);
Utils.setAttributeIfExist(external, 'groups', this);
Utils.setAttributeIfExist(external, 'groupPickedIds', this);
return external;
}
onRefreshPoints() {
super.onRefreshPoints();
let bodyNode = this.bodyNode;
if (this._groups.length) {
bodyNode.setGroups(this._groups);
}
bodyNode.setUVMode(this._uvModeType);
bodyNode.setAttribute('Closure', this._flags.has(Flag.Closure));
}
// #endregion
// #region Accessor
/**
* Get/Set UV mode type.
* @type {UVModeType}
* @private
*/
get uvModeType() {
return this._uvModeType;
}
set uvModeType(value) {
if (this._uvModeType == value) {
return;
}
this._uvModeType = value;
this.onRefreshPoints();
}
/**
* Get/Set groups of points index.
* @type {Array<Array<Number>>}
* @private
*/
get groups() {
return this._groups;
}
set groups(value) {
if (value) {
this._groups = value.slice(0);
}
else {
this._groups = [];
}
this.onRefreshPoints();
}
/**
* Get/Set the group picked Ids.
* @type {Array<Number>}
* @private
*/
get groupPickedIds() {
return this._groupPickedIds;
}
set groupPickedIds(value) {
if (value) {
this._groupPickedIds = value.slice(0);
}
else {
this._groupPickedIds.length = 0;
}
this.bodyNode.setGroupPickedIds(this._groupPickedIds);
}
/**
* Enable/Disable closure.
* @type {Boolean}
* @private
*/
get closure() {
return this._flags.has(Flag.Closure);
}
set closure(value) {
if (this._flags.enable(Flag.Closure, value)) {
this.onRefreshPoints();
}
}
// #endregion
get isLine() {
return true;
}
}
export { BaseLine }