import { Utils } from '../common/Utils'
import { BaseModelObject3D } from './BaseModelObject3D';
function _getParam(width, height, param) {
if (Utils.isObject(width)) {
return width;
}
if (Utils.isObject(height)) {
return height;
}
return param;
}
function _buildParam(width, height, param) {
param = _getParam(width, height, param);
param['body'] = param['body'] || {};
param['body']['localScale'] = param['body']['localScale'] || [
Utils.parseFloat(width, Utils.parseFloat(param['width'], 1)),
Utils.parseFloat(height, Utils.parseFloat(param['height'], 1)),
1
];
param['body']['localAngles'] = param['body']['localAngles'] || [-90, 0, 0];
return param;
}
/**
* @class Plane
* The plane entity object.
* @memberof THING
* @extends THING.BaseModelObject3D
* @public
*/
class Plane extends BaseModelObject3D {
static defaultTagArray = ['Geometry'];
/**
* The plane object in scene.
* @param {Number} width The width, default is 1.
* @param {Number} height The height, default is 1.
* @param {Object} param The initial parameters.
*/
constructor(width, height, param = {}) {
super(_buildParam(width, height, param));
}
// #region Overrides
// #endregion
// #region Accessor
/**
* Get/Set the width.
* @type {Number}
* @public
*/
get width() {
return this.body.scale[0];
}
set width(value) {
this._processBodyWithoutPivot((body) => {
let scale = body.scale;
body.scale = [value, scale[1], scale[2]];
});
}
/**
* Get/Set the height.
* @type {Number}
* @public
*/
get height() {
return this.body.scale[1];
}
set height(value) {
this._processBodyWithoutPivot((body) => {
let scale = body.scale;
body.scale = [scale[0], value, scale[2]];
});
}
// #endregion
/**
* Check whether it's plane object.
* @type {Boolean}
*/
get isPlane() {
return true;
}
}
export { Plane }